private void UpdatePaymentCollection() { try { string Error = string.Empty; if (grdLister.Rows.Count() > 0 && grdLister.Rows.Count(c => c.Cells["IsPaid"].Value.ToBool() == true) == 0) { Error = "Please select record to update"; } if (!string.IsNullOrEmpty(Error)) { ENUtils.ShowMessage(Error); return; } if (grdLister.Rows.Count(c => c.Cells["IsPaid"].Value.ToBool() == true) > 0) { foreach (var item in grdLister.Rows.Where(c => c.Cells["IsPaid"].Value.ToBool() == true)) { long TranId = item.Cells["TransId"].Value.ToLong(); if (TranId > 0) { try { int IsPaid = item.Cells["IsPaid"].Value.ToBool() == true ? 1 : 0; // decimal adjustments = row.Cells[COLS.Adjustment].Value.ToDecimal(); string query = "update fleet_drivercommision set IsWeeklyPaid=" + IsPaid + " where Id=" + TranId; using (TaxiDataContext db = new TaxiDataContext()) { db.stp_RunProcedure(query); } UpdateDriverCommission(item.Cells["TotalRentCommission"].Value.ToDecimal()); //PopulateData(); DateTime?dtFrom = item.Cells["FromDate"].Value.ToDateorNull(); DateTime?dtTill = item.Cells["ToDate"].Value.ToDateorNull(); string DateRange = string.Format("{0:dd/MMMM/yyyy}", dtFrom) + " to " + string.Format("{0:dd/MMMM/yyyy}", dtTill); int DriverId = item.Cells["Id"].Value.ToInt(); int Id = 0; objDriverWeeklyRentHistory = new DriverWeeklyRentHistoryBO(); var MasterQuery = General.GetObject <Fleet_DriverWeeklyRentHistory>(c => (c.FromDate == dtFrom && c.TillDate == dtTill)); if (MasterQuery != null) { Id = MasterQuery.Id; objDriverWeeklyRentHistory.GetByPrimaryKey(Id); objDriverWeeklyRentHistory.Edit(); objDriverWeeklyRentHistory.Current.EditBy = AppVars.LoginObj.LuserId.ToInt(); objDriverWeeklyRentHistory.Current.EditLog = AppVars.LoginObj.UserName; objDriverWeeklyRentHistory.Current.EditOn = DateTime.Now; } else { objDriverWeeklyRentHistory.New(); objDriverWeeklyRentHistory.Current.AddBy = AppVars.LoginObj.LuserId.ToInt(); objDriverWeeklyRentHistory.Current.AddLog = AppVars.LoginObj.UserName; objDriverWeeklyRentHistory.Current.AddOn = DateTime.Now; } objDriverWeeklyRentHistory.Current.DateRange = DateRange; objDriverWeeklyRentHistory.Current.FromDate = dtFrom; objDriverWeeklyRentHistory.Current.TillDate = dtTill; objDriverWeeklyRentHistory.Current.CreatedOn = DateTime.Now; if (objDriverWeeklyRentHistory.Current.Fleet_DriverWeeklyRentHistory_Details.Count(c => c.DriverId == DriverId) == 0) { objDriverWeeklyRentHistory.Current.Fleet_DriverWeeklyRentHistory_Details.Add(new Fleet_DriverWeeklyRentHistory_Detail { TransId = objDriverWeeklyRentHistory.PrimaryKeyValue.ToInt(), AccountBookings = item.Cells["AccountBookings"].Value.ToDecimal(), Active = item.Cells["Active"].Value.ToStr(), DriverNo = item.Cells["DriverNo"].Value.ToStr(), DriverId = DriverId, RentComm = item.Cells["TotalRentCommission"].Value.ToDecimal(), IsPaid = item.Cells["IsPaid"].Value.ToBool(), OfficeToPay = item.Cells["OfficeToPay"].Value.ToDecimal(), PreviousBalance = item.Cells["PreviousBalance"].Value.ToDecimal(), DriverToPay = item.Cells["DriverToPay"].Value.ToDecimal() }); } else { Fleet_DriverWeeklyRentHistory_Detail objDriverWeeklyRentDetail = objDriverWeeklyRentDetail = objDriverWeeklyRentHistory.Current.Fleet_DriverWeeklyRentHistory_Details.FirstOrDefault(c => c.DriverId == DriverId); objDriverWeeklyRentDetail.TransId = objDriverWeeklyRentHistory.PrimaryKeyValue.ToInt(); objDriverWeeklyRentDetail.IsPaid = item.Cells["IsPaid"].Value.ToBool();; objDriverWeeklyRentDetail.AccountBookings = item.Cells["AccountBookings"].Value.ToDecimal(); objDriverWeeklyRentDetail.Active = item.Cells["Active"].Value.ToStr(); objDriverWeeklyRentDetail.DriverNo = item.Cells["DriverNo"].Value.ToStr(); objDriverWeeklyRentDetail.DriverId = DriverId; objDriverWeeklyRentDetail.RentComm = item.Cells["TotalRentCommission"].Value.ToDecimal(); objDriverWeeklyRentDetail.OfficeToPay = item.Cells["OfficeToPay"].Value.ToDecimal(); objDriverWeeklyRentDetail.PreviousBalance = item.Cells["PreviousBalance"].Value.ToDecimal(); objDriverWeeklyRentDetail.DriverToPay = item.Cells["DriverToPay"].Value.ToDecimal(); } objDriverWeeklyRentHistory.Save(); objDriverWeeklyRentHistory.Clear(); } catch (Exception ex) { ENUtils.ShowMessage(ex.Message); } } } } PopulateData(); } catch (Exception ex) { ENUtils.ShowMessage(ex.Message); } }
void grdLister_CommandCellClick(object sender, EventArgs e) { GridCommandCellElement gridCell = (GridCommandCellElement)sender; if (gridCell.ColumnInfo.Name == "btnUpdate") { GridViewRowInfo row = gridCell.RowInfo; if (row is GridViewDataRowInfo) { long TranId = row.Cells["TransId"].Value.ToLong(); if (TranId > 0) { try { int IsPaid = row.Cells["IsPaid"].Value.ToBool() == true ? 1 : 0; // decimal adjustments = row.Cells[COLS.Adjustment].Value.ToDecimal(); string query = "update fleet_drivercommision set IsWeeklyPaid=" + IsPaid + " where Id=" + TranId; using (TaxiDataContext db = new TaxiDataContext()) { db.stp_RunProcedure(query); } UpdateDriverCommission(grdLister.CurrentRow.Cells["TotalRentCommission"].Value.ToDecimal()); PopulateData(); DateTime?dtFrom = grdLister.CurrentRow.Cells["FromDate"].Value.ToDateorNull(); DateTime?dtTill = grdLister.CurrentRow.Cells["ToDate"].Value.ToDateorNull(); string DateRange = string.Format("{0:dd/MMMM/yyyy}", dtFrom) + " to " + string.Format("{0:dd/MMMM/yyyy}", dtTill); int DriverId = grdLister.CurrentRow.Cells["Id"].Value.ToInt(); int Id = 0; objDriverWeeklyRentHistory = new DriverWeeklyRentHistoryBO(); var MasterQuery = General.GetObject <Fleet_DriverWeeklyRentHistory>(c => (c.FromDate == dtFrom && c.TillDate == dtTill)); if (MasterQuery != null) { Id = MasterQuery.Id; objDriverWeeklyRentHistory.GetByPrimaryKey(Id); objDriverWeeklyRentHistory.Edit(); objDriverWeeklyRentHistory.Current.EditBy = AppVars.LoginObj.LuserId.ToInt(); objDriverWeeklyRentHistory.Current.EditLog = AppVars.LoginObj.UserName; objDriverWeeklyRentHistory.Current.EditOn = DateTime.Now; } else { objDriverWeeklyRentHistory.New(); objDriverWeeklyRentHistory.Current.AddBy = AppVars.LoginObj.LuserId.ToInt(); objDriverWeeklyRentHistory.Current.AddLog = AppVars.LoginObj.UserName; objDriverWeeklyRentHistory.Current.AddOn = DateTime.Now; } objDriverWeeklyRentHistory.Current.DateRange = DateRange; objDriverWeeklyRentHistory.Current.FromDate = dtFrom; objDriverWeeklyRentHistory.Current.TillDate = dtTill; objDriverWeeklyRentHistory.Current.CreatedOn = DateTime.Now; if (objDriverWeeklyRentHistory.Current.Fleet_DriverWeeklyRentHistory_Details.Count(c => c.DriverId == DriverId) == 0) { objDriverWeeklyRentHistory.Current.Fleet_DriverWeeklyRentHistory_Details.Add(new Fleet_DriverWeeklyRentHistory_Detail { TransId = objDriverWeeklyRentHistory.PrimaryKeyValue.ToInt(), AccountBookings = grdLister.CurrentRow.Cells["AccountBookings"].Value.ToDecimal(), Active = grdLister.CurrentRow.Cells["Active"].Value.ToStr(), DriverNo = grdLister.CurrentRow.Cells["DriverNo"].Value.ToStr(), DriverId = DriverId, RentComm = grdLister.CurrentRow.Cells["TotalRentCommission"].Value.ToDecimal(), IsPaid = grdLister.CurrentRow.Cells["IsPaid"].Value.ToBool(), OfficeToPay = grdLister.CurrentRow.Cells["OfficeToPay"].Value.ToDecimal(), PreviousBalance = grdLister.CurrentRow.Cells["PreviousBalance"].Value.ToDecimal(), DriverToPay = grdLister.CurrentRow.Cells["DriverToPay"].Value.ToDecimal() }); } else { Fleet_DriverWeeklyRentHistory_Detail objDriverWeeklyRentDetail = objDriverWeeklyRentDetail = objDriverWeeklyRentHistory.Current.Fleet_DriverWeeklyRentHistory_Details.FirstOrDefault(c => c.DriverId == DriverId); //var query2 = General.GetObject<Fleet_DriverWeeklyRentHistory_Detail>(c => (c.TransId == objDriverWeeklyRentHistory.PrimaryKeyValue.ToInt() && c.DriverId == DriverId)); //if (query2 != null) //{ // int HistoryId = query2.Id; // using (TaxiDataContext db = new TaxiDataContext()) // { // Fleet_DriverWeeklyRentHistory_Detail objDriverWeeklyRentDetail = db.Fleet_DriverWeeklyRentHistory_Details.FirstOrDefault(c => c.Id == HistoryId); objDriverWeeklyRentDetail.TransId = objDriverWeeklyRentHistory.PrimaryKeyValue.ToInt(); objDriverWeeklyRentDetail.IsPaid = grdLister.CurrentRow.Cells["IsPaid"].Value.ToBool();; objDriverWeeklyRentDetail.AccountBookings = grdLister.CurrentRow.Cells["AccountBookings"].Value.ToDecimal(); objDriverWeeklyRentDetail.Active = grdLister.CurrentRow.Cells["Active"].Value.ToStr(); objDriverWeeklyRentDetail.DriverNo = grdLister.CurrentRow.Cells["DriverNo"].Value.ToStr(); objDriverWeeklyRentDetail.DriverId = DriverId; objDriverWeeklyRentDetail.RentComm = grdLister.CurrentRow.Cells["TotalRentCommission"].Value.ToDecimal(); objDriverWeeklyRentDetail.OfficeToPay = grdLister.CurrentRow.Cells["OfficeToPay"].Value.ToDecimal(); objDriverWeeklyRentDetail.PreviousBalance = grdLister.CurrentRow.Cells["PreviousBalance"].Value.ToDecimal(); objDriverWeeklyRentDetail.DriverToPay = grdLister.CurrentRow.Cells["DriverToPay"].Value.ToDecimal(); // db.SubmitChanges(); // } // } } objDriverWeeklyRentHistory.Save(); objDriverWeeklyRentHistory.Clear(); } catch (Exception ex) { ENUtils.ShowMessage(ex.Message); } } } } }