public override void Save() { try { int Id = 0; foreach (var item in grdLister.Rows) { Id = item.Cells["Id"].Value.ToInt(); if (Id > 0) { objMaster.GetByPrimaryKey(Id); objMaster.Edit(); objMaster.Current.PerMinJourneyCharges = item.Cells[COLS.PerMinJourneyCharges].Value.ToDecimal(); objMaster.CheckDataValidation = false; objMaster.Save(); objMaster.Clear(); } } } catch (Exception ex) { if (objMaster.Errors.Count > 0) { ENUtils.ShowMessage(objMaster.ShowErrors()); } else { ENUtils.ShowMessage(ex.Message); } } }
public void CopyCompanyFares(int CompanyId) { try { // int VehicleTypeId = cVehicleTypeId; if (SaveFares == false) { int FareId = 0; var Query = General.GetObject <Fare>(c => c.CompanyId == CompanyId); if (CompanyId == 0 && Vechileid > 0) { var Query2 = General.GetObject <Fare>(c => c.VehicleTypeId == Vechileid); if (Query2 != null) { FareId = Query2.Id; } } if (Query != null) { FareId = Query.Id; } var FareList = (from a in General.GetQueryable <Fare_ChargesDetail>(c => c.FareId == FareId) select new { Id = a.Id, FareId = a.FareId, OriginLocationTypeId = a.OriginLocationTypeId, DestinationLocationTypeId = a.DestinationLocationTypeId, OriginId = a.OriginId, DestinationId = a.DestinationId, FromAddress = a.FromAddress, ToAddress = a.ToAddress, Rate = a.Rate, NightTimeRate = HasOffPeakRate ? a.NightTimeRate : 0, }).ToList(); ChargesDetail.Clear(); foreach (var item in FareList) { decimal Rate = item.Rate.ToDecimal(); if (ApplyAdditionOrSubtractionOnFareRates) { decimal Amount = 0.00m; decimal PercentValue = numPercent.Value.ToDecimal(); if (rbtnAdd.IsChecked) { Amount = ((Rate * PercentValue) / 100); Rate = (Rate + Amount); } else { Amount = ((Rate * PercentValue) / 100); Rate = (Rate - Amount); } } ChargesDetail.Add(new Fare_ChargesDetail { Id = item.Id, FareId = item.FareId, OriginLocationTypeId = item.OriginLocationTypeId, DestinationLocationTypeId = item.DestinationLocationTypeId, OriginId = item.OriginId, DestinationId = item.DestinationId, FromAddress = item.FromAddress, ToAddress = item.ToAddress, Rate = Rate, NightTimeRate = item.NightTimeRate }); } var OtherChargesList = (from a in General.GetQueryable <Fare_OtherCharge>(c => c.FareId == FareId) select new { Id = a.Id, FareId = a.FareId, FromMile = a.FromMile, ToMile = a.ToMile, Rate = a.Rate, FromStartTime = HasOffPeakRate ? a.FromStartTime : null, TillStartTime = HasOffPeakRate ? a.TillStartTime : null, FromEndTime = HasOffPeakRate ? a.FromEndTime : null, TillEndTime = HasOffPeakRate ? a.TillEndTime : null, PeakTimeRate = HasOffPeakRate ? a.PeakTimeRate : 0, OffPeakTimeRate = HasOffPeakRate ? a.OffPeakTimeRate : 0, NightTimeRate = HasOffPeakRate ? a.NightTimeRate : 0, }).ToList(); OtherCharge.Clear(); foreach (var item in OtherChargesList) { OtherCharge.Add(new Fare_OtherCharge { Id = item.Id, FareId = item.FareId, FromMile = item.FromMile, ToMile = item.ToMile, Rate = item.Rate, FromStartTime = item.FromStartTime, TillStartTime = item.TillStartTime, FromEndTime = item.TillEndTime, TillEndTime = item.TillEndTime, PeakTimeRate = item.PeakTimeRate, OffPeakTimeRate = item.OffPeakTimeRate, NightTimeRate = item.NightTimeRate }); } var PDAMeterList = (from a in General.GetQueryable <Fare_PDAMeter>(c => c.FareId == FareId) select new { Id = a.Id, FareId = a.FareId, FromMile = a.FromMile, ToMile = a.ToMile, Rate = a.Rate, FromStartTime = HasOffPeakRate ? a.FromStartTime : null, TillStartTime = HasOffPeakRate ? a.TillStartTime : null, FromEndTime = HasOffPeakRate ? a.FromEndTime : null, TillEndTime = HasOffPeakRate ? a.TillEndTime : null, PeakTimeRate = HasOffPeakRate ? a.PeakTimeRate : 0, OffPeakTimeRate = HasOffPeakRate ? a.OffPeakTimeRate : 0, NightTimeRate = HasOffPeakRate ? a.NightTimeRate : 0, }).ToList(); PDAMeter.Clear(); foreach (var item in PDAMeterList) { PDAMeter.Add(new Fare_PDAMeter { Id = item.Id, FareId = item.FareId, FromMile = item.FromMile, ToMile = item.ToMile, Rate = item.Rate, FromStartTime = item.FromStartTime, TillStartTime = item.TillStartTime, FromEndTime = item.FromEndTime, TillEndTime = item.TillEndTime, PeakTimeRate = item.PeakTimeRate, OffPeakTimeRate = item.OffPeakTimeRate, NightTimeRate = item.NightTimeRate }); } var ZoneWisePricingList = (from a in General.GetQueryable <Fare_ZoneWisePricing>(c => c.FareId == FareId) select new { Id = a.Id, FareId = a.FareId, FromZoneId = a.FromZoneId, ToZoneId = a.ToZoneId, Price = a.Price, }).ToList(); ZoneWisePricing.Clear(); foreach (var item in ZoneWisePricingList) { ZoneWisePricing.Add(new Fare_ZoneWisePricing { Id = item.Id, FareId = item.FareId, FromZoneId = item.FromZoneId, ToZoneId = item.ToZoneId, Price = item.Price }); } var AirportAndStationList = (from a in General.GetQueryable <Gen_Company_AgentCommission>(c => c.FareId == FareId) select new { Id = a.Id, a.CompanyId, FareId = a.FareId, LocationId = a.LocationId, LocationTypeId = a.LocationTypeId, CommissionPercent = a.CommissionPercent, CommissionAmount = a.CommissionAmount, CommissionOnPercent = a.CommissionOnPercent, DayWise = a.DayWise, NightWise = a.NightWise, VehicleTypeId = a.VehicleTypeId, CompanyPrice = a.CompanyPrice, DriverPrice = a.DriverPrice, CustomerPrice = a.CustomerPrice }).ToList(); CompanyAirportandStation.Clear(); foreach (var item in AirportAndStationList) { CompanyAirportandStation.Add(new Gen_Company_AgentCommission { Id = item.Id, FareId = item.FareId, CompanyId = item.CompanyId, LocationId = item.LocationId, LocationTypeId = item.LocationTypeId, CommissionAmount = item.CommissionAmount, CommissionOnPercent = item.CommissionOnPercent, CommissionPercent = item.CommissionPercent, CompanyPrice = item.CompanyPrice, CustomerPrice = item.CustomerPrice, DayWise = item.DayWise, NightWise = item.NightWise, DriverPrice = item.DriverPrice, VehicleTypeId = item.VehicleTypeId }); } } else { var CompanyList = (from a in General.GetQueryable <Gen_Company>(null) select new { Id = a.Id, CompanyName = a.CompanyName }).ToList(); var queryy = CompanyList.Where(item => selectlist.Contains(item.Id)); foreach (var item in queryy) { if (objMaster.PrimaryKeyValue == null) { objMaster.New(); } else { objMaster.Edit(); } objMaster.Current.VehicleTypeId = Vechileid; // objMaster.Current.VehicleTypeId = VehicleTypeId.ToInt(); objMaster.Current.CompanyId = item.Id; objMaster.Current.IsCompanyWise = true; objMaster.Current.AddOn = DateTime.Now; objMaster.Current.AddBy = AppVars.LoginObj.LuserId.ToIntorNull(); objMaster.Current.StartRate = numStartRate.Value; objMaster.Current.StartRateValidMiles = numStartRateValidMiles.Value; string[] skipProperties = { "Gen_Company", "Gen_Location", "Gen_Location1", "Gen_LocationType", "Gen_LocationType1", "Fare", "Gen_Zone1", "Gen_Zone", "Fare_ZoneWisePricing1","Fare_ZoneWisePricing", "Fleet_VehicleType" }; IList <Fare_ChargesDetail> savedList = objMaster.Current.Fare_ChargesDetails; List <Fare_ChargesDetail> ListDetail = (from a in ChargesDetail select new Fare_ChargesDetail { Id = a.Id, FareId = objMaster.Current.Id, OriginLocationTypeId = a.OriginLocationTypeId, DestinationLocationTypeId = a.OriginLocationTypeId, OriginId = a.OriginId, DestinationId = a.DestinationId, FromAddress = a.FromAddress, ToAddress = a.ToAddress, Rate = a.Rate, NightTimeRate = a.NightTimeRate }).ToList(); Utils.General.SyncChildCollection(ref savedList, ref ListDetail, "Id", skipProperties); // OtherCharge IList <Fare_OtherCharge> savedList2 = objMaster.Current.Fare_OtherCharges; List <Fare_OtherCharge> listofOtherDetail = (from a in OtherCharge select new Fare_OtherCharge { Id = a.Id, FareId = a.FareId, FromMile = a.FromMile, ToMile = a.ToMile, Rate = a.Rate, FromStartTime = HasOffPeakRate ? a.FromStartTime : null, TillStartTime = HasOffPeakRate ? a.TillStartTime : null, FromEndTime = HasOffPeakRate ? a.FromEndTime : null, TillEndTime = HasOffPeakRate ? a.TillEndTime : null, PeakTimeRate = HasOffPeakRate ? a.PeakTimeRate : 0, OffPeakTimeRate = HasOffPeakRate ? a.OffPeakTimeRate : 0, NightTimeRate = HasOffPeakRate ? a.NightTimeRate : 0 }).ToList(); Utils.General.SyncChildCollection(ref savedList2, ref listofOtherDetail, "Id", skipProperties); // PDA METER IList <Fare_PDAMeter> savedList3 = objMaster.Current.Fare_PDAMeters; List <Fare_PDAMeter> listofpdaOtherDetail = (from a in PDAMeter select new Fare_PDAMeter { Id = a.Id, FareId = a.FareId, FromMile = a.FromMile, ToMile = a.ToMile, Rate = a.Rate, FromStartTime = HasOffPeakRate ? a.FromStartTime : null, TillStartTime = HasOffPeakRate ? a.TillStartTime : null, FromEndTime = HasOffPeakRate ? a.FromEndTime : null, TillEndTime = HasOffPeakRate ? a.TillEndTime : null, PeakTimeRate = HasOffPeakRate ? a.PeakTimeRate : 0, OffPeakTimeRate = HasOffPeakRate ? a.OffPeakTimeRate : 0, NightTimeRate = HasOffPeakRate ? a.NightTimeRate : 0 }).ToList(); Utils.General.SyncChildCollection(ref savedList3, ref listofpdaOtherDetail, "Id", skipProperties); IList <Fare_ZoneWisePricing> saveList4 = objMaster.Current.Fare_ZoneWisePricings; List <Fare_ZoneWisePricing> listofDetail4 = (from a in ZoneWisePricing select new Fare_ZoneWisePricing { Id = a.Id, FareId = a.FareId, FromZoneId = a.FromZoneId, ToZoneId = a.ToZoneId, Price = a.Price, }).ToList(); Utils.General.SyncChildCollection(ref saveList4, ref listofDetail4, "Id", skipProperties); //HP IList <Gen_Company_AgentCommission> saveList5 = objMaster.Current.Gen_Company_AgentCommissions; List <Gen_Company_AgentCommission> listofDetail5 = (from a in CompanyAirportandStation select new Gen_Company_AgentCommission { Id = a.Id, FareId = a.FareId, LocationId = a.LocationId, LocationTypeId = a.LocationTypeId, CommissionPercent = a.CommissionPercent, CommissionAmount = a.CommissionAmount, CommissionOnPercent = a.CommissionOnPercent, DayWise = a.DayWise, NightWise = a.NightWise, VehicleTypeId = a.VehicleTypeId, CompanyPrice = a.CompanyPrice, DriverPrice = a.DriverPrice, CustomerPrice = a.CustomerPrice, CompanyId = item.Id }).ToList(); Utils.General.SyncChildCollection(ref saveList5, ref listofDetail5, "Id", skipProperties); // objMaster.Save(); objMaster.Clear(); objMaster = new FareBO(); FaresSaved(item.Id); } } } catch (Exception ex) { if (objMaster.Errors.Count > 0) { ENUtils.ShowMessage(objMaster.ShowErrors()); } else { ENUtils.ShowMessage(ex.Message); } } }
public override void Save() { try { if (objMaster.PrimaryKeyValue == null) { objMaster.New(); } else { objMaster.Edit(); } // objMaster.Current.EffectiveDate = dtpEffectiveDate.Value.ToDateorNull(); objMaster.Current.VehicleTypeId = ddlVehicleType.SelectedValue.ToIntorNull(); objMaster.Current.IsCompanyWise = chkCompanyWise.Checked; objMaster.Current.CompanyId = ddlCompany.SelectedValue.ToIntorNull(); objMaster.Current.SubCompanyId = ddlSubCompanyId.SelectedValue.ToIntorNull(); // Fare_ChargesDetail c = new Fare_ChargesDetail(); //NC 16/12/16 decimal StartRate = numStartRate.Value.ToDecimal(); decimal ValidMiles = numValidMiles.Value.ToDecimal(); decimal FromStartRate = numFromStartRate.Value.ToDecimal(); decimal FromValidMiles = numFromValidMiles.Value.ToDecimal(); decimal TillStartRate = numTillStartRate.Value.ToDecimal(); decimal TillValidMiles = numTillValidMiles.Value.ToDecimal(); //DateTime dateValue = new DateTime(1900, 1, 1, 0, 0, 0); //DateTime? fromPeakTimeStartTime = string.Format("{0:dd/MM/yyyy HH:mm}", dateValue.ToDate() + dtpPeakTimeFromStartTime.Value.Value.TimeOfDay).ToDateTime(); //DateTime? tillPeakTimeStartTime = string.Format("{0:dd/MM/yyyy HH:mm}", dateValue.ToDate() + dtpPeakTimeToStartTime.Value.Value.TimeOfDay).ToDateTime(); //DateTime? fromOffPeakFromEndTime = string.Format("{0:dd/MM/yyyy HH:mm}", dateValue.ToDate() + dtpOffPeakFromEndTime.Value.Value.TimeOfDay).ToDateTime(); //DateTime? tillOffPeakToEndTime = string.Format("{0:dd/MM/yyyy HH:mm}", dateValue.ToDate() + dtpOffPeakToEndTime.Value.Value.TimeOfDay).ToDateTime(); DateTime dateValue = new DateTime(1900, 1, 1, 0, 0, 0); DateTime?fromPeakTimeStartTime = null; DateTime?tillPeakTimeStartTime = null; DateTime?fromOffPeakFromEndTime = null; DateTime?tillOffPeakToEndTime = null; if (dtpPeakTimeFromStartTime.Value != null) { fromPeakTimeStartTime = string.Format("{0:dd/MM/yyyy HH:mm}", dateValue.ToDate() + dtpPeakTimeFromStartTime.Value.Value.TimeOfDay).ToDateTime(); } if (dtpPeakTimeToStartTime.Value != null) { tillPeakTimeStartTime = string.Format("{0:dd/MM/yyyy HH:mm}", dateValue.ToDate() + dtpPeakTimeToStartTime.Value.Value.TimeOfDay).ToDateTime(); } if (dtpOffPeakFromEndTime.Value != null) { fromOffPeakFromEndTime = string.Format("{0:dd/MM/yyyy HH:mm}", dateValue.ToDate() + dtpOffPeakFromEndTime.Value.Value.TimeOfDay).ToDateTime(); } if (dtpOffPeakToEndTime.Value != null) { tillOffPeakToEndTime = string.Format("{0:dd/MM/yyyy HH:mm}", dateValue.ToDate() + dtpOffPeakToEndTime.Value.Value.TimeOfDay).ToDateTime(); } if (radPanel8.Visible == false) { fromPeakTimeStartTime = null; tillPeakTimeStartTime = null; fromOffPeakFromEndTime = null; tillOffPeakToEndTime = null; FromStartRate = 0; FromValidMiles = 0; TillStartRate = 0; TillValidMiles = 0; } else { StartRate = 0; ValidMiles = 0; } objMaster.FromStartTime = fromPeakTimeStartTime != null?fromPeakTimeStartTime.Value.ToDateTimeorNull() : null; objMaster.FromEndTime = tillPeakTimeStartTime != null?tillPeakTimeStartTime.Value.ToDateTimeorNull() : null; objMaster.TillStartTime = fromOffPeakFromEndTime != null?fromOffPeakFromEndTime.Value.ToDateTimeorNull() : null; objMaster.TillEndTime = tillOffPeakToEndTime != null?tillOffPeakToEndTime.Value.ToDateTimeorNull() : null; objMaster.FromStartRate = FromStartRate; objMaster.FromStartRateValidMiles = FromValidMiles; objMaster.TillStartRate = TillStartRate; objMaster.TillStartRateValidMiles = TillValidMiles; objMaster.StartRate = StartRate; objMaster.StartRateValidMiles = ValidMiles; // string[] skipProperties = { "Gen_Location", "Gen_Location1", "Gen_LocationType", "Gen_LocationType1", "Fare", "Gen_Zone1", "Gen_Zone","Fare_ZoneWisePricing1", "Fare_ZoneWisePricing" }; // PDA METER IList <Fare_PDAMeter> savedList3 = objMaster.Current.Fare_PDAMeters; List <Fare_PDAMeter> listofpdaOtherDetail = (from r in grdPDAOtherCharges.Rows select new Fare_PDAMeter { Id = r.Cells[COLS_OTHERDETAILS.ID].Value.ToLong(), FareId = r.Cells[COLS_OTHERDETAILS.FAREID].Value.ToInt(), FromMile = r.Cells[COLS_OTHERDETAILS.FROMMILE].Value.ToDecimal(), ToMile = r.Cells[COLS_OTHERDETAILS.TOMILE].Value.ToDecimal(), Rate = r.Cells[COLS_OTHERDETAILS.FARE].Value.ToDecimal(), FromStartTime = fromPeakTimeStartTime != null ? string.Format("{0:dd/MM/yyyy HH:mm}", dateValue.ToDate() + r.Cells[COLS_OTHERDETAILS.FROMSTARTTIME].Value.ToDateTimeorNull().Value.TimeOfDay).ToDateTime() : dateValue, TillStartTime = tillPeakTimeStartTime != null? string.Format("{0:dd/MM/yyyy HH:mm}", dateValue.ToDate() + r.Cells[COLS_OTHERDETAILS.TILLSTARTTIME].Value.ToDateTimeorNull().Value.TimeOfDay).ToDateTime():dateValue, FromEndTime = fromOffPeakFromEndTime != null? string.Format("{0:dd/MM/yyyy HH:mm}", dateValue.ToDate() + r.Cells[COLS_OTHERDETAILS.FROMENDTIME].Value.ToDateTimeorNull().Value.TimeOfDay).ToDateTime():dateValue, TillEndTime = tillOffPeakToEndTime != null ? string.Format("{0:dd/MM/yyyy HH:mm}", dateValue.ToDate() + r.Cells[COLS_OTHERDETAILS.TILLENDTIME].Value.ToDateTimeorNull().Value.TimeOfDay).ToDateTime() : dateValue, PeakTimeRate = HasOffPeakRate ? r.Cells[COLS_OTHERDETAILS.PEAKRATE].Value.ToDecimal() : 0, OffPeakTimeRate = HasOffPeakRate ? r.Cells[COLS_OTHERDETAILS.OFFPEAKRATE].Value.ToDecimal() : 0, }).ToList(); Utils.General.SyncChildCollection(ref savedList3, ref listofpdaOtherDetail, "Id", skipProperties); objMaster.UpdateStartRates = true; objMaster.Save(); General.RefreshListWithoutSelected <frmFaresList>("frmFaresList1"); } catch (Exception ex) { if (objMaster.Errors.Count > 0) { ENUtils.ShowMessage(objMaster.ShowErrors()); } else { ENUtils.ShowMessage(ex.Message); } } }