Esempio n. 1
0
 private void PurchasedataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.RowIndex != -1 && e.ColumnIndex != -1)
     {
         if (e.ColumnIndex == 6)
         {
             DataGridViewRow row = PurchasedataGridView.Rows[e.RowIndex];
             DialogResult    dr  = MessageBox.Show("Are you sure, you want to delete " + row.Cells["NameGV"].Value.ToString() + " from purchase invoice?\n\t\tWARNING\nDELETION OF PRODUCT WILL EFFECT STOCK", "Question...", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
             if (dr == DialogResult.Yes)
             {
                 using (TransactionScope sc = new TransactionScope())
                 {
                     i.insertDeletedItem(Convert.ToInt64(InvoiceDD.SelectedValue.ToString()), retrieval.USER_ID, Convert.ToInt32(row.Cells["ProductIDGV"].Value.ToString()), Convert.ToInt32(row.Cells["QuantityGV"].Value.ToString()), DateTime.Today);
                     object ob = r.getProductQuantity(Convert.ToInt32(row.Cells["ProductIDGV"].Value.ToString()));
                     int    q  = Convert.ToInt32(ob);
                     if (ob != null)
                     {
                         q -= Convert.ToInt32(row.Cells["ProductIDGV"].Value.ToString());
                         u.UpdateStock(Convert.ToInt32(row.Cells["ProductIDGV"].Value.ToString()), Convert.ToInt32(row.Cells["QuantityGV"].Value.ToString()));
                         float tot = Convert.ToSingle(GrossLbl.Text) - Convert.ToSingle(row.Cells["TotGV"].Value.ToString());
                         GrossLbl.Text = tot.ToString();
                         d.delete(Convert.ToInt64(row.Cells["PIDGV"].Value.ToString()), "st_deleteProductFromPID", "@PID");
                         PurchasedataGridView.Rows.Remove(row);
                     }
                     sc.Complete();
                 }
             }
         }
     }
 }
Esempio n. 2
0
        public override void SaveBtn_Click(object sender, EventArgs e)
        {
            if (PurchasedataGridView.Rows.Count > 0)
            {
                Int64     purchaseInvoiceID;
                Insertion i = new Insertion();
                using (TransactionScope sc = new TransactionScope())
                {
                    purchaseInvoiceID = i.insertPurchaseInvoice(DateTime.Today, retrieval.USER_ID, Convert.ToInt32(SupplierDD.SelectedValue));
                    foreach (DataGridViewRow row in PurchasedataGridView.Rows)
                    {
                        co += i.insertPurchaseInvoiceDetails(purchaseInvoiceID, Convert.ToInt32(row.Cells["ProductIDGV"].Value.ToString()), Convert.ToInt32(row.Cells["QuantityGV"].Value.ToString()), Convert.ToSingle(row.Cells["TotGV"].Value.ToString()));
                        if (r.checkProductPriceExistance(Convert.ToInt32(row.Cells["ProductIDGV"].Value.ToString())))
                        {
                            u.UpdateProductPrice(Convert.ToInt32(row.Cells["ProductIDGV"].Value.ToString()), Convert.ToSingle(row.Cells["PerUnitGV"].Value.ToString()));
                        }
                        else
                        {
                            i.insertProductPrice(Convert.ToInt32(row.Cells["ProductIDGV"].Value.ToString()), Convert.ToSingle(row.Cells["PerUnitGV"].Value.ToString()));
                        }
                        object ob = r.getProductQuantity(Convert.ToInt32(row.Cells["ProductIDGV"].Value.ToString()));
                        int    q  = Convert.ToInt32(ob);

                        if (ob != null)
                        {
                            q += Convert.ToInt32(row.Cells["QuantityGV"].Value.ToString());
                            u.UpdateStock(Convert.ToInt32(row.Cells["ProductIDGV"].Value.ToString()), q);
                        }
                        else
                        {
                            i.insertStock(Convert.ToInt32(row.Cells["ProductIDGV"].Value.ToString()), Convert.ToInt32(row.Cells["QuantityGV"].Value.ToString()));
                        }
                    }
                    if (co > 0)
                    {
                        MainClass.ShowMSG("Purchase invoice created Successfully.", "Success", "Success");
                    }
                    else
                    {
                        MainClass.ShowMSG("Unable to create Purchase invoice.", "Error", "Error");
                    }
                    sc.Complete();
                }
            }
        }