打印string。
给你个类
public class TicketSet
{
public struct keyAndValue
{
public String keyStr;
public String valueStr;
}
private List
///
/// 小票头部信息
///
public List
{
get { return keyAndValueListTop; }
}
///
/// 增加小票头部键值对
///
/// 键
/// 值
public void AddKeyAndValueTop(String keyStr, String valueStr)
{
keyAndValue keyandvale = new keyAndValue();
keyandvale.keyStr = keyStr;
keyandvale.valueStr = valueStr;
this.keyAndValueListTop.Add(keyandvale);
}
private List
///
/// 小票中间费用信息
///
public List
{
get { return keyAndValueListMid; }
}
///
/// 增加小票中间费用键值对
///
/// 键
/// 值
public void AddKeyAndValueMid(String keyStr, String valueStr)
{
keyAndValue keyandvale = new keyAndValue();
keyandvale.keyStr = keyStr;
keyandvale.valueStr = valueStr;
this.keyAndValueListMid.Add(keyandvale);
}
private List
///
/// 小票底部信息
///
public List
{
get { return keyAndValueListFoot; }
}
///
/// 增加小票底部键值对
///
/// 键
/// 值
public void AddKeyAndValueFoot(String keyStr, String valueStr)
{
keyAndValue keyandvale = new keyAndValue();
keyandvale.keyStr = keyStr;
keyandvale.valueStr = valueStr;
this.keyAndValueListFoot.Add(keyandvale);
}
private String ticketSignature;
///
/// 小票顶部签名
///
public String TicketSignature
{
get { return ticketSignature; }
set { ticketSignature = value; }
}
private String ticketTitle;
///
/// 小票的标题
///
public String TicketTitle
{
get { return ticketTitle; }
set { ticketTitle = value; }
}
private String ticketFooter;
///
/// 小票底部签名
///
public String TicketFooter
{
get { return ticketFooter; }
set { ticketFooter = value; }
}
private DataTable dtGoodsList;
///
/// 商品列表信息
///
public DataTable DtGoodsList
{
get { return dtGoodsList; }
set { dtGoodsList = value; }
}
private int ticketWidth;
///
/// 小票宽度,按字符数计算
///
public int TicketWidth
{
get { return ticketWidth; }
set { ticketWidth = value; }
}
private Decimal colper1;
///
/// 商品列表中第一个标题所占小票总宽度的百分比
///
public Decimal Colper1
{
get { return colper1; }
set { colper1 = value; }
}
private Decimal colper2;
///
/// 商品列表中第二个标题所占小票总宽度的百分比
///
public Decimal Colper2
{
get { return colper2; }
set { colper2 = value; }
}
private Decimal colper3;
///
/// 商品列表中第三个标题所占小票总宽度的百分比
///
public Decimal Colper3
{
get { return colper3; }
set { colper3 = value; }
}
private Decimal colper4;
///
/// 商品列表中第四个标题所占小票总宽度的百分比
///
public Decimal Colper4
{
get { return colper4; }
set { colper4 = value; }
}
private Char signWeight;
///
/// 重要分隔符的样式
///
public Char SignWeight
{
get { return signWeight; }
set { signWeight = value; }
}
private Char signLight;
///
/// 一般分隔符的样式
///
public Char SignLight
{
get { return signLight; }
set { signLight = value; }
}
///
/// 商品列表设置
///
/// TicketSet对象
///
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();
}
///
/// 排列商品列表的表头信息
///
/// 表头标题
/// 标题所占总字符数,一般按照小票总宽度的百分比来设置
///
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();
}
///
/// 设置小票头部信息,可以自动区分汉字还是英文,格式只限2行
///
/// 小票头部内容
/// 小票宽度,按照字符个数计算
/// 是否中间对齐
///
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();
}
///
/// 设置小票各部分的分隔线
///
/// 小票的宽度,按照字符个数计算
/// 分隔线的样式
///
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();
}
///
/// 生成小票
///
/// TicketSet对象
///
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();
}
}
肯定是可以做出来那种效果的,具体的打印功能,你要去看看打印方面的API,至于你说的用什么框架来编系统?这个不明白啥意思。是指BS和CS的程序吗?
那一般都是CS的程序了,不会很复杂,你在网上搜一下C#。
单纯的asp.net应该做不出来,因为你需要调用POS机的驱动啥的。
一般都是用c/s的架构来做一个打印的程序,然后做成activex插件,加载带浏览器边使用。
你要有打印机的API文档,然后使用C#中Dllmport属性调用
可以调用系统自带的打印的功能的