public override void saveBtn_Click(object sender, EventArgs e)
        {
            if (proTxt.Text == "")
            {
                proErrorLabel.Visible = true;
            }
            else
            {
                proErrorLabel.Visible = false;
            }
            if (barTxt.Text == "")
            {
                barErrorLabel.Visible = true;
            }
            else
            {
                barErrorLabel.Visible = false;
            }
            if (expireTxt.Value < DateTime.Now)
            {
                expErrorLabel.Visible = true;
            }
            else
            {
                expErrorLabel.Visible = false;
            }
            if (expireTxt.Value.Date == DateTime.Now.Date)
            {
                expErrorLabel.Visible = false;
            }
            if (priceTxt.Text == "")
            {
                priceErrorLabel.Visible = true;
            }
            else
            {
                priceErrorLabel.Visible = false;
            }
            if (categoryCombo.SelectedIndex == -1 || categoryCombo.SelectedIndex == 0)
            {
                catErrorLabel.Visible = true;
            }
            else
            {
                catErrorLabel.Visible = false;
            }

            if (proErrorLabel.Visible || barErrorLabel.Visible || priceErrorLabel.Visible || catErrorLabel.Visible)
            {
                MainClass.showMessage("Fields with * are mandatory", "Stop", "Error");
            }
            else
            {
                if (edit == 0)//Code for Save Operation
                {
                    Insertion i = new Insertion();
                    if (expireTxt.Value.Date == DateTime.Now.Date)
                    {
                        i.insertProduct(proTxt.Text, barTxt.Text, Convert.ToSingle(priceTxt.Text), Convert.ToInt32(categoryCombo.SelectedValue));
                    }
                    else
                    {
                        i.insertProduct(proTxt.Text, barTxt.Text, Convert.ToSingle(priceTxt.Text), Convert.ToInt32(categoryCombo.SelectedValue), expireTxt.Value);
                    }


                    r.showProduct(dataGridView1, proidGV, productGV, barGV, expiryGV, priceGV, categoryGV, catidGV);
                    MainClass.disable_reset(leftPanel);
                }
                else if (edit == 1)//Code for Update Operation
                {
                    DialogResult dr = MessageBox.Show("Are you sure, you want to update recored", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dr == DialogResult.Yes)
                    {
                        Updation u = new Updation();
                        if (expireTxt.Value.Date == DateTime.Now.Date)
                        {
                            u.updateProduct(prodId, proTxt.Text, barTxt.Text, Convert.ToSingle(priceTxt.Text), Convert.ToInt32(categoryCombo.SelectedValue));
                        }
                        else
                        {
                            u.updateProduct(prodId, proTxt.Text, barTxt.Text, Convert.ToSingle(priceTxt.Text), Convert.ToInt32(categoryCombo.SelectedValue), expireTxt.Value);
                        }

                        r.showProduct(dataGridView1, proidGV, productGV, barGV, expiryGV, priceGV, categoryGV, catidGV);
                        MainClass.disable_reset(leftPanel);
                    }
                }
            }
        }
Exemple #2
0
 public override void BtnSave_Click(object sender, EventArgs e)
 {
     //validation for Users form
     if (proNameTxt.Text == string.Empty)
     {
         proNameErrorLabel.Visible = true;
     }
     else
     {
         proNameErrorLabel.Visible = false;
     }
     if (barCodeTxt.Text == string.Empty)
     {
         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;
     }
     if (PriceTxt.Text == string.Empty)
     {
         PriceErrorLabel.Visible = true;
     }
     else
     {
         PriceErrorLabel.Visible = false;
     }
     if (CatDD.SelectedIndex == -1 || CatDD.SelectedIndex == 0)
     {
         catErrorLabel.Visible = true;
     }
     else
     {
         catErrorLabel.Visible = false;
     }
     if (proNameErrorLabel.Visible || BarcodeErrorLabel.Visible || ExpiryErrorLabel.Visible || PriceErrorLabel.Visible || catErrorLabel.Visible)
     {
         MainClass.showMSG("Fields with * are mandatory", "Stop", "Error"); //Error is the type of message
     }
     else
     {
         if (edit == 0) // Code for SAVE Operation
         {
             Insertion i = new Insertion();
             if (ExpiryPicker.Value.Date == DateTime.Now.Date)
             {
                 i.insertProduct(proNameTxt.Text, barCodeTxt.Text, Convert.ToSingle(PriceTxt.Text), Convert.ToInt32(CatDD.SelectedValue));
             }
             else
             {
                 i.insertProduct(proNameTxt.Text, barCodeTxt.Text, Convert.ToSingle(PriceTxt.Text), Convert.ToInt32(CatDD.SelectedValue), ExpiryPicker.Value);
             }
             r.showProducts(dataGridView1, proIDGV, proNameGV, barcodeGV, expiryGV, priceGV, catGV, catIDGV);
             MainClass.disable_reset(LeftPanel);
         }
         else if (edit == 1) // Code for EDIT 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)
                 {
                     u.updateProduct(proID, proNameTxt.Text, barCodeTxt.Text, Convert.ToSingle(PriceTxt.Text), Convert.ToInt32(CatDD.SelectedValue));
                 }
                 else
                 {
                     u.updateProduct(proID, proNameTxt.Text, barCodeTxt.Text, Convert.ToSingle(PriceTxt.Text), Convert.ToInt32(CatDD.SelectedValue), ExpiryPicker.Value);
                 }
                 r.showProducts(dataGridView1, proIDGV, proNameGV, barcodeGV, expiryGV, priceGV, catGV, catIDGV);
                 MainClass.disable_reset(LeftPanel);
             }
         }
     }
     MainClass.enable_reset(LeftPanel);
 }