Ejemplo n.º 1
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;
     }
 }
Ejemplo n.º 2
0
        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();
            }
        }