예제 #1
0
        private void UpdateCustomerBtn_Click(object sender, EventArgs e)
        {
            try
            {
                if (NameTxtBox.Text.ToUpper() == "CASH")
                {
                    return;
                }
                if (Validators.TxtBoxNotEmpty(NameTxtBox.Text) && Validators.TxtBoxNotEmpty(Phone1TxtBox.Text))
                {
                    Phone1TxtBox.BackColor = PhoneColor;
                    NameTxtBox.BackColor   = NameColor;

                    if (!CustomerMgmt.IsPhoneUsed(Phone1TxtBox.Text) || Phone1TxtBox.Text == Phone1ComboBox.Text)
                    {
                        Customer aCustomer = new Customer();
                        aCustomer.Customer_Name    = NameTxtBox.Text;
                        aCustomer.Customer_Address = AddressTxtBox.Text;
                        aCustomer.Customer_Email   = EmailTxtBox.Text;
                        aCustomer.Customer_Phone1  = Phone1TxtBox.Text;
                        aCustomer.Customer_ID      = CustomerID;
                        DataRow CusAccount = CustomersAccountsMgmt.SelectCustomerAccountRowByCusID(CustomerID);

                        if (MakeUserAccountChkBox.Checked == false)
                        {
                            if (CusAccount != null)
                            {
                                Err1.Show();
                            }
                            else
                            {
                                CustomerMgmt.UpdateInfomationByID(aCustomer);
                                MessageBox.Show(MsgTxt.UpdateSuccessfully, MsgTxt.UpdateSuccessfully, MessageBoxButtons.OK, MessageBoxIcon.Information);
                                this.Close();
                            }
                        }
                        else
                        {
                            if (CusAccount == null)
                            {
                                if (!CustomersAccountsMgmt.InsertCustomerAccount(CustomerID))
                                {
                                    MessageBox.Show(MsgTxt.UnexpectedError, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                            if (!CustomerMgmt.UpdateInfomationByID(aCustomer))
                            {
                                MessageBox.Show(MsgTxt.UnexpectedError, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                throw new Exception("Database Error in [Update Information By ID]");
                            }
                            else
                            {
                                MessageBox.Show(MsgTxt.UpdateSuccessfully, MsgTxt.AddedSuccessfully, MessageBoxButtons.OK, MessageBoxIcon.Information);
                                this.Close();
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show(MsgTxt.PhoneInUse, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    MessageBox.Show(MsgTxt.PleaseAddAllRequiredFields, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);

                    if (!Validators.TxtBoxNotEmpty(Phone1TxtBox.Text))
                    {
                        Phone1TxtBox.BackColor = SharedVariables.TxtBoxRequiredColor;
                        Phone1TxtBox.Focus();
                    }
                    else
                    {
                        Phone1TxtBox.BackColor = PhoneColor;
                    }

                    if (!Validators.TxtBoxNotEmpty(NameTxtBox.Text))
                    {
                        NameTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor;
                        NameTxtBox.Focus();
                    }
                    else
                    {
                        NameTxtBox.BackColor = NameColor;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [UpdateCustomerBtn_Click] \n Exception: \n" + ex.ToString() + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }
        }
예제 #2
0
        private void AddCustomerBtn_Click(object sender, EventArgs e)
        {
            try
            {
                double TestParserBal = 0.00;
                if (Validators.TxtBoxNotEmpty(NameTxtBox.Text) && Validators.TxtBoxNotEmpty(Phone1TxtBox.Text))
                {
                    if (MakeUserAccountChkBox.Checked)
                    {
                        if (!double.TryParse(OpenBalTxtBox.Text, out TestParserBal))
                        {
                            MessageBox.Show(MsgTxt.PleaseAddAllRequiredFields, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }
                    if (!CustomerMgmt.IsPhoneUsed(Phone1TxtBox.Text))
                    {
                        Customer aCustomer = new Customer();
                        aCustomer.Customer_Name    = NameTxtBox.Text;
                        aCustomer.Customer_Address = AddressTxtBox.Text;
                        aCustomer.Customer_Email   = EmailTxtBox.Text;
                        aCustomer.Customer_Phone1  = Phone1TxtBox.Text;

                        if (CustomerMgmt.InsertCustomer(aCustomer))
                        {
                            if (MakeUserAccountChkBox.Checked)
                            {
                                int CustomerID = CustomerMgmt.SelectCustomerIDByPhone1(Phone1TxtBox.Text);
                                if (!CustomersAccountsMgmt.InsertCustomerAccount(CustomerID))
                                {
                                    MessageBox.Show(MsgTxt.UnexpectedError, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                                int AccountID = int.Parse(CustomersAccountsMgmt.SelectCustomerAccountRowByCusID(CustomerID)["ID"].ToString());
                                CustomersAccountsMgmt.UpdateAccountAmountByAccountID(AccountID, TestParserBal);
                            }

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

                            DialogResult ret;
                            ret = MessageBox.Show(MsgTxt.AddAnotherItemTxt, MsgTxt.InformationCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                            if (ret == DialogResult.Yes)
                            {
                                foreach (TextBox aTextBox in this.CustomerInfoGB.Controls.OfType <TextBox>())
                                {
                                    aTextBox.Text = "";
                                }
                            }
                            else
                            {
                                this.Close();
                            }
                        }
                        else
                        {
                            MessageBox.Show(MsgTxt.UnexpectedError, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show(MsgTxt.PhoneInUse, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    MessageBox.Show(MsgTxt.PleaseAddAllRequiredFields, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);

                    if (!Validators.TxtBoxNotEmpty(Phone1TxtBox.Text))
                    {
                        Phone1TxtBox.BackColor = SharedVariables.TxtBoxRequiredColor;
                        Phone1TxtBox.Focus();
                    }
                    else
                    {
                        Phone1TxtBox.BackColor = PhoneColor;
                    }

                    if (!Validators.TxtBoxNotEmpty(NameTxtBox.Text))
                    {
                        NameTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor;
                        NameTxtBox.Focus();
                    }
                    else
                    {
                        NameTxtBox.BackColor = NameColor;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [AddCustomerBtn_Click] \n Exception: \n" + ex.ToString() + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }
        }