Пример #1
0
 private void PaymentMethodCheckBox_SelectedValueChanged(object sender, EventArgs e)
 {
     if (PaymentMethodCheckBox.SelectedValue != null)
     {
         DataRow aMethodRow = PaymentMethodMgmt.SelectMethodRowByID(int.Parse(PaymentMethodCheckBox.SelectedValue.ToString()));
         AccountComboBox.SelectedValue   = int.Parse(aMethodRow["DefaultAccountID"].ToString()); //PaymentMethodMgmt.SelectDefaultAccountIDByMethodID(int.Parse(PaymentMethodCheckBox.SelectedValue.ToString()));
         AccountDescriptionTxtBox.Text   = AccountsMgmt.SelectAccountDescriptionByID(int.Parse(aMethodRow["DefaultAccountID"].ToString()));
         PaymentMethodDescripTxtBox.Text = aMethodRow["Description"].ToString();                 //PaymentMethodMgmt.SelectDescriptionByID(int.Parse(PaymentMethodCheckBox.SelectedValue.ToString()));
         if (aMethodRow["IsCash"].ToString() == "1")
         {
             CashPaymentGB.Show();
             CashPaymentGB.BringToFront();
             PayInVisaGB.Hide();
             CheckGB.Hide();
         }
         else if (aMethodRow["IsCredit"].ToString() == "1")
         {
             PayInVisaGB.Show();
             PayInVisaGB.BringToFront();
             CashPaymentGB.Hide();
             CheckGB.Hide();
         }
         else
         {
             CheckGB.Show();
             CheckGB.BringToFront();
             CashPaymentGB.Hide();
             PayInVisaGB.Hide();
             CheckNumberTxtBox.Text = ChecksMgmt.NextCheckNumber().ToString();
         }
     }
 }
Пример #2
0
        private void RevisePaymentBtn_Click(object sender, EventArgs e)
        {
            try
            {
                if (aVendorPaymentRowGlobal["IsRevised"].ToString() == "0")
                {
                    string  RevisedBy     = SharedFunctions.ReturnLoggedUserName();
                    string  ReviseDate    = DateTime.Now.ToShortDateString();
                    string  ReviseTime    = DateTime.Now.ToShortTimeString();
                    int     PaymentNumber = int.Parse(aVendorPaymentRowGlobal["PaymentNumber"].ToString());
                    DataRow aMethodRow    = PaymentMethodMgmt.SelectMethodRowByID(int.Parse(aVendorPaymentRowGlobal["PaymentMethodID"].ToString()));
                    if (aMethodRow == null)
                    {
                        // MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EditBill-SelectMethodRowByID Returned Null] " + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        throw new Exception("EditVendorPayment-aMethodRow Returned Null");
                    }

                    if (!VendorsPaymentsMgmt.UpdatePaymentToRevised(RevisedBy, ReviseDate, ReviseTime, PaymentNumber))
                    {
                        MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [DB-ERROR-EditVendorPayment-UpdatePaymentToRevised-FUNC:UpdatePaymentToRevised] " + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Close();
                    }

                    if (aMethodRow["IsCheck"].ToString() == "1")
                    {
                        ChecksMgmt.MakeCheckRevised(int.Parse(aVendorPaymentRowGlobal["CheckNumber"].ToString()), DateTime.Now.ToShortDateString());
                    }
                    double Amount        = double.Parse(aVendorPaymentRowGlobal["Amount"].ToString());
                    double CurrentAmount = double.Parse(aVendorAccount["Amount"].ToString());
                    int    AccountID     = int.Parse(aVendorAccount["ID"].ToString());
                    double NewAmount     = CurrentAmount + Amount;
                    VendorsAccountsMgmt.UpdateAccountAmountByAccountID(AccountID, NewAmount);
                    double MyOldAccountAmount = double.Parse(aAccount["Amount"].ToString());
                    double MyNewAccountAmount = MyOldAccountAmount + Amount;
                    int    MyAccountID        = int.Parse(aAccount["ID"].ToString());
                    if (!AccountsMgmt.UpdateAccountAmountByAccountID(MyAccountID, MyNewAccountAmount))
                    {
                        MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [DB-ERROR-EditcustomerPayment-RevisePaymentBtn_Click-FUNC:UpdateAccountAmountByAccountID] " + 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 [EditVendorPayment-RevisePaymentBtn_Click] \n Exception: \n" + ex.ToString() + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
                throw;
            }
        }
Пример #3
0
 private void PaymentMethodCheckBox_SelectedValueChanged(object sender, EventArgs e)
 {
     try
     {
         //no need to lock because this changes the account table which needed to be updated
         if (PaymentMethodCheckBox.SelectedValue != null)
         {
             aMethodRow = PaymentMethodMgmt.SelectMethodRowByID(int.Parse(PaymentMethodCheckBox.SelectedValue.ToString()));
             AccountComboBox.SelectedValue   = int.Parse(aMethodRow["DefaultAccountID"].ToString());
             AccountDescriptionTxtBox.Text   = AccountsMgmt.SelectAccountDescriptionByID(int.Parse(aMethodRow["DefaultAccountID"].ToString()));
             PaymentMethodDescripTxtBox.Text = aMethodRow["Description"].ToString();
             if (aMethodRow["IsCash"].ToString() == "1")
             {
                 PayInVisaGB.Hide();
                 CheckGB.Hide();
             }
             else if (aMethodRow["IsCredit"].ToString() == "1")
             {
                 PayInVisaGB.Show();
                 PayInVisaGB.BringToFront();
                 CheckGB.Hide();
             }
             else
             {
                 CheckGB.Show();
                 CheckGB.BringToFront();
                 PayInVisaGB.Hide();
                 CheckNumberTxtBox.Text = ChecksMgmt.NextCheckNumber().ToString();
             }
         }
         else
         {
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [PaymentMethodCheckBox_SelectedValueChanged] \n Exception: \n" + ex.ToString() + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
         this.Close();
     }
 }
Пример #4
0
        public void UpdateVariables(DataRow aGeneralVoucherDataRow)
        {
            try
            {
                aPurchaseDataRow = aGeneralVoucherDataRow;
                PurchaseVoucherNumTxtBox.Text = aGeneralVoucherDataRow["VoucherNumber"].ToString();
                aVendorDataRow = VendorsMgmt.SelectVendorRowByID(int.Parse(aGeneralVoucherDataRow["VendorID"].ToString()));
                if (aVendorDataRow == null)
                {
                    // MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EditBill-SelectCustomerRowByID Returned Null] " + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw new Exception("EditVoucher-SelectVendorRowByID Returned Null");
                }

                VendorsComboBox.Text         = aVendorDataRow["Name"].ToString();
                VendorDescriptionTxtBox.Text = aVendorDataRow["Company"].ToString();
                //account amount is latered to iscredit
                DateLbl.Text   = DateTime.Parse(aGeneralVoucherDataRow["Date"].ToString()).ToShortDateString();
                TimeLbl.Text   = DateTime.Parse(aGeneralVoucherDataRow["Time"].ToString()).ToShortTimeString();
                TellerLbl.Text = UsersMgmt.SelectUserNameByID(int.Parse(aGeneralVoucherDataRow["TellerID"].ToString()));
                if (TellerLbl.Text == null)
                {
                    //MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EditBill-UsersMgmt.UsrById Returned Null] " + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw new Exception("[EditVoucher-UsersMgmt.UsrById Returned Null]");
                }
                //DOWN RIGHT
                SubtotalTxtBox.Text      = aGeneralVoucherDataRow["Subtotal"].ToString();
                DiscountPercTxtBox.Text  = aGeneralVoucherDataRow["DiscountPerc"].ToString();
                DiscountTxtBox.Text      = (float.Parse(SubtotalTxtBox.Text) * float.Parse(DiscountPercTxtBox.Text) / 100).ToString();
                ItemsDiscountTxtBox.Text = aGeneralVoucherDataRow["TotalItemsDiscount"].ToString();
                TotalDiscountTxtBox.Text = aGeneralVoucherDataRow["TotalDiscount"].ToString();
                TotalTaxTxtBox.Text      = aGeneralVoucherDataRow["TotalTax"].ToString();
                FeesTxtBox.Text          = aGeneralVoucherDataRow["Fees"].ToString();
                TotalTxtBox.Text         = aGeneralVoucherDataRow["TotalCost"].ToString();
                //GroupBox1 Elements
                if (aPurchaseDataRow["IsRevised"].ToString() == "1")
                {
                    ReviseInfoGB.Show();
                    ReviseDatelbl.Text       = DateTime.Parse(aPurchaseDataRow["ReviseDate"].ToString()).ToShortDateString();
                    ReviseTime.Text          = DateTime.Parse(aPurchaseDataRow["ReviseTime"].ToString()).ToShortTimeString();
                    RevisedBylbl.Text        = aPurchaseDataRow["RevisedBy"].ToString();
                    IsRevisedLbl.Visible     = true;
                    ReviseLossProfitLbl.Text = aPurchaseDataRow["ReviseLoss"].ToString();
                }
                else
                {
                    ReviseInfoGB.Hide();
                }

                if (aPurchaseDataRow["IsChecked"].ToString() == "1")
                {
                    ChkedByUserNameLbl.Text = aPurchaseDataRow["CheckedBy"].ToString();

                    ChkDateLbl.Text = DateTime.Parse(aPurchaseDataRow["CheckDate"].ToString()).ToShortDateString();
                    CheckTime.Text  = DateTime.Parse(aPurchaseDataRow["CheckTime"].ToString()).ToShortTimeString();
                    CheckInfoGB.Show();
                }
                else
                {
                    CheckInfoGB.Hide();
                }
                //PaymentInformation
                DataRow aMethodRow = PaymentMethodMgmt.SelectMethodRowByID(int.Parse(aPurchaseDataRow["PaymentMethodID"].ToString()));
                if (aMethodRow == null)
                {
                    // MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EditBill-SelectMethodRowByID Returned Null] " + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw new Exception("EditVoucher-SelectMethodRowByID Returned Null");
                }
                PaymentMethodCheckBox.Text      = aMethodRow["Name"].ToString();
                PaymentMethodDescripTxtBox.Text = aMethodRow["Description"].ToString();//PaymentMethodMgmt.SelectDescriptionByID(int.Parse(PaymentMethodCheckBox.SelectedValue.ToString()));
                if (aMethodRow["IsCash"].ToString() == "1")
                {
                    CashPaymentGB.Show();
                    CashPaymentGB.BringToFront();
                    PayInVisaGB.Hide();
                    CheckGB.Hide();
                }
                else if (aMethodRow["IsCredit"].ToString() == "1")
                {
                    PayInVisaGB.Show();
                    PayInVisaGB.BringToFront();
                    CashPaymentGB.Hide();
                    CheckGB.Hide();
                }
                else
                {
                    CheckGB.Show();
                    CheckGB.BringToFront();
                    CashPaymentGB.Hide();
                    PayInVisaGB.Hide();
                    CheckNumberTxtBox.Text = aPurchaseDataRow["CheckNumber"].ToString();
                    DataRow aCheckDataRow = ChecksMgmt.SelectCheckRowByNumber(int.Parse(aPurchaseDataRow["CheckNumber"].ToString()));
                    if (aCheckDataRow == null)
                    {
                        //MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EditBill-SelectCheckRowByNumber Returned Null] " + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        throw new Exception("EditVoucher-SelectCheckRowByNumber Returned Null");
                    }
                    HolderNameTxtBox.Text    = aCheckDataRow["HolderName"].ToString();
                    CheckCommentsTxtBox.Text = aCheckDataRow["Comments"].ToString();
                    CheckDatePicker.Text     = aCheckDataRow["PaymentDate"].ToString();
                }
                DataRow aAccountRow = AccountsMgmt.SelectAccountRowByID(int.Parse(aPurchaseDataRow["AccountID"].ToString()));
                if (aAccountRow == null)
                {
                    // MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EditBill-SelectAccountRowByID Returned Null] " + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw new Exception("EditBill-SelectAccountRowByID Returned Null");
                }
                else
                {
                    AccountComboBox.Text          = aAccountRow["Name"].ToString();
                    AccountDescriptionTxtBox.Text = aAccountRow["Description"].ToString();
                    CurrencyComboBox.Text         = CurrencyMgmt.SelectCurrencyNameByID(int.Parse(aAccountRow["CurrencyID"].ToString()));
                    if (CurrencyComboBox.Text == null)
                    {
                        MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EditVoucher-SelectCurrencyNameByID Returned Null] " + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Close();
                    }
                    CreditCardInfoTxtBox.Text = aPurchaseDataRow["CreditCardInfo"].ToString();
                }
                if (aPurchaseDataRow["IsCashCredit"].ToString() == "1")
                {
                    CashMethodComboBox.SelectedIndex = 1;
                    VendorAccountAmountTxtBox.Show();
                    VendorAccountAmountTxtBox.Text = aPurchaseDataRow["VendorAccountAmountOld"].ToString();
                    AccountComboBox.Hide();
                    AccountLbl.Hide();
                    CashInTxtBox.Hide();
                    ExchangeTxtBox.Hide();
                    CashInLbl.Hide();
                    ExchangeLbl.Hide();
                    JODstatic.Hide();
                    CurrencyLbl.Hide();
                    IsCreditLbl.Show();
                }
                else
                {
                    CashMethodComboBox.SelectedIndex = 0;
                    VendorAccountAmountTxtBox.Hide();
                    AccountComboBox.Show();
                    AccountLbl.Show();
                    CashInTxtBox.Show();
                    ExchangeTxtBox.Show();
                    CashInLbl.Show();
                    ExchangeLbl.Show();
                    JODstatic.Show();
                    CurrencyLbl.Show();
                    IsCreditLbl.Hide();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EditVoucher-UpdateVariables] \n Exception: \n" + ex.ToString() + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }
        }
Пример #5
0
 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;
     }
 }
Пример #6
0
        public void UpdateVariables(DataRow aGeneralBillDataRow)
        {
            try
            {
                aBillGeneralRow = aGeneralBillDataRow;

                InvoiceNumTxtBox.Text = aGeneralBillDataRow["Number"].ToString();

                DateLbl.Text = DateTime.Parse(aGeneralBillDataRow["Date"].ToString()).ToShortDateString();

                TimeLbl.Text = aGeneralBillDataRow["BillTime"].ToString();

                TellerLbl.Text = UsersMgmt.SelectUserNameByID(int.Parse(aGeneralBillDataRow["TellerID"].ToString()));
                if (TellerLbl.Text == null)
                {
                    //MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EditBill-UsersMgmt.UsrById Returned Null] " + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw new Exception("[EditBill-UsersMgmt.UsrById Returned Null]");
                }
                aUserDataRow = CustomerMgmt.SelectCustomerRowByID(int.Parse(aGeneralBillDataRow["CustomerID"].ToString()));
                if (aUserDataRow == null)
                {
                    // MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EditBill-SelectCustomerRowByID Returned Null] " + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw new Exception("EditBill-SelectCustomerRowByID Returned Null");
                }
                PriceLevelComboBox.Text = PriceLevelsMgmt.SelectPriceLevelNameByID(int.Parse(aGeneralBillDataRow["PriceLevelID"].ToString()));
                if (PriceLevelComboBox.Text == null)
                {
                    //MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EditBill-SelectPriceLevelNameByID Returned Null] " + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw new Exception("EditBill-SelectPriceLevelNameByID Returned Null");
                }
                PhoneTxtBox.Text        = aUserDataRow["Phone1"].ToString();
                CustomerNameTxtBox.Text = aUserDataRow["Name"].ToString();
                CommentsTxtBox.Text     = aGeneralBillDataRow["Comments"].ToString();
                PriceLevelDiscount.Text = aGeneralBillDataRow["SalesDiscount"].ToString();
                DiscountPercTxtBox.Text = aGeneralBillDataRow["DiscountPerc"].ToString();
                SubtotalTxtBox.Text     = aGeneralBillDataRow["Subtotal"].ToString();
                NetAmountTxtBox.Text    = aGeneralBillDataRow["NetAmount"].ToString();
                TaxTxtBox.Text          = aGeneralBillDataRow["TotalTax"].ToString();
                DiscountBillTxtBox.Text = (double.Parse(DiscountPercTxtBox.Text) / 100 * double.Parse(NetAmountTxtBox.Text)).ToString();

                TotalDiscountTxtBox.Text = aGeneralBillDataRow["TotalDiscount"].ToString();
                TotalTxtBox.Text         = aGeneralBillDataRow["TotalPrice"].ToString();

                if (aGeneralBillDataRow["IsRevised"].ToString() == "1")
                {
                    ReviseInfoGB.Show();
                    ReviseDatelbl.Text       = DateTime.Parse(aGeneralBillDataRow["ReviseDate"].ToString()).ToShortDateString();
                    RevisedBylbl.Text        = aGeneralBillDataRow["RevisedBy"].ToString();
                    IsRevisedLbl.Visible     = true;
                    ReviseLossProfitLbl.Text = aGeneralBillDataRow["ReviseLoss"].ToString();
                }
                else
                {
                    ReviseInfoGB.Hide();
                }

                if (aGeneralBillDataRow["IsChecked"].ToString() == "1")
                {
                    ChkedByUserNameLbl.Text = aGeneralBillDataRow["CheckedBy"].ToString();
                    ChkDateLbl.Text         = DateTime.Parse(aGeneralBillDataRow["CheckedDate"].ToString()).ToShortDateString();
                    CheckInfoGB.Show();
                }
                else
                {
                    CheckInfoGB.Hide();
                }

                //PaymentInformation
                DataRow aMethodRow = PaymentMethodMgmt.SelectMethodRowByID(int.Parse(aGeneralBillDataRow["PaymentMethodID"].ToString()));
                if (aMethodRow == null)
                {
                    // MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EditBill-SelectMethodRowByID Returned Null] " + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw new Exception("EditBill-SelectMethodRowByID Returned Null");
                }
                PaymentMethodCheckBox.Text      = aMethodRow["Name"].ToString();
                PaymentMethodDescripTxtBox.Text = aMethodRow["Description"].ToString();//PaymentMethodMgmt.SelectDescriptionByID(int.Parse(PaymentMethodCheckBox.SelectedValue.ToString()));

                if (aMethodRow["IsCash"].ToString() == "1")
                {
                    CashPaymentGB.Show();
                    CashPaymentGB.BringToFront();
                    PayInVisaGB.Hide();
                    CheckGB.Hide();
                }
                else if (aMethodRow["IsCredit"].ToString() == "1")
                {
                    PayInVisaGB.Show();
                    PayInVisaGB.BringToFront();
                    CashPaymentGB.Hide();
                    CheckGB.Hide();
                }
                else
                {
                    CheckGB.Show();
                    CheckGB.BringToFront();
                    CashPaymentGB.Hide();
                    PayInVisaGB.Hide();
                    CheckNumberTxtBox.Text = aGeneralBillDataRow["CheckNumber"].ToString();

                    DataRow aCheckDataRow = ChecksMgmt.SelectCheckRowByNumber(int.Parse(aGeneralBillDataRow["CheckNumber"].ToString()));
                    if (aCheckDataRow == null)
                    {
                        //MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EditBill-SelectCheckRowByNumber Returned Null] " + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        throw new Exception("EditBill-SelectCheckRowByNumber Returned Null");
                    }

                    HolderNameTxtBox.Text    = aCheckDataRow["HolderName"].ToString();
                    CheckCommentsTxtBox.Text = aCheckDataRow["Comments"].ToString();
                    CheckDatePicker.Text     = aCheckDataRow["PaymentDate"].ToString();
                }

                DataRow aAccountRow = AccountsMgmt.SelectAccountRowByID(int.Parse(aGeneralBillDataRow["AccountID"].ToString()));
                if (aAccountRow == null)
                {
                    // MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EditBill-SelectAccountRowByID Returned Null] " + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw new Exception("EditBill-SelectAccountRowByID Returned Null");
                }
                else
                {
                    AccountComboBox.Text          = aAccountRow["Name"].ToString();
                    AccountDescriptionTxtBox.Text = aAccountRow["Description"].ToString();

                    CurrencyComboBox.Text = CurrencyMgmt.SelectCurrencyNameByID(int.Parse(aGeneralBillDataRow["CurrencyID"].ToString()));
                    if (CurrencyComboBox.Text == null)
                    {
                        MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EditBill-SelectCurrencyNameByID Returned Null] " + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Close();
                    }
                    CashInCurrency.Text       = CurrencyComboBox.Text;
                    CashInTxtBox.Text         = aGeneralBillDataRow["CashIn"].ToString();
                    BuyRateTxtBox.Text        = CurrencyMgmt.SelectBuyRateByID(int.Parse(aGeneralBillDataRow["CurrencyID"].ToString())).ToString();
                    SellRateTxtBox.Text       = CurrencyMgmt.SelectSellRateByID(int.Parse(aGeneralBillDataRow["CurrencyID"].ToString())).ToString();
                    ExchangeTxtBox.Text       = (double.Parse(CashInTxtBox.Text) * double.Parse(BuyRateTxtBox.Text) - double.Parse(TotalTxtBox.Text)).ToString();
                    CreditCardInfoTxtBox.Text = aGeneralBillDataRow["CreditCardInfo"].ToString();
                }

                if (aBillGeneralRow["IsCashCredit"].ToString() == "1")
                {
                    CashMethodComboBox.SelectedIndex = 1;

                    //CustomerAccountAmountlbl.Show();
                    CustomerAccountAmountTxtBox.Show();
                    CustomersAccountAmount.Show();

                    CustomerAccountAmountTxtBox.Text = aBillGeneralRow["CustomerAccountAmountOld"].ToString();
                    CashInTxtBox.Hide();
                    ExchangeTxtBox.Hide();
                    CashInLbl.Hide();
                    ExchangeLbl.Hide();
                    JODstatic.Hide();
                    CurrencyLbl.Hide();
                    IsCreditLbl.Show();
                }
                else
                {
                    CashMethodComboBox.SelectedIndex = 0;
                    //CustomerAccountAmountlbl.Hide();
                    CustomerAccountAmountTxtBox.Hide();
                    CustomersAccountAmount.Hide();

                    CashInTxtBox.Show();
                    ExchangeTxtBox.Show();
                    CashInLbl.Show();
                    ExchangeLbl.Show();
                    JODstatic.Show();
                    CurrencyLbl.Show();

                    IsCreditLbl.Hide();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EditBill-UpdateVariables] \n Exception: \n" + ex.ToString() + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }
        }
Пример #7
0
        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;
            }
        }
Пример #8
0
        public void UpdateVariables(DataRow aCustomerPaymentRow)
        {
            try
            {
                PaymentNumberTxtBox.Text  = aCustomerPaymentRow["PaymentNumber"].ToString();
                aCustomerPaymentRowGlobal = aCustomerPaymentRow;

                DateLbl.Text   = DateTime.Parse(aCustomerPaymentRow["Date"].ToString()).ToShortDateString();
                TimeLbl.Text   = aCustomerPaymentRow["Time"].ToString();
                TellerLbl.Text = UsersMgmt.SelectUserNameByID(int.Parse(aCustomerPaymentRow["TellerID"].ToString()));
                if (TellerLbl.Text == null)
                {
                    //MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EditBill-UsersMgmt.UsrById Returned Null] " + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw new Exception("[EditCustomerPayment-UsersMgmt.UsrById Returned Null]");
                }

                DataRow aCustomerRow = CustomerMgmt.SelectCustomerRowByID(int.Parse(aCustomerPaymentRow["CustomerID"].ToString()));
                if (aCustomerRow == null)
                {
                    // MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EditBill-SelectCustomerRowByID Returned Null] " + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw new Exception("EditCustomerPayment-SelectCustomerRowByID Returned Null");
                }

                CustomerPhoneTxtBox.Text = aCustomerRow["Phone1"].ToString();
                CustomerNameTxtBox.Text  = aCustomerRow["Name"].ToString();
                double OldBalance = double.Parse(aCustomerPaymentRow["OldUsrAccountAmount"].ToString());
                double Amount     = double.Parse(aCustomerPaymentRow["Amount"].ToString());
                double NewBalance = OldBalance - Amount;

                CustomerBalanceTxtBox.Text = OldBalance.ToString();
                NewBalanceTxtBox.Text      = NewBalance.ToString();

                aCustomerAccount = CustomersAccountsMgmt.SelectCustomerAccountRowByCusID(int.Parse(aCustomerPaymentRow["CustomerID"].ToString()));
                if (aCustomerAccount == null)
                {
                    // MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EditBill-SelectCustomerRowByID Returned Null] " + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw new Exception("EditCustomerPayment-SelectCustomerAccountRowByCusID Returned Null");
                }
                CurrentBalanceTxtBox.Text = double.Parse(aCustomerAccount["Amount"].ToString()).ToString();

                PaymentAmountTxtBox.Text = Amount.ToString();
                CommentsTxtBox.Text      = aCustomerPaymentRow["Comments"].ToString();

                if (aCustomerPaymentRow["IsRevised"].ToString() == "1")
                {
                    ReviseInfoGB.Show();
                    ReviseDatelbl.Text   = DateTime.Parse(aCustomerPaymentRow["ReviseDate"].ToString()).ToShortDateString();
                    ReviseTime.Text      = aCustomerPaymentRow["ReviseTime"].ToString();
                    RevisedBylbl.Text    = aCustomerPaymentRow["RevisedBy"].ToString();
                    IsRevisedLbl.Visible = true;
                }
                else
                {
                    ReviseInfoGB.Hide();
                }

                if (aCustomerPaymentRow["IsChecked"].ToString() == "1")
                {
                    ChkedByUserNameLbl.Text = aCustomerPaymentRow["CheckedBy"].ToString();
                    ChkDateLbl.Text         = DateTime.Parse(aCustomerPaymentRow["CheckDate"].ToString()).ToShortDateString();
                    CheckTime.Text          = aCustomerPaymentRow["CheckTime"].ToString();
                    CheckInfoGB.Show();
                }
                else
                {
                    CheckInfoGB.Hide();
                }

                //PaymentInformation
                DataRow aMethodRow = PaymentMethodMgmt.SelectMethodRowByID(int.Parse(aCustomerPaymentRow["PaymentMethodID"].ToString()));
                if (aMethodRow == null)
                {
                    // MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EditBill-SelectMethodRowByID Returned Null] " + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw new Exception("EditCustomerPayment-SelectMethodRowByID Returned Null");
                }
                PaymentMethodCheckBox.Text      = aMethodRow["Name"].ToString();
                PaymentMethodDescripTxtBox.Text = aMethodRow["Description"].ToString();//PaymentMethodMgmt.SelectDescriptionByID(int.Parse(PaymentMethodCheckBox.SelectedValue.ToString()));
                if (aMethodRow["IsCash"].ToString() == "1")
                {
                    CashPaymentGB.Show();
                    CashPaymentGB.BringToFront();
                    PayInVisaGB.Hide();
                    CheckGB.Hide();
                }
                else if (aMethodRow["IsCredit"].ToString() == "1")
                {
                    PayInVisaGB.Show();
                    PayInVisaGB.BringToFront();
                    CashPaymentGB.Hide();
                    CheckGB.Hide();
                }
                else
                {
                    CheckGB.Show();
                    CheckGB.BringToFront();
                    CashPaymentGB.Hide();
                    PayInVisaGB.Hide();
                    CheckNumberTxtBox.Text = aCustomerPaymentRow["CheckNumber"].ToString();
                    DataRow aCheckDataRow = ChecksMgmt.SelectCheckRowByNumber(int.Parse(aCustomerPaymentRow["CheckNumber"].ToString()));
                    if (aCheckDataRow == null)
                    {
                        //MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EditBill-SelectCheckRowByNumber Returned Null] " + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        throw new Exception("EditCustomerPayment-SelectCheckRowByNumber Returned Null");
                    }
                    HolderNameTxtBox.Text    = aCheckDataRow["HolderName"].ToString();
                    BanksComboBox.Text       = aCheckDataRow["BankName"].ToString();
                    CheckCommentsTxtBox.Text = aCheckDataRow["Comments"].ToString();
                    CheckDatePicker.Text     = aCheckDataRow["PaymentDate"].ToString();
                }

                DataRow aAccountRow = AccountsMgmt.SelectAccountRowByID(int.Parse(aCustomerPaymentRow["AccountID"].ToString()));
                if (aAccountRow == null)
                {
                    // MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EditBill-SelectAccountRowByID Returned Null] " + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw new Exception("EditCustomerPayment-SelectAccountRowByID Returned Null");
                }
                else
                {
                    AccountComboBox.Text          = aAccountRow["Name"].ToString();
                    AccountDescriptionTxtBox.Text = aAccountRow["Description"].ToString();
                    CreditCardInfoTxtBox.Text     = aCustomerPaymentRow["CreditCardInfo"].ToString();
                    AccountBalanceTxtBox.Text     = aAccountRow["Amount"].ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EditCustomerPayment-UpdateVariables] \n Exception: \n" + ex.ToString() + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }
        }
Пример #9
0
        public void UpdateVariables(DataRow aVendorPaymentRow)
        {
            try
            {
                PaymentNumberTxtBox.Text = aVendorPaymentRow["PaymentNumber"].ToString();
                aVendorPaymentRowGlobal  = aVendorPaymentRow;
                DateLbl.Text             = DateTime.Parse(aVendorPaymentRow["Date"].ToString()).ToShortDateString();
                TimeLbl.Text             = aVendorPaymentRow["Time"].ToString();
                TellerLbl.Text           = UsersMgmt.SelectUserNameByID(int.Parse(aVendorPaymentRow["TellerID"].ToString()));

                DataRow aVendorRow = VendorsMgmt.SelectVendorRowByID(int.Parse(aVendorPaymentRow["VendorID"].ToString()));
                if (aVendorRow == null)
                {
                    throw new Exception("LOWER in aVendorRow==null");
                }
                VendorNameTxtBox.Text    = aVendorRow["Name"].ToString();
                VendorCompanyTxtBox.Text = aVendorRow["Company"].ToString();
                double OldBalance = double.Parse(aVendorPaymentRow["OldVendorAccountAmount"].ToString());
                double Amount     = double.Parse(aVendorPaymentRow["Amount"].ToString());
                double NewBalance = OldBalance - Amount;//+ because its reversed
                VendorAccountBalanceTxtBox.Text = OldBalance.ToString();
                NewBalanceTxtBox.Text           = NewBalance.ToString();

                aAccount = AccountsMgmt.SelectAccountRowByID(int.Parse(aVendorPaymentRow["MyAccountID"].ToString()));
                if (aAccount == null)
                {
                    throw new Exception("LOWER in aAccount == null");
                }
                AccountDescriptionTxtBox.Text = aAccount["Description"].ToString();

                aVendorAccount = VendorsAccountsMgmt.SelectVendorAccountRowByVendorID(int.Parse(aVendorPaymentRow["VendorID"].ToString()));
                if (aVendorAccount == null)
                {
                    throw new Exception("LOWER in aVendorAccount == null");
                }
                CurrentBalanceTxtBox.Text = double.Parse(aVendorAccount["Amount"].ToString()).ToString();
                PaymentAmountTxtBox.Text  = Amount.ToString();
                CommentsTxtBox.Text       = aVendorPaymentRow["Comments"].ToString();
                if (aVendorPaymentRow["IsRevised"].ToString() == "1")
                {
                    ReviseInfoGB.Show();
                    ReviseDatelbl.Text   = DateTime.Parse(aVendorPaymentRow["ReviseDate"].ToString()).ToShortDateString();
                    ReviseTime.Text      = aVendorPaymentRow["ReviseTime"].ToString();
                    RevisedBylbl.Text    = aVendorPaymentRow["RevisedBy"].ToString();
                    IsRevisedLbl.Visible = true;
                }
                else
                {
                    ReviseInfoGB.Hide();
                }

                if (aVendorPaymentRow["IsChecked"].ToString() == "1")
                {
                    ChkedByUserNameLbl.Text = aVendorPaymentRow["CheckedBy"].ToString();
                    ChkDateLbl.Text         = DateTime.Parse(aVendorPaymentRow["CheckDate"].ToString()).ToShortDateString();
                    CheckTime.Text          = aVendorPaymentRow["CheckTime"].ToString();
                    CheckInfoGB.Show();
                }
                else
                {
                    CheckInfoGB.Hide();
                }

                //PaymentInformation
                DataRow aMethodRow = PaymentMethodMgmt.SelectMethodRowByID(int.Parse(aVendorPaymentRow["PaymentMethodID"].ToString()));
                if (aMethodRow == null)
                {
                    throw new Exception("LOWER in aMethodRow == null");
                }
                PaymentMethodCheckBox.Text      = aMethodRow["Name"].ToString();
                PaymentMethodDescripTxtBox.Text = aMethodRow["Description"].ToString();//PaymentMethodMgmt.SelectDescriptionByID(int.Parse(PaymentMethodCheckBox.SelectedValue.ToString()));
                if (aMethodRow["IsCash"].ToString() == "1")
                {
                    CashPaymentGB.Show();
                    CashPaymentGB.BringToFront();
                    PayInVisaGB.Hide();
                    CheckGB.Hide();
                }
                else if (aMethodRow["IsCredit"].ToString() == "1")
                {
                    PayInVisaGB.Show();
                    PayInVisaGB.BringToFront();
                    CashPaymentGB.Hide();
                    CheckGB.Hide();
                }
                else
                {
                    CheckGB.Show();
                    CheckGB.BringToFront();
                    CashPaymentGB.Hide();
                    PayInVisaGB.Hide();
                    CheckNumberTxtBox.Text = aVendorPaymentRow["CheckNumber"].ToString();
                    DataRow aCheckDataRow = ChecksMgmt.SelectCheckRowByNumber(int.Parse(aVendorPaymentRow["CheckNumber"].ToString()));
                    if (aCheckDataRow == null)
                    {
                        throw new Exception("LOWER in aCheckDataRow == null");
                    }
                    HolderNameTxtBox.Text    = aCheckDataRow["HolderName"].ToString();
                    CheckCommentsTxtBox.Text = aCheckDataRow["Comments"].ToString();
                    CheckDatePicker.Text     = DateTime.Parse(aCheckDataRow["PaymentDate"].ToString()).ToShortDateString();
                }
                DataRow aAccountRow = AccountsMgmt.SelectAccountRowByID(int.Parse(aVendorPaymentRow["MyAccountID"].ToString()));
                if (aAccountRow == null)
                {
                    throw new Exception("LOWER in aAccountRow == null");
                }
                AccountComboBox.Text          = aAccountRow["Name"].ToString();
                AccountDescriptionTxtBox.Text = aAccountRow["Description"].ToString();
                CreditCardInfoTxtBox.Text     = aVendorPaymentRow["CreditCardInfo"].ToString();
                AccountBalanceTxtBox.Text     = aAccountRow["Amount"].ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [EDIT Vendor Payment: UpdateVariables] \n Exception: \n" + ex.ToString() + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
                throw;
            }
        }
Пример #10
0
        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);
        }
Пример #11
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);
            }
        }