private bool AddPayment() { semaphore = true; int NextCheckNumber = -1; double Amount = 0; try { if (CustomerDoNotHaveAccount) { MessageBox.Show(MsgTxt.PleaseSelectTxt + "\n 1)" + MsgTxt.CustomerTxt + "\n2)" + MsgTxt.ValidAccountTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); semaphore = false; return(false); } else { if (!double.TryParse(PaymentAmountTxtBox.Text, out Amount) || PaymentAmountTxtBox.Text == string.Empty) { MessageBox.Show(MsgTxt.PleaseSelectCorrectAmountTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); PaymentAmountTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor; return(false); } else if (Amount == 0) { MessageBox.Show(MsgTxt.PleaseSelectCorrectAmountTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); PaymentAmountTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor; return(false); } else { PaymentAmountTxtBox.BackColor = PaymentAmountTxtBoxCOLOR; //This is Added To Take The New Value //انه لو صارت حركة بيع في اثناء التعديل DataRow aMethodRow = PaymentMethodMgmt.SelectMethodRowByID(int.Parse(PaymentMethodCheckBox.SelectedValue.ToString())); aCusomerAccountRow = CustomersAccountsMgmt.SelectCustomerAccountRowByCusID(CustomerID); Balance = Double.Parse(aCusomerAccountRow["Amount"].ToString()); aCustomerPayment = new CustomersPayments(); int PaymentNumber = CustomersPaymentsMgmt.NextPaymentNumber(); if (PaymentNumber == 0)//ERROR PAYMENT NUMBER ZERO { MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [Payment Number = 0] \n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); semaphore = false; this.Close(); return(false); } aCustomerPayment.Customer_Payment_PaymentNumber = PaymentNumber; aCustomerPayment.Customer_Payment_CustomerID = CustomerID; aCustomerPayment.Customer_Payment_Date = DateTime.Now.ToShortDateString(); aCustomerPayment.Customer_Payment_Time = DateTime.Now.ToShortTimeString(); int TellerID = UsersMgmt.SelectUserIDByUserName(SharedFunctions.ReturnLoggedUserName()); if (TellerID == 0) { MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [TellerID = 0] \n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); semaphore = false; this.Close(); return(false); } aCustomerPayment.Customer_Payment_TellerID = TellerID; aCustomerPayment.Customer_Payment_OldAmount = Balance; aCustomerPayment.Customer_Payment_Amount = Amount; aCustomerPayment.Customer_Payment_Comments = CommentsTxtBox.Text; aCustomerPayment.PaymentMethodID = int.Parse(PaymentMethodCheckBox.SelectedValue.ToString()); aCustomerPayment.AccountID = int.Parse(AccountComboBox.SelectedValue.ToString()); Checks aCheck = new Checks(); if (aMethodRow["IsCash"].ToString() == "1") { aCustomerPayment.IsCreditCard = 0; aCustomerPayment.CreditCardInfo = "NOT-CREDIT"; if (!CustomersPaymentsMgmt.AddCustomerPayment(aCustomerPayment)) { MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [DataBase Error:CANNOT ADD PAYMENT] \n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); semaphore = false; this.Close(); return(false); } int CusAccountID = int.Parse(aCusomerAccountRow["ID"].ToString()); double NewAmount = aCustomerPayment.Customer_Payment_OldAmount - aCustomerPayment.Customer_Payment_Amount; if (!CustomersAccountsMgmt.UpdateAccountAmountByAccountID(CusAccountID, NewAmount)) { CustomersPaymentsMgmt.DeleteCustomerPayment(aCustomerPayment); MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [DataBase Error:CANNOT UPDATE ACCOUNT AMOUNT] \n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); semaphore = false; this.Close(); return(false); } MessageBox.Show(MsgTxt.AddedSuccessfully, MsgTxt.AddedSuccessfully, MessageBoxButtons.OK, MessageBoxIcon.Information); semaphore = false; return(true); } else if (aMethodRow["IsCredit"].ToString() == "1")//----------------------------------------------------------------------------- { if (CreditCardInfoTxtBox.Text.Trim() != "") { aCustomerPayment.IsCreditCard = 1; aCustomerPayment.CreditCardInfo = CreditCardInfoTxtBox.Text; if (!CustomersPaymentsMgmt.AddCustomerPayment(aCustomerPayment)) { MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [DataBase Error:CANNOT ADD PAYMENT] \n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); return(false); } int CusAccountID = int.Parse(aCusomerAccountRow["ID"].ToString()); double NewAmount = aCustomerPayment.Customer_Payment_OldAmount - aCustomerPayment.Customer_Payment_Amount; if (!CustomersAccountsMgmt.UpdateAccountAmountByAccountID(CusAccountID, NewAmount)) { CustomersPaymentsMgmt.DeleteCustomerPayment(aCustomerPayment); MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [DataBase Error:CANNOT UPDATE ACCOUNT AMOUNT] \n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); return(false); } MessageBox.Show(MsgTxt.AddedSuccessfully, MsgTxt.AddedSuccessfully, MessageBoxButtons.OK, MessageBoxIcon.Information); semaphore = false; return(true); } else { MessageBox.Show(MsgTxt.PleaseAddCreditCardInfoTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); CreditCardInfoTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor; semaphore = false; return(true); } } else //its cheque---------------------------------------------------------------------------------- { if (HolderNameTxtBox.Text.Trim() != "") { aCheck.Chekcs_HolderName = HolderNameTxtBox.Text; } else { MessageBox.Show(MsgTxt.CheckHolderNameTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); semaphore = false; HolderNameTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor; return(false); } aCustomerPayment.IsCreditCard = 0; aCustomerPayment.CreditCardInfo = "NOT-CREDIT"; //its check NextCheckNumber = ChecksMgmt.NextCheckNumber(); if (NextCheckNumber == 0) //ERRO IN CHEQUES { MessageBox.Show("ERROR IN CHEQUE"); semaphore = false; return(false); } aCustomerPayment.CheckNumber = NextCheckNumber; if (!CustomersPaymentsMgmt.AddCustomerPayment(aCustomerPayment)) { MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [DataBase Error: CANNOT ADD PAYMENT] \n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); semaphore = false; this.Close(); return(false); } aCheck.Chekcs_PaymentDate = CheckDatePicker.Value.ToShortDateString(); aCheck.Chekcs_IsBill = 0; aCheck.Chekcs_IsPurchaseVoucher = 0; aCheck.Chekcs_AccountID = 0; aCheck.Chekcs_Comments = CheckCommentsTxtBox.Text; aCheck.Chekcs_Amount = aCustomerPayment.Customer_Payment_Amount; aCheck.Chekcs_IsPaid = 0; aCheck.CheckNumber = NextCheckNumber; aCheck.AddingDate = DateTime.Now.ToShortDateString(); aCheck.Chekcs_PaymentDate = CheckDatePicker.Text; aCheck.Chekcs_IsVendorPayment = 0; aCheck.Chekcs_IsCustomerPayment = 1; aCheck.Chekcs_CustomerPaymentNumber = aCustomerPayment.Customer_Payment_PaymentNumber; if (!ChecksMgmt.InsertCheck(aCheck)) { CustomersPaymentsMgmt.DeleteCustomerPayment(aCustomerPayment); MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [DataBase Error: CANNOT ADD CHECK] \n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); semaphore = false; return(true); } int CusAccountID = int.Parse(aCusomerAccountRow["ID"].ToString()); double NewAmount = aCustomerPayment.Customer_Payment_OldAmount - aCustomerPayment.Customer_Payment_Amount; if (!CustomersAccountsMgmt.UpdateAccountAmountByAccountID(CusAccountID, NewAmount)) { ChecksMgmt.DeleteCheckByCheckNumber(aCheck.CheckNumber); CustomersPaymentsMgmt.DeleteCustomerPayment(aCustomerPayment); MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [DataBase Error:CANNOT UPDATE ACCOUNT AMOUNT] \n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); semaphore = false; this.Close(); return(false); } MessageBox.Show(MsgTxt.AddedSuccessfully, MsgTxt.AddedSuccessfully, MessageBoxButtons.OK, MessageBoxIcon.Information); semaphore = false; return(true); } //end of cheque } } } catch (Exception ex) { semaphore = false; MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [AddPaymentBtn_Click] \n Exception: \n" + ex.ToString() + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } return(false); }
private bool AddPayment() { try { semaphore = true; int NextCheckNumber = -1; double Amount = 0; if (VendorDoNotHaveAccount || AccountNotJOD) { MessageBox.Show(MsgTxt.PleaseSelectTxt + "\n 1)" + MsgTxt.VendorTxt + "\n2)" + MsgTxt.ValidAccountTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); semaphore = false; return(false); } else { if (!double.TryParse(PaymentAmountTxtBox.Text, out Amount)) { MessageBox.Show(MsgTxt.PleaseSelectCorrectAmountTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); PaymentAmountTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor; return(false); } else if (Amount == 0) { MessageBox.Show(MsgTxt.PleaseSelectCorrectAmountTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); PaymentAmountTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor; return(false); } else { PaymentAmountTxtBox.BackColor = PaymentAmountTxtBoxCOLOR; DataRow aMethodRow = PaymentMethodMgmt.SelectMethodRowByID(int.Parse(PaymentMethodCheckBox.SelectedValue.ToString())); if (aMethodRow == null) { throw new Exception("aMethodRow==null"); } aVendorAccountRow = VendorsAccountsMgmt.SelectVendorAccountRowByVendorID(VendorID); Balance = Double.Parse(aVendorAccountRow["Amount"].ToString()); aVendorPayment = new VendorsPayments(); int PaymentNumber = VendorsPaymentsMgmt.NextPaymentNumber(); aVendorPayment.Vendor_Payment_PaymentNumber = PaymentNumber; aVendorPayment.Vendor_Payment_VendorID = VendorID; aVendorPayment.Vendor_Payment_Date = DateTime.Now.ToShortDateString(); aVendorPayment.Vendor_Payment_Time = DateTime.Now.ToShortTimeString(); int TellerID = UsersMgmt.SelectUserIDByUserName(SharedFunctions.ReturnLoggedUserName()); aVendorPayment.Vendor_Payment_TellerID = TellerID; aVendorPayment.Vendor_Payment_OldAmount = Balance; aVendorPayment.PaymentMethodID = int.Parse(PaymentMethodCheckBox.SelectedValue.ToString()); aVendorPayment.Vendor_Payment_Comments = CommentsTxtBox.Text; aVendorPayment.MyAccountID = int.Parse(AccountComboBox.SelectedValue.ToString()); aVendorPayment.Vendor_Payment_Amount = double.Parse(PaymentAmountTxtBox.Text); Checks aCheck = new Checks(); if (aMethodRow["IsCash"].ToString() == "1") { aVendorPayment.IsCreditCard = 0; aVendorPayment.CreditCardInfo = "NOT-CREDIT"; VendorsPaymentsMgmt.AddVendorPayment(aVendorPayment); //IS REVISED AND IS CHECKED ADDED TO ZERO IN QUERY int VenAccountID = int.Parse(aVendorAccountRow["ID"].ToString()); double NewAmount = Balance - aVendorPayment.Vendor_Payment_Amount; VendorsAccountsMgmt.UpdateAccountAmountByAccountID(VenAccountID, NewAmount); double MyOldAmount = AccountsMgmt.SelectAccountAmountByID(int.Parse(AccountComboBox.SelectedValue.ToString())); AccountsMgmt.UpdateAccountAmountByAccountID(int.Parse(AccountComboBox.SelectedValue.ToString()), MyOldAmount - aVendorPayment.Vendor_Payment_Amount); } else if (aMethodRow["IsCredit"].ToString() == "1") { aVendorPayment.IsCreditCard = 1; aVendorPayment.CreditCardInfo = CreditCardInfoTxtBox.Text; VendorsPaymentsMgmt.AddVendorPayment(aVendorPayment); //IS REVISED AND IS CHECKED ADDED TO ZERO IN QUERY int VenAccountID = int.Parse(aVendorAccountRow["ID"].ToString()); double NewAmount = Balance - aVendorPayment.Vendor_Payment_Amount; VendorsAccountsMgmt.UpdateAccountAmountByAccountID(VenAccountID, NewAmount); int AccountID = int.Parse(AccountComboBox.SelectedValue.ToString()); DataRow aAccountRow = AccountsMgmt.SelectAccountRowByID(AccountID); double OldAmount = double.Parse(aAccountRow["Amount"].ToString()); double NewAmount2 = OldAmount - aVendorPayment.Vendor_Payment_Amount; AccountsMgmt.UpdateAccountAmountByAccountID(AccountID, NewAmount2); } else { aVendorPayment.IsCreditCard = 0; aVendorPayment.CreditCardInfo = "NOT-CREDIT"; NextCheckNumber = ChecksMgmt.NextCheckNumber(); aVendorPayment.CheckNumber = NextCheckNumber; VendorsPaymentsMgmt.AddVendorPayment(aVendorPayment); aCheck.Chekcs_HolderName = HolderNameTxtBox.Text; aCheck.Chekcs_PaymentDate = CheckDatePicker.Value.ToShortDateString(); aCheck.Chekcs_IsBill = 0; aCheck.Chekcs_IsPurchaseVoucher = 0; aCheck.Chekcs_AccountID = 0; aCheck.Chekcs_Comments = CheckCommentsTxtBox.Text; aCheck.Chekcs_Amount = aVendorPayment.Vendor_Payment_Amount; aCheck.Chekcs_IsPaid = 0; aCheck.CheckNumber = NextCheckNumber; aCheck.AddingDate = DateTime.Now.ToShortDateString(); aCheck.Chekcs_PaymentDate = CheckDatePicker.Text; aCheck.Chekcs_IsVendorPayment = 1; aCheck.Chekcs_VendorPaymentNumber = aVendorPayment.Vendor_Payment_PaymentNumber; aCheck.Chekcs_IsCustomerPayment = 0; if (!ChecksMgmt.InsertCheck(aCheck)) { VendorsPaymentsMgmt.DeleteVendorPayment(aVendorPayment); MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [DataBase Error: CANNOT ADD CHECK] \n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); semaphore = false; //ReloadForm(); return(false); } } MessageBox.Show(MsgTxt.AddedSuccessfully, MsgTxt.AddedSuccessfully, MessageBoxButtons.OK, MessageBoxIcon.Information); semaphore = false; return(true); } } } catch (Exception ex) { semaphore = false; MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [AddPaymentBtn_Click] \n Exception: \n" + ex.ToString() + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); return(false); } }