private void CalculateUtangPrint() { System.Windows.Forms.PrintPreviewDialog dlgPreview = new System.Windows.Forms.PrintPreviewDialog(); Graphics g = dlgPreview.CreateGraphics(); int y; // Print receipt Font myFont = new Font("Small Font", 7, FontStyle.Regular); y = 0; try { Bitmap bmp2 = new Bitmap("logo.png"); Rectangle rec2 = new Rectangle(0, 0, bmp2.Width, bmp2.Height); g.DrawImage(bmp2, 0, 0, rec2, GraphicsUnit.Pixel); } catch { } List <string> strmsg = new List <string>(); List <string> strmsg2 = new List <string>(); Profile _myProfile = new Profile(); _myProfile.ReadXML(); strmsg.Add(_myProfile.Company); strmsg.Add(_myProfile.Address); strmsg.Add(_myProfile.TIN); strmsg.Add(_myProfile.ContactNum); strmsg.Add(" "); strmsg.Add(" "); strmsg.Add("Date:" + dtPick.Value.ToString()); strmsg.Add("Item(s) Purchased"); strmsg.Add("--------------------------------------------------------------------------------"); double total = 0.0; foreach (Receipt r in m_receipts) { strmsg.Add(string.Format("{0}:Name={1} Balance={2}", r.TransDate, r.CustomerName, (r.TotalAmount - r.CashTendered < 0 ? 0 : r.TotalAmount - r.CashTendered))); foreach (KeyValuePair <string, clsProductItem> fi in r.PurchasedItems) { strmsg.Add(string.Format("\t{0}:{1}x{2}={3}", fi.Value.Description, fi.Value.Qty, fi.Value.Amount, fi.Value.Qty * fi.Value.Amount)); } total += (r.TotalAmount - r.CashTendered < 0 ? 0 : r.TotalAmount - r.CashTendered); } strmsg.Add("--------------------------------------------------------------------------------"); strmsg.Add("Total Balance:" + total.ToString("0.00")); strmsg.Add("--------------------------------------------------------------------------------"); int ctr = 1; foreach (string str in strmsg) { if (ctr < 5) { myFont = new Font("Small Font", 5, FontStyle.Bold); g.DrawString(str, myFont, Brushes.Black, 50, y); } else { myFont = new Font("Small Font", 5, FontStyle.Regular); g.DrawString(str, myFont, Brushes.Black, 0, y); } y += (int)g.MeasureString(str, myFont).Height; ctr++; } m_ReceiptSize = y + 30; }
private void CalculatePrint() { System.Windows.Forms.PrintPreviewDialog dlgPreview = new System.Windows.Forms.PrintPreviewDialog(); Graphics g = dlgPreview.CreateGraphics(); int y; // Print receipt Font myFont = new Font("Small Font", 7, FontStyle.Regular); y = 0; try { Bitmap bmp2 = new Bitmap("logo.png"); Rectangle rec2 = new Rectangle(0, 0, bmp2.Width, bmp2.Height); g.DrawImage(bmp2, 0, 0, rec2, GraphicsUnit.Pixel); } catch { } List <string> strmsg = new List <string>(); List <string> strmsg2 = new List <string>(); Profile _myProfile = new Profile(); _myProfile.ReadXML(); strmsg.Add(_myProfile.Company); strmsg.Add(_myProfile.Address); strmsg.Add(_myProfile.TIN); strmsg.Add(_myProfile.ContactNum); strmsg.Add(" "); strmsg.Add(" "); strmsg.Add("Date:" + dtPick.Value.ToShortDateString()); strmsg.Add("Sales Inventory"); strmsg.Add("--------------------------------------------------------------------------------"); double total = 0.0; foreach (KeyValuePair <string, clsProductItem> fi in dicProdSold) { strmsg.Add(fi.Value.ToString()); total += fi.Value.Total; } strmsg.Add("--------------------------------------------------------------------------------"); strmsg.Add("Grand Total:" + total.ToString("0.00")); strmsg.Add(string.Format("Total Income: {0:0.00}", Convert.ToDouble(txtIncome.Text))); strmsg.Add(" "); strmsg.Add(" "); strmsg.Add("Products Left"); strmsg.Add("--------------------------------------------------------------------------------"); for (int ctr2 = 0; ctr2 < lstSales.Items.Count; ctr2++) { strmsg.Add(lstSales.Items[ctr2].ToString()); } strmsg.Add("--------------------------------------------------------------------------------"); int ctr = 1; foreach (string str in strmsg) { if (ctr < 5) { myFont = new Font("Small Font", 5, FontStyle.Bold); g.DrawString(str, myFont, Brushes.Black, 50, y); } else { myFont = new Font("Small Font", 5, FontStyle.Regular); g.DrawString(str, myFont, Brushes.Black, 0, y); } y += (int)g.MeasureString(str, myFont).Height; ctr++; } m_ReceiptSize = y + 30; }