public override void button3_Click(object sender, EventArgs e)
        {
            if (productTxt.Text == "")
            {
                proErrorLbl.Visible = true;
            }
            else
            {
                proErrorLbl.Visible = false;
            }
            if (barcodeTxt.Text == "")
            {
                barcodeErrorlbl.Visible = true;
            }
            else
            {
                barcodeErrorlbl.Visible = false;
            }
            //   if (expiryPicker.Value < DateTime.Now) { ExpiryErrorlbl.Visible = true; ExpiryErrorlbl.Text = "Invalid Date"; } else { ExpiryErrorlbl.Visible = true ; }
            if (categoryDD.SelectedIndex == -1 || categoryDD.SelectedIndex == 0)
            {
                categoryErrorlbl.Visible = true;
            }
            else
            {
                categoryErrorlbl.Visible = false;
            }
            if (proErrorLbl.Visible || barcodeErrorlbl.Visible || categoryErrorlbl.Visible)
            {
                MainClass.showMG("Filds With * Are Mandatory", "Stop", "Error"); // Error is the type of Message
            }
            else
            {
                if (edit == 0)
                {
                    insertion i = new insertion();
                    i.insertProduct(productTxt.Text, barcodeTxt.Text, expiryPicker.Value, Convert.ToInt32(categoryDD.SelectedValue));
                    r.showProducts(dataGridView1, proIDGV, proGV, expiryGV, catGV, barcodeGV, catIDGV);
                    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();

                        u.updateProduct(prodID, productTxt.Text, barcodeTxt.Text, expiryPicker.Value, Convert.ToInt32(categoryDD.SelectedValue));
                        r.showProducts(dataGridView1, proIDGV, proGV, expiryGV, catGV, barcodeGV, catIDGV);
                        MainClass.disable_reset(lftPanel);
                    }
                }
            }
        }
Beispiel #2
0
        public override void saveBtn_Click(object sender, EventArgs e)
        {
            if (proTxt.Text == "")
            {
                proErrorLabel.Visible = true;
            }
            else
            {
                proErrorLabel.Visible = false;
            }
            if (barcodeTxt.Text == "")
            {
                barcodeErrorLabel.Visible = true;
            }
            else
            {
                barcodeErrorLabel.Visible = false;
            }
            if (expiryPicker.Value < DateTime.Now)
            {
                expiryErrorLabel.Visible = true; expiryErrorLabel.Text = "Invalid Date";
            }
            else
            {
                expiryErrorLabel.Visible = false;
            }
            if (expiryPicker.Value.Date == DateTime.Now.Date)
            {
                expiryErrorLabel.Visible = false;
            }                                                                                       //this fix the problem that we can use the current date
            if (priceTxt.Text == "")
            {
                priceErrorLabel.Visible = true;
            }
            else
            {
                priceErrorLabel.Visible = false;
            }
            if (categoryDD.SelectedIndex == -1 || categoryDD.SelectedIndex == 0)
            {
                catErrorLabel.Visible = true;
            }
            else
            {
                catErrorLabel.Visible = false;
            }

            //final if
            if (proErrorLabel.Visible || barcodeErrorLabel.Visible || expiryErrorLabel.Visible || priceErrorLabel.Visible || catErrorLabel.Visible)
            {
                MainClass.ShowMSG("Fields with * are mandatory", "Stop", "Error");
            }
            else
            {
                if (edit == 0) //Code for SAVE operation
                {
                    insertion i = new insertion();
                    if (expiryPicker.Value.Date == DateTime.Now.Date) //if the expiry date is set now, then we set the value null
                    {
                        i.insertProduct(proTxt.Text, barcodeTxt.Text, Convert.ToSingle(priceTxt.Text), Convert.ToInt32(categoryDD.SelectedValue));
                    }
                    else //if the expiry date is set in another date different from now, we save the value
                    {
                        i.insertProduct(proTxt.Text, barcodeTxt.Text, Convert.ToSingle(priceTxt.Text), Convert.ToInt32(categoryDD.SelectedValue), expiryPicker.Value);
                    }
                    r.showProducts(dataGridView1, proIDGV, proGV, expiryGV, catGV, priceGV, barcodeGV, catIDGV);
                    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 (expiryPicker.Value.Date == DateTime.Now.Date) //if the expiry date is set now, then we set the value null
                        {
                            u.updateProduct(prodID, proTxt.Text, barcodeTxt.Text, Convert.ToSingle(priceTxt.Text), Convert.ToInt32(categoryDD.SelectedValue));
                        }
                        else //if the expiry date is set in another date different from now, we save the value
                        {
                            u.updateProduct(prodID, proTxt.Text, barcodeTxt.Text, Convert.ToSingle(priceTxt.Text), Convert.ToInt32(categoryDD.SelectedValue), expiryPicker.Value);
                        }
                        r.showProducts(dataGridView1, proIDGV, proGV, expiryGV, catGV, priceGV, barcodeGV, catIDGV);
                        MainClass.disable_reset(leftPanel);
                    }
                }
            }
        }