private void ListItemsBtn_Click(object sender, EventArgs e) { try { ListItemsDgView.Rows.Clear(); if (RndrPointChkBox.Checked) { ItemsDatatable = ItemsMgmt.RenderPoint(); } else { ItemsDatatable = ItemsMgmt.SelectAllItems(); } if (ItemsDatatable == null) { MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [ListItemsBtn_Click:DB-ERROR ItemsDatatable=null] \n \n", MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } TotalITemsTxtBox.Text = ItemsDatatable.Rows.Count.ToString(); TaxLevelDataTable = ItemTaxLevelMgmt.SelectAll(); ItemCategoryDataTable = ItemCategoryMgmt.SelectAll(); VendorsDataTable = VendorsMgmt.SelectAllVendors(); ItemsTypeDataTalbe = ItemTypeMgmt.SelectAll(); if (TaxLevelDataTable == null || ItemCategoryDataTable == null || VendorsDataTable == null || ItemsTypeDataTalbe == null) { MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [ListItemsBtn_Click:DB-ERROR TaxLevelDataTable=null ||ItemCategoryDataTable=null || VendorsDataTable==null || ItemsTypeDataTalbe==null] \n \n", MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } taxlevelrowsnumber = TaxLevelDataTable.Rows.Count; itemcategoryrowsnumber = ItemCategoryDataTable.Rows.Count; vendorrowsnumber = VendorsDataTable.Rows.Count; typerowsnumber = ItemsTypeDataTalbe.Rows.Count; if (ItemsDatatable.Rows.Count > 0) { //TestingFor Paging pagesnumber = (int)ItemsDatatable.Rows.Count / ItemsPerPage; if ((double.Parse(ItemsDatatable.Rows.Count.ToString()) / ItemsPerPage - int.Parse(ItemsDatatable.Rows.Count.ToString()) / ItemsPerPage) > 0) { pagesnumber++; } RowNum = 0; ListItemsDgView.Rows.Clear(); foreach (DataRow r in ItemsDatatable.Rows) { if (ListItemsDgView.Rows.Count < ItemsPerPage) { ListItemsDgView.Rows.Add(); // TRIAL 2 CODE ListItemsDgView.Rows[RowNum].Cells["Barcode"].Value = ItemsDatatable.Rows[RowNum]["Barcode"].ToString(); for (int i = 0; i < typerowsnumber; i++) { if (int.Parse(ItemsTypeDataTalbe.Rows[i]["ID"].ToString()) == int.Parse(ItemsDatatable.Rows[RowNum]["Type"].ToString())) { ListItemsDgView.Rows[RowNum].Cells["Type"].Value = ItemsTypeDataTalbe.Rows[i]["Name"].ToString(); break; } } for (int i = 0; i < itemcategoryrowsnumber; i++) { if (int.Parse(ItemCategoryDataTable.Rows[i]["ID"].ToString()) == int.Parse(ItemsDatatable.Rows[RowNum]["Category"].ToString())) { ListItemsDgView.Rows[RowNum].Cells["Category"].Value = ItemCategoryDataTable.Rows[i]["Name"].ToString(); break; } } for (int i = 0; i < taxlevelrowsnumber; i++) { if (int.Parse(TaxLevelDataTable.Rows[i]["ID"].ToString()) == int.Parse(ItemsDatatable.Rows[RowNum]["TaxLevel"].ToString())) { ListItemsDgView.Rows[RowNum].Cells["TaxLevel"].Value = TaxLevelDataTable.Rows[i]["Percentage"].ToString(); break; } } for (int i = 0; i < vendorrowsnumber; i++) { if (int.Parse(VendorsDataTable.Rows[i]["ID"].ToString()) == int.Parse(ItemsDatatable.Rows[RowNum]["Vendor"].ToString())) { ListItemsDgView.Rows[RowNum].Cells["Vendor"].Value = VendorsDataTable.Rows[i]["Name"].ToString(); break; } } ListItemsDgView.Rows[RowNum].Cells["Description"].Value = ItemsDatatable.Rows[RowNum]["Description"].ToString(); ListItemsDgView.Rows[RowNum].Cells["Qty"].Value = ItemsDatatable.Rows[RowNum]["Qty"].ToString(); ListItemsDgView.Rows[RowNum].Cells["AvgUnitCost"].Value = Math.Round(double.Parse(ItemsDatatable.Rows[RowNum]["AvgUnitCost"].ToString()), 3); ListItemsDgView.Rows[RowNum].Cells["SellPrice"].Value = ItemsDatatable.Rows[RowNum]["SellPrice"].ToString(); ListItemsDgView.Rows[RowNum].Cells["RenderPoint"].Value = ItemsDatatable.Rows[RowNum]["RenderPoint"].ToString(); ListItemsDgView.Rows[RowNum].Cells["Margincol"].Value = (Convert.ToDouble(ListItemsDgView.Rows[RowNum].Cells["SellPrice"].Value) - Convert.ToDouble(ListItemsDgView.Rows[RowNum].Cells["AvgUnitCost"].Value)) / Convert.ToDouble(ListItemsDgView.Rows[RowNum].Cells["AvgUnitCost"].Value) * 100; ListItemsDgView.Rows[RowNum].Cells["DateAdded"].Value = ItemsDatatable.Rows[RowNum]["EntryDate"].ToString(); RowNum++; } } } } catch (Exception ex) { MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [ListCustomersBtn_Click] \n Exception: \n" + ex.ToString(), MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); throw; } /* TimeSpan ts = DateTime.Now.Subtract(StartTime); * string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", * ts.Hours, ts.Minutes, ts.Seconds, * ts.Milliseconds / 10);*/ PageOfTotalTxtBox.Text = "1/" + pagesnumber.ToString(); currentpage = 1; // Console.WriteLine(elapsedTime, "RunTime"); // MessageBox.Show("Elasped Time in Seconds for [[1,300]] items [TRIAL 2 new code] is =" + elapsedTime); }
public bool PrintItemsList(bool RenderPoint, bool PrintToThermal, bool ExportToPdf = false, bool ExportToExcel = false, string ExportPath = "", bool TableBorder = false, bool Preview = false, bool colored = false) { try { List <DataTable> aDTlist = new List <DataTable>(); DataTable ItemsDatatable = null; if (RenderPoint) { ItemsDatatable = ItemsMgmt.RenderPoint(); } else { ItemsDatatable = ItemsMgmt.SelectAllItems(); } if (ItemsDatatable == null) { return(false); } else { if (ItemsDatatable.Rows.Count == 0) { return(false); } } DataTable ItemCategoryDataTable = ItemCategoryMgmt.SelectAll(); DataTable VendorsDataTable = VendorsMgmt.SelectAllVendors(); DataTable ItemsTypeDataTalbe = ItemTypeMgmt.SelectAll(); int itemcategoryrowsnumber = ItemCategoryDataTable.Rows.Count; int vendorrowsnumber = VendorsDataTable.Rows.Count; int typerowsnumber = ItemsTypeDataTalbe.Rows.Count; DataTable ToPrintTable = new DataTable(); ToPrintTable.Columns.Add("Barcode"); ToPrintTable.Columns.Add("Description"); ToPrintTable.Columns.Add("Ava.Qty"); ToPrintTable.Columns.Add("Avg Cost"); ToPrintTable.Columns.Add("Type"); ToPrintTable.Columns.Add("Category"); ToPrintTable.Columns.Add("Pref.Vendor"); if (RenderPoint) { ToPrintTable.Columns.Add("Phone"); } foreach (DataRow r in ItemsDatatable.Rows) { DataRow aRow = ToPrintTable.Rows.Add(); aRow["Barcode"] = r["Barcode"]; aRow["Description"] = r["Description"]; aRow["Ava.Qty"] = Math.Round(double.Parse(r["Qty"].ToString()), 3); aRow["Avg Cost"] = Math.Round(double.Parse(r["AvgUnitCost"].ToString()), 3); for (int i = 0; i < typerowsnumber; i++) { if (int.Parse(ItemsTypeDataTalbe.Rows[i]["ID"].ToString()) == int.Parse(r["Type"].ToString())) { aRow["Type"] = ItemsTypeDataTalbe.Rows[i]["Name"].ToString(); break; } } for (int i = 0; i < itemcategoryrowsnumber; i++) { if (int.Parse(ItemCategoryDataTable.Rows[i]["ID"].ToString()) == int.Parse(r["Category"].ToString())) { aRow["Category"] = ItemCategoryDataTable.Rows[i]["Name"].ToString(); break; } } for (int i = 0; i < vendorrowsnumber; i++) { if (int.Parse(VendorsDataTable.Rows[i]["ID"].ToString()) == int.Parse(r["Vendor"].ToString())) { aRow["Pref.Vendor"] = VendorsDataTable.Rows[i]["Name"].ToString(); if (RenderPoint) { aRow["Phone"] = VendorsDataTable.Rows[i]["Phone1"].ToString(); } break; } } } if (TableBorder) { ToPrintTable.Columns[0].ColumnName = "[Border=true1]" + ToPrintTable.Columns[0].ColumnName; } if (RenderPoint) { ToPrintTable.Columns.Remove("Category"); } ToPrintTable.Columns["Description"].ColumnName = ("<th width=30%> Description"); ToPrintTable.Columns.Remove("Type"); aDTlist.Add(ToPrintTable); List <string> aHeaderList = ReportsHelper.ImportReportHeader(0, 1); List <string> aFooterList = ReportsHelper.ImportReportHeader(1, 1); aHeaderList.Add("<td>" + SharedVariables.Line_Solid_10px_Black); if (RenderPoint) { aHeaderList.Add("<b><font size=4>" + Text.ReportsNames.RenPointListRepNm + " </font>"); } else { aHeaderList.Add("<b><font size=4>" + Text.ReportsNames.ItemsListRepNm + " </font>"); } aHeaderList.Add("<b><font size=2>" + Text.ReportsText.DateRepTxt + ": " + DateTime.Now.ToShortDateString() + " </font>"); aHeaderList.Add("<td>" + SharedVariables.Line_Solid_10px_Black); if (Preview) { PrintingManager.Instance.PrintTables(aDTlist, aHeaderList, aFooterList, ReportsHelper.TempOutputPath, ReportsHelper.TempOutputPath, PrintToThermal, false, false, "", false, "", colored); return(true); } else if (ExportToPdf) { PrintingManager.Instance.PrintTables(aDTlist, aHeaderList, aFooterList, ReportsHelper.TempOutputPath, ReportsHelper.TempOutputPath, PrintToThermal, false, true, ExportPath, false, "", colored); return(true); } else if (ExportToExcel) { PrintingManager.Instance.PrintTables(aDTlist, aHeaderList, aFooterList, ReportsHelper.TempOutputPath, ReportsHelper.TempOutputPath, PrintToThermal, false, false, "", true, ExportPath, colored); return(true); } else if (PrintToThermal) { PrintingManager.Instance.PrintTables(aDTlist, aHeaderList, aFooterList, ReportsHelper.TempOutputPath, ReportsHelper.TempOutputPath, true, true, false, "", false, "", colored); return(true); } else { return(false); } } catch (Exception ex) { throw new Exception(ex.Message); } }