private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { if (e.ColumnIndex == 9) // for print { BillEL objBillEL = new BillEL(); objBillEL.Bill_Id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Bill_Id"].Value); BillReportViewer objBillReportViewer = new BillReportViewer(companyEL, objBillEL); objBillReportViewer.ShowDialog(); objBillReportViewer.Dispose(); } if (e.ColumnIndex == 10) //For Delete { if (Common.MessageConfim("Are You Want To Delete This ")) { SQLHelper objSQLHelper = new SQLHelper(); SqlTransaction objSqlTransaction = objSQLHelper.BeginTrans(); BillDL objBillDL = new BillDL(); BillEL objBillEL = new BillEL(); objBillEL.Bill_Id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Bill_Id"].Value); BillDetailDL objBillDetailDL = new BillDetailDL(); List <BillDetailEL> lstBillDetail = objBillDetailDL.GetBillDetailByBillId(objBillEL.Bill_Id); BillItemDL objBillItemDL = new BillItemDL(); List <BillItemEL> lstBillItemEL = objBillItemDL.GetBillItemByBillId(objBillEL.Bill_Id); BillItemNarrationDL _BillItemNarrationDL = new BillItemNarrationDL(); List <BillItemNarrationEL> lstBillItemNarration = new List <BillItemNarrationEL>(); try { lstBillItemEL.ForEach(r => lstBillItemNarration.AddRange(_BillItemNarrationDL.GetBillItemNarrationBy_BillItemId(r.Bill_Item_Id))); lstBillItemNarration.ForEach(n => _BillItemNarrationDL.Delete(objSqlTransaction, n)); lstBillDetail.ForEach(r => objBillDetailDL.Delete(objSqlTransaction, r)); lstBillItemEL.ForEach(r => objBillItemDL.Delete(objSqlTransaction, r)); objBillDL.Delete(objSqlTransaction, objBillEL); objSqlTransaction.Commit(); Common.MessageDelete(); GridBind(); } catch (Exception) { objSqlTransaction.Rollback(); } } } if (e.ColumnIndex == 11)//For bill Edit { BillDL _BillDL = new BillDL(); BillEL objBillEL = _BillDL.GetBillById(Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Bill_Id"].Value)); CreateBill objCreateBill = new CreateBill(companyEL, objBillEL); objCreateBill.ControlBox = true; objCreateBill.MinimizeBox = false; objCreateBill.ShowDialog(); GridBind(); } } catch { } }
private void btnSave_Click(object sender, EventArgs e) { { BillItemEL _BillItemEL; BillItemDL _BillItemDL = new BillItemDL(); List <BillItemEL> lstBillItem = new List <BillItemEL>(); try { for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { _BillItemEL = new BillItemEL(); _BillItemEL.Bill_Id = _BillParentItem.Bill_Id; _BillItemEL.Purchase_Order_Detail_Id = null; _BillItemEL.Form = Convert.ToDecimal(dataGridView1.Rows[i].Cells["Form"].Value); _BillItemEL.Color = Convert.ToInt32(dataGridView1.Rows[i].Cells["Color"].Value); _BillItemEL.Rate = Convert.ToDecimal(dataGridView1.Rows[i].Cells["Rate"].Value); _BillItemEL.Quantity = Convert.ToDouble(dataGridView1.Rows[i].Cells["Quantity"].Value); //_BillItemEL.Item_Name = dataGridView1.Rows[i].Cells["Bill_Item_Name"].Value.ToString(); _BillItemEL.Item_Id = Convert.ToInt32(dataGridView1.Rows[i].Cells["ItemName"].Value); _BillItemEL.Parent_Id = _BillParentItem.Bill_Item_Id; if ((dataGridView1.Rows[i].Cells["Bill_Item_Id"].Value != null)) { _BillItemEL.Bill_Item_Id = Convert.ToInt32(dataGridView1.Rows[i].Cells["Bill_Item_Id"].Value);; } else { _BillItemEL.Bill_Item_Id = 0; } lstBillItem.Add(_BillItemEL); } } catch (Exception) { } SQLHelper _SQLHelper = new SQLHelper(); SqlTransaction transaction = _SQLHelper.BeginTrans(); try { for (int i = 0; i < lstBillItem.Count; i++) { if (lstBillItem[i].Bill_Item_Id == 0) { _BillItemDL.Insert(transaction, lstBillItem[i]); } else { _BillItemDL.Update(transaction, lstBillItem[i]); } } BillItemNarrationDL _BillItemNarrationDL = new BillItemNarrationDL(); List <BillItemNarrationEL> lstBillItemNarrationEL = new List <BillItemNarrationEL>(); DeletedlstBillItem.ForEach(r => lstBillItemNarrationEL.AddRange(_BillItemNarrationDL.GetBillItemNarrationBy_BillItemId(r.Bill_Item_Id))); lstBillItemNarrationEL.ForEach(n => _BillItemNarrationDL.Delete(transaction, n)); DeletedlstBillItem.ForEach(r => _BillItemDL.Delete(transaction, r)); transaction.Commit(); Common.MessageSave(); GridBind(); } catch (Exception) { transaction.Rollback(); } } }