void grdLister_CommandCellClick(object sender, EventArgs e) { GridCommandCellElement gridCell = (GridCommandCellElement)sender; if (gridCell.ColumnInfo.Name == "btnDelete") { GridViewRowInfo row = gridCell.RowInfo; if (row is GridViewDataRowInfo) { long TranId = row.Cells[COLS.TranId].Value.ToLong(); if (TranId > 0) { try { int Id = row.Cells[COLS.Id].Value.ToInt(); int TransId = row.Cells[COLS.TranId].Value.ToInt(); using (TaxiDataContext db = new TaxiDataContext()) { if (db.GetTable <Fleet_DriverCommissionCollectionHistory_Detail>().Count(c => c.TransId == TransId) == 1) { Fleet_DriverCommissionCollectionHistory objHistory = db.GetTable <Fleet_DriverCommissionCollectionHistory>().FirstOrDefault(c => (c.Id == TranId)); if (objHistory != null) { db.Fleet_DriverCommissionCollectionHistories.DeleteOnSubmit(objHistory); db.SubmitChanges(); } } else { Fleet_DriverCommissionCollectionHistory_Detail objDetail = db.Fleet_DriverCommissionCollectionHistory_Details.FirstOrDefault(c => c.Id == Id); if (objDetail != null) { db.Fleet_DriverCommissionCollectionHistory_Details.DeleteOnSubmit(objDetail); db.SubmitChanges(); } } } PopulateData(); } catch (Exception ex) { ENUtils.ShowMessage(ex.Message); } } } } }
private void DeleteDriverPayment() { try { string Error = string.Empty; if (grdLister.Rows.Count() > 0 && grdLister.Rows.Count(c => c.Cells["Check"].Value.ToBool() == true) == 0) { Error = "Please select record to delete"; } if (!string.IsNullOrEmpty(Error)) { ENUtils.ShowMessage(Error); return; } //long TranId = row.Cells[COLS.TranId].Value.ToLong(); int Id = 0; int TransId = 0; long TranId = 0; if (grdLister.Rows.Count(c => c.Cells["Check"].Value.ToBool() == true) > 0) { if (DialogResult.Yes == RadMessageBox.Show("Are you sure you want to delete Driver Payment", "", MessageBoxButtons.YesNo, RadMessageIcon.Question)) { foreach (var item in grdLister.Rows.Where(c => c.Cells["Check"].Value.ToBool() == true)) { //long TranId = row.Cells["TranId"].Value.ToLong(); Id = item.Cells["Id"].Value.ToInt(); TransId = item.Cells["TranId"].Value.ToInt(); TranId = item.Cells["TranId"].Value.ToLong(); if (TranId > 0) { try { using (TaxiDataContext db = new TaxiDataContext()) { if (db.GetTable <Fleet_DriverCommissionCollectionHistory_Detail>().Count(c => c.TransId == TransId) == 1) { Fleet_DriverCommissionCollectionHistory objHistory = db.GetTable <Fleet_DriverCommissionCollectionHistory>().FirstOrDefault(c => (c.Id == TranId)); if (objHistory != null) { db.Fleet_DriverCommissionCollectionHistories.DeleteOnSubmit(objHistory); db.SubmitChanges(); } } else { Fleet_DriverCommissionCollectionHistory_Detail objDetail = db.Fleet_DriverCommissionCollectionHistory_Details.FirstOrDefault(c => c.Id == Id); if (objDetail != null) { db.Fleet_DriverCommissionCollectionHistory_Details.DeleteOnSubmit(objDetail); db.SubmitChanges(); } } } } catch (Exception ex) { ENUtils.ShowMessage(ex.Message); } } } PopulateData(); } } } catch (Exception ex) { ENUtils.ShowMessage(ex.Message); } }