Ejemplo n.º 1
0
        private void picSaveADDSupp_Click(object sender, EventArgs e)
        {
            MySupplier mySupp = new MySupplier();
            bool       ok     = true;

            errP.Clear();

            try
            {
                mySupp.SupplierID = lblSupplierID.Text.Trim();
            }
            catch (MyException MyEx)
            {
                ok = false;
                errP.SetError(lblSupplierID, MyEx.toString());
            }
            try
            {
                mySupp.SupplierName = txtSuppName.Text.Trim();
            }
            catch (MyException MyEx)
            {
                ok = false;
                errP.SetError(txtSuppName, MyEx.toString());
            }
            try
            {
                mySupp.SupplierAddress = txtSuppAddress.Text.Trim();
            }
            catch (MyException MyEx)
            {
                ok = false;
                errP.SetError(txtSuppAddress, MyEx.toString());
            }
            try
            {
                mySupp.SupplierTown = txtSuppTown.Text.Trim();
            }
            catch (MyException MyEx)
            {
                ok = false;
                errP.SetError(txtSuppTown, MyEx.toString());
            }
            try
            {
                mySupp.SupplierCounty = txtSuppCounty.Text.Trim();
            }
            catch (MyException MyEx)
            {
                ok = false;
                errP.SetError(txtSuppCounty, MyEx.toString());
            }
            try
            {
                mySupp.SupplierPostCode = txtSuppPC.Text.Trim();
            }
            catch (MyException MyEx)
            {
                ok = false;
                errP.SetError(txtSuppPC, MyEx.toString());
            }
            try
            {
                mySupp.SupplierEmail = txtSuppEmail.Text.Trim();
            }
            catch (MyException MyEx)
            {
                ok = false;
                errP.SetError(txtSuppEmail, MyEx.toString());
            }
            try
            {
                mySupp.SupplierTelNo = txtSuppTel.Text.Trim();
            }
            catch (MyException MyEx)
            {
                ok = false;
                errP.SetError(txtSuppTel, MyEx.toString());
            }

            //Try Adding
            try
            {
                if (ok)
                {
                    drSupplier = dsBelfray.Tables["Supplier"].NewRow();
                    drSupplier["supplierID"]       = mySupp.SupplierID;
                    drSupplier["supplierName"]     = mySupp.SupplierName;
                    drSupplier["supplierAddress"]  = mySupp.SupplierAddress;
                    drSupplier["supplierTown"]     = mySupp.SupplierTown;
                    drSupplier["supplierCounty"]   = mySupp.SupplierCounty;
                    drSupplier["supplierPostCode"] = mySupp.SupplierPostCode;
                    drSupplier["supplierEmail"]    = mySupp.SupplierEmail;
                    drSupplier["supplierTelNo"]    = mySupp.SupplierTelNo;
                    dsBelfray.Tables["Supplier"].Rows.Add(drSupplier);
                    daSupplier.Update(dsBelfray, "Supplier");

                    MessageBox.Show("Supplier Added");
                    if (MessageBox.Show("Do you wish to add another Supplier?", "AddSupplier", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                    {
                        clearSuppPanel();
                        test = true;
                    }
                    else
                    {
                        pnlSuppDetails.Enabled = false;
                        pnlDetails.Enabled     = true;
                        clearSuppPanel();
                        test = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("" + ex.TargetSite + "", ex.Message + "Error!", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
            }
        }
        private void PicSaveSupplier_Click(object sender, EventArgs e)
        {
            drSupplier = dsBelfray.Tables["Supplier"].Rows.Find(lblESupplierID.Text);

            MySupplier mySupp = new MySupplier();
            bool       ok     = true;

            errP.Clear();

            try
            {
                mySupp.SupplierID = lblESupplierID.Text.Trim();
            }
            catch (MyException MyEx)
            {
                ok = false;
                errP.SetError(lblESupplierID, MyEx.toString());
            }
            try
            {
                mySupp.SupplierName = txtSuppName.Text.Trim();
            }
            catch (MyException MyEx)
            {
                ok = false;
                errP.SetError(txtSuppName, MyEx.toString());
            }
            try
            {
                mySupp.SupplierAddress = txtSuppAddress.Text.Trim();
            }
            catch (MyException MyEx)
            {
                ok = false;
                errP.SetError(txtSuppAddress, MyEx.toString());
            }
            try
            {
                mySupp.SupplierTown = txtSuppTown.Text.Trim();
            }
            catch (MyException MyEx)
            {
                ok = false;
                errP.SetError(txtSuppTown, MyEx.toString());
            }
            try
            {
                mySupp.SupplierCounty = txtSuppCounty.Text.Trim();
            }
            catch (MyException MyEx)
            {
                ok = false;
                errP.SetError(txtSuppCounty, MyEx.toString());
            }
            try
            {
                mySupp.SupplierPostCode = txtSuppPC.Text.Trim();
            }
            catch (MyException MyEx)
            {
                ok = false;
                errP.SetError(txtSuppPC, MyEx.toString());
            }
            try
            {
                mySupp.SupplierEmail = txtSuppEmail.Text.Trim();
            }
            catch (MyException MyEx)
            {
                ok = false;
                errP.SetError(txtSuppEmail, MyEx.toString());
            }
            try
            {
                mySupp.SupplierTelNo = txtSuppTel.Text.Trim();
            }
            catch (MyException MyEx)
            {
                ok = false;
                errP.SetError(txtSuppTel, MyEx.toString());
            }

            //Try Adding
            try
            {
                if (ok)
                {
                    drSupplier.BeginEdit();
                    drSupplier["supplierName"]     = mySupp.SupplierName;
                    drSupplier["supplierAddress"]  = mySupp.SupplierAddress;
                    drSupplier["supplierTown"]     = mySupp.SupplierTown;
                    drSupplier["supplierCounty"]   = mySupp.SupplierCounty;
                    drSupplier["supplierPostCode"] = mySupp.SupplierPostCode;
                    drSupplier["supplierEmail"]    = mySupp.SupplierEmail;
                    drSupplier["supplierTelNo"]    = mySupp.SupplierTelNo;
                    drSupplier.EndEdit();
                    daSupplier.Update(dsBelfray, "Supplier");
                    MessageBox.Show("Supplier Updated");
                    chkBxEditSupp.Checked = false;
                    this.Update();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("" + ex.TargetSite + "", ex.Message + "Error!", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
            }
        }