void Item2Buffer(ByteBuilder Buf, CSaleItem item) { int index = productBindingSource.Find("ProductID", item.ProductID); string s = "產品" + item.ProductID.ToString(); if (index >= 0) { object o = productBindingSource.DataSource; BasicDataSet ds = (BasicDataSet)o; BasicDataSet.ProductDataTable t = ds.Product; BasicDataSet.ProductRow row = t[index]; s = row.Name; } int m; do { m = GB2312.GetByteCount(s); if (m <= 16) { break; } s = s.Substring(0, s.Length - 1); } while (true); int n = 16 - m + s.Length; Buf.AppendPadRight(s, n, GB2312); Buf.Append(d2str(item.Volume, 6), GB2312); // Buf.Append(d2str(item.Price , 5), GB2312); Buf.Append(d2str(item.Total, 10), GB2312); Buf.Append("\r\n", GB2312); }
private void btnPrintSmall_Click(object sender, EventArgs e) { if (!Print()) { return; } if (MessageBox.Show("此功能將從熱敏印表機印出! 要繼續嗎?", "", MessageBoxButtons.OKCancel) != DialogResult.OK) { return; } byte[] BorderMode = new byte[] { 0x1c, 0x21, 0x28 }; byte[] NormalMode = new byte[] { 0x1c, 0x21, 0 }; ByteBuilder Buf = new ByteBuilder(2048); Buf.SetEncoding(GB2312); Buf.Append(BorderMode); // 設定列印模式28 // Buf.Append(" 吴记老锅底大华店\r\n", GB2312); Buf.Append(" 销售物料统计表\r\n", GB2312); Buf.Append(NormalMode); // 設定列印模式正常 Buf.Append("\r\n"); Buf.AppendPadRight("印表时间:" + DateTime.Now.ToString("yy/MM/dd hh:mm"), 19, GB2312); Buf.Append("\r\n表单: " + cbBoxTable.Text + "\r\n", GB2312); string str = cbBoxMonth.Text.Trim() + cbBoxFrom.Text.Trim() + "至" + cbBoxTo.Text.Trim() + " "; if (ckBoxUse12.Checked) { str += "营业日"; } else { str += "0_24时"; } Buf.Append("时段: " + str + "\r\n\r\n"); Buf.Append(" 品名 数量 金额\r\n", GB2312); Buf.Append("- - - - - - - - - - - - - - - -\r\n", GB2312); decimal no = 0, total = 0; foreach (CSaleItem item in m_SaleList) // 印不可折扣項 { Item2Buffer(Buf, item); no += item.Volume; total += item.Total; } Buf.Append("- - - - - - - - - - - - - - - -\r\n", GB2312); Buf.Append("合计: " + d2str(no, 9) + d2str(total, 10) + "\r\n", GB2312); Buf.Append(NormalMode); Buf.Append("* * * * * * * * * * * * * * * *\r\n\r\n\r\n\r\n\r\n\r\n", GB2312); Buf.Append("\f", GB2312); // File.WriteAllText("TestPrn.txt",GB2312.GetString(Buf.ToBytes()),Encoding.Unicode); RawPrint.SendManagedBytes(LoadConfigPrinterName(), Buf.ToBytes()); }
void Item2Buffer(ByteBuilder Buf, CSaleItem item) { string s = "產品" + item.ProductID.ToString(); //int index = productBindingSource.Find("ProductID", item.ProductID); // //if (index >= 0) //{ // object o = productBindingSource.DataSource; // BasicDataSet ds=(BasicDataSet)o; // BasicDataSet.ProductDataTable t = ds.Product; // BasicDataSet.ProductRow row = t[index]; // s = row.Name; //} var pr = from r in m_OrderSet.Product where r.ProductID == item.ProductID select r; if (pr.Count() > 0) { if (!pr.First().IsNameNull()) { s = pr.First().Name; } } int m; do { m = GB2312.GetByteCount(s); if (m <= 16) { break; } s = s.Substring(0, s.Length - 1); } while (true); int n = 16 - m + s.Length; Buf.AppendPadRight(s, n, GB2312); Buf.Append(d2str(item.Volume, 6), GB2312); // Buf.Append(d2str(item.Price , 5), GB2312); Buf.Append(d2str(item.Total, 10), GB2312); Buf.Append("\r\n", GB2312); }