public override void Save() { try { if (objNotes.PrimaryKeyValue != null) { objNotes.Edit(); string[] skipProperties = { "Gen_Location", "Booking", "Gen_LocationType" }; IList <Booking_Note> savedList3 = objNotes.Current.Booking_Notes; List <Booking_Note> listofDetail3 = (from r in grdNotes.Rows select new Booking_Note { Id = r.Cells[COL_NOTE.ID].Value.ToInt(), BookingId = BookingId, notes = r.Cells[COL_NOTE.NOTES].Value.ToStr(), }).ToList(); Utils.General.SyncChildCollection(ref savedList3, ref listofDetail3, "Id", skipProperties); objNotes.Save(); } this.Close(); } catch (Exception ex) { if (objNotes.Errors.Count > 0) { ENUtils.ShowMessage(objNotes.ShowErrors()); } else { ENUtils.ShowMessage(ex.Message); } } }
private void btnSend_Click(object sender, EventArgs e) { try { int?[] drvIds = grdDrivers.Rows.Where(c => c.Cells["colChk"].Value.ToBool()).Select(a => a.Cells["colId"].Value.ToIntorNull()).ToArray <int?>(); if (drvIds.Count() == 0) { ENUtils.ShowMessage("Please select atleast one driver"); return; } string msg = string.Empty; string driverIds = string.Empty; // lblPrice.Text = objBooking.Current.FareRate.ToStr(); long JobId = _objBooking.Id.ToLong(); DateTime currentDateTime = DateTime.Now; DateTime?currentJobPickupDateTime = _objBooking.PickupDateTime; var existingJobs = General.GetQueryable <Booking>(c => c.Id != JobId && c.DriverId != null && (c.BookingStatusId == Enums.BOOKINGSTATUS.PENDING || c.BookingStatusId == Enums.BOOKINGSTATUS.PENDING_START) && c.PickupDateTime > currentDateTime ).AsEnumerable().Where(c => drvIds.Count(a => a == c.DriverId) > 0).ToList(); string errorMsg = string.Empty; if (existingJobs.Count() > 0) { foreach (var job in existingJobs) { if (job.PickupDateTime < currentJobPickupDateTime && currentJobPickupDateTime.Value.Subtract(job.PickupDateTime.ToDateTime()).TotalHours < 1) { errorMsg += job.Fleet_Driver.DefaultIfEmpty().DriverNo + " already have a job at " + string.Format("{0:dd/MM - HH:mm}", job.PickupDateTime) + Environment.NewLine; } else if (job.PickupDateTime > currentJobPickupDateTime && job.PickupDateTime.ToDateTime().Subtract(currentJobPickupDateTime.ToDateTime()).TotalHours < 1) { errorMsg += job.Fleet_Driver.DefaultIfEmpty().DriverNo + " already have a job at " + string.Format("{0:dd/MM - HH:mm}", job.PickupDateTime) + Environment.NewLine; } } } if (!string.IsNullOrEmpty(errorMsg)) { ENUtils.ShowMessage(errorMsg); return; } objBooking.Edit(); string[] skipProperties = new string[] { "Booking", "Fleet_Driver", "BiddingStatus" }; if (grdDrivers.Columns.Count > 0) { msg = "Bid Price Alert>>Price Bidding Alert " + lblPrice.Text + "=13"; // List<obj.Current.Booking_Biddings> listofAirportPickup = (from a in grdDrivers.Rows List <Booking_Bidding> listofBidding = (from a in grdDrivers.Rows.Where(c => c.Cells["colChk"].Value.ToBool()) select new Booking_Bidding { Id = a.Cells["Id"].Value.ToInt(), JobId = JobId, DriverId = a.Cells["colId"].Value.ToIntorNull(), }).ToList(); IList <Booking_Bidding> savedList = objBooking.Current.Booking_Biddings; Utils.General.SyncChildCollection(ref savedList, ref listofBidding, "Id", skipProperties); // int?[] loginDrvs= General.GetQueryable<Fleet_DriverQueueList>(c => c.Status == true).Select(args=>args.DriverId).ToArray<int?>(); int[] loginDrvs = General.GetQueryable <Fleet_Driver_Location>(c => c.UpdateDate > (currentDateTime.AddSeconds(-30))) .Select(args => args.DriverId).ToArray <int>(); IList <Fleet_Driver_OfflineJob> savedList2 = objBooking.Current.Fleet_Driver_OfflineJobs; List <Fleet_Driver_OfflineJob> listofOfflineMsgs = (from a in grdDrivers.Rows.Where(c => c.Cells["colChk"].Value.ToBool()) select new Fleet_Driver_OfflineJob { BookingId = JobId, DriverId = a.Cells["colId"].Value.ToIntorNull(), UpdatedOn = currentDateTime, OfflineMessage = msg, }).ToList(); listofOfflineMsgs.RemoveAll(c => loginDrvs.Count(a => a == c.DriverId) > 0); Utils.General.SyncChildCollection(ref savedList2, ref listofOfflineMsgs, "Id", skipProperties, c => c.OfflineMessage == msg); string[] drvIdArr = listofBidding.Select(c => c.DriverId.ToStr()).ToArray <string>(); driverIds = string.Join(",", drvIdArr); int loopCnt = 1; new Thread(delegate() { while (loopCnt < 3) { bool success = General.SendMessageToPDA("request pda=" + driverIds + "=" + _objBooking.Id + "=" + msg).Result.ToBool(); if (success) { break; } else { loopCnt++; } } }).Start(); } objBooking.CheckCustomerValidation = false; objBooking.CheckDataValidation = false; DateTime?biddingExpiryDateTime = objBooking.Current.PickupDateTime.Value.AddHours(-2); if (objBooking.Current.PickupDateTime.Value.Date <= DateTime.Now.Date) { biddingExpiryDateTime = objBooking.Current.PickupDateTime.Value.AddMinutes(-15); } objBooking.Current.PriceBiddingExpiryDate = biddingExpiryDateTime; objBooking.Save(); // using(TaxiDataContext db= //string queryDeleteOfflineMsgs="delete from fleet_driver_offlinejobs where offlinemessage='"+msg+"' and driverid in("+driverIds+")"; //using (TaxiDataContext db = new TaxiDataContext()) //{ // // db.stp_RunProcedure(.Where(c => c.Status == true).Select(c=>c.DriverId.ToList(); //} Close(); } catch (Exception ex) { ENUtils.ShowMessage(ex.Message); } }
private void Save() { decimal Fare = txtFare.Value; decimal custFare = txtCustFare.Value; decimal compFare = txtCompFare.Value; decimal oldFares = 0.00m; decimal oldTotalCharges = 0.00m; decimal TotalCharges = 0.00m; if (ObjMaster.Current != null) { bool allowUpdateTransaction = false; try { long id = ObjMaster.Current.Id; if (AppVars.listUserRights.Count(c => c.formName == "frmBooking" && (c.functionId == "LOCK BOOKING AFTER TRANSACTION")) > 0) { int reasonCnt = 0; string error = string.Empty; using (TaxiDataContext db = new TaxiDataContext()) { if (db.Invoice_Charges.Count(c => c.BookingId == id) > 0) { reasonCnt++; error = reasonCnt + ". Account Invoice Exist" + Environment.NewLine; } if (db.DriverRent_Charges.Count(c => c.BookingId == id) > 0) { reasonCnt++; error += reasonCnt + ". Driver Rent Statement Exist" + Environment.NewLine; } if (db.Fleet_DriverCommision_Charges.Count(c => c.BookingId == id) > 0) { reasonCnt++; error += reasonCnt + ". Driver Commission Statement Exist" + Environment.NewLine; } } if (error.Length > 0) { ENUtils.ShowMessage("You cannot edit this booking" + Environment.NewLine + Environment.NewLine + "Reasons:-" + Environment.NewLine + error); return; } } else { allowUpdateTransaction = true; } } catch { } string pdafares = AppVars.objPolicyConfiguration.PDAFaresPropertyName.ToStr().ToLower().Trim(); ObjMaster.CheckDataValidation = false; ObjMaster.AllowUpdateTransaction = allowUpdateTransaction; ObjMaster.Edit(); oldFares = ObjMaster.Current.FareRate.ToDecimal(); oldTotalCharges = ObjMaster.Current.TotalCharges.ToDecimal(); ObjMaster.Current.FareRate = Fare; ObjMaster.Current.CustomerPrice = custFare; ObjMaster.Current.CompanyPrice = compFare; ObjMaster.DisableUpdateReturnJob = true; ObjMaster.CheckCustomerValidation = false; farerate = Fare; if (oldFares != Fare) { ObjMaster.Current.Booking_Logs.Add(new Booking_Log { BookingId = ObjMaster.Current.Id, User = AppVars.LoginObj.LoginName, BeforeUpdate = "Fares : " + oldFares, AfterUpdate = "Update from (Edit Fare) ,Fares : " + Fare, UpdateDate = DateTime.Now }); General.UpdateOnlineBookingFares(ObjMaster.Current.OnlineBookingId.ToLong(), Fare, ObjMaster.Current.BookingTypeId.ToInt()); } if (ObjMaster.Current.CompanyId == null) { ObjMaster.Current.TotalCharges = ObjMaster.Current.FareRate.ToDecimal() + ObjMaster.Current.ExtraDropCharges.ToDecimal() + ObjMaster.Current.MeetAndGreetCharges.ToDecimal() + ObjMaster.Current.CongtionCharges.ToDecimal(); } else { ObjMaster.Current.TotalCharges = ObjMaster.Current.CompanyPrice.ToDecimal() + ObjMaster.Current.ParkingCharges.ToDecimal() + ObjMaster.Current.WaitingCharges.ToDecimal() + ObjMaster.Current.ExtraDropCharges.ToDecimal(); } TotalCharges = ObjMaster.Current.TotalCharges.ToDecimal(); ObjMaster.Save(); this.Close(); //if (openForm == 1) //{ // // AppVars.frmMDI.RefreshDashBoardBookings(); // // General.RefreshListWithoutSelected<frmBookingDashBoard>("frmBookingDashBoard1"); //} if (openForm == 2) { (Application.OpenForms.OfType <Form>().FirstOrDefault(c => c.Name == "frmBookingDashBoard") as frmBookingDashBoard).RefreshBookingList(); // AppVars.frmMDI.RefreshDashBoardBookings(); } else if (openForm == 0) { General.RefreshListWithoutSelected <frmBookingsList>("frmBookingsList1"); } // For TCP Connection if (ObjMaster.Current.DriverId != null && ObjMaster.Current.Gen_PaymentType.ShowFaresOnPDA.ToStr() == "1" && (ObjMaster.Current.BookingStatusId == Enums.BOOKINGSTATUS.ONROUTE || ObjMaster.Current.BookingStatusId == Enums.BOOKINGSTATUS.ARRIVED || ObjMaster.Current.BookingStatusId == Enums.BOOKINGSTATUS.POB || ObjMaster.Current.BookingStatusId == Enums.BOOKINGSTATUS.STC) && AppVars.objPolicyConfiguration.IsListenAll.ToBool() && !string.IsNullOrEmpty(AppVars.objPolicyConfiguration.ListenerIP.ToStr().Trim())) { if (pdafares == "totalcharges") { oldFares = oldTotalCharges; Fare = TotalCharges; } if (oldFares != Fare) { string A_Phone = ObjMaster.Current.CustomerPhoneNo.ToStr(); string Phone = ObjMaster.Current.CustomerPhoneNo.ToStr(); string mobNo = ObjMaster.Current.CustomerMobileNo; if (string.IsNullOrEmpty(mobNo)) { mobNo = " "; } else if (!string.IsNullOrEmpty(A_Phone)) { mobNo = Phone + "/" + A_Phone; } string A_Account = ObjMaster.Current.Gen_Company.DefaultIfEmpty().CompanyName.ToStr(); if (string.IsNullOrEmpty(A_Account)) { A_Account = " "; } string babySeats = ObjMaster.Current.BabySeats.ToStr().Trim(); if (string.IsNullOrEmpty(babySeats)) { babySeats = " "; } string A_journeyType = "O/W"; if (ObjMaster.Current.JourneyTypeId.ToInt() == Enums.JOURNEY_TYPES.WAITANDRETURN) { A_journeyType = "W/R"; } string A_Via = " "; if (ObjMaster.Current.ViaString.ToStr().Trim().Length > 0) { int i = 1; A_Via = string.Join(" * ", ObjMaster.Current.Booking_ViaLocations.Select(c => "(" + i++.ToStr() + ")" + c.ViaLocValue.ToStr()).ToArray <string>()); } string msg = (!string.IsNullOrEmpty(ObjMaster.Current.FromDoorNo) ? ObjMaster.Current.FromDoorNo + "-" + ObjMaster.Current.FromAddress + ObjMaster.Current.Gen_Zone1.DefaultIfEmpty().ZoneName.ToStr() : ObjMaster.Current.FromAddress + ObjMaster.Current.Gen_Zone1.DefaultIfEmpty().ZoneName.ToStr()) + ">>" + (!string.IsNullOrEmpty(ObjMaster.Current.ToDoorNo) ? ObjMaster.Current.ToDoorNo + "-" + ObjMaster.Current.ToAddress + ObjMaster.Current.Gen_Zone.DefaultIfEmpty().ZoneName.ToStr() : ObjMaster.Current.ToAddress + ObjMaster.Current.Gen_Zone.DefaultIfEmpty().ZoneName.ToStr()) + ">>" + string.Format("{0:dd/MM/yyyy HH:mm}", ObjMaster.Current.PickupDateTime) + ">>" + ObjMaster.Current.CustomerName + ">>" + mobNo + ">>" + ObjMaster.Current.SpecialRequirements.ToStr() + " " + ">>" + Fare + ">>" + ObjMaster.Current.Fleet_VehicleType.DefaultIfEmpty().VehicleType.ToStr() + ">>" + A_Account + ">>" + A_journeyType + ">>" + ObjMaster.Current.Gen_PaymentType.PaymentType.ToStr() + ">>" + A_Via + ">>" + ObjMaster.Current.NoofPassengers.ToInt() + ">>" + ObjMaster.Current.NoofLuggages.ToInt() + ">>" + babySeats; new Thread(delegate() { General.SendMessageToPDA("request pda=" + ObjMaster.Current.DriverId + "=" + ObjMaster.Current.Id + "=" + "Update Job>>" + ObjMaster.Current.DriverId + ">>" + ObjMaster.Current.Id + ">>" + msg + "=8"); }).Start(); } } } }
private void Save() { try { int defaultAllocationLimit = AppVars.objPolicyConfiguration.AllocateDrvPreExistJobLimit.ToInt(); int? driverId = ddl_Driver.SelectedValue.ToIntorNull(); int? oldDriverId = null; string oldDriverNo = string.Empty; long jobId = 0; bool cancelJob = false; DateTime?pickupDateAndTime = ObjMaster.Current.PickupDateTime.ToDateTimeorNull(); //if (driverId != null && defaultAllocationLimit>0 && // General.GetQueryable<Booking>(null).Count(c => c.DriverId == driverId && c.Id!=ObjMaster.Current.Id // && (c.BookingStatusId==Enums.BOOKINGSTATUS.WAITING || c.BookingStatusId==Enums.BOOKINGSTATUS.PENDING) // && // ( // (c.PickupDateTime.Value<=pickupDateAndTime // && (c.PickupDateTime.Value >= pickupDateAndTime.Value.AddMinutes(-defaultAllocationLimit)) ) // || (c.PickupDateTime.Value >= pickupDateAndTime // && (c.PickupDateTime.Value <= pickupDateAndTime.Value.AddMinutes(defaultAllocationLimit))) // ) // ) > 0) //{ // if (DialogResult.No == MessageBox.Show("This driver already have a Job Allocated at this time "+ // Environment.NewLine + "Do you still want to Allocate it ? ", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) // { // return; // } //} if (driverId != null) { var ObjDriver = General.GetObject <Fleet_Driver>(c => c.Id == driverId); if (ObjDriver != null) { allocateDrvNo = ObjDriver.DriverNo.ToStr().Trim(); if (ObjDriver.VehicleTypeId != null) { if (ObjMaster.Current.AttributeValues.ToStr().Trim().Length > 0) { string[] bookingAttrs = ObjMaster.Current.AttributeValues.ToStr().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string drvAttributes = ObjDriver.AttributeValues.ToStr() + "," + ObjDriver.Fleet_VehicleType.AttributeValues; int totalAttr = bookingAttrs.Count(); int matchCnt = 0; string unmatchedAttrValue = string.Empty; string[] drvAttrsArr = drvAttributes.ToStr().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (var item in bookingAttrs) { if (drvAttrsArr.Count(c => c.ToLower() == item.ToLower()) > 0) { matchCnt++; } else { unmatchedAttrValue += item + ","; } } if (matchCnt != totalAttr) { if (unmatchedAttrValue.EndsWith(",")) { unmatchedAttrValue = unmatchedAttrValue.Substring(0, unmatchedAttrValue.LastIndexOf(",")); } MessageBox.Show(("Driver : " + ObjDriver.DriverNo + " doesn't have attributes (" + unmatchedAttrValue + ")"), "Warning"); return; } } if (AppVars.listUserRights.Count(c => c.functionId == "RESTRICT ON DESPATCH JOB TO INVALID VEHICLE DRIVER") > 0) { string vehAttributes = ObjMaster.Current.Fleet_VehicleType.DefaultIfEmpty().AttributeValues.ToStr().Trim(); if (vehAttributes.Length > 0) { bool MatchedAttr = false; foreach (var item in vehAttributes.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { if (ObjDriver.VehicleTypeId.ToInt() == item.ToInt()) { MatchedAttr = true; break; } } if (MatchedAttr == false) { MessageBox.Show("This Job is for " + ObjMaster.Current.Fleet_VehicleType.VehicleType.ToStr() + " Vehicle" + Environment.NewLine + "and Driver no " + ObjDriver.DriverNo + " have " + ObjDriver.Fleet_VehicleType.VehicleType + "."); return; } } else { if (ObjDriver.Fleet_VehicleType.NoofPassengers.ToInt() < ObjMaster.Current.Fleet_VehicleType.NoofPassengers.ToInt()) { MessageBox.Show("This Job is for " + ObjMaster.Current.Fleet_VehicleType.VehicleType.ToStr() + " Vehicle" + Environment.NewLine + "and Driver no " + ObjDriver.DriverNo + " have " + ObjDriver.Fleet_VehicleType.VehicleType + "."); return; } } } else { if (ObjDriver.Fleet_VehicleType.NoofPassengers.ToInt() < ObjMaster.Current.Fleet_VehicleType.NoofPassengers.ToInt()) { if (DialogResult.No == MessageBox.Show("This Job is for " + ObjMaster.Current.Fleet_VehicleType.VehicleType.ToStr() + " Vehicle" + Environment.NewLine + "and Driver no " + ObjDriver.DriverNo + " have " + ObjDriver.Fleet_VehicleType.VehicleType + "." + Environment.NewLine + "Do you still want to Allocate this Job to that Driver " + ObjDriver.DriverNo + " ?", "Despatch", MessageBoxButtons.YesNo)) { return; } } } } } try { if ((driverId != null && ObjMaster.Current.DriverId == null) || (driverId != null && ObjMaster.Current.DriverId != null && driverId != ObjMaster.Current.DriverId)) { if (IsDriverDocumentExpired(driverId.ToInt(), ObjDriver)) { return; } } } catch { } } if (ObjMaster.Current != null) { if (driverId != null || (ObjMaster.Current.DriverId != null && ObjMaster.Current.BookingStatusId.ToInt() == Enums.BOOKINGSTATUS.WAITING)) { //if ((driverId != null && ObjMaster.Current.DriverId == null) || (driverId!=null && ObjMaster.Current.DriverId!=null && driverId!=ObjMaster.Current.DriverId)) //{ // if (IsDriverDocumentExpired(driverId.ToInt())) // return; //} if (driverId == null && ObjMaster.Current.DriverId != null) { oldDriverNo = ObjMaster.Current.Fleet_Driver.DriverNo.ToStr(); } if (ObjMaster.Current.DriverId != null) { oldDriverId = ObjMaster.Current.DriverId; } ObjMaster.CheckDataValidation = false; ObjMaster.Edit(); ObjMaster.Current.DriverId = driverId; ObjMaster.Current.IsConfirmedDriver = driverId != null ? chkConfirmed.Checked:false; if (ObjMaster.Current.BookingStatusId.ToInt() == Enums.BOOKINGSTATUS.NOTACCEPTED) { ObjMaster.Current.BookingStatusId = Enums.BOOKINGSTATUS.WAITING; } if (driverId == null || (oldDriverId != null && oldDriverId != driverId && ObjMaster.Current.BookingStatusId != Enums.BOOKINGSTATUS.WAITING)) { ObjMaster.Current.BookingStatusId = Enums.BOOKINGSTATUS.WAITING; cancelJob = true; } jobId = ObjMaster.Current.Id; allocatedJobId = jobId; ObjMaster.CheckCustomerValidation = false; ObjMaster.DisableUpdateReturnJob = true; ObjMaster.Save(); if (ObjMaster.Current.BookingTypeId.ToInt() == Enums.BOOKING_TYPES.THIRDPARTY && ObjMaster.Current.OnlineBookingId != null) { General.UpdateThirdPartyJobStatus(null, jobId, "allocated"); } this.Close(); if (IsOpenFrom == 1) { RefreshTodayBookingsDashboard(); } else { RefreshTodayAndPreBookingsDashboard(); // AppVars.frmMDI.RefreshTodayAnPreDashboard(); } string Msg = string.Empty; if (driverId != null) { if (chkConfirmed.Checked) { Msg = "Job is Allocated and confirmed to Driver (" + ObjMaster.Current.Fleet_Driver.DriverNo.ToStr() + ")"; } else { Msg = "Job is Allocated to Driver (" + ObjMaster.Current.Fleet_Driver.DriverNo.ToStr() + ")"; } } else if (driverId == null && !string.IsNullOrEmpty(oldDriverNo)) { Msg = "Job is De-Allocated from Driver (" + oldDriverNo + ")"; } using (TaxiDataContext db = new TaxiDataContext()) { db.stp_BookingLog(ObjMaster.Current.Id, AppVars.LoginObj.UserName.ToStr(), Msg); if (cancelJob) { if (AppVars.objPolicyConfiguration.DespatchOfflineJobs.ToBool()) { db.stp_DeleteDrvOfflineJob(ObjMaster.Current.Id, oldDriverId); } } } if (cancelJob) { //For TCP Connection if (AppVars.objPolicyConfiguration.IsListenAll.ToBool()) { new Thread(delegate() { General.SendMessageToPDA("request pda=" + oldDriverId + "=" + jobId + "=Cancelled Pre Job>>" + jobId + "=2"); }).Start(); } } } else { ENUtils.ShowMessage("Required: Driver"); } } } catch (Exception ex) { } }