예제 #1
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;
            }
        }
예제 #2
0
        private void VendorNameComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (VendorNameComboBox.SelectedValue != null)
                {
                    semaphore = true;

                    aVendorRow = VendorsMgmt.SelectVendorRowByID(int.Parse(VendorNameComboBox.SelectedValue.ToString()));
                    if (aVendorRow == null)
                    {
                        throw new Exception("Vendor Row==null");
                    }

                    VendorCompanyTxtBox.Text = aVendorRow["Company"].ToString();
                    VendorID = int.Parse(VendorNameComboBox.SelectedValue.ToString());

                    aVendorAccountRow = VendorsAccountsMgmt.SelectVendorAccountRowByVendorID(int.Parse(VendorNameComboBox.SelectedValue.ToString()));
                    if (aVendorAccountRow == null)
                    {
                        VendorAccountBalanceTxtBox.Text = "Vendor Have No Account";
                        VendorDoNotHaveAccount          = true;
                    }
                    else
                    {
                        VendorAccountBalanceTxtBox.Text = aVendorAccountRow["Amount"].ToString();
                        Balance = Double.Parse(aVendorAccountRow["Amount"].ToString());
                        VendorDoNotHaveAccount = false;
                    }
                    semaphore = false;
                }
                else
                {
                    //EXCEPTION
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [VendorNameComboBox_SelectedIndexChanged] \n Exception: \n" + ex.ToString() + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }
        }
예제 #3
0
        private void VendorNameComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (VendorNameComboBox.SelectedValue == null)
            {
                return;
            }
            DataRow aVendorRow = VendorsMgmt.SelectVendorRowByID(int.Parse(VendorNameComboBox.SelectedValue.ToString()));

            VendorCompanyTxtBox.Text = aVendorRow["Company"].ToString();

            DataRow aVendorAccountRow = VendorsAccountsMgmt.SelectVendorAccountRowByVendorID(int.Parse(VendorNameComboBox.SelectedValue.ToString()));

            if (aVendorAccountRow == null)
            {
                VendorAccountBalanceTxtBox.Text = "Vendor Have No Account";
                CustomerDoNotHaveAccount        = true;
            }
            else
            {
                VendorAccountBalanceTxtBox.Text = aVendorAccountRow["Amount"].ToString();
                CustomerDoNotHaveAccount        = false;
            }
        }
예제 #4
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;
     }
 }
예제 #5
0
        public bool VendorsBalanceListReport(bool PrintToThermal, bool ExportToPdf = false, bool ExportToExcel = false, string ExportPath = "", bool TableBorder = false, bool Preview = false, bool colored = false)
        {
            List <DataTable> aDTlist = new List <DataTable>();

            DataTable aVendorsTable = VendorsMgmt.SelectAllVendors();

            aVendorsTable.Columns.Add("Balance");
            DataTable aVendorAccountTable = VendorsAccountsMgmt.SelectAll();

            if (aVendorsTable.Rows.Count > 0)
            {
                int RowNum = 0;
                foreach (DataRow r in aVendorsTable.Rows)
                {
                    if (aVendorAccountTable != null)
                    {
                        for (int i = 0; i < aVendorAccountTable.Rows.Count; i++)
                        {
                            if (int.Parse(aVendorsTable.Rows[RowNum]["ID"].ToString()) == int.Parse(aVendorAccountTable.Rows[i]["VendorID"].ToString()))
                            {
                                aVendorsTable.Rows[RowNum]["Balance"] = aVendorAccountTable.Rows[i]["Amount"].ToString();
                            }
                        }
                    }
                    RowNum++;
                }
                aVendorsTable.Columns.Remove("ID");
                if (TableBorder)
                {
                    aVendorsTable.Columns[0].ColumnName = "[Border=true1]" + aVendorsTable.Columns[0].ColumnName;
                }

                //REMOVING EMPTY COLUMNS
                List <string> aColumnsToRemove = new List <string>();
                foreach (DataColumn aColumn in aVendorsTable.Columns)
                {
                    bool ColumnEmpty = false;
                    for (int i = 0; i < aVendorsTable.Rows.Count - 1; i++)
                    {
                        if (aVendorsTable.Rows[i][aColumn].ToString().Trim() == "")
                        {
                            ColumnEmpty = true;
                        }
                        else
                        {
                            ColumnEmpty = false;
                            break;
                        }
                    }
                    if (ColumnEmpty)
                    {
                        aColumnsToRemove.Add(aColumn.ColumnName);
                    }
                }
                for (int i = 0; i < aColumnsToRemove.Count; i++)
                {
                    aVendorsTable.Columns.Remove(aColumnsToRemove[i]);
                }
                //END REMOVING EMPTY COLUMNS


                aDTlist.Add(aVendorsTable);

                List <string> aHeaderList = ReportsHelper.ImportReportHeader(0, 1);
                List <string> aFooterList = ReportsHelper.ImportReportHeader(1, 1);
                aHeaderList.Add("<td>" + SharedVariables.Line_Solid_10px_Black);
                aHeaderList.Add("<b><font size=4>" + "Vendors Balances List" + " </font>");
                aHeaderList.Add("<td>" + SharedVariables.Line_Solid_10px_Black);

                if (Preview)
                {
                    PrintingManager.Instance.PrintTables(aDTlist, aHeaderList, aFooterList, ReportsHelper.TempOutputPath, ReportsHelper.TempOutputPath, PrintToThermal, false, false, "", false, "", colored);
                    return(true);
                }

                else if (ExportToPdf)
                {
                    PrintingManager.Instance.PrintTables(aDTlist, aHeaderList, aFooterList, ReportsHelper.TempOutputPath, ReportsHelper.TempOutputPath, PrintToThermal, false, true, ExportPath, false, "", colored);
                    return(true);
                }
                else if (ExportToExcel)
                {
                    PrintingManager.Instance.PrintTables(aDTlist, aHeaderList, aFooterList, ReportsHelper.TempOutputPath, ReportsHelper.TempOutputPath, PrintToThermal, false, false, "", true, ExportPath, colored);
                    return(true);
                }
                else if (PrintToThermal)
                {
                    PrintingManager.Instance.PrintTables(aDTlist, aHeaderList, aFooterList, ReportsHelper.TempOutputPath, ReportsHelper.TempOutputPath, true, true);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false); //there is no items in the customer table
            }
        }
예제 #6
0
파일: AddVendor.cs 프로젝트: SariSultan/RMS
        private void AddVendorBtn_Click(object sender, EventArgs e)
        {
            try
            {
                if (CheckRequiredFields())
                {
                    if (!VendorsMgmt.IsVendorExist(NameTxtBox.Text))
                    {
                        Vendors aVendor = new Vendors();
                        aVendor.Vendor_Name     = NameTxtBox.Text;
                        aVendor.Vendor_Email    = EmailTxtBox.Text;
                        aVendor.Vendor_Location = LocationTxtBox.Text;
                        aVendor.Vendor_Phone1   = Phone1TxtBox.Text;
                        aVendor.Vendor_Phone2   = Phone2TxtBox.Text;
                        aVendor.Vendor_Company  = CompanyTxtBox.Text;

                        DateTime aDate = DateTime.Now;
                        aVendor.Vendor_Start_Date = aDate.Date.ToShortDateString();

                        if (VendorsMgmt.AddVendor(aVendor))
                        {
                            int VendorID = VendorsMgmt.SelectVendorIDByName(aVendor.Vendor_Name);

                            if (VendorID == 0)
                            {
                                MessageBox.Show(MsgTxt.UnexpectedError + " \n [DataBase ERROR 1 IN[AddVendorBtn_Click] VendorID=0", MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }

                            if (!VendorsAccountsMgmt.InserVendorAccount(VendorID))
                            {
                                MessageBox.Show(MsgTxt.UnexpectedError + " \n [DataBase ERROR 2 IN[AddVendorBtn_Click] ", MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                            else
                            {
                                int AccountID = int.Parse(VendorsAccountsMgmt.SelectVendorAccountRowByVendorID(VendorID)["ID"].ToString());
                                VendorsAccountsMgmt.UpdateAccountAmountByAccountID(AccountID, double.Parse(OpenBalTxtBox.Text));
                            }

                            MessageBox.Show(MsgTxt.AddedSuccessfully, MsgTxt.AddedSuccessfully, MessageBoxButtons.OK, MessageBoxIcon.Information);

                            DialogResult ret;
                            ret = MessageBox.Show(MsgTxt.AddAnotherItemTxt, MsgTxt.InformationCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                            if (ret == DialogResult.Yes)
                            {
                                foreach (TextBox aTextBox in this.CustomerInfoGB.Controls.OfType <TextBox>())
                                {
                                    aTextBox.Text = "";
                                }
                            }
                            else
                            {
                                this.Close();
                            }
                        }
                        else
                        {
                            MessageBox.Show(MsgTxt.UnexpectedError + " \n [DataBase ERROR 3 IN[AddVendorBtn_Click]", MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show(MsgTxt.VendorTxt + " [ " + NameTxtBox.Text + " ] " + MsgTxt.AlreadyUsedTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [AddVendorBtn_Click] \n Exception: \n" + ex.ToString() + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }
        }
예제 #7
0
        private void ListVendorsBtn_Click(object sender, EventArgs e)
        {
            try
            {
                aVendorTable = VendorsMgmt.SelectAllVendors();
                if (aVendorTable == null)
                {
                    MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [ListVendorsBtn_Click:DB-ERROR  aVendorTable=null] \n  \n", MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                aVendorAccountTable = VendorsAccountsMgmt.SelectAll();
                if (aVendorAccountTable == null && aVendorTable.Rows.Count != 0)
                {
                    MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [ListVendorsBtn_Click:DB-ERROR  aVendorAccountTable=null] \n  \n", MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                TotalITemsTxtBox.Text = aVendorTable.Rows.Count.ToString();
                if (aVendorTable.Rows.Count > 0)
                {
                    pagesnumber = (int)aVendorTable.Rows.Count / ItemsPerPage;
                    if ((double.Parse(aVendorTable.Rows.Count.ToString()) / ItemsPerPage - int.Parse(aVendorTable.Rows.Count.ToString()) / ItemsPerPage) > 0)
                    {
                        pagesnumber++;
                    }

                    RowNum = 0;
                    ListVendorsDGView.Rows.Clear();

                    foreach (DataRow r in aVendorTable.Rows)
                    {
                        if (ListVendorsDGView.Rows.Count < ItemsPerPage)
                        {
                            ListVendorsDGView.Rows.Add();
                            ListVendorsDGView.Rows[RowNum].Cells["Namecol"].Value     = aVendorTable.Rows[RowNum]["Name"].ToString();
                            ListVendorsDGView.Rows[RowNum].Cells["Locationcol"].Value = aVendorTable.Rows[RowNum]["Location"].ToString();
                            ListVendorsDGView.Rows[RowNum].Cells["Phone1"].Value      = aVendorTable.Rows[RowNum]["Phone1"].ToString();
                            ListVendorsDGView.Rows[RowNum].Cells["Phone2"].Value      = aVendorTable.Rows[RowNum]["Phone2"].ToString();
                            ListVendorsDGView.Rows[RowNum].Cells["Email"].Value       = aVendorTable.Rows[RowNum]["Email"].ToString();
                            ListVendorsDGView.Rows[RowNum].Cells["Company"].Value     = aVendorTable.Rows[RowNum]["Company"].ToString();
                            ListVendorsDGView.Rows[RowNum].Cells["StartDate"].Value   = Convert.ToDateTime(aVendorTable.Rows[RowNum]["StartDate"].ToString()).ToShortDateString();
                            if (aVendorTable != null)
                            {
                                for (int i = 0; i < aVendorAccountTable.Rows.Count; i++)
                                {
                                    if (int.Parse(aVendorTable.Rows[RowNum]["ID"].ToString()) == int.Parse(aVendorAccountTable.Rows[i]["VendorID"].ToString()))
                                    {
                                        ListVendorsDGView.Rows[RowNum].Cells["AccountAmount"].Value = aVendorAccountTable.Rows[i]["Amount"].ToString();
                                    }
                                }
                            }
                            RowNum++;
                        }
                    }
                    PageOfTotalTxtBox.Text = "1/" + pagesnumber.ToString();
                    currentpage            = 1;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [ListVendorsBtn_Click] \n Exception: \n" + ex.ToString(), MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw;
            }
        }
예제 #8
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;
            }
        }
예제 #9
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);
            }
        }