Exemple #1
0
        private void purchaseinvoice_dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (LoginCodeClass.isAdmin != true)
                {
                    if (e.RowIndex != -1 && e.ColumnIndex != -1)
                    {
                        if (e.ColumnIndex == 6)
                        {
                            DataGridViewRow row = purchaseinvoice_dataGridView.Rows[e.RowIndex];

                            DialogResult dr = MessageBox.Show("Are you sure you want to delete?\n\nIt will affect your stock.", "PRODUCT DELETION", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                            if (dr == DialogResult.Yes)
                            {
                                using (TransactionScope sc = new TransactionScope())
                                {
                                    Hashtable ht = new Hashtable();

                                    ht.Add("@purchID", Convert.ToInt64(purchaseinvoice_comboBox.SelectedValue.ToString()));

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

                                    ht.Add("@proID", Convert.ToInt32(row.Cells["productIDGV"].Value));

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

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

                                    SQL_TASKS.insert_update_delete("st_insertDeletedItemPI", ht);

                                    int q; object ob;

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

                                    bool update = true;

                                    if (ob != null || Convert.ToInt32(ob) != 0)
                                    {
                                        update = true;
                                    }
                                    else
                                    {
                                        update = false;
                                    }

                                    if (update)
                                    {
                                        //update

                                        q = Convert.ToInt32(ob);

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

                                        Hashtable ht1 = new Hashtable();

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

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

                                        SQL_TASKS.insert_update_delete("st_updateSTOCK", ht1);

                                        Hashtable ht3 = new Hashtable();

                                        ht3.Add("@purchaseinvoicedetailsID", Convert.ToInt64(row.Cells["purchaseinvoiceIDGV"].Value.ToString()));

                                        if (SQL_TASKS.insert_update_delete("st_deletePRODUCTSfromPURCHASEINVOICEDETAILS", ht3) > 0)
                                        {
                                            MainClass.ShowMsg("Deleted successfully.", "Success");

                                            gross_total_price_label.Text = "0.00";

                                            LoadPurchaseInvoiceDetails(); purchaseinvoice_comboBox.SelectedIndex = -1;
                                        }
                                        else
                                        {
                                            MainClass.ShowMsg("Unable to delete.", "Error");

                                            gross_total_price_label.Text = "0.00";

                                            purchaseinvoice_comboBox.SelectedIndex = -1;
                                        }

                                        sc.Complete();
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    throw new Exception("Admin cannot delete purchase invoice details.To delete purchase invoice details login with an user account.");
                }
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");
            }
        }