public IActionResult DeleteCustomersPayment(int idnt, string code, StationsService service) { CustomersPayments payment = service.GetCustomerPayment(idnt, service.GetStation(code)); payment.Delete(); payment.Customer.UpdateBalance(); return(Ok("success")); }
public static bool DeleteCustomerPayment(CustomersPayments aCustomerPayment) { if (Helper.Instance.con.State == ConnectionState.Closed) { try { Helper.Instance.con.Open(); SqlCommand cmd = new SqlCommand("DELETE FROM CustomersPayments WHERE PaymentNumber=@PaymentNumber", Helper.Instance.con); cmd.Parameters.Add("@PaymentNumber", SqlDbType.Int).Value = aCustomerPayment.Customer_Payment_PaymentNumber; cmd.ExecuteNonQuery(); Helper.Instance.con.Close(); return(true); } catch (Exception ex) { Helper.Instance.con.Close(); MessageBox.Show("ERROR IN *CustomersPayments* MGMT (DeleteCustomerPayment FUNCTION) EX=" + ex.Message.ToString()); return(false); } } return(false); }
public static bool AddCustomerPayment(CustomersPayments aCustomerPayment) { if (Helper.Instance.con.State == ConnectionState.Closed) { try { Helper.Instance.con.Open(); SqlCommand cmd = new SqlCommand("INSERT INTO CustomersPayments (CustomerID,PaymentNumber,Date,Time,TellerID,Amount,OldUsrAccountAmount,IsChecked,IsRevised,Comments,IsCreditCard,CreditCardInfo,PaymentMethodID,CheckNumber,AccountID) VALUES (@CustomerID,@PaymentNumber,@Date,@Time,@TellerID,@Amount,@OldAccountAmount,0,0,@Comments,@IsCreditCard,@CreditCardInfo,@PaymentMethodID,@CheckNumber,@AccountID)", Helper.Instance.con); // CustomerID,Date,Time,TellerID,Amount,OldAccountAmount,IsChecked,IsRevised,Comments cmd.Parameters.Add("@CustomerID", SqlDbType.Int).Value = aCustomerPayment.Customer_Payment_CustomerID; cmd.Parameters.Add("@PaymentNumber", SqlDbType.Int).Value = aCustomerPayment.Customer_Payment_PaymentNumber; cmd.Parameters.Add("@Date", SqlDbType.Date).Value = aCustomerPayment.Customer_Payment_Date; cmd.Parameters.Add("@Time", SqlDbType.NVarChar).Value = aCustomerPayment.Customer_Payment_Time; cmd.Parameters.Add("@TellerID", SqlDbType.Int).Value = aCustomerPayment.Customer_Payment_TellerID; cmd.Parameters.Add("@Amount", SqlDbType.Float).Value = aCustomerPayment.Customer_Payment_Amount; cmd.Parameters.Add("@OldAccountAmount", SqlDbType.Float).Value = aCustomerPayment.Customer_Payment_OldAmount; //IS CHECKED AND IS REVISED ADDED TO ZEROS IN THE QUERY cmd.Parameters.Add("@Comments", SqlDbType.NVarChar).Value = aCustomerPayment.Customer_Payment_Comments; cmd.Parameters.Add("@IsCreditCard", SqlDbType.Int).Value = aCustomerPayment.IsCreditCard; cmd.Parameters.Add("@CreditCardInfo", SqlDbType.NVarChar).Value = aCustomerPayment.CreditCardInfo; cmd.Parameters.Add("@PaymentMethodID", SqlDbType.Int).Value = aCustomerPayment.PaymentMethodID; cmd.Parameters.Add("@CheckNumber", SqlDbType.Int).Value = aCustomerPayment.CheckNumber; cmd.Parameters.Add("@AccountID", SqlDbType.Int).Value = aCustomerPayment.AccountID; cmd.ExecuteNonQuery(); Helper.Instance.con.Close(); return(true); } catch (Exception ex) { Helper.Instance.con.Close(); MessageBox.Show("ERROR IN *CustomersPayments* MGMT (AddCustomerPayment FUNCTION) EX=" + ex.Message.ToString()); return(false); } } return(false); }
private void AddCustomerPayment_Load(object sender, EventArgs e) { try { semaphore = true; PayDateStaticPicker.Text = DateTime.Now.ToString(); // TODO: This line of code loads data into the 'dBDataSet.Customer' table. You can move, or remove it, as needed. this.customerTableAdapter.Fill(this.dBDataSet.Customer); aCustomerPayment = new CustomersPayments(); int PaymentNumber = CustomersPaymentsMgmt.NextPaymentNumber(); PaymentNumberTxtBox.Text = PaymentNumber.ToString(); // TODO: This line of code loads data into the 'dBDataSet.PaymentMethod' table. You can move, or remove it, as needed. this.paymentMethodTableAdapter.Fill(this.dBDataSet.PaymentMethod); // TODO: This line of code loads data into the 'dBDataSet.Accounts' table. You can move, or remove it, as needed. this.accountsTableAdapter.Fill(this.dBDataSet.Accounts); semaphore = false; } catch (Exception ex) //Launching Error Please Report It To Sari King [Database error 99%] { semaphore = false; MessageBox.Show(MsgTxt.ErrorLoadingFrom + "\nException: IN[AddCustomerPayment_Load] \n" + ex.ToString() + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } }
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); }