示例#1
0
        public override void saveBtn_Click(object sender, EventArgs e)
        {
            //Here we enable and disable the red asterisc "*" in the form, validating that no txt left unfilled
            if (supplierCompanyTxt.Text == "")
            {
                supplierNameErrorLbl.Visible = true;
            }
            else
            {
                supplierNameErrorLbl.Visible = false;
            }
            if (personNameTxt.Text == "")
            {
                contactPersonErrorLbl.Visible = true;
            }
            else
            {
                contactPersonErrorLbl.Visible = false;
            }
            if (Phone1Txt.Text == "")
            {
                phone1ErrorLbl.Visible = true;
            }
            else
            {
                phone1ErrorLbl.Visible = false;
            }
            if (addressTxt.Text == "")
            {
                addressErrorLbl.Visible = true;
            }
            else
            {
                addressErrorLbl.Visible = false;
            }
            if (statusDD.SelectedIndex == -1)
            {
                statusErrorLbl.Visible = true;
            }
            else
            {
                statusErrorLbl.Visible = false;
            }

            if (supplierNameErrorLbl.Visible || contactPersonErrorLbl.Visible || phone1ErrorLbl.Visible || addressErrorLbl.Visible || statusErrorLbl.Visible)
            {
                MainClass.ShowMSG("Fields with * are mandatory", "Stop", "Error"); //Error is the type of msg
            }
            else
            {
                if (statusDD.SelectedIndex == 0)
                {
                    stat = 1;
                }
                else if (statusDD.SelectedIndex == 1)
                {
                    stat = 0;
                }
                if (edit == 0) //Code for SAVE operation
                {
                    insertion i = new insertion();
                    //validating the null fields
                    if (phone2Txt.Text == "" && ntnTxt.Text != "")
                    {
                        i.insertSupplier(supplierCompanyTxt.Text, personNameTxt.Text, Phone1Txt.Text, addressTxt.Text, stat, null, ntnTxt.Text);
                    }
                    else if (phone2Txt.Text != "" && ntnTxt.Text == "")
                    {
                        i.insertSupplier(supplierCompanyTxt.Text, personNameTxt.Text, Phone1Txt.Text, addressTxt.Text, stat, phone2Txt.Text, null);
                    }
                    else if (phone2Txt.Text == "" && ntnTxt.Text == "")
                    {
                        i.insertSupplier(supplierCompanyTxt.Text, personNameTxt.Text, Phone1Txt.Text, addressTxt.Text, stat, null, null);
                    }
                    else
                    {
                        i.insertSupplier(supplierCompanyTxt.Text, personNameTxt.Text, Phone1Txt.Text, addressTxt.Text, stat, phone2Txt.Text, ntnTxt.Text);
                    }

                    r.showSuppliers(dataGridView1, SuppIDGV, companyGV, personGV, phone1GV, phone2GV, addressGV, ntnGV, StatusGV);
                    MainClass.disable_reset(leftPanel);
                }
                else if (edit == 1) //Code for UPDATE operation
                {
                    DialogResult dr = MessageBox.Show("Are you sure , you want to update record?", "Question...", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dr == DialogResult.Yes)
                    {
                        updation u = new updation();
                        if (statusDD.SelectedIndex == 0)
                        {
                            stat = 1;
                        }
                        else if (statusDD.SelectedIndex == 1)
                        {
                            stat = 0;
                        }
                        //validating the null fields
                        if (phone2Txt.Text == "" && ntnTxt.Text != "")
                        {
                            u.updateSupplier(supplierID, supplierCompanyTxt.Text, personNameTxt.Text, Phone1Txt.Text, addressTxt.Text, stat, null, ntnTxt.Text);
                        }
                        else if (phone2Txt.Text != "" && ntnTxt.Text == "")
                        {
                            u.updateSupplier(supplierID, supplierCompanyTxt.Text, personNameTxt.Text, Phone1Txt.Text, addressTxt.Text, stat, phone2Txt.Text, null);
                        }
                        else if (phone2Txt.Text == "" && ntnTxt.Text == "")
                        {
                            u.updateSupplier(supplierID, supplierCompanyTxt.Text, personNameTxt.Text, Phone1Txt.Text, addressTxt.Text, stat, null, null);
                        }
                        else
                        {
                            u.updateSupplier(supplierID, supplierCompanyTxt.Text, personNameTxt.Text, Phone1Txt.Text, addressTxt.Text, stat, phone2Txt.Text, ntnTxt.Text);
                        }

                        r.showSuppliers(dataGridView1, SuppIDGV, companyGV, personGV, phone1GV, phone2GV, addressGV, ntnGV, StatusGV);
                        MainClass.disable_reset(leftPanel);
                    }
                }
            }
        }
        public override void button3_Click(object sender, EventArgs e)
        {
            if (supplierComTxt.Text == "")
            {
                nameErrorLbl.Visible = true;
            }
            else
            {
                nameErrorLbl.Visible = false;
            }
            if (personNameTxt.Text == "")
            {
                ContPerErrorlbl.Visible = true;
            }
            else
            {
                ContPerErrorlbl.Visible = false;
            }
            if (phone1txt.Text == "")
            {
                phone1Errorlbl.Visible = true;
            }
            else
            {
                phone1Errorlbl.Visible = false;
            }
            //   if (phone2txt.Text == "") { phone2Errorlbl.Visible = true; } else { phone2Errorlbl.Visible = false; }
            if (addresstxt.Text == "")
            {
                AddressErroorlbl.Visible = true;
            }
            else
            {
                AddressErroorlbl.Visible = false;
            }
            //  if (TaxNotxt.Text == "") { TaxNoErrorlbl.Visible = true; } else { TaxNoErrorlbl.Visible = false; }
            if (statusDD.SelectedIndex == -1)
            {
                statusErrorlbl.Visible = true;
            }
            else
            {
                statusErrorlbl.Visible = false;
            }

            if (nameErrorLbl.Visible || ContPerErrorlbl.Visible || phone1Errorlbl.Visible || AddressErroorlbl.Visible || statusErrorlbl.Visible)
            {
                MainClass.showMG("Filds With * Are Mandatory", "Stop", "Error"); // Error is the type of Message
            }
            else
            {
                if (statusDD.SelectedIndex == 0)
                {
                    stat = 1;
                }
                else if (statusDD.SelectedIndex == 1)
                {
                    stat = 0;
                }
                if (edit == 0)//code for save operation
                {
                    insertion i = new insertion();
                    if (phone2txt.Text == "" && TaxNotxt.Text != "")
                    {
                        i.insertSupplier(supplierComTxt.Text, personNameTxt.Text, phone1txt.Text, addresstxt.Text, stat, null, TaxNotxt.Text);
                    }
                    else if (phone2txt.Text != "" && TaxNotxt.Text == "")
                    {
                        i.insertSupplier(supplierComTxt.Text, personNameTxt.Text, phone1txt.Text, addresstxt.Text, stat, phone2txt.Text, null);
                    }
                    else if (phone2txt.Text == "" && TaxNotxt.Text == "")
                    {
                        i.insertSupplier(supplierComTxt.Text, personNameTxt.Text, phone1txt.Text, addresstxt.Text, stat, null, null);
                    }
                    else
                    {
                        i.insertSupplier(supplierComTxt.Text, personNameTxt.Text, phone1txt.Text, addresstxt.Text, stat, phone2txt.Text);
                    }
                    r.showSupplier(dataGridView1, suppIDGV, companyGV, personGV, phone1GV, phone2GV, addressGV, ntnGV, statusGV);
                    MainClass.disable_reset(lftPanel);
                }
                else if (edit == 1)///for Updte Operation
                {
                    DialogResult dr = MessageBox.Show("Are you sure, you want to updata Record", "Question..", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dr == DialogResult.Yes)
                    {
                        updation u = new updation();
                        if (statusDD.SelectedIndex == 0)
                        {
                            stat = 1;
                        }
                        else if (statusDD.SelectedIndex == 1)
                        {
                            stat = 0;
                        }
                        if (phone2txt.Text == "" && TaxNotxt.Text != "")
                        {
                            u.updateSupplier(SupplierID, supplierComTxt.Text, personNameTxt.Text, phone1txt.Text, addresstxt.Text, stat, null, TaxNotxt.Text);
                        }
                        else if (phone2txt.Text != "" && TaxNotxt.Text == "")
                        {
                            u.updateSupplier(SupplierID, supplierComTxt.Text, personNameTxt.Text, phone1txt.Text, addresstxt.Text, stat, phone2txt.Text, null);
                        }
                        else if (phone2txt.Text == "" && TaxNotxt.Text == "")
                        {
                            u.updateSupplier(SupplierID, supplierComTxt.Text, personNameTxt.Text, phone1txt.Text, addresstxt.Text, stat, null, null);
                        }
                        else
                        {
                            u.updateSupplier(SupplierID, supplierComTxt.Text, personNameTxt.Text, phone1txt.Text, addresstxt.Text, stat, phone1txt.Text, phone2txt.Text);
                        }
                        r.showSupplier(dataGridView1, suppIDGV, companyGV, personGV, phone1GV, phone2GV, addressGV, ntnGV, statusGV);


                        MainClass.disable_reset(lftPanel);
                    }
                }
            }
        }