Пример #1
0
 private void UpdateVendorBtn_Click(object sender, EventArgs e)
 {
     try
     {
         if (CheckRequiredFields())
         {
             if (!VendorsMgmt.IsVendorExist(NameTxtBox.Text) && NameTxtBox.Text != OldNameLbl.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;
                 if (VendorsMgmt.UpdateVendorByName(OldName, aVendor))
                 {
                     MessageBox.Show(MsgTxt.UpdateSuccessfully, MsgTxt.UpdateSuccessfully, MessageBoxButtons.OK, MessageBoxIcon.Information);
                     this.Close();
                 }
                 else
                 {
                     MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [DB-ERROR in:VendorsMgmt.UpdateVendorByName returned false] \n Exception: " + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                     this.Close();
                 }
             }
             else
             {
                 MessageBox.Show(MsgTxt.VendorTxt + " " + MsgTxt.AlreadyUsedTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [UpdateVendorBtn_Click] \n Exception: \n" + ex.ToString() + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
         throw;
     }
 }
Пример #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();
            }
        }