111,088
社区成员




class print_reg_paper
{
const int OPEN_EXISTING = 3;
string prnPort = "LPT1";
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr CreateFile(string lpFileName,
int dwDesiredAccess,
int dwShareMode,
int lpSecurityAttributes,
int dwCreationDisposition,
int dwFlagsAndAttributes,
int hTemplateFile);
ArrayList al;
public print_reg_paper(ArrayList als)
{
al = new ArrayList();
this.al = als;
}
public string PrintLine(string str)
{
try
{
IntPtr iHandle = CreateFile(prnPort, 0x50000000, 0, 0, OPEN_EXISTING, 0, 0);
if (iHandle.ToInt32() == -1)
{
Console.WriteLine(iHandle.ToString());
return "没有连接打印机或者打印机端口不是LPT1";
}
else
{
Console.WriteLine(iHandle.ToString());
FileStream fs = new FileStream(iHandle, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("GB2312"));
Console.WriteLine(al[2].ToString());
sw.WriteLine(str);
sw.WriteLine();
sw.WriteLine(al[1].ToString() + " " + al[2].ToString() + " " + al[3].ToString() + " " + al[4].ToString() + "件");
sw.WriteLine();
sw.WriteLine(DateTime.Now);
sw.WriteLine(); sw.WriteLine(); sw.WriteLine(); sw.WriteLine();
sw.Close();
fs.Close();
return "打印机连接成功";
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}