public override void edit_button_Click(object sender, EventArgs e)
        {
            if (name_textBox.Text == "" || phone_number_textBox.Text == "" || email_textBox.Text == "" || password_textBox.Text == "")
            {
                MainClass.ShowMsg("Please enter a record to edit.", "error");

                MainClass.disbale_reset(left_panel_sample2);

                enable_crude_buttons();
            }
            else
            {
                edit = 1;

                temp_name = name_textBox.Text;

                temp_phone = phone_number_textBox.Text;

                temp_password = password_textBox.Text;

                temp_mail = email_textBox.Text;

                temp_status = status_comboBox.Text;

                save_button.Enabled = true;

                add_button.Enabled = false;

                MainClass.enable(left_panel_sample2);
            }
        }
Esempio n. 2
0
        private string[] loadProductswrtBarcode(string proc, Hashtable ht)
        {
            SqlConnection sql_con = new SqlConnection(MainClass.connection());

            string[] productswrt = new string[6];

            try
            {
                SqlCommand command = new SqlCommand(proc, sql_con);

                command.CommandType = CommandType.StoredProcedure;

                foreach (DictionaryEntry item in ht)
                {
                    command.Parameters.AddWithValue(item.Key.ToString(), item.Value);
                }

                sql_con.Open();

                SqlDataReader dr = command.ExecuteReader();

                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        productswrt[0] = dr[0].ToString(); //prod ID

                        productswrt[1] = dr[1].ToString(); //product

                        productswrt[2] = dr[2].ToString(); //Barcode

                        productswrt[3] = dr[3].ToString(); //Per Unit Price

                        productswrt[4] = dr[4].ToString(); //Per Unit Discount

                        productswrt[5] = dr[5].ToString(); //Total Amount
                    }
                }
                else
                {
                    MainClass.ShowMsg("No products available....", "Error");

                    MainClass.disbale_reset(left_panel_sample2);

                    sql_con.Close();
                }

                sql_con.Close();
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");

                MainClass.disbale_reset(left_panel_sample2);

                sql_con.Close();
            }

            return(productswrt);
        }
        public override void edit_button_Click(object sender, EventArgs e)
        {
            if (supplier_comboBox.SelectedIndex == -1 || product_barcode_textBox_purchase_invoice.Text == "" || product_quantity_textBox.Text == "")
            {
                MainClass.ShowMsg("Please enter/select a record to edit.", "error");

                MainClass.disbale_reset(left_panel_sample2);

                enable_crude_buttons();
            }
            else
            {
                supplier_comboBox.Enabled = false; product_barcode_textBox_purchase_invoice.Enabled = false;

                product_name_textBox_purchase_invoice.Enabled = false;

                delete_button.Enabled = true;

                save_button.Enabled = true;

                add_button.Enabled = false; edit = true;

                per_unit_price_textBox.Enabled = true; product_quantity_textBox.Enabled = true;
            }
        }
Esempio n. 4
0
        public override void cancel_button_Click(object sender, EventArgs e)
        {
            MainClass.disbale_reset(left_panel_sample2);

            enable_crude_buttons();

            loadSuppliers();
        }
Esempio n. 5
0
        private void SUPPLIERS_Load(object sender, EventArgs e)
        {
            loadSuppliers();

            enable_crude_buttons();

            MainClass.disbale_reset(left_panel_sample2);
        }
        private void purchaseinvoice_dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.RowIndex != -1 && e.ColumnIndex != -1)
                {
                    add_button.Enabled = false;

                    if (edit == true) //updating member
                    {
                        save_button.Enabled = true;
                    }
                    else if (edit == false) //adding member
                    {
                        save_button.Enabled = false;
                    }

                    if (e.ColumnIndex == 8)
                    {
                        DataGridViewRow row = purchase_dataGridView.Rows[e.RowIndex];

                        gross_total -= Convert.ToSingle(row.Cells["totalGV"].Value.ToString());

                        gross_total_price_label.Text = gross_total.ToString();

                        purchase_dataGridView.Rows.Remove(row);

                        save_button.Enabled = true;

                        view_button.Enabled = false;
                    }
                    else
                    {
                        DataGridViewRow row = purchase_dataGridView.Rows[e.RowIndex];

                        supplier_comboBox.Text = row.Cells["suppliernameGV"].Value.ToString();

                        product_name_textBox_purchase_invoice.Text = row.Cells["productnameGV"].Value.ToString();

                        product_barcode_textBox_purchase_invoice.Text = row.Cells["productbarcodeGV"].Value.ToString();

                        per_unit_price_textBox.Text = row.Cells["perunitpriceGV"].Value.ToString();

                        product_quantity_textBox.Text = row.Cells["productquantityGV"].Value.ToString();

                        MainClass.disbale(left_panel_sample2);

                        delete_button.Enabled = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");

                MainClass.disbale_reset(left_panel_sample2); enable_crude_buttons();
            }
        }
        private void PURCHASE_INVOICE_Load(object sender, EventArgs e)
        {
            enable_crude_buttons(); MainClass.disbale_reset(left_panel_sample2);

            SQL_TASKS.LoadList("st_loadlistSUPPLIERS", supplier_comboBox, "ID", "Supplier Company");

            total_amount_label.Text = "0.00";

            gross_total_price_label.Text = "0.00";
        }
        private void users_Load(object sender, EventArgs e)
        {
            loadUsers();

            MainClass.disbale_reset(left_panel_sample2);

            enable_crude_buttons();

            not_found_label.Visible = false;
        }
        public override void delete_button_Click(object sender, EventArgs e)
        {
            if (supplier_comboBox.SelectedIndex == -1 || product_barcode_textBox_purchase_invoice.Text == "" || product_quantity_textBox.Text == "")
            {
                MainClass.ShowMsg("Please enter/select a record to delete.", "error");

                MainClass.disbale_reset(left_panel_sample2);

                enable_crude_buttons();
            }
            else
            {
                try
                {
                    DialogResult ans = MessageBox.Show("Are you sure you want to delete current record.", "CONFIRM?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    if (ans == DialogResult.Yes)
                    {
                        purchase_dataGridView.Rows.Remove(purchase_dataGridView.CurrentRow);

                        MainClass.disbale_reset(left_panel_sample2);

                        gross_total = 0;

                        foreach (DataGridViewRow row in purchase_dataGridView.Rows)
                        {
                            gross_total += Convert.ToSingle(row.Cells["totalGV"].Value);

                            gross_total_price_label.Text = gross_total.ToString();
                        }

                        MainClass.disbale_reset(left_panel_sample2);

                        enable_crude_buttons();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);

                    MainClass.disbale_reset(left_panel_sample2);

                    enable_crude_buttons();
                }
            }
        }
Esempio n. 10
0
        public override void edit_button_Click(object sender, EventArgs e)
        {
            if (supplier_name_textBox.Text == "" || contact_person_textBox.Text == "" || phone1_textBox.Text == "" || address_textBox_suppliers.Text == "" || NTN_textBox.Text == "" || supplier_status_comboBox.SelectedIndex == -1)
            {
                MainClass.ShowMsg("Please enter a record to edit.", "error");

                MainClass.disbale_reset(left_panel_sample2);

                enable_crude_buttons();
            }
            else
            {
                edit = true;

                save_button.Enabled = true;

                add_button.Enabled = false;

                MainClass.enable(left_panel_sample2);
            }
        }
Esempio n. 11
0
 public override void cancel_button_Click(object sender, EventArgs e)
 {
     MainClass.disbale_reset(left_panel_sample2);
 }
Esempio n. 12
0
        private void pay_button_Click(object sender, EventArgs e)
        {
            try
            {
                if (gross_textBox.Text != "" && discount_textBox.Text != "" && payment_Type_comboBox.SelectedIndex != -1 && change_to_give_textBox.Text != "" && amount_given_textBox.Text != "")
                {
                    Hashtable ht = new Hashtable();

                    ht.Add("@done", LoginCodeClass.USERID);

                    ht.Add("@date", DateTime.Now);

                    ht.Add("@totalamt", Convert.ToSingle(gross_textBox.Text));

                    ht.Add("@totaldisc", Convert.ToSingle(discount_textBox.Text));

                    ht.Add("@givenamt", Convert.ToSingle(amount_given_textBox.Text));

                    ht.Add("@return", Convert.ToSingle(change_to_give_textBox.Text));

                    if (payment_Type_comboBox.SelectedIndex == 0)
                    {
                        ht.Add("@payType", 0); //0 means cash
                    }
                    else if (payment_Type_comboBox.SelectedIndex == 1)
                    {
                        ht.Add("@payType", 1);//1 means debit
                    }
                    else
                    {
                        ht.Add("@payType", 2);
                    }                               //2 means credit

                    DialogResult dr = MessageBox.Show("\n\tTotal Amount: " + gross_textBox.Text + "\n\tTotal Discount: " + discount_textBox.Text + "\n\tAmount Given: " + amount_given_textBox.Text + "\n\tAmount to return: " + change_to_give_textBox.Text + "\n\tPayment Type: " + payment_Type_comboBox.SelectedItem.ToString() + " \n\nAre you sure you want to submit current sales?", "Question...", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    if (DialogResult.Yes == dr)
                    {
                        using (TransactionScope sc = new TransactionScope())
                        {
                            if (SQL_TASKS.insert_update_delete("st_insertSALES", ht) > 0)
                            {
                                foreach (DataGridViewRow row in sales_dataGridView.Rows)
                                {
                                    int CurrentProductQuan = SQL_TASKS.getStockwrtProduct(Convert.ToInt32(row.Cells["ProductIDGV"].Value));

                                    Hashtable ht1 = new Hashtable();

                                    int x = CurrentProductQuan - Convert.ToInt32(row.Cells["ProductquantityGV"].Value);

                                    ht1.Add("@prodID", Convert.ToInt32(row.Cells["ProductIDGV"].Value));

                                    ht1.Add("@quan", x);

                                    SQL_TASKS.insert_update_delete("st_updateSTOCK", ht1);

                                    Hashtable ht2 = new Hashtable();

                                    ht2.Add("@saleID", SQL_TASKS.getLASTID("st_getSalesID"));

                                    ht2.Add("@prodID", Convert.ToInt64(row.Cells["productIDGV"].Value.ToString()));

                                    ht2.Add("@quantity", Convert.ToInt32(row.Cells["productquantityGV"].Value.ToString()));

                                    ht2.Add("@discount", Convert.ToSingle(row.Cells["discountGV"].Value.ToString()));

                                    ht2.Add("@sellingprice", Convert.ToSingle(row.Cells["TotalAmountGV"].Value.ToString()));

                                    SQL_TASKS.insert_update_delete("st_insertSalesDetails", ht2);
                                }

                                MainClass.ShowMsg("Record saved successfully.", "Success");

                                MainClass.disbale_reset(left_panel_sample2);

                                sales_dataGridView.Rows.Clear();

                                SALES_REPORT sr = new SALES_REPORT();

                                sr.ShowDialog();

                                gross_total_price_label.Text = "0.00";
                            }
                            else
                            {
                                throw new Exception("Unable to save record.");
                            }
                            sc.Complete();
                        }
                    }
                }
                else
                {
                    throw new Exception("Please fill all required fields.");
                }
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");
            }
        }
Esempio n. 13
0
        public override void delete_button_Click(object sender, EventArgs e)
        {
            if (supplier_name_textBox.Text == "" || contact_person_textBox.Text == "" || phone1_textBox.Text == "" || address_textBox_suppliers.Text == "" || NTN_textBox.Text == "" || supplier_status_comboBox.SelectedIndex == -1)
            {
                MainClass.ShowMsg("Please enter a record to delete.", "error");

                MainClass.disbale_reset(left_panel_sample2);

                enable_crude_buttons();
            }
            else if (supplier_name_textBox.Enabled == true || contact_person_textBox.Enabled == true || phone1_textBox.Enabled == true || address_textBox_suppliers.Enabled == true || NTN_textBox.Enabled == true || supplier_status_comboBox.Enabled == true)
            {
                MainClass.ShowMsg("Please select record from the table.", "error");

                MainClass.disbale_reset(left_panel_sample2);

                enable_crude_buttons();
            }
            else if ((supplier_name_textBox.Enabled == false || contact_person_textBox.Enabled == false || phone1_textBox.Enabled == false || address_textBox_suppliers.Enabled == false || NTN_textBox.Enabled == false || supplier_status_comboBox.Enabled == false) && (supplier_name_textBox.Text != "" || contact_person_textBox.Text != "" || phone1_textBox.Text != "" || address_textBox_suppliers.Text != "" || NTN_textBox.Text != "" || supplier_status_comboBox.SelectedIndex != -1))
            {
                try
                {
                    DialogResult ans = MessageBox.Show("Are you sure you want to delete current record.", "CONFIRM?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    if (ans == DialogResult.Yes)
                    {
                        Hashtable ht = new Hashtable();

                        ht.Add("@supp_id", supplierID);

                        if (SQL_TASKS.insert_update_delete("st_deleteSUPPLIERS", ht) > 0)
                        {
                            MainClass.ShowMsg(supplier_name_textBox.Text + " deleted successfully.", "Success");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();

                            loadSuppliers();
                        }
                        else
                        {
                            MainClass.ShowMsg("Unable to save record.", "Error");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();
                        }

                        MainClass.disbale_reset(left_panel_sample2);

                        enable_crude_buttons();

                        loadSuppliers();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);

                    MainClass.disbale_reset(left_panel_sample2);

                    enable_crude_buttons();
                }
            }
        }
Esempio n. 14
0
        public override void save_button_Click(object sender, EventArgs e)
        {
            if (supplier_name_textBox.Text == "" || contact_person_textBox.Text == "" || phone1_textBox.Text == "" || address_textBox_suppliers.Text == "" || NTN_textBox.Text == "" || supplier_status_comboBox.SelectedIndex == -1)
            {
                MainClass.ShowMsg("Please enter all required information.", "error");

                MainClass.disbale_reset(left_panel_sample2);

                enable_crude_buttons();
            }
            else
            {
                if (Convert.ToString(supplier_status_comboBox.SelectedItem) == "Active")
                {
                    stat = 1; //active
                }
                else if (Convert.ToString(supplier_status_comboBox.SelectedItem) == "In-active")
                {
                    stat = 0; //in-active
                }

                if (edit == false) //0 to add record
                {
                    try
                    {
                        Hashtable ht = new Hashtable();

                        ht.Add("@suppliername", supplier_name_textBox.Text);

                        ht.Add("@contactpersonname", contact_person_textBox.Text);

                        ht.Add("@phone1", phone1_textBox.Text);

                        ht.Add("@phone2", phone2_textBox.Text);

                        ht.Add("@address", address_textBox_suppliers.Text);

                        ht.Add("@ntn", NTN_textBox.Text);

                        ht.Add("@status", stat);

                        if (SQL_TASKS.insert_update_delete("st_insertSUPPLIERS", ht) > 0)
                        {
                            MainClass.ShowMsg(supplier_name_textBox.Text + " added successfully to the system.", "Success");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();

                            loadSuppliers();
                        }
                        else
                        {
                            MainClass.ShowMsg("Unable to save record.", "Error");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();
                        }
                    }
                    catch (Exception ex)
                    {
                        MainClass.ShowMsg(ex.Message, "Error");

                        MainClass.disbale_reset(left_panel_sample2);

                        enable_crude_buttons();
                    }
                }
                else if (edit == true) // to update record
                {
                    if (Convert.ToString(supplier_status_comboBox.SelectedItem) == "Active")
                    {
                        stat = 1; //active
                    }
                    else if (Convert.ToString(supplier_status_comboBox.SelectedItem) == "In-active")
                    {
                        stat = 0; //in-active
                    }

                    try
                    {
                        Hashtable ht = new Hashtable();

                        ht.Add("@suppliername", supplier_name_textBox.Text);

                        ht.Add("@contactpersonname", contact_person_textBox.Text);

                        ht.Add("@phone1", phone1_textBox.Text);

                        ht.Add("@phone2", phone2_textBox.Text);

                        ht.Add("@address", address_textBox_suppliers.Text);

                        ht.Add("@ntn", NTN_textBox.Text);

                        ht.Add("@status", stat);

                        ht.Add("@supp_id", supplierID);

                        if (SQL_TASKS.insert_update_delete("st_updateSUPPLIERS", ht) > 0)
                        {
                            MainClass.ShowMsg(supplier_name_textBox.Text + " updated successfully.", "Success");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();

                            loadSuppliers();
                        }
                        else
                        {
                            MainClass.ShowMsg("Unable to save record.", "Error");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();
                        }
                        edit = false;

                        loadSuppliers();
                    }
                    catch (Exception ex)
                    {
                        MainClass.ShowMsg(ex.Message, "error");

                        MainClass.disbale_reset(left_panel_sample2);

                        enable_crude_buttons();
                    }
                }
            }
        }
        public override void delete_button_Click(object sender, EventArgs e)
        {
            if (name_textBox.Text == "" || phone_number_textBox.Text == "" || password_textBox.Text == "" || email_textBox.Text == "")
            {
                MainClass.ShowMsg("Please enter a record to delete.", "error");

                MainClass.disbale_reset(left_panel_sample2);

                enable_crude_buttons();
            }
            else if (name_textBox.Enabled == true || phone_number_textBox.Enabled == true || password_textBox.Enabled == true || email_textBox.Enabled == true)
            {
                MainClass.ShowMsg("Please select record from the table.", "error");

                MainClass.disbale_reset(left_panel_sample2);

                enable_crude_buttons();
            }
            else if ((name_textBox.Enabled == false && phone_number_textBox.Enabled == false && password_textBox.Enabled == false && email_textBox.Enabled == false) && (name_textBox.Text != "" && phone_number_textBox.Text != "" && password_textBox.Text != "" && email_textBox.Text != ""))
            {
                try
                {
                    DialogResult ans = MessageBox.Show("Are you sure you want to delete current record.", "CONFIRM?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    if (ans == DialogResult.Yes)
                    {
                        Hashtable ht = new Hashtable();

                        ht.Add("@id", USERID);

                        if (SQL_TASKS.insert_update_delete("st_deleteusers", ht) > 0)
                        {
                            MainClass.ShowMsg("User deleted successfully.", "Success");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();

                            loadUsers();
                        }
                        else
                        {
                            MainClass.ShowMsg("Unable to save record.", "Error");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();
                        }

                        MainClass.disbale_reset(left_panel_sample2);

                        enable_crude_buttons();

                        loadUsers();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);

                    MainClass.disbale_reset(left_panel_sample2);

                    enable_crude_buttons();
                }
            }
        }
        public override void save_button_Click(object sender, EventArgs e)
        {
            if (name_textBox.Text == "" || password_textBox.Text == "" || email_textBox.Text == "" || phone_number_label.Text == "" || status_comboBox.SelectedIndex == -1)
            {
                MainClass.ShowMsg("Please enter all required information.", "error");

                MainClass.disbale_reset(left_panel_sample2);

                enable_crude_buttons();
            }
            else
            {
                if (Convert.ToString(status_comboBox.SelectedItem) == "Active")
                {
                    stat = 1; //active
                }
                else if (Convert.ToString(status_comboBox.SelectedItem) == "In-active")
                {
                    stat = 0; //in-active
                }

                if (edit == 0) //0 to add record
                {
                    try
                    {
                        Hashtable ht = new Hashtable();

                        ht.Add("@name", name_textBox.Text);

                        ht.Add("@email", email_textBox.Text);

                        ht.Add("@password", password_textBox.Text);

                        ht.Add("@phone", phone_number_textBox.Text);

                        ht.Add("@status", stat);

                        ht.Add("@role", role_textBox.Text);

                        if (SQL_TASKS.insert_update_delete("st_insertusers", ht) > 0)
                        {
                            MainClass.ShowMsg("User added successfully to the system.", "Success");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();

                            loadUsers();
                        }
                        else
                        {
                            MainClass.ShowMsg("Unable to save record.", "Error");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();
                        }
                    }
                    catch (Exception ex)
                    {
                        MainClass.ShowMsg(ex.Message, "Error");

                        MainClass.disbale_reset(left_panel_sample2);

                        enable_crude_buttons();
                    }
                }
                else if (edit == 1) // to update record
                {
                    if (Convert.ToString(status_comboBox.SelectedItem) == "Active")
                    {
                        stat = 1; //active
                    }
                    else if (Convert.ToString(status_comboBox.SelectedItem) == "In-active")
                    {
                        stat = 0; //in-active
                    }

                    try
                    {
                        if (name_textBox.Text == temp_name && phone_number_textBox.Text == temp_phone && password_textBox.Text == temp_password && email_textBox.Text == temp_mail && status_comboBox.Text == temp_status)
                        {
                            MainClass.ShowMsg("This record is already saved.", "error");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();
                        }

                        Hashtable ht = new Hashtable();

                        ht.Add("@name", name_textBox.Text);

                        ht.Add("@email", email_textBox.Text);

                        ht.Add("@password", password_textBox.Text);

                        ht.Add("@phone", phone_number_textBox.Text);

                        ht.Add("@status", stat);

                        ht.Add("@role", role_textBox.Text);

                        ht.Add("@id", USERID);

                        if (SQL_TASKS.insert_update_delete("st_updateusers", ht) > 0)
                        {
                            MainClass.ShowMsg("User updated successfully.", "Success");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();

                            loadUsers();
                        }
                        else
                        {
                            MainClass.ShowMsg("Unable to save record.", "Error");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();
                        }
                        edit = 0;

                        loadUsers();
                    }
                    catch (Exception ex)
                    {
                        MainClass.ShowMsg(ex.Message, "error");

                        MainClass.disbale_reset(left_panel_sample2);

                        enable_crude_buttons();
                    }
                }
            }
        }
        public override void save_button_Click(object sender, EventArgs e)
        {
            if (purchase_dataGridView.Rows.Count == 0 || purchase_dataGridView.Rows.Count < 0)
            {
                MainClass.ShowMsg("Please enter all required information.", "error");

                MainClass.disbale_reset(left_panel_sample2);

                enable_crude_buttons();
            }
            else
            {
                MainClass.disbale_reset(left_panel_sample2); enable_crude_buttons();

                try
                {
                    using (TransactionScope sc = new TransactionScope())
                    {
                        int compare, compareTO;

here:

                        for (int i = 0; i < purchase_dataGridView.Rows.Count; ++i)
                        {
                            compare = Convert.ToInt32(purchase_dataGridView.Rows[i].Cells["productIDGV"].Value);

                            for (int j = i + 1; j < purchase_dataGridView.Rows.Count; ++j)
                            {
                                compareTO = Convert.ToInt32(purchase_dataGridView.Rows[j].Cells["productIDGV"].Value);

                                if (compare == compareTO)
                                {
                                    if (correctIT == false)
                                    {
                                        DialogResult dr = MessageBox.Show("You added a duplicate product which is not allowed.\n\nDo you want to remove that duplicate product and add its quantity?", "Duplicate product(s) encountered!", MessageBoxButtons.YesNo, MessageBoxIcon.Error);

                                        if (DialogResult.Yes == dr)
                                        {
                                            correctIT = true;

                                            goto here;
                                        }
                                        else
                                        {
                                            correctIT = false;

                                            throw new Exception("Duplicate products are not allowed!");
                                        }
                                    }
                                    else
                                    {
                                        Int32 originalproductTOTAL, originalproductVALUE, dupliactedproductVALUE, dupliactedproductTOTAL;

                                        originalproductVALUE = Convert.ToInt32(purchase_dataGridView.Rows[i].Cells["productquantityGV"].Value);

                                        dupliactedproductVALUE = Convert.ToInt32(purchase_dataGridView.Rows[j].Cells["productquantityGV"].Value);

                                        originalproductTOTAL = Convert.ToInt32(purchase_dataGridView.Rows[i].Cells["totalGV"].Value);

                                        dupliactedproductTOTAL = Convert.ToInt32(purchase_dataGridView.Rows[j].Cells["totalGV"].Value);

                                        originalproductVALUE += dupliactedproductVALUE;

                                        originalproductTOTAL += dupliactedproductTOTAL;

                                        purchase_dataGridView.Rows[i].Cells["productquantityGV"].Value = originalproductVALUE;

                                        purchase_dataGridView.Rows[i].Cells["totalGV"].Value = originalproductTOTAL;

                                        int beforeREMOVE = purchase_dataGridView.Rows.Count; int afterREMOVE;

                                        purchase_dataGridView.Rows.Remove(purchase_dataGridView.Rows[j]);

                                        afterREMOVE = purchase_dataGridView.Rows.Count;

                                        if (afterREMOVE < beforeREMOVE)
                                        {
                                            MainClass.ShowMsg("Operation successfull.", "Success");
                                        }
                                        else
                                        {
                                            throw new Exception("An error occured during removing duplicated products!");
                                        }
                                    }
                                }
                            }
                        }

                        SQL_TASKS ss = new SQL_TASKS();

                        foreach (DataGridViewRow row in purchase_dataGridView.Rows)
                        {
                            //inserting purchase invoice

                            purchaseinvoiceID_FROM_SQL_TASKS = ss.InsertPurchaseinvoice(DateTime.Today, LoginCodeClass.USERID, Convert.ToInt32(row.Cells["supplierIDGV"].Value));

                            //inserting purchase invoice details

                            count += ss.insertPurchaseinvoicedetails(purchaseinvoiceID_FROM_SQL_TASKS, Convert.ToInt32(row.Cells["productIDGV"].Value.ToString()), Convert.ToInt32(row.Cells["productquantityGV"].Value.ToString()), Convert.ToSingle(row.Cells["totalGV"].Value.ToString()));

                            SqlConnection sql_con = new SqlConnection(MainClass.connection());

                            SqlCommand cmd = new SqlCommand();

                            cmd.Connection = sql_con;

                            cmd.CommandType = CommandType.Text;

                            cmd.CommandText = "select pp_prodID from ProductPrice where pp_ProductBarcode='" + row.Cells["productbarcodeGV"].Value.ToString() + "' ";

                            sql_con.Open();
                            object check = cmd.ExecuteScalar();

                            sql_con.Close();

                            if (check == null) //product not present
                            {
                                Hashtable ht1 = new Hashtable();

                                ht1.Add("@prodID", row.Cells["productIDGV"].Value.ToString());

                                ht1.Add("@bp", Convert.ToSingle(row.Cells["totalGV"].Value.ToString()));

                                ht1.Add("@sp", DBNull.Value);

                                ht1.Add("@buyingdate", DateTime.Today);

                                ht1.Add("@profitper", DBNull.Value);

                                ht1.Add("@discount", DBNull.Value);

                                ht1.Add("@productbarcode", row.Cells["productbarcodeGV"].Value.ToString());

                                // inserting product price:

                                if (SQL_TASKS.insert_update_delete("st_insertPRODUCTPRICE", ht1) > 0)
                                {
                                    success = true;
                                }
                                else
                                {
                                    success = false;
                                }
                            }
                            else //product present
                            {
                                Hashtable ht2 = new Hashtable();

                                ht2.Add("@prodID", row.Cells["productIDGV"].Value.ToString());

                                cmd.CommandText = "select pp_buyingPrice from ProductPrice where pp_prodID='" + row.Cells["productIDGV"].Value.ToString() + "' ";

                                sql_con.Open();

                                Int64 ExistingProductBuyingPrice = Convert.ToInt64(cmd.ExecuteScalar());

                                sql_con.Close();

                                Int64 finalp = Convert.ToInt64(row.Cells["totalGV"].Value) + ExistingProductBuyingPrice;

                                Hashtable htx = new Hashtable();

                                htx.Add("@prodID", row.Cells["productIDGV"].Value.ToString());

                                htx.Add("@bp", finalp);

                                if (SQL_TASKS.insert_update_delete("st_updatePRODUCTPRICEforPURCHASEINVOICE", htx) > 0)
                                {
                                    success = true;
                                }
                                else
                                {
                                    success = false;
                                }
                            }

                            int q;

                            object stockcount;

                            bool DoesExist = SQL_TASKS.IfProductExist(Convert.ToInt64(row.Cells["productIDGV"].Value.ToString()));

                            if (DoesExist) //if product does exist
                            {
                                //update stock

                                stockcount = SQL_TASKS.getProductQuantityfromSTOCK(Convert.ToInt32(row.Cells["productIDGV"].Value.ToString()));

                                q = Convert.ToInt32(stockcount);

                                q += Convert.ToInt32(row.Cells["productquantityGV"].Value.ToString());

                                Hashtable hta = new Hashtable();

                                hta.Add("@prodID", Convert.ToInt32(row.Cells["productIDGV"].Value.ToString()));

                                hta.Add("@quan", q);

                                //updating stock:

                                if (SQL_TASKS.insert_update_delete("st_updateSTOCK", hta) > 0)
                                {
                                    success = true;
                                }
                            }
                            else //if product does not exist
                            {
                                //insert

                                Hashtable htb = new Hashtable();

                                htb.Add("@prodID", Convert.ToInt32(row.Cells["productIDGV"].Value.ToString()));

                                htb.Add("@quan", Convert.ToInt32(row.Cells["productquantityGV"].Value.ToString()));

                                // inserting stock:

                                if (SQL_TASKS.insert_update_delete("st_insertSTOCK", htb) > 0)
                                {
                                    success = true;
                                }
                                else
                                {
                                    success = false;
                                }
                            }
                        }

                        if (count > 0 && success == true)
                        {
                            MainClass.ShowMsg("Purchase Invoice created successfully.", "Success");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();

                            purchase_dataGridView.Rows.Clear(); gross_total_price_label.Text = "";
                        }
                        else
                        {
                            MainClass.ShowMsg("Unable to create Purchase Invoice", "Error");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();

                            purchase_dataGridView.Rows.Clear(); gross_total_price_label.Text = "";
                        }

                        sc.Complete();
                    }
                }
                catch (Exception ex)
                {
                    MainClass.ShowMsg(ex.Message, "Error");

                    MainClass.disbale_reset(left_panel_sample2);

                    enable_crude_buttons();
                }
            }
        }
        private void add_to_cart_button_Click(object sender, EventArgs e)
        {
            try
            {
                if (LoginCodeClass.isAdmin != true)
                {
                    if (supplier_comboBox.SelectedIndex == -1 || product_barcode_textBox_purchase_invoice.Text == "" || product_quantity_textBox.Text == "")
                    {
                        MainClass.ShowMsg("Please enter a record to delete.", "error");

                        MainClass.disbale_reset(left_panel_sample2);

                        enable_crude_buttons();
                    }
                    else
                    {
                        if (edit == false)
                        {
                            purchase_dataGridView.Rows.Add(productID, product_name_textBox_purchase_invoice.Text, product_quantity_textBox.Text, per_unit_price_textBox.Text, total_amount_label.Text, supplier_comboBox.SelectedValue, supplier_comboBox.Text.ToString(), product_barcode_textBox_purchase_invoice.Text);

                            gross_total += Convert.ToSingle(total_amount_label.Text);

                            gross_total_price_label.Text = gross_total.ToString();

                            product_barcode_textBox_purchase_invoice.Text = "";

                            product_name_textBox_purchase_invoice.Text = "";

                            product_quantity_textBox.Text = "";

                            per_unit_price_textBox.Text = "";

                            product_barcode_textBox_purchase_invoice.Focus();

                            int exist = -2;
                        }
                        else
                        {
                            purchase_dataGridView.CurrentRow.Cells["suppliernameGV"].Value = supplier_comboBox.Text;

                            purchase_dataGridView.CurrentRow.Cells["productnameGV"].Value = product_name_textBox_purchase_invoice.Text;

                            purchase_dataGridView.CurrentRow.Cells["productbarcodeGV"].Value = product_barcode_textBox_purchase_invoice.Text;

                            int productQUANTITY = Convert.ToInt32(product_quantity_textBox.Text);

                            int productPERUNITPRICE = Convert.ToInt32(per_unit_price_textBox.Text);

                            purchase_dataGridView.CurrentRow.Cells["perunitpriceGV"].Value = per_unit_price_textBox.Text;

                            purchase_dataGridView.CurrentRow.Cells["productquantityGV"].Value = product_quantity_textBox.Text;

                            int productTOTALPRICE = productQUANTITY * productPERUNITPRICE;

                            purchase_dataGridView.CurrentRow.Cells["totalGV"].Value = productTOTALPRICE;

                            gross_total = 0; MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();

                            foreach (DataGridViewRow row in purchase_dataGridView.Rows)
                            {
                                gross_total += Convert.ToSingle(row.Cells["totalGV"].Value);

                                gross_total_price_label.Text = gross_total.ToString();
                            }
                        }
                    }
                }
                else
                {
                    throw new Exception("Admin cannot create purchase invoice.To create purchase invoice login with a user account.");
                }
            }
            catch (Exception ex)
            { MainClass.ShowMsg(ex.Message, "Error"); }
        }