Ejemplo n.º 1
0
        private void PlotDriver(int?driverId, int?zoneId, int?FleetId)
        {
            DriverQueueBO objMaster = null;

            try
            {
                Fleet_DriverQueueList objPlottedDriver = General.GetObject <Fleet_DriverQueueList>(c => c.Status == true && c.DriverId == driverId);

                objMaster = new DriverQueueBO();
                if (objPlottedDriver == null)
                {
                    objMaster.New();
                    objMaster.Current.LoginDateTime = DateTime.Now;
                }
                else
                {
                    objMaster.GetByPrimaryKey(objPlottedDriver.Id);
                }

                objMaster.Current.FleetMasterId = FleetId;
                objMaster.Current.ZoneId        = zoneId;
                objMaster.Current.DriverId      = driverId;
                objMaster.Current.Status        = true;


                if (objMaster.Current.Fleet_Driver == null || objMaster.Current.Fleet_Driver.HasPDA.ToBool() == false)
                {
                    objMaster.Current.QueueDateTime = DateTime.Now;
                }

                objMaster.Save();

                if (objMaster.Current.Fleet_Driver.HasPDA.ToBool())
                {
                    if (zoneId != null)
                    {
                        string zoneName = ddlZone.Text.ToUpper().Trim();


                        if (objMaster.Current.CurrentJobId != null)
                        {
                            string msg         = string.Empty;
                            string pickUpPlot  = string.Empty;
                            string dropOffPlot = string.Empty;

                            if (AppVars.objPolicyConfiguration.DefaultClientId.ToStr() == "AbbeyCarsleeds")
                            {
                                pickUpPlot = objMaster.Current.ZoneId != null ? "<<<" + objMaster.Current.Booking.Gen_Zone1.ZoneName.ToStr() : "";

                                if (zoneName.Contains("("))
                                {
                                    zoneName = zoneName.Remove(zoneName.IndexOf("("));
                                }

                                if (zoneName.Contains("."))
                                {
                                    zoneName = zoneName.Substring(zoneName.IndexOf(".") + 1);
                                }

                                dropOffPlot = objMaster.Current.Booking.DropOffZoneId != null ? "<<<" + zoneName.Trim() : "";
                            }

                            string mobNo = objMaster.Current.Booking.CustomerMobileNo;
                            if (string.IsNullOrEmpty(mobNo))
                            {
                                mobNo = " ";
                            }


                            msg = (!string.IsNullOrEmpty(objMaster.Current.Booking.FromDoorNo) ? objMaster.Current.Booking.FromDoorNo + "-" + objMaster.Current.Booking.FromAddress + pickUpPlot : objMaster.Current.Booking.FromAddress + pickUpPlot) +
                                  ">>" +
                                  (!string.IsNullOrEmpty(objMaster.Current.Booking.ToDoorNo) ? objMaster.Current.Booking.ToDoorNo + "-" + objMaster.Current.Booking.ToAddress + dropOffPlot : objMaster.Current.Booking.ToAddress + dropOffPlot) +
                                  ">>" +
                                  string.Format("{0:dd/MM/yyyy   HH:mm}", objMaster.Current.Booking.PickupDateTime) +
                                  ">>" +
                                  objMaster.Current.Booking.CustomerName +
                                  ">>" +
                                  mobNo;


                            // For TCP Connection
                            if (AppVars.objPolicyConfiguration.IsListenAll.ToBool() && !string.IsNullOrEmpty(AppVars.objPolicyConfiguration.ListenerIP.ToStr().Trim()))
                            {
                                new Thread(delegate()
                                {
                                    General.SendMessageToPDA("request pda=" + driverId + "=" + objMaster.Current.CurrentJobId + "=" + "Update Job>>" + driverId + ">>" + objMaster.Current.CurrentJobId + ">>" + msg + "=8");
                                }).Start();
                            }

                            new TaxiDataContext().stp_UpdateJobDropOffPlot(objMaster.Current.CurrentJobId, driverId, zoneId);

                            new BroadcasterData().BroadCastToAll(RefreshTypes.REFRESH_DASHBOARD_DRIVER);
                        }
                    }
                }
                else
                {
                    General.RefreshListWithoutSelected <frmDriverLoginList>("frmDriverLoginList1");
                    //  General.RefreshWaitingDrivers();
                }


                this.PlottedDriverId = driverId;
                this.Plotted         = true;

                this.Close();
            }

            catch (Exception ex)
            {
                if (objMaster.Errors.Count > 0)
                {
                    ENUtils.ShowMessage(objMaster.ShowErrors());
                }
                else
                {
                    ENUtils.ShowMessage(ex.Message);
                }
            }
        }
        private void LoginDriver()
        {
            try
            {
                bool IsValidate = false;

                List <int?> ids = grdDrivers.Rows.Where(c => c.Cells["colChk"].Value.ToBool()).Select(c => c.Cells["colId"].Value.ToIntorNull()).ToList();

                if (ids.Count == 0)
                {
                    IsValidate = true;
                    ENUtils.ShowMessage("Please select a Driver");
                    return;
                }

                //  List<int?> ids = lstDriver.SelectedItems.Select(c => c.Value.ToIntorNull()).ToList();

                using (TaxiDataContext db = new TaxiDataContext())
                {
                    if (db.Fleet_DriverQueueLists.Count(c => ids.Contains(c.DriverId) && c.Status == true) > 0)
                    {
                        ENUtils.ShowMessage("Some Selected Driver(s)  already in the Login List..");
                        IsValidate = true;
                        grdDrivers.Focus();
                        // lstDriver.Focus();
                        return;
                    }
                }

                //if (totalFleets> 0 &&  grdDrivers.Rows.Where(c=>c.Cells["colChk"].Value.ToBool().Any(c => c.Cells["colVeh"].Value.ToIntorNull()==null))
                //{
                //    ENUtils.ShowMessage("Required Vehicle");
                //    return;


                //}



                DriverQueueBO objMaster = null;
                int?          driverId  = null;
                string        driverNos = "";
                foreach (GridViewRowInfo row in grdDrivers.Rows.Where(c => c.Cells["colChk"].Value.ToBool()))
                {
                    driverId = row.Cells["colId"].Value.ToIntorNull();

                    objMaster = new DriverQueueBO();
                    objMaster.New();

                    objMaster.Current.DriverId      = driverId;
                    objMaster.Current.FleetMasterId = row.Cells["colVeh"].Value.ToIntorNull();

                    objMaster.Current.IsManualLogin = true;


                    if (objMaster.Current.FleetMasterId == null)
                    {
                        using (TaxiDataContext db = new TaxiDataContext())
                        {
                            int cnt = db.Fleet_Driver_PDASettings.Where(c => c.DriverId == objMaster.Current.DriverId && (c.HasCompanyCars != null && c.HasCompanyCars == true)).Count();


                            if (cnt > 0)
                            {
                                IsValidate = true;
                                ENUtils.ShowMessage("Required Vehicle");
                                break;
                            }
                        }
                    }
                    else
                    {
                        using (TaxiDataContext db = new TaxiDataContext())
                        {
                            int cnt = db.Fleet_DriverQueueLists.Where(c => c.Status == true && c.FleetMasterId == objMaster.Current.FleetMasterId).Count();


                            if (cnt > 0)
                            {
                                IsValidate = true;
                                ENUtils.ShowMessage("Driver is already loggedIn with this Vehicle");
                                break;
                            }
                        }
                    }


                    objMaster.Current.Status        = true;
                    objMaster.Current.LoginDateTime = DateTime.Now;
                    objMaster.Current.QueueDateTime = DateTime.Now;
                    objMaster.Current.WaitSinceOn   = DateTime.Now;


                    DateTime nowDate = DateTime.Now.ToDate();
                    TimeSpan TimeNow = DateTime.Now.TimeOfDay;
                    int?     LoginID = AppVars.LoginObj.LgroupId.ToInt();

                    bool manualuntickHasPda = true;
                    //     bool manualuntickHasPda = AppVars.listUserRights.Count(c => c.functionId == "DISABLE HASPDA ON MANUAL LOGIN DRIVER") > 0;


                    var data1 = General.GetQueryable <Fleet_Driver>(c => c.Id == driverId).AsEnumerable();
                    var data2 = General.GetQueryable <Fleet_Driver_Shift>(c => c.DriverId == driverId);
                    var query = (from a in data1
                                 join b in data2 on a.Id equals b.DriverId
                                 select new
                    {
                        DriverNo = a.DriverNo,
                        ShiftName = b.Driver_Shift.ShiftName,
                        FTime = b.FromTime.Value.TimeOfDay,
                        TTime = b.ToTime.Value.TimeOfDay,
                    }).AsQueryable();
                    DataTable dt     = query.ToDataTable();
                    string    ShiftN = "";

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        ShiftN += dt.Rows[i]["ShiftName"].ToStr() + " " + dt.Rows[i]["FTime"].ToStr().Substring(0, 5) + " to " + dt.Rows[i]["TTime"].ToStr().Substring(0, 5) + " ";
                    }



                    Fleet_Driver obj      = General.GetObject <Fleet_Driver>(c => c.Id == driverId);
                    string       DriverNo = obj.DriverNo.ToStr();

                    if (General.GetQueryable <Fleet_Driver_Shift>(c => c.DriverId == driverId && c.Driver_Shift_ID == 7).Count() > 0)
                    {
                        if (General.GetQueryable <Fleet_Driver>(c => c.Id == driverId && c.MOTExpiryDate < nowDate || c.MOTExpiryDate == null && c.MOT2ExpiryDate < nowDate || c.MOT2ExpiryDate == null && c.DrivingLicenseExpiryDate < nowDate || c.DrivingLicenseExpiryDate == null && c.PCODriverExpiryDate < nowDate || c.PCODriverExpiryDate == null && c.PCOVehicleExpiryDate < nowDate || c.PCOVehicleExpiryDate == null).Count(c => ids.Contains(c.Id)) > 0)
                        {
                            if (LoginID == 2)
                            {
                                IsValidate = true;
                                ENUtils.ShowMessage("Driver License Is Expire Driver Not Login..");
                                return;
                            }
                        }
                        driverNos += "," + row.Cells["DriverNo"].Value.ToStr();


                        objMaster.IsManualLoggedInUnTickHasPDA = manualuntickHasPda;

                        objMaster.Save();
                    }
                    else
                    {
                        if (General.GetQueryable <Fleet_Driver_Shift>(c => c.DriverId == driverId && c.FromTime.Value.TimeOfDay < TimeNow && c.ToTime.Value.TimeOfDay > TimeNow).Count() > 0)
                        {
                            if (General.GetQueryable <Fleet_Driver>(c => c.Id == driverId && c.MOTExpiryDate < nowDate || c.MOTExpiryDate == null && c.MOT2ExpiryDate < nowDate || c.MOT2ExpiryDate == null && c.DrivingLicenseExpiryDate < nowDate || c.DrivingLicenseExpiryDate == null && c.PCODriverExpiryDate < nowDate || c.PCODriverExpiryDate == null && c.PCOVehicleExpiryDate < nowDate || c.PCOVehicleExpiryDate == null).Count(c => ids.Contains(c.Id)) > 0)
                            {
                                if (LoginID == 2)
                                {
                                    IsValidate = true;
                                    ENUtils.ShowMessage("Driver License Is Expire Driver Not Login..");
                                    return;
                                }
                            }
                            driverNos += "," + row.Cells["DriverNo"].Value.ToStr();

                            objMaster.IsManualLoggedInUnTickHasPDA = manualuntickHasPda;
                            objMaster.Save();
                        }
                        else
                        {
                            IsValidate = true;
                            ENUtils.ShowMessage("Driver " + DriverNo + " not available \n Driver Shift: " + ShiftN);
                        }
                    }
                }

                General.RefreshListWithoutSelected <frmDriverLoginList>("frmDriverLoginList1");

                General.BroadCastRefreshWaitingDrivers();

                if (IsValidate == false)
                {
                    try
                    {
                        if (driverNos.ToStr().StartsWith(","))
                        {
                            driverNos = driverNos.Remove(0, 1);
                        }

                        if (driverNos.ToStr().EndsWith(","))
                        {
                            driverNos = driverNos.Remove(driverNos.Length - 1);
                        }

                        //GridViewComboBoxColumn comboBoxColumn = this.radGridView1.Columns["column"] as GridViewComboBoxColumn;
                        //object value = this.radGridView1.Rows[0].Cells["SupplierColumn"].Value;
                        //string text = (string)comboBoxColumn.GetLookupValue(value);
                    }
                    catch
                    {
                    }

                    General.AddUserLog("Driver(s) (" + driverNos + ") Manually Login Controller", 3);



                    this.Close();
                }
            }
            catch (Exception ex)
            {
                ENUtils.ShowMessage(ex.Message);
            }
        }