private void Add1000ItemsBtn_Click(object sender, EventArgs e) { var types = ItemTypeMgmt.SelectAll(); var categories = ItemCategoryMgmt.SelectAll(); var vendors = VendorsMgmt.SelectAllVendors(); if (types.Rows.Count == 0 || categories.Rows.Count == 0 | vendors.Rows.Count == 0) { GenerateItemsConfigs(); types = ItemTypeMgmt.SelectAll(); categories = ItemCategoryMgmt.SelectAll(); vendors = VendorsMgmt.SelectAllVendors(); } var cnt = 2; var aRandom = new Random(); while (cnt < NumberOfItems) { var aItem = new Items(); aItem.Item_Barcode = $"Test Item {cnt}"; aItem.Item_Type = int.Parse(types.Rows[cnt % NumberOfConfigs]["ID"].ToString()); aItem.Item_Category = int.Parse(categories.Rows[cnt % NumberOfConfigs]["ID"].ToString()); aItem.Vendor = int.Parse(vendors.Rows[cnt % NumberOfConfigs]["ID"].ToString()); aItem.Item_Description = $"Test Item {cnt}"; aItem.Item_Tax_Level = (cnt % 6 != 0) ? cnt % 6 : 1; aItem.OnHandQty = cnt; aItem.Render_Point = 10; aItem.Sell_Price = aRandom.Next(50, 300); aItem.PriceLevelID = 1; aItem.Entry_Date = "1/1/2009"; aItem.Avg_Unit_Cost = aItem.Sell_Price - 10; aItem.Avalable_Qty = cnt; cnt++; if (!ItemsMgmt.AddItem(aItem)) { return; } if (cnt % 100 == 0) { label1.Text = $"Adding Item {cnt}/{NumberOfItems} ... ({(cnt / NumberOfItems) * 100 })%"; Application.DoEvents(); } } }
private void AddItemBtn_Click(object sender, EventArgs e) { try { if (Validators.TxtBoxNotEmpty(BarcodeTxtBox.Text) || WithoutBarcodeChkBox.Checked) { BarcodeTxtBox.BackColor = BarcodeTxtBoxBGColor; double ParsingOutTester = 0; if (Validators.TxtBoxNotEmpty(QtyTxtBox.Text) && double.TryParse(QtyTxtBox.Text, out ParsingOutTester)) { QtyTxtBox.BackColor = QtyTxtBoxBGColor; if (Validators.TxtBoxNotEmpty(RenderPointTxtBox.Text) && double.TryParse(RenderPointTxtBox.Text, out ParsingOutTester)) { RenderPointTxtBox.BackColor = RenderTxtBoxBGColor; if (Validators.TxtBoxNotEmpty(DescriptionTxtBox.Text)) { DescriptionTxtBox.BackColor = DescriptionBGColor; if (Validators.TxtBoxNotEmpty(SellPriceTxtBox.Text) && double.TryParse(SellPriceTxtBox.Text, out ParsingOutTester)) { SellPriceTxtBox.BackColor = SellPriceBGColor; if (Validators.TxtBoxNotEmpty(AvgCostTxtBox.Text) && double.TryParse(AvgCostTxtBox.Text, out ParsingOutTester)) { AvgCostTxtBox.BackColor = AvgUnitCostBGColor; bool IsPriceLevelsEmpty = false; foreach (var tb in Pricing.Controls.OfType <TextBox>()) { if (!Validators.TxtBoxNotEmpty(tb.Text) || !double.TryParse(tb.Text, out ParsingOutTester)) { IsPriceLevelsEmpty = true; tb.BackColor = SharedVariables.TxtBoxRequiredColor; } else { tb.BackColor = Color.White; } } if (IsPriceLevelsEmpty) { MessageBox.Show(MsgTxt.PleaseSelectTxt + "\n1)" + MsgTxt.PriceLevelsTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { Items aItem = new Items(); if (TypeComboBox.SelectedValue == null || CategoryComboBox.SelectedValue == null || VendorComboBox.SelectedValue == null || TaxLevelComboBox.SelectedValue == null) { MessageBox.Show(MsgTxt.PleaseAddAllRequiredFields, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } aItem.Item_Type = (int)TypeComboBox.SelectedValue; aItem.Item_Category = (int)CategoryComboBox.SelectedValue; aItem.Vendor = (int)VendorComboBox.SelectedValue; aItem.Item_Tax_Level = (int)TaxLevelComboBox.SelectedValue; if (WithoutBarcodeChkBox.Checked) { aItem.IsWithoutBarcode = 1; int aWithoutBarcode_Barcode = ItemsMgmt.SelectWithoutBarcode_Barcode();; if (aWithoutBarcode_Barcode == 0) { MessageBox.Show(MsgTxt.UnexpectedError + "\nException: IN[AddItemBtn_Click:Cannot Select Without Barcode _ Barcode] \n" + MsgTxt.PleaseTryAgainLaterTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } while (ItemsMgmt.IsItemExist(aWithoutBarcode_Barcode.ToString())) { aWithoutBarcode_Barcode++; } aItem.Item_Barcode = "NOBC" + aWithoutBarcode_Barcode.ToString(); } else { if (aThereIsWeigth && WeightChkBox.Checked && BarcodeTxtBox.Text.Length >= BarcodeLength) { aItem.IsWeight = 1; aItem.IsWithoutBarcode = 0; aItem.Item_Barcode = BarcodeTxtBox.Text.Substring(0, BarcodeLength); } else { aItem.IsWeight = 0; aItem.IsWithoutBarcode = 0; aItem.Item_Barcode = BarcodeTxtBox.Text; } } if (!ItemsMgmt.IsItemExist(aItem.Item_Barcode)) { aItem.Item_Description = DescriptionTxtBox.Text; aItem.Avalable_Qty = double.Parse(QtyTxtBox.Text); aItem.Render_Point = double.Parse(RenderPointTxtBox.Text); aItem.Entry_Date = DateTime.Now.ToShortDateString(); double aSellPrice = double.Parse(SellPriceTxtBox.Text); double aUnitCost = double.Parse(AvgCostTxtBox.Text); double aTax = double.Parse(ItemTaxLevelMgmt.SelectItemTaxByID(aItem.Item_Tax_Level)); if (TaxEnclodedChkBox.Checked) { aItem.Sell_Price = Math.Round(aSellPrice / ((aTax / 100) + 1), 5); aItem.Avg_Unit_Cost = Math.Round(aUnitCost / ((aTax / 100) + 1), 5); } else { aItem.Sell_Price = aSellPrice; aItem.Avg_Unit_Cost = aUnitCost; } if (!ItemsMgmt.AddItem(aItem)) { MessageBox.Show(MsgTxt.UnexpectedError + "DataBase: ItemsMgmt.AddItem" + MsgTxt.DidnotAdded + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } int ItemID = ItemsMgmt.SelectItemIDByBarcode(aItem.Item_Barcode); foreach (var tb in Pricing.Controls.OfType <TextBox>()) { double atbSellPrice = double.Parse(tb.Text); if (TaxEnclodedChkBox.Checked) { atbSellPrice = Math.Round(atbSellPrice / ((aTax / 100) + 1), 5); } Nullable <int> PriceLevelID = PriceLevelsMgmt.SelectPriceLevelIDByName(tb.Name); if (PriceLevelID != null) { Nullable <int> IsAddSpecialPriceOK = SpecialPricesMgmt.AddSpecialPrice(ItemID, (int)PriceLevelID, atbSellPrice); if (IsAddSpecialPriceOK == null) { MessageBox.Show(MsgTxt.PriceLevelsTxt + " " + tb.Name + " " + MsgTxt.DidnotAdded + "\n", MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show(MsgTxt.UnexpectedError + "DataBase: " + MsgTxt.PriceLevelsTxt + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } } MessageBox.Show(MsgTxt.AddedSuccessfully, MsgTxt.AddedSuccessfully, MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult ret; ret = MessageBox.Show(MsgTxt.AddAnotherItemTxt, MsgTxt.InformationCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); if (ret == DialogResult.Yes) { ReloadForm(); } else { this.Close(); } } else { MessageBox.Show(MsgTxt.BarcodeTxt + " " + MsgTxt.AlreadyUsedTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); BarcodeTxtBox.Text = ""; } } } else { MessageBox.Show(MsgTxt.PleaseSelectTxt + "\n1)" + MsgTxt.UnitCostTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); AvgCostTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor; AvgCostTxtBox.Focus(); } } else { MessageBox.Show(MsgTxt.PleaseSelectTxt + "\n1)" + MsgTxt.SellingPriceTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); SellPriceTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor; SellPriceTxtBox.Focus(); } } else { MessageBox.Show(MsgTxt.PleaseSelectTxt + "\n1)" + MsgTxt.DescriptionTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); DescriptionTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor; DescriptionTxtBox.Focus(); } } else { MessageBox.Show(MsgTxt.PleaseSelectTxt + "\n1)" + MsgTxt.RenderPointTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); RenderPointTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor; RenderPointTxtBox.Focus(); } } else { MessageBox.Show(MsgTxt.PleaseSelectTxt + "\n1)" + MsgTxt.ValidQtyTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); QtyTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor; QtyTxtBox.Focus(); } } else { MessageBox.Show(MsgTxt.PleaseSelectTxt + "\n1)" + MsgTxt.BarcodeTxt + "\n2)" + MsgTxt.IfNotBarChkWithoutBarcodeTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); BarcodeTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor; BarcodeTxtBox.Focus(); } } catch (Exception ex) { MessageBox.Show(MsgTxt.UnexpectedError + "\nException: IN[AddItemBtn_Click] \n" + ex.ToString() + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); throw; } }