private bool AddDisposalGeneral() { if (TeldgView.Rows.Count > 0) { if (DisposalReasonComboBox.SelectedValue == null) { MessageBox.Show(MsgTxt.PleaseSelectTxt + " " + MsgTxt.DisposalReasonTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Hand); return(false); } DisposalGeneral aDisposalGeneral = FillDisposalGeneral(); if (aDisposalGeneral == null) { MessageBox.Show(MsgTxt.UnexpectedError, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (!DisposalGeneralMgmt.InsertDisposal(aDisposalGeneral)) { return(false); } DisposalDetailed aDisposalDetailed = new DisposalDetailed(); foreach (DataGridViewRow r in TeldgView.Rows) { if (!r.IsNewRow) { aDisposalDetailed.Disposal_Detailed_ItemID = ItemsMgmt.SelectItemIDByBarcode(TeldgView.Rows[r.Index].Cells["Barcode"].Value.ToString()); aDisposalDetailed.Disposal_Detailed_ItemDescription = TeldgView.Rows[r.Index].Cells["Description"].Value.ToString(); aDisposalDetailed.Disposal_Detailed_Date = DateTime.Now.ToShortDateString(); double TestParser = 0; if (double.TryParse(TeldgView.Rows[r.Index].Cells["Qty"].Value.ToString(), out TestParser)) { aDisposalDetailed.Disposal_Detailed_Qty = TestParser;//double.Parse(TeldgView.Rows[r.Index].Cells["Qty"].Value.ToString()); } else { TestParser = 1; } aDisposalDetailed.Disposal_Detailed_UnitCost = double.Parse(TeldgView.Rows[r.Index].Cells["PricePerUnit"].Value.ToString()); aDisposalDetailed.Disposal_Detailed_TotalPerUnit = double.Parse(TeldgView.Rows[r.Index].Cells["PriceTotal"].Value.ToString()); aDisposalDetailed.Disposal_Detailed_GeneralNumber = aDisposalGeneral.Disposal_General_Number; DisposalDetailedMgmt.InsertDisposalItem(aDisposalDetailed); string Barcode = TeldgView.Rows[r.Index].Cells["Barcode"].Value.ToString(); ItemsMgmt.UpdateItemQtyByBarcode(Barcode, ItemsMgmt.SelectItemQtyByBarcode(Barcode), (0 - TestParser));//0-qty wich is negative to be subtracted from orginnal } } return(true); } else { MessageBox.Show(MsgTxt.NotItemsTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } }
private void UpdateItemBtn_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.Black; } } if (IsPriceLevelsEmpty) { MessageBox.Show(MsgTxt.PleaseSelectTxt + "\n1)" + MsgTxt.PriceLevelsTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { bool IsBarcodeUsed = false; //CHECK IF NEW BARCODE IS NOT CHECKED string OldBarcode; if (!WithoutBarcodeChkBox.Checked) { IsBarcodeUsed = ItemsMgmt.IsItemExist(BarcodeTxtBox.Text); if (ByBarcDescChkBox.Checked) { OldBarcode = BarcodeToEditTxtBox.Text; } else { OldBarcode = ItemDescriptionComboBox.SelectedValue.ToString(); } } else { OldBarcode = WithoutBarcodeComboBox.SelectedValue.ToString(); } Items aItem = new Items(); 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.Item_Barcode = WithoutBarcodeComboBox.SelectedValue.ToString(); } else { //aItem.IsWithoutBarcode = 0; aItem.Item_Barcode = BarcodeTxtBox.Text; } aItem.Item_ID = ItemsMgmt.SelectItemIDByBarcode(OldBarcode); if (!IsBarcodeUsed || WithoutBarcodeChkBox.Checked || OldBarcode == 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), 4); aItem.Avg_Unit_Cost = Math.Round(aUnitCost / ((aTax / 100) + 1), 4); } else { aItem.Sell_Price = aSellPrice; aItem.Avg_Unit_Cost = aUnitCost; } ItemsMgmt.UpdateItemByID(aItem); int ItemID = aItem.Item_ID; foreach (var tb in Pricing.Controls.OfType <TextBox>()) { Nullable <int> PriceLevelID = PriceLevelsMgmt.SelectPriceLevelIDByName(tb.Name); if (PriceLevelID != null) { double atbSellPrice = double.Parse(tb.Text); if (TaxEnclodedChkBox.Checked) { atbSellPrice = Math.Round(atbSellPrice / ((aTax / 100) + 1), 4); } Nullable <int> IsAddSpecialPriceOK; if (SpecialPricesMgmt.IsSpecialPriceExist(ItemID, (int)PriceLevelID) == true)//exist update { IsAddSpecialPriceOK = SpecialPricesMgmt.UpdatePriceLevel(ItemID, (int)PriceLevelID, atbSellPrice); } else if (SpecialPricesMgmt.IsSpecialPriceExist(ItemID, (int)PriceLevelID) == false)//not exist create new { IsAddSpecialPriceOK = SpecialPricesMgmt.AddSpecialPrice(ItemID, (int)PriceLevelID, atbSellPrice); } //null database error else { MessageBox.Show(MsgTxt.UnexpectedError + "DataBase: SpecialPricesMgmt.AddSpecialPrice", MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { MessageBox.Show("UNEXPECTED ERROR !!ITEM ADDED SUCCESSFULY, NOT PRICE LEVELS ADDED " + "\n" + "PLEASE ADD PRICE LEVELS MANUALLY FROM EDIT ITEM PAGE", "PRICE LEVEL ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); throw new System.ArgumentException("Parameter cannot be null", "original"); } } MessageBox.Show(MsgTxt.UpdateSuccessfully, MsgTxt.AddedSuccessfully, MessageBoxButtons.OK, MessageBoxIcon.Information); } 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) { IsUpdating = false; MessageBox.Show(MsgTxt.UnexpectedError + "\nException: IN[UpdateItemBtn_Click] \n" + ex.ToString(), MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); throw; } }
private void ReviseBillBtn_Click(object sender, EventArgs e) { try { if (aPurchaseDataRow["IsRevised"].ToString() == "0") { if (CashMethodComboBox.SelectedIndex == 1)//iscredit { int VendorID = VendorsMgmt.SelectVendorIDByName(VendorsComboBox.Text); DataRow aVendorAccount = VendorsAccountsMgmt.SelectVendorAccountRowByVendorID(VendorID); double OldAmount = double.Parse(aVendorAccount["Amount"].ToString()); double NewAmount = OldAmount - double.Parse(TotalTxtBox.Text); int AccountID = int.Parse(aVendorAccount["ID"].ToString()); VendorsAccountsMgmt.UpdateAccountAmountByAccountID(AccountID, NewAmount); } else { int AccountID = int.Parse(aPurchaseDataRow["AccountID"].ToString()); DataRow aAccountRow = AccountsMgmt.SelectAccountRowByID(AccountID); double OldAmount = double.Parse(aAccountRow["Amount"].ToString()); double NewAmount = OldAmount + double.Parse(TotalTxtBox.Text);; AccountsMgmt.UpdateAccountAmountByAccountID(AccountID, NewAmount); } //Mark the check (if any) as revised DataRow aMethodRow = PaymentMethodMgmt.SelectMethodRowByID(int.Parse(aPurchaseDataRow["PaymentMethodID"].ToString())); if (aMethodRow["IsCheck"].ToString() == "1") { ChecksMgmt.MakeCheckRevised(int.Parse(aPurchaseDataRow["CheckNumber"].ToString()), DateTime.Now.ToShortDateString()); } //Now Update AvgUnitCost double CostLoss = 0; foreach (DataGridViewRow r in TeldgView.Rows) { if (!r.IsNewRow) { int ItemID = ItemsMgmt.SelectItemIDByBarcode(TeldgView.Rows[r.Index].Cells["Barcode"].Value.ToString()); double ItemCost = PurchaseVoucherDetailedMgmt.SelectItemCostByNumber(ItemID, int.Parse(aPurchaseDataRow["VoucherNumber"].ToString())); double ReturnQty = double.Parse(TeldgView.Rows[r.Index].Cells["Qty"].Value.ToString()); double CurrentAvgUnitCost = ItemsMgmt.SelectItemCostByBarcode(TeldgView.Rows[r.Index].Cells["Barcode"].Value.ToString()); double CurrentAvaQty = ItemsMgmt.SelectItemQtyByID(ItemID); double NewAvgUnitCost = ((CurrentAvgUnitCost * CurrentAvaQty) + (ReturnQty * ItemCost)) / (ReturnQty + CurrentAvaQty); ItemsMgmt.UpdateItemQtyandAvgUnitCostByID(ItemID, (ReturnQty + CurrentAvaQty), NewAvgUnitCost); PurchaseVoucherDetailedMgmt.MakeItemAsRevised(int.Parse(aPurchaseDataRow["VoucherNumber"].ToString()), ItemID); } } //Now we should mark the bill general as reversed if (!PurchaseVoucherGeneralMgmt.UpdateVoucherToRevised(TellerUserNameLbl.Text, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), int.Parse(aPurchaseDataRow["VoucherNumber"].ToString()), CostLoss)) { MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [DB-ERROR-EditBill-ReviseBillBtn_Click] " + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } else { MessageBox.Show(MsgTxt.ReversedSuccessfullyTxt, MsgTxt.AddedSuccessfully, MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } else { MessageBox.Show(MsgTxt.AlreadyReversedTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } catch (Exception ex) { MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EditVoucher-ReviseBillBtn_Click] \n Exception: \n" + ex.ToString() + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); throw; } }
private void ReviseBillBtn_Click(object sender, EventArgs e) { try { if (aBillGeneralRow["IsRevised"].ToString() == "0") { if (CashMethodComboBox.SelectedIndex == 1)//iscredit { int CustomerID = CustomerMgmt.SelectCustomerIDByPhone1(PhoneTxtBox.Text); DataRow aCustomerAccount = CustomersAccountsMgmt.SelectCustomerAccountRowByCusID(CustomerID); double OldAmount = double.Parse(aCustomerAccount["Amount"].ToString()); double NewAmount = OldAmount - double.Parse(TotalTxtBox.Text); int AccountID = int.Parse(aCustomerAccount["ID"].ToString()); CustomersAccountsMgmt.UpdateAccountAmountByAccountID(AccountID, NewAmount); } else {//int.Parse(AccountComboBox.SelectedValue.ToString()); int AccountID = int.Parse(aBillGeneralRow["AccountID"].ToString()); DataRow aAccountRow = AccountsMgmt.SelectAccountRowByID(AccountID); double OldAmount = double.Parse(aAccountRow["Amount"].ToString()); double NewAmount = OldAmount - double.Parse(TotalTxtBox.Text);; AccountsMgmt.UpdateAccountAmountByAccountID(AccountID, NewAmount); } //Mark the check (if any) as revised DataRow aMethodRow = PaymentMethodMgmt.SelectMethodRowByID(int.Parse(aBillGeneralRow["PaymentMethodID"].ToString())); if (aMethodRow["IsCheck"].ToString() == "1") { ChecksMgmt.MakeCheckRevised(int.Parse(aBillGeneralRow["CheckNumber"].ToString()), DateTime.Now.ToShortDateString()); } //Now Update AvgUnitCost double CostLoss = 0; foreach (DataGridViewRow r in TeldgView.Rows) { if (!r.IsNewRow) { int ItemID = ItemsMgmt.SelectItemIDByBarcode(TeldgView.Rows[r.Index].Cells["Barcode"].Value.ToString()); double OldAvgUnitCost = BillDetailedMgmt.SelectOldAvgUnitCostByID(ItemID, int.Parse(aBillGeneralRow["Number"].ToString())); double ReturnQty = double.Parse(TeldgView.Rows[r.Index].Cells["Qty"].Value.ToString()); double CurrentAvgUnitCost = ItemsMgmt.SelectItemCostByBarcode(TeldgView.Rows[r.Index].Cells["Barcode"].Value.ToString()); double CurrentAvaQty = ItemsMgmt.SelectItemQtyByID(ItemID); double NewAvgUnitCost = CurrentAvgUnitCost; if ((ReturnQty + CurrentAvaQty) != 0) //to avoid division by zero { NewAvgUnitCost = ((CurrentAvgUnitCost * CurrentAvaQty) + (ReturnQty * OldAvgUnitCost)) / (ReturnQty + CurrentAvaQty); } CostLoss += (NewAvgUnitCost - OldAvgUnitCost) * BillDetailedMgmt.SelectAllItemsSoldAfterBillNumber(ItemID, int.Parse(aBillGeneralRow["Number"].ToString())); ItemsMgmt.UpdateItemQtyandAvgUnitCostByID(ItemID, (ReturnQty + CurrentAvaQty), NewAvgUnitCost); BillDetailedMgmt.MakeItemAsRevised(int.Parse(aBillGeneralRow["Number"].ToString()), ItemID); } } //Now we should mark the bill general as reversed if (!BillGeneralMgmt.UpdateBillToRevised(SharedFunctions.ReturnLoggedUserName(), DateTime.Now.ToShortDateString(), int.Parse(aBillGeneralRow["Number"].ToString()), CostLoss)) { MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [DB-ERROR-EditBill-ReviseBillBtn_Click] " + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } MessageBox.Show(MsgTxt.ReversedSuccessfullyTxt, MsgTxt.AddedSuccessfully, MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { MessageBox.Show(MsgTxt.AlreadyReversedTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } catch (Exception ex) { MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EditBill-ReviseBillBtn_Click] \n Exception: \n" + ex.ToString() + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); throw; } }
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; } }