17,740
社区成员
发帖
与我相关
我的任务
分享
int nCount = 0; //已打印行数
decimal sumMoney = this.m_lstSale[0].MoneySum;
long sumNum = 0;
for (int i = 1; i < this.m_lstSale.Count; i++)
{
sumNum += this.m_lstSale[i].SaleNum;
}
Graphics g = e.Graphics;
float fltYPos = 0; //每一行的Y坐标
float fltXPos = 0; //每一行的X坐标
float fltLeftMargin = e.MarginBounds.Left; //获取打印起始位置
float fltTopMargin = e.MarginBounds.Top;
//=======================表头部分===================================//
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Center;
fltXPos = fltLeftMargin;
fltYPos = fltTopMargin;
RectangleF rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width, printFont.GetHeight(e.Graphics));
g.DrawString("欢迎光临", printFont, Brushes.Black, rec, stringFormat);
stringFormat.Alignment = StringAlignment.Near;
fltYPos += printFont.GetHeight(e.Graphics);
rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width, printFont.GetHeight(e.Graphics));
g.DrawString("===销售单号:" + m_lstSale[0].AutoID + "==", printFont, Brushes.Black, rec, stringFormat);
fltYPos += printFont.GetHeight(e.Graphics);
rec = new RectangleF(fltXPos, fltYPos, 80, printFont.GetHeight(e.Graphics));
g.DrawString("货号", printFont, Brushes.Black, rec, stringFormat);
fltXPos +=80;
rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width-60, printFont.GetHeight(e.Graphics));
g.DrawString("品名", printFont, Brushes.Black, rec, stringFormat);
fltYPos += printFont.GetHeight(e.Graphics);
fltXPos -= 30;
rec = new RectangleF(fltXPos, fltYPos, 60, printFont.GetHeight(e.Graphics));
g.DrawString("单价", printFont, Brushes.Black, rec, stringFormat);
fltXPos += 60;
rec = new RectangleF(fltXPos, fltYPos, 60, printFont.GetHeight(e.Graphics));
g.DrawString("数量", printFont, Brushes.Black, rec, stringFormat);
fltXPos += 60;
rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width - 120, printFont.GetHeight(e.Graphics));
g.DrawString("金额", printFont, Brushes.Black, rec, stringFormat);
//==============================表体部分===========================================
//m_lstSale.RemoveAt(0); //移除表头部分
List <Sale> tmpLstSale = new List<Sale>();
for (int i = 1; i < m_lstSale.Count; i++)
{
tmpLstSale .Add (m_lstSale [i]);
}
while (nCount < tmpLstSale.Count)
{
Sale sa = tmpLstSale[curLine + nCount];
MerchDatum md = sa.MerchDatum;
fltXPos = fltLeftMargin;
fltYPos += printFont.GetHeight(e.Graphics);
rec = new RectangleF(fltXPos, fltYPos,80, printFont.GetHeight(e.Graphics));
g.DrawString(md.MerchCode, printFont, Brushes.Black, rec, stringFormat);
fltXPos += 80;
rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width - 60, printFont.GetHeight(e.Graphics));
g.DrawString(md.MerchName, printFont, Brushes.Black, rec, stringFormat);
fltXPos -= 30;
fltYPos += printFont.GetHeight(e.Graphics);
rec = new RectangleF(fltXPos, fltYPos, 60, printFont.GetHeight(e.Graphics));
g.DrawString(md.SalePrice1.ToString() + "*", printFont, Brushes.Black, rec, stringFormat);
fltXPos += 60;
rec = new RectangleF(fltXPos, fltYPos, 60, printFont.GetHeight(e.Graphics));
g.DrawString(sa.SaleNum.ToString() + "=", printFont, Brushes.Black, rec, stringFormat);
fltXPos += 60;
rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width - 120, printFont.GetHeight(e.Graphics));
g.DrawString(Convert.ToString (md.SalePrice1 * sa.SaleNum), printFont, Brushes.Black, rec, stringFormat);
nCount++;
}
fltXPos = fltLeftMargin;
fltYPos += printFont.GetHeight(e.Graphics);
rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width, printFont.GetHeight(e.Graphics));
g.DrawString("====================================", printFont, Brushes.Black, rec, stringFormat);
fltYPos += printFont.GetHeight(e.Graphics);
fltXPos += 50;
rec = new RectangleF(fltXPos, fltYPos, 60, printFont.GetHeight(e.Graphics));
g.DrawString("合计:", printFont, Brushes.Black, rec, stringFormat);
fltXPos += 60;
rec = new RectangleF(fltXPos, fltYPos, 60, printFont.GetHeight(e.Graphics));
g.DrawString(sumNum.ToString(), printFont, Brushes.Black, rec, stringFormat);
fltXPos += 60;
rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width - 120, printFont.GetHeight(e.Graphics));
g.DrawString(Generic.GetMoney (sumMoney), printFont, Brushes.Black, rec, stringFormat);
fltYPos += printFont.GetHeight(e.Graphics);
fltXPos = fltLeftMargin;
rec = new RectangleF(fltXPos, fltYPos, 120, printFont.GetHeight(e.Graphics));
g.DrawString("支付:" + Generic.GetMoney (Convert.ToDecimal (this.txtActualPay.Text)), printFont, Brushes.Black, rec, stringFormat);
fltXPos += 120;
rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width - 120, printFont.GetHeight(e.Graphics));
g.DrawString("找零:" + Generic.GetMoney(Convert.ToDecimal(this.txtReturn.Text)), printFont, Brushes.Black, rec, stringFormat);
fltXPos = fltLeftMargin;
fltYPos += printFont.GetHeight(e.Graphics);
rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width, printFont.GetHeight(e.Graphics));
g.DrawString("营业员:"+Program.loginUser , printFont, Brushes.Black, rec, stringFormat);
fltYPos += printFont.GetHeight(e.Graphics);
rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width, printFont.GetHeight(e.Graphics));
g.DrawString("--------" + DateTime.Now.ToString() + "--------", printFont, Brushes.Black, rec, stringFormat);
stringFormat.Alignment = StringAlignment.Center;
fltYPos = fltYPos +=2* printFont.GetHeight(e.Graphics);
rec = new RectangleF(fltXPos, fltYPos, this.printDocument.DefaultPageSettings.PaperSize.Width, printFont.GetHeight(e.Graphics));
g.DrawString("欢迎再来", printFont, Brushes.Black, rec, stringFormat);
e.HasMorePages = false;