代码出自票据打印类:http://www.csharpwin.com/csharpspace/9090r8371.shtml
代码片段如下:
public void Print(string str, string align)
{
if (TicketPrinterHandle == null)
return;
if (TicketPrinterHandle.IsInvalid)
return;
int PadCount = 30;
PadCount -= StrLen(str);
if (align == "center")
str = str.PadLeft(PadCount / 2 + str.Length, ' ');
else if (align == "right")
str = str.PadLeft(PadCount,' ');
int RetryCount = 10;
Retry:
int sta = 0;
if (_PPort == "LPT1")
sta = Input(0x379);
else if (_PPort == "LPT2")
sta = Input(0x279);
if (sta == 0x7F)
{
Status = "未连接";
return;
} if ((sta & 0x10) == 0)
{
Status = "未上电";
return;
} if((sta&0x80)==0)
{
Status = "打印机忙";
RetryCount--;
if (RetryCount <= 0)
return;
goto Retry;
} if((sta&0x20)!=0)
{
Status = "打印机缺纸";
return;
} }
代码片段如下:
public void Print(string str, string align)
{
if (TicketPrinterHandle == null)
return;
if (TicketPrinterHandle.IsInvalid)
return;
int PadCount = 30;
PadCount -= StrLen(str);
if (align == "center")
str = str.PadLeft(PadCount / 2 + str.Length, ' ');
else if (align == "right")
str = str.PadLeft(PadCount,' ');
int RetryCount = 10;
Retry:
int sta = 0;
if (_PPort == "LPT1")
sta = Input(0x379);
else if (_PPort == "LPT2")
sta = Input(0x279);
if (sta == 0x7F)
{
Status = "未连接";
return;
} if ((sta & 0x10) == 0)
{
Status = "未上电";
return;
} if((sta&0x80)==0)
{
Status = "打印机忙";
RetryCount--;
if (RetryCount <= 0)
return;
goto Retry;
} if((sta&0x20)!=0)
{
Status = "打印机缺纸";
return;
} }
解决方案 »
- 帮忙
- 使用TransactionScope在程序中执行事物时,出现错误:服务器 'test-80FF14' 上的 MSDTC 不可用。
- 我在检测页面中所有DataGrid控件内的子控件时,为什么会False?
- OWC画曲线如何改变线型和颜色?
- 两个数据库跨网络进行数据交换怎样做呢?
- web中有父模板的treeview
- c#程序中怎样给%ROWTYPE传值?
- 如何读取Excel数据
- 请问什么是web Service ,它的用途是什么? XML Web Service 又是什么?它们有什么区别?
- 关于Excel文件的数据导入问题
- c#.net 连接数据库
- 请问大侠们下面的数据库连接字符串是什么意思?
问题3:“PadLeft”是个什么方法,作用是什么?
问题4:这段代码的作用是什么?
问题五:为什么“sta == 0x7F”,其中的“0x7F”表示什么?
在.net中,可以使用String.PadLeft函数右对齐字符串,在左边用指定的Unicode字符填充一达到指定的总长度。
例如 在做自动编号这样使用
int nextID=da.GetMaxNum()+1;
this.txtCode.Text = nextID.ToString().PadLeft(6, '0');