Beispiel #1
0
        private void btnEditEdit_Click(object sender, EventArgs e)
        {
            if (btnEditEditCust.Text == "EDIT CUSTOMER")
            {
                enableEditTxtboxes();

                btnEditEditCust.Text = "Save";
            }
            else
            {
                MyCustomer myCustomer = new MyCustomer();
                bool       ok         = true;
                errP.Clear();


                try
                {
                    myCustomer.Title = cmbEditTitle.SelectedItem.ToString();
                }
                catch (MyException MyEx)
                {
                    ok = false;
                    errP.SetError(cmbEditTitle, MyEx.toString());
                }

                try
                {
                    myCustomer.Surname = txtEditSurname.Text.Trim();
                }

                catch (MyException MyEx)
                {
                    ok = false;
                    errP.SetError(txtEditSurname, MyEx.toString());
                }

                try
                {
                    myCustomer.Forename = txtEditForename.Text.Trim();
                }

                catch (MyException MyEx)
                {
                    ok = false;
                    errP.SetError(txtEditForename, MyEx.toString());
                }

                try
                {
                    myCustomer.Street = txtEditAddress.Text.Trim();
                }

                catch (MyException MyEx)
                {
                    ok = false;
                    errP.SetError(txtEditAddress, MyEx.toString());
                }

                try
                {
                    myCustomer.Town = txtEditTown.Text.Trim();
                }

                catch (MyException MyEx)
                {
                    ok = false;
                    errP.SetError(txtEditTown, MyEx.toString());
                }

                try
                {
                    myCustomer.County = txtEditCounty.Text.Trim();
                }

                catch (MyException MyEx)
                {
                    ok = false;
                    errP.SetError(txtEditCounty, MyEx.toString());
                }

                try
                {
                    myCustomer.Postcode = txtEditPostcode.Text.Trim();
                }

                catch (MyException MyEx)
                {
                    ok = false;
                    errP.SetError(txtEditPostcode, MyEx.toString());
                }

                try
                {
                    myCustomer.TelNo = txtEditTel.Text.Trim();
                }

                catch (MyException MyEx)
                {
                    ok = false;
                    errP.SetError(txtEditTel, MyEx.toString());
                }

                try
                {
                    myCustomer.Email = txtEditEmail.Text.Trim();
                }

                catch (MyException MyEx)
                {
                    ok = false;
                    errP.SetError(txtEditEmail, MyEx.toString());
                }

                try
                {
                    if (ok)
                    {
                        drCustomer.BeginEdit();
                        drCustomer["CustTitle"]   = myCustomer.Title;
                        drCustomer["CustFname"]   = myCustomer.Forename;
                        drCustomer["CustSname"]   = myCustomer.Surname;
                        drCustomer["CustAddress"] = myCustomer.Street;
                        drCustomer["TownCity"]    = myCustomer.Town;
                        drCustomer["County"]      = myCustomer.County;
                        drCustomer["CustPCode"]   = myCustomer.Postcode;
                        drCustomer["CustTel"]     = myCustomer.TelNo;
                        drCustomer["CustEmail"]   = myCustomer.Email;

                        drCustomer.EndEdit();
                        daCustomer.Update(dsKaizen, "Customer");

                        MessageBox.Show("Customer Details Updated", "Customer");

                        disableEditTxtboxes();

                        btnEditEditCust.Text      = "EDIT CUSTOMER";
                        tabCustomer.SelectedIndex = 0;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("" + ex.TargetSite + "" + ex.Message, "Error !", MessageBoxButtons.AbortRetryIgnore,
                                    MessageBoxIcon.Error);
                }
            }
        }
Beispiel #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            MyCustomer myCustomer = new MyCustomer();
            bool       ok         = true;

            errP.Clear();
            try
            {
                myCustomer.CustID = Convert.ToInt32(lblAdCustNo.Text.Trim());
            }
            catch (MyException MyEx)
            {
                ok = false;
                errP.SetError(lblAdCustNo, MyEx.toString());
            }

            try
            {
                myCustomer.Title = cmbAddTitle.SelectedItem.ToString();
            }
            catch (MyException MyEx)
            {
                ok = false;
                errP.SetError(cmbAddTitle, MyEx.toString());
            }


            try
            {
                myCustomer.Surname = txtAddSurname.Text.Trim();
            }

            catch (MyException MyEx)
            {
                ok = false;
                errP.SetError(txtAddSurname, MyEx.toString());
            }

            try
            {
                myCustomer.Forename = txtAddForename.Text.Trim();
            }

            catch (MyException MyEx)
            {
                ok = false;
                errP.SetError(txtAddForename, MyEx.toString());
            }

            try
            {
                myCustomer.Street = txtAddAddress.Text.Trim();
            }

            catch (MyException MyEx)
            {
                ok = false;
                errP.SetError(txtAddAddress, MyEx.toString());
            }

            try
            {
                myCustomer.Town = txtAddTown.Text.Trim();
            }

            catch (MyException MyEx)
            {
                ok = false;
                errP.SetError(txtAddTown, MyEx.toString());
            }

            try
            {
                myCustomer.County = txtAddCounty.Text.Trim();
            }

            catch (MyException MyEx)
            {
                ok = false;
                errP.SetError(txtAddCounty, MyEx.toString());
            }

            try
            {
                myCustomer.Postcode = txtAddPostcode.Text.Trim();
            }

            catch (MyException MyEx)
            {
                ok = false;
                errP.SetError(txtAddPostcode, MyEx.toString());
            }

            try
            {
                myCustomer.TelNo = txtAddTel.Text.Trim();
            }

            catch (MyException MyEx)
            {
                ok = false;
                errP.SetError(txtAddTel, MyEx.toString());
            }

            try
            {
                myCustomer.Email = txtAddEmail.Text.Trim();
            }

            catch (MyException MyEx)
            {
                ok = false;
                errP.SetError(txtAddEmail, MyEx.toString());
            }

            try
            {
                if (ok)
                {
                    drCustomer                = dsKaizen.Tables["Customer"].NewRow();
                    drCustomer["CustID"]      = myCustomer.CustID;
                    drCustomer["CustTitle"]   = myCustomer.Title;
                    drCustomer["CustFname"]   = myCustomer.Forename;
                    drCustomer["CustSname"]   = myCustomer.Surname;
                    drCustomer["CustAddress"] = myCustomer.Street;
                    drCustomer["TownCity"]    = myCustomer.Town;
                    drCustomer["County"]      = myCustomer.County;
                    drCustomer["CustPCode"]   = myCustomer.Postcode;
                    drCustomer["CustTel"]     = myCustomer.TelNo;
                    drCustomer["CustEmail"]   = myCustomer.Email;

                    dsKaizen.Tables["Customer"].Rows.Add(drCustomer);
                    daCustomer.Update(dsKaizen, "Customer");

                    MessageBox.Show("Customer Added");

                    if (MessageBox.Show("Do you wish to add another customer?", "Add Customer", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                    {
                        clearAddForm();

                        getNumber(dsKaizen.Tables["Customer"].Rows.Count);
                    }
                    else
                    {
                        tabCustomer.SelectedIndex = 0;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("" + ex.TargetSite + "" + ex.Message, "Error !", MessageBoxButtons.AbortRetryIgnore,
                                MessageBoxIcon.Error);
            }
        }