Exemple #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["proGV"].Value.ToString() + " from purchase invoice?\n\t\t\tWARNING\nDELETION OF PRODUCT WILL EFFECT STOCK", "Question...", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
             int             q;
             if (dr == DialogResult.Yes)
             {
                 using (TransactionScope sc = new TransactionScope())
                 {
                     i.insertDeletedItem(Convert.ToInt64(purDD.SelectedValue.ToString()), Convert.ToInt32(row.Cells["proIDGV"].Value.ToString()), Convert.ToInt32(row.Cells["quantGV"].Value.ToString()), retrieval.USER_ID, DateTime.Today);
                     object ob = r.getProductQuantity(Convert.ToInt32(row.Cells["proIDGV"].Value.ToString()));
                     if (ob != null)
                     {
                         q  = Convert.ToInt32(ob);
                         q -= Convert.ToInt32(row.Cells["quantGV"].Value.ToString());
                         u.updateStock(Convert.ToInt32(row.Cells["proIDGV"].Value.ToString()), q);
                         float tot = Convert.ToSingle(grossTotLabel.Text) - Convert.ToSingle(row.Cells["TotGV"].Value.ToString());
                         grossTotLabel.Text = tot.ToString();
                         d.delete(Convert.ToInt64(row.Cells["mPIDgv"].Value.ToString()), "st_deleteProductFromPID", "@mPID");
                         dataGridView1.Rows.Remove(row);
                     }
                     sc.Complete();
                 }
             }
         }
     }
 }
 public override void saveBtn_Click(object sender, EventArgs e)
 {
     if (dataGridView1.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 dataGridView1.Rows)
             {
                 co += i.insertPurchaseInvoiceDetails(purchaseInvoiceID, Convert.ToInt32(row.Cells["proIDGV"].Value.ToString()), Convert.ToInt32(row.Cells["quantGV"].Value.ToString()), Convert.ToSingle(row.Cells["TotGV"].Value.ToString()));
                 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["quantGV"].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["quantGV"].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();
         }
     }
 }