Пример #1
0
 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.RowIndex != -1 && e.ColumnIndex != -1)
     {
         if (e.ColumnIndex == 6)
         {
             DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
             DialogResult    dr  = MessageBox.Show("Are you sure you want to delete" + row.Cells["proNameGV"].Value.ToString() + "from purchase invoice?\n\t\t\tWarning\nDeletion of product will effect stock", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
             if (dr == DialogResult.Yes)
             {
                 using (TransactionScope sc = new TransactionScope())
                 {
                     i.insertdeleteditems(Convert.ToInt64(PurchaseinvoiceDD.SelectedValue.ToString()), Convert.ToInt32(row.Cells["proIDGV"].Value.ToString()), Convert.ToInt32(row.Cells["quantityGV"].Value.ToString()), retrieval.User_ID, DateTime.Today);
                     int    q;
                     object ob = r.getProductQuantity(Convert.ToInt32(row.Cells["proIDGV"].Value.ToString()));
                     if (ob != null)
                     {
                         q  = Convert.ToInt32(ob);
                         q -= Convert.ToInt32(row.Cells["quantityGV"].Value.ToString());
                         u.updateStock(Convert.ToInt32(row.Cells["proIDGV"].Value.ToString()), q);
                         float tot = Convert.ToSingle(grossLabel.Text) - Convert.ToSingle(row.Cells["TotGV"].Value.ToString());
                         grossLabel.Text = tot.ToString();
                         d.deleteFromPurchaseInvoice(Convert.ToInt64(row.Cells["mPIDGV"].Value.ToString()), "st_deleteProductFromPID", "@mPID");
                         dataGridView1.Rows.Remove(row);
                     }
                     sc.Complete();
                 }
             }
         }
     }
 }
Пример #2
0
        public override void saveBtn_Click(object sender, EventArgs e)
        {
            if (dataGridView1.Rows.Count > 0)
            {
                Int64      purchaseInvoiceID;
                insertions i = new insertions();
                updation   u = new updation();
                //transaction is use jab tak ap ka sara code successfull ni chal jata excecute ni hota or agar ik code ni chalta tou dusre ko bi roll back kar deta hai jo successfull chala ho
                //transaction rokti hai invalid operations ko
                using (TransactionScope sc = new TransactionScope())
                {
                    purchaseInvoiceID = i.insertPurchaseInvoice(DateTime.Today, retrieval.User_ID, Convert.ToInt32(SupplierDD.SelectedValue));

                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        CO += i.insertPurchaseInvoiceDetails(purchaseInvoiceID, Convert.ToInt32(row.Cells["proIDGV"].Value.ToString()), Convert.ToInt32(row.Cells["quantityGV"].Value.ToString()), Convert.ToSingle(row.Cells["TotGV"].Value.ToString()));

                        if (r.checkProductPriceExist(Convert.ToInt32(row.Cells["proIDGV"].Value.ToString())))
                        {
                            u.updateProductPriceWRTPI(Convert.ToInt32(row.Cells["proIDGV"].Value.ToString()), Convert.ToSingle(row.Cells["pupGV"].Value.ToString()));
                        }
                        else
                        {
                            i.insertProductPrice(Convert.ToInt32(row.Cells["proIDGV"].Value.ToString()), Convert.ToSingle(row.Cells["pupGV"].Value.ToString()));
                        }

                        //for stocks
                        int    q;
                        object ob = r.getProductQuantity(Convert.ToInt32(row.Cells["proIDGV"].Value.ToString()));
                        if (ob != null)
                        {
                            q  = Convert.ToInt32(ob);
                            q += Convert.ToInt32(row.Cells["quantityGV"].Value.ToString());
                            u.updateStock(Convert.ToInt32(row.Cells["proIDGV"].Value.ToString()), q);
                        }
                        else
                        {
                            i.insertStock(Convert.ToInt32(row.Cells["proIDGV"].Value.ToString()), Convert.ToInt32(row.Cells["quantityGV"].Value.ToString()));
                        }
                    }
                    if (CO > 0)
                    {
                        MainClass.ShowMSG("Purchase Invoice Created SuccessFully", "Success", "Success");
                        PurchaseInvoiceDetail sr = new PurchaseInvoiceDetail();
                        sr.Show();
                    }
                    else
                    {
                        MainClass.ShowMSG("Unable to create Purchase Invoice", "Error", "Error");
                    }

                    sc.Complete();
                }
            }
        }