private void LoadDefaultData() { JSManagementDataSetTableAdapters.BrandTableAdapter brandTableAdapter = new JSManagementDataSetTableAdapters.BrandTableAdapter(); brandTableAdapter.Connection = CommonHelper.GetSQLConnection(); JSManagementDataSetTableAdapters.ProductTypeTableAdapter productTypeTableAdapter = new JSManagementDataSetTableAdapters.ProductTypeTableAdapter(); productTypeTableAdapter.Connection = CommonHelper.GetSQLConnection(); cbBoxBrand.DataSource = brandTableAdapter.GetDistinctBrand(); cbBoxProductType.DataSource = productTypeTableAdapter.GetDistinctProductType(); }
private void prnDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { Graphics g = e.Graphics; int heightPageSize = e.PageSettings.PaperSize.Height; int curentX = 10; int curentY = 70; SolidBrush brush = new SolidBrush(Color.Black); Pen p = new Pen(brush); Font font = new Font("Arial", 10, FontStyle.Regular); Font boldFont = new Font("Arial", 10, FontStyle.Bold); Font boldFontHeader = new Font("Arial", 14, FontStyle.Bold); //Print Column Header g.DrawString(Setting.GetStringSetting("InvoiceHeader"), boldFontHeader, brush, 10, 10); g.DrawString(Setting.GetStringSetting("StockReportHeader").ToUpper(), boldFont, brush, 350, 10); g.DrawString(DateTime.Now.ToShortDateString(), font, brush, new PointF(400, 30)); g.DrawString(string.Format("{0} {1}", Setting.GetStringSetting("PageNumber"), pageIndex), font, brush, 400, 50); g.DrawLine(p, new Point(curentX, curentY), new Point(curentX + 1000, curentY)); curentY += 5; g.DrawString(NUBER_INCREASE, boldFont, brush, new PointF(curentX, curentY)); curentX += 50; g.DrawString(grvProductList.Columns[PRODUCT_CODE].HeaderText, boldFont, brush, new PointF(curentX, curentY)); curentX += 100; g.DrawString(grvProductList.Columns[BRAND].HeaderText, boldFont, brush, new PointF(curentX, curentY)); curentX += 100; g.DrawString(grvProductList.Columns[SIZE].HeaderText, boldFont, brush, new PointF(curentX, curentY)); curentX += 50; g.DrawString(grvProductList.Columns[PRICE].HeaderText, boldFont, brush, new PointF(curentX, curentY)); curentX += 100; g.DrawString(grvProductList.Columns[PRODUCT_TYPE].HeaderText, boldFont, brush, new PointF(curentX, curentY)); curentX += 100; g.DrawString(grvProductList.Columns[OPENING_BALANCE].HeaderText, boldFont, brush, new PointF(curentX, curentY)); curentX += 100; g.DrawString(grvProductList.Columns[INPUT].HeaderText, boldFont, brush, new PointF(curentX, curentY)); curentX += 50; g.DrawString(grvProductList.Columns[OUTPUT].HeaderText, boldFont, brush, new PointF(curentX, curentY)); curentX += 50; g.DrawString(grvProductList.Columns[CLOSING_BALANCE].HeaderText, boldFont, brush, new PointF(curentX, curentY)); curentY += 25; g.DrawLine(p, new Point(10, curentY), new Point(1000, curentY)); CultureInfo cul = CultureInfo.GetCultureInfo(Constant.VN_CULTURE_FORMAT); while (rowIndex < grvProductList.Rows.Count) { DataGridViewRow row = grvProductList.Rows[rowIndex]; if (row.IsNewRow) { return; } curentX = 10; string productCode = row.Cells[PRODUCT_CODE].Value == null ? string.Empty : row.Cells[PRODUCT_CODE].Value.ToString(); string brand = row.Cells[BRAND].Value == null ? string.Empty : row.Cells[BRAND].Value.ToString(); string size = row.Cells[SIZE].Value == null ? string.Empty : row.Cells[SIZE].Value.ToString(); string price = row.Cells[PRICE].Value == null ? string.Empty : decimal.Parse(row.Cells[PRICE].Value.ToString()).ToString("#,###", cul.NumberFormat); string productType = row.Cells[PRODUCT_TYPE].Value == null ? string.Empty : row.Cells[PRODUCT_TYPE].Value.ToString(); string openingBallance = row.Cells[OPENING_BALANCE].Value == null ? string.Empty : row.Cells[OPENING_BALANCE].Value.ToString(); string input = row.Cells[INPUT].Value == null ? string.Empty : row.Cells[INPUT].Value.ToString(); string output = row.Cells[OUTPUT].Value == null ? string.Empty : row.Cells[OUTPUT].Value.ToString(); string closingBallance = row.Cells[CLOSING_BALANCE].Value == null ? string.Empty : row.Cells[CLOSING_BALANCE].Value.ToString(); g.DrawLine(p, new Point(curentX, curentY), new Point(curentX + 1000, curentY)); curentY += 5; g.DrawString((rowIndex + 1).ToString(), font, brush, new PointF(curentX, curentY)); curentX += 50; g.DrawString(productCode, font, brush, new PointF(curentX, curentY)); curentX += 100; g.DrawString(brand, font, brush, new PointF(curentX, curentY)); curentX += 100; g.DrawString(size, font, brush, new PointF(curentX, curentY)); curentX += 50; g.DrawString(price, font, brush, new PointF(curentX, curentY)); curentX += 100; g.DrawString(productType, font, brush, new PointF(curentX, curentY)); curentX += 100; g.DrawString(openingBallance, font, brush, new PointF(curentX, curentY)); curentX += 100; g.DrawString(input, font, brush, new PointF(curentX, curentY)); curentX += 50; g.DrawString(output, font, brush, new PointF(curentX, curentY)); curentX += 50; g.DrawString(closingBallance, font, brush, new PointF(curentX, curentY)); curentY += 20; g.DrawLine(p, new Point(10, curentY), new Point(1000, curentY)); rowIndex++; //Print Report Footer if (rowIndex == grvProductList.RowCount - 1) { JSManagementDataSetTableAdapters.GetProductInOutDetailTableAdapter productInOutDetailTableAdapter = new JSManagementDataSetTableAdapters.GetProductInOutDetailTableAdapter(); productInOutDetailTableAdapter.Connection = CommonHelper.GetSQLConnection(); JSManagementDataSetTableAdapters.ProductTypeTableAdapter productTypeTableAdapter = new JSManagementDataSetTableAdapters.ProductTypeTableAdapter(); productTypeTableAdapter.Connection = CommonHelper.GetSQLConnection(); JSManagementDataSet.ProductTypeDataTable productTypeDataTable = productTypeTableAdapter.GetDistinctProductType(); int total = 0; foreach (DataRow r in productTypeDataTable.Rows) { string productTypeName = r[0].ToString(); int subTotal = productInOutDetailTableAdapter.GetProductInOutDetail("", productTypeName, "", "", "", null, null)[0].ClosingBalance; total = total + subTotal; curentX = 50; curentY += 20; g.DrawString(productTypeName, boldFont, brush, new PointF(curentX, curentY)); curentX += 100; g.DrawString(subTotal.ToString(), boldFont, brush, new PointF(curentX, curentY)); } curentY += 20; curentX = 50; g.DrawString(TOTAL, boldFont, brush, new PointF(curentX, curentY)); curentX += 100; g.DrawString(total.ToString(), boldFont, brush, new PointF(curentX, curentY)); } if (curentY < heightPageSize - 25) { e.HasMorePages = false; } else { e.HasMorePages = true; pageIndex++; curentY = 70; return; } } }