private void grid_CommandCellClick(object sender, EventArgs e)
        {
            GridCommandCellElement gridCell = (GridCommandCellElement)sender;

            if (gridCell.ColumnInfo.Name.ToLower() == "btnlogout")
            {
                if (DialogResult.Yes == RadMessageBox.Show("Are you sure you want to logout this Driver ? ", "", MessageBoxButtons.YesNo, RadMessageIcon.Question))
                {
                    RadGridView grid = gridCell.GridControl;
                    if (Logout(grid.CurrentRow.Cells["Id"].Value.ToLong(), grid.CurrentRow.Cells["DriverId"].Value.ToIntorNull()))
                    {
                        General.AddUserLog("Driver {" + grid.CurrentRow.Cells["DriverNo"].Value.ToStr() + "} manually logout by Controller", 3);
                    }
                    PopulateData();

                    General.BroadCastRefresh(RefreshTypes.REFRESH_DASHBOARD_DRIVER);
                }
            }
        }
        private void btnMultiLogout_Click(object sender, EventArgs e)
        {
            var selectedRows = grdLister.Rows.Where(c => c.Cells["Select"].Value.ToBool());

            if (selectedRows.Count() > 0)
            {
                foreach (var item in selectedRows)
                {
                    Logout(item.Cells["Id"].Value.ToLong(), item.Cells["DriverId"].Value.ToIntorNull());
                }

                General.AddUserLog("Driver(s) {" + string.Join(",", selectedRows.Select(c => c.Cells["DriverNo"].Value.ToStr())) + "} manually logout by Controller", 3);


                PopulateData();

                General.BroadCastRefresh(RefreshTypes.REFRESH_DASHBOARD_DRIVER);
            }
        }
        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);
            }
        }