示例#1
0
 public static bool DeleteVendorPayment(VendorsPayments aVendorsPayment)
 {
     if (Helper.Instance.con.State == ConnectionState.Closed)
     {
         try
         {
             Helper.Instance.con.Open();
             SqlCommand cmd = new SqlCommand("DELETE FROM VendorsPayments WHERE PaymentNumber=@PaymentNumber", Helper.Instance.con);
             cmd.Parameters.Add("@PaymentNumber", SqlDbType.Int).Value = aVendorsPayment.Vendor_Payment_PaymentNumber;
             cmd.ExecuteNonQuery();
             Helper.Instance.con.Close();
             return(true);
         }
         catch (Exception ex)
         {
             Helper.Instance.con.Close();
             MessageBox.Show("ERROR IN *VendorsPayments* MGMT (DeleteVendorPayment FUNCTION) EX=" + ex.Message.ToString());
             return(false);
         }
     }
     return(false);
 }
示例#2
0
        public static bool AddVendorPayment(VendorsPayments aVendorPayment)
        {
            if (Helper.Instance.con.State == ConnectionState.Closed)
            {
                try
                {
                    Helper.Instance.con.Open();
                    SqlCommand cmd = new SqlCommand("INSERT INTO VendorsPayments (VendorID,PaymentNumber,Date,Time,TellerID,Amount,OldVendorAccountAmount,IsChecked,IsRevised,Comments,MyAccountID,IsCreditCard,CreditCardInfo,PaymentMethodID,CheckNumber) VALUES (@VendorID,@PaymentNumber,@Date,@Time,@TellerID,@Amount,@OldAccountAmount,0,0,@Comments,@MyAccountID,@IsCreditCard,@CreditCardInfo,@PaymentMethodID,@CheckNumber)", Helper.Instance.con);

                    // CustomerID,Date,Time,TellerID,Amount,OldAccountAmount,IsChecked,IsRevised,Comments
                    cmd.Parameters.Add("@VendorID", SqlDbType.Int).Value           = aVendorPayment.Vendor_Payment_VendorID;
                    cmd.Parameters.Add("@PaymentNumber", SqlDbType.Int).Value      = aVendorPayment.Vendor_Payment_PaymentNumber;
                    cmd.Parameters.Add("@Date", SqlDbType.Date).Value              = aVendorPayment.Vendor_Payment_Date;
                    cmd.Parameters.Add("@Time", SqlDbType.NVarChar).Value          = aVendorPayment.Vendor_Payment_Time;
                    cmd.Parameters.Add("@TellerID", SqlDbType.Int).Value           = aVendorPayment.Vendor_Payment_TellerID;
                    cmd.Parameters.Add("@Amount", SqlDbType.Float).Value           = aVendorPayment.Vendor_Payment_Amount;
                    cmd.Parameters.Add("@OldAccountAmount", SqlDbType.Float).Value = aVendorPayment.Vendor_Payment_OldAmount;
                    //IS CHECKED AND IS REVISED ADDED TO ZEROS IN THE QUERY
                    cmd.Parameters.Add("@Comments", SqlDbType.NVarChar).Value       = aVendorPayment.Vendor_Payment_Comments;
                    cmd.Parameters.Add("@MyAccountID", SqlDbType.Int).Value         = aVendorPayment.MyAccountID;
                    cmd.Parameters.Add("@IsCreditCard", SqlDbType.Int).Value        = aVendorPayment.IsCreditCard;
                    cmd.Parameters.Add("@CreditCardInfo", SqlDbType.NVarChar).Value = aVendorPayment.CreditCardInfo;

                    cmd.Parameters.Add("@PaymentMethodID", SqlDbType.Int).Value = aVendorPayment.PaymentMethodID;
                    cmd.Parameters.Add("@CheckNumber", SqlDbType.Int).Value     = aVendorPayment.CheckNumber;

                    cmd.ExecuteNonQuery();
                    Helper.Instance.con.Close();
                    return(true);
                }
                catch (Exception ex)
                {
                    Helper.Instance.con.Close();
                    MessageBox.Show("ERROR IN *VendorsPayments* MGMT (AddVendorPayment FUNCTION) EX=" + ex.Message.ToString());
                    return(false);
                }
            }
            return(false);
        }
示例#3
0
        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);
            }
        }