急,加高分帮我解决了问题,asp.net(C#)如何实现小票打印功能?

asp.net(C#)如何实现小票打印功能?asp.net能做出像超市的超赢系统那样的效果吗?用asp.net(C#)的什么框架来编系统啊?要用asp.net的哪个功能来... asp.net(C#)如何实现小票打印功能?asp.net能做出像超市的超赢系统那样的效果吗?用asp.net(C#)的什么框架来编系统啊?
要用asp.net的哪个功能来编啊?我是刚入门的,但是进了公司,公司要我编这个程序。就是超市pos机的打印小纸条的功能。
展开
 我来答
wisecn
推荐于2016-11-30 · 超过34用户采纳过TA的回答
知道答主
回答量:117
采纳率:0%
帮助的人:78.3万
展开全部
打印string。

给你个类

public class TicketSet
{
public struct keyAndValue
{
public String keyStr;
public String valueStr;
}
private List<keyAndValue> keyAndValueListTop = new List<keyAndValue>();
/// <summary>
/// 小票头部信息
/// </summary>
public List<keyAndValue> KeyAndValueListTop
{
get { return keyAndValueListTop; }
}
/// <summary>
/// 增加小票头部键值对
/// </summary>
/// <param name="keyStr">键</param>
/// <param name="valueStr">值</param>
public void AddKeyAndValueTop(String keyStr, String valueStr)
{
keyAndValue keyandvale = new keyAndValue();
keyandvale.keyStr = keyStr;
keyandvale.valueStr = valueStr;
this.keyAndValueListTop.Add(keyandvale);
}
private List<keyAndValue> keyAndValueListMid = new List<keyAndValue>();
/// <summary>
/// 小票中间费用信息
/// </summary>
public List<keyAndValue> KeyAndValueListMid
{
get { return keyAndValueListMid; }
}
/// <summary>
/// 增加小票中间费用键值对
/// </summary>
/// <param name="keyStr">键</param>
/// <param name="valueStr">值</param>
public void AddKeyAndValueMid(String keyStr, String valueStr)
{
keyAndValue keyandvale = new keyAndValue();
keyandvale.keyStr = keyStr;
keyandvale.valueStr = valueStr;
this.keyAndValueListMid.Add(keyandvale);
}
private List<keyAndValue> keyAndValueListFoot = new List<keyAndValue>();
/// <summary>
/// 小票底部信息
/// </summary>
public List<keyAndValue> KeyAndValueListFoot
{
get { return keyAndValueListFoot; }
}
/// <summary>
/// 增加小票底部键值对
/// </summary>
/// <param name="keyStr">键</param>
/// <param name="valueStr">值</param>
public void AddKeyAndValueFoot(String keyStr, String valueStr)
{
keyAndValue keyandvale = new keyAndValue();
keyandvale.keyStr = keyStr;
keyandvale.valueStr = valueStr;
this.keyAndValueListFoot.Add(keyandvale);
}
private String ticketSignature;
/// <summary>
/// 小票顶部签名
/// </summary>
public String TicketSignature
{
get { return ticketSignature; }
set { ticketSignature = value; }
}
private String ticketTitle;
/// <summary>
/// 小票的标题
/// </summary>
public String TicketTitle
{
get { return ticketTitle; }
set { ticketTitle = value; }
}
private String ticketFooter;
/// <summary>
/// 小票底部签名
/// </summary>
public String TicketFooter
{
get { return ticketFooter; }
set { ticketFooter = value; }
}
private DataTable dtGoodsList;
/// <summary>
/// 商品列表信息
/// </summary>
public DataTable DtGoodsList
{
get { return dtGoodsList; }
set { dtGoodsList = value; }
}
private int ticketWidth;
/// <summary>
/// 小票宽度,按字符数计算
/// </summary>
public int TicketWidth
{
get { return ticketWidth; }
set { ticketWidth = value; }
}
private Decimal colper1;
/// <summary>
/// 商品列表中第一个标题所占小票总宽度的百分比
/// </summary>
public Decimal Colper1
{
get { return colper1; }
set { colper1 = value; }
}
private Decimal colper2;
/// <summary>
/// 商品列表中第二个标题所占小票总宽度的百分比
/// </summary>
public Decimal Colper2
{
get { return colper2; }
set { colper2 = value; }
}
private Decimal colper3;
/// <summary>
/// 商品列表中第三个标题所占小票总宽度的百分比
/// </summary>
public Decimal Colper3
{
get { return colper3; }
set { colper3 = value; }
}
private Decimal colper4;
/// <summary>
/// 商品列表中第四个标题所占小票总宽度的百分比
/// </summary>
public Decimal Colper4
{
get { return colper4; }
set { colper4 = value; }
}
private Char signWeight;
/// <summary>
/// 重要分隔符的样式
/// </summary>
public Char SignWeight
{
get { return signWeight; }
set { signWeight = value; }
}
private Char signLight;
/// <summary>
/// 一般分隔符的样式
/// </summary>
public Char SignLight
{
get { return signLight; }
set { signLight = value; }
}
/// <summary>
/// 商品列表设置
/// </summary>
/// <param name="ticket">TicketSet对象</param>
/// <returns>带格式的商品列表</returns>
private String ItemsList()
{
StringBuilder result = new StringBuilder();

if (this.dtGoodsList != null && this.dtGoodsList.Columns.Count > 0 && this.dtGoodsList.Rows.Count > 0)
{
result.Append(CreateLine(this.TicketWidth, this.SignWeight));
result.Append(ArrangeArgPosition(this.dtGoodsList.Columns[0].Caption, this.TicketWidth, this.Colper1));
result.Append(ArrangeArgPosition(this.dtGoodsList.Columns[1].Caption, this.TicketWidth, this.Colper2));
result.Append(ArrangeArgPosition(this.dtGoodsList.Columns[2].Caption, this.TicketWidth, this.Colper3));
//result.Append(ArrangeArgPosition(this.dtGoodsList.Columns[3].Caption, this.TicketWidth, this.Colper4));
result.Append("\r\n");
result.Append(CreateLine(this.ticketWidth, this.SignLight));
for (int i = 0; i < this.dtGoodsList.Rows.Count; i++)
{
//result.Append(SetArgPosition(this.dtGoodsList.Rows[i][0].ToString(), this.TicketWidth, false));
result.Append(ArrangeArgPosition(this.dtGoodsList.Rows[i][0].ToString(), this.TicketWidth, this.Colper1));
result.Append(ArrangeArgPosition(this.dtGoodsList.Rows[i][1].ToString(), this.TicketWidth, this.Colper2));
result.Append(ArrangeArgPosition(this.dtGoodsList.Rows[i][2].ToString(), this.TicketWidth, this.Colper3));
//result.Append(ArrangeArgPosition(this.dtGoodsList.Rows[i][3].ToString(), this.TicketWidth, this.Colper4));
result.Append("\r\n");
}
result.Append(CreateLine(this.ticketWidth, this.SignLight));
}
return result.ToString();
}
/// <summary>
/// 排列商品列表的表头信息
/// </summary>
/// <param name="arg">表头标题</param>
/// <param name="charNum">标题所占总字符数,一般按照小票总宽度的百分比来设置</param>
/// <returns>带有格式的标题</returns>
private String ArrangeArgPosition(String arg, int ticketwidth, Decimal colPer)
{
StringBuilder result = new StringBuilder(arg);
int charNum = Convert.ToInt32(ticketWidth * colPer);
if (0 != charNum)
{
int argcount = System.Text.Encoding.Default.GetByteCount(arg);
for (int i = 0; i < charNum - argcount; i++)
{
result.Append(" ");
}
}
return result.ToString();
}
/// <summary>
/// 设置小票头部信息,可以自动区分汉字还是英文,格式只限2行
/// </summary>
/// <param name="arg">小票头部内容</param>
/// <param name="ticketwidth">小票宽度,按照字符个数计算</param>
/// <param name="isMiddle">是否中间对齐</param>
/// <returns>带格式的小票头部信息</returns>
private String SetArgPosition(String arg, int ticketwidth, bool isMiddle)
{
StringBuilder result = new StringBuilder();
int argnum = System.Text.Encoding.Default.GetByteCount(arg);
if (argnum <= ticketwidth)
{
if (isMiddle)
{
for (int i = 0; i < (ticketwidth - argnum) / 2; i++)
{
result.Append(" ");
}
}
result.Append(arg);
result.Append("\r\n");
}
else
{
for (int i = 0; i <= ticketwidth / 2; i++)
{
int temp = ticketwidth / 2 + i;
if (ticketwidth == System.Text.Encoding.Default.GetByteCount(arg.Substring(0, temp)) || ticketwidth == System.Text.Encoding.Default.GetByteCount(arg.Substring(0, temp)) - 1)
{
result.Append(arg.Substring(0, temp));
result.Append("\r\n");
result.Append(arg.Substring(temp, arg.Length - (temp)));
result.Append("\r\n");
break;
}
}
}
return result.ToString();
}
/// <summary>
/// 设置小票各部分的分隔线
/// </summary>
/// <param name="ticketwidth">小票的宽度,按照字符个数计算</param>
/// <param name="signChar">分隔线的样式</param>
/// <returns>小票的分隔线</returns>
private String CreateLine(int ticketwidth, Char signChar)
{
StringBuilder result = new StringBuilder();
for (int i = 0; i < ticketwidth; i++)
{
result.Append(signChar);
}
result.Append("\r\n");
return result.ToString();
}
/// <summary>
/// 生成小票
/// </summary>
/// <param name="ticket">TicketSet对象</param>
/// <returns>最终小票结果</returns>
public String Ticket()
{
StringBuilder ticketStr = new StringBuilder();
//小票头部
ticketStr.Append(SetArgPosition(this.TicketSignature, this.TicketWidth, true));
ticketStr.Append(SetArgPosition(this.TicketTitle, this.TicketWidth, true));
ticketStr.Append(CreateLine(this.TicketWidth, this.signWeight));
//小票上部内容
for (int i = 0; i < this.KeyAndValueListTop.Count; i++)
{
ticketStr.Append(this.KeyAndValueListTop[i].keyStr + this.KeyAndValueListTop[i].valueStr + "\r\n");
}
//商品列表
ticketStr.Append(ItemsList());
//小票中部内容
for (int i = 0; i < this.KeyAndValueListMid.Count; i++)
{
ticketStr.Append(this.KeyAndValueListMid[i].keyStr + this.KeyAndValueListMid[i].valueStr + "\r\n");
}
ticketStr.Append(CreateLine(this.TicketWidth, this.signWeight));
//小票下部内容
for (int i = 0; i < this.KeyAndValueListFoot.Count; i++)
{
ticketStr.Append(this.KeyAndValueListFoot[i].keyStr + this.KeyAndValueListFoot[i].valueStr + "\r\n");
}
//小票底部
ticketStr.Append(this.TicketFooter + "\r\n");
return ticketStr.ToString();

}
}
百度网友24f9d7b
2012-03-20 · 超过60用户采纳过TA的回答
知道小有建树答主
回答量:243
采纳率:0%
帮助的人:120万
展开全部
肯定是可以做出来那种效果的,具体的打印功能,你要去看看打印方面的API,至于你说的用什么框架来编系统?这个不明白啥意思。是指BS和CS的程序吗?

那一般都是CS的程序了,不会很复杂,你在网上搜一下C#。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
gushoushi
2012-03-20 · TA获得超过219个赞
知道小有建树答主
回答量:272
采纳率:0%
帮助的人:241万
展开全部
单纯的asp.net应该做不出来,因为你需要调用POS机的驱动啥的。
一般都是用c/s的架构来做一个打印的程序,然后做成activex插件,加载带浏览器边使用。
追问
是用网页的形式做吗?
追答
不是,是用windows模式开发的,然后做成activex插件,加载到IEl里边。U盾用过么?就是那么个意思,让你加载一个插件,然后在插件里进行相关处理。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2012-03-20
展开全部
你要有打印机的API文档,然后使用C#中Dllmport属性调用
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
yangbless
2012-03-20 · 超过29用户采纳过TA的回答
知道答主
回答量:171
采纳率:33%
帮助的人:26.8万
展开全部
可以调用系统自带的打印的功能的
追问
问题是,我要编那个程序。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(3)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式