Exemplo n.º 1
0
 private void BindGridViewEmployee(string search)
 {
     FiltersModel fm = Session["FiltersModel"] as FiltersModel;
     List<EmpView> _View = new List<EmpView>();
     List<EmpView> _TempView = new List<EmpView>();
     User LoggedInUser = HttpContext.Current.Session["LoggedUser"] as User;
     QueryBuilder qb = new QueryBuilder();
        string query = qb.QueryForEmployeeReports(LoggedInUser);
        DataTable dt = qb.GetValuesfromDB("select * from EmpView " + query+" order by EmpName asc");
     _View = dt.ToList<EmpView>();
     if (fm.CompanyFilter.Count > 0)
     {
         _TempView.Clear();
         foreach (var comp in fm.CompanyFilter)
         {
             short _compID = Convert.ToInt16(comp.ID);
             _TempView.AddRange(_View.Where(aa => aa.CompanyID == _compID).ToList());
         }
         _View = _TempView.ToList();
     }
     if (fm.RegionFilter.Count > 0)
     {
         _TempView.Clear();
         foreach (var reg in fm.RegionFilter)
         {
             short _regID = Convert.ToInt16(reg.ID);
             _TempView.AddRange(_View.Where(aa => aa.RegionID == _regID).ToList());
         }
         _View = _TempView.ToList();
     }
     if (fm.CityFilter.Count > 0)
     {
         _TempView.Clear();
         foreach (var city in fm.CityFilter)
         {
             short _cityID = Convert.ToInt16(city.ID);
             _TempView.AddRange(_View.Where(aa => aa.CityID == _cityID).ToList());
         }
         _View = _TempView.ToList();
     }
     if (fm.DivisionFilter.Count > 0)
     {
         _TempView.Clear();
         foreach (var comp in fm.DivisionFilter)
         {
             short _compID = Convert.ToInt16(comp.ID);
             _TempView.AddRange(_View.Where(aa => aa.DivID == _compID).ToList());
         }
         _View = _TempView.ToList();
     }
     if (fm.DepartmentFilter.Count > 0)
     {
         _TempView.Clear();
         foreach (var comp in fm.DepartmentFilter)
         {
             short _compID = Convert.ToInt16(comp.ID);
             _TempView.AddRange(_View.Where(aa => aa.DeptID == _compID).ToList());
         }
         _View = _TempView.ToList();
     }
     if (fm.SectionFilter.Count > 0)
     {
         _TempView.Clear();
         foreach (var comp in fm.SectionFilter)
         {
             short _compID = Convert.ToInt16(comp.ID);
             _TempView.AddRange(_View.Where(aa => aa.SecID == _compID).ToList());
         }
         _View = _TempView.ToList();
     }
     if (fm.TypeFilter.Count > 0)
     {
         _TempView.Clear();
         foreach (var comp in fm.TypeFilter)
         {
             short _compID = Convert.ToInt16(comp.ID);
             _TempView.AddRange(_View.Where(aa => aa.TypeID == _compID).ToList());
         }
         _View = _TempView.ToList();
     }
     if (fm.LocationFilter.Count > 0)
     {
         _TempView.Clear();
         foreach (var comp in fm.LocationFilter)
         {
             short _compID = Convert.ToInt16(comp.ID);
             _TempView.AddRange(_View.Where(aa => aa.LocID == _compID).ToList());
         }
         _View = _TempView.ToList();
     }
     if (fm.ShiftFilter.Count > 0)
     {
         _TempView.Clear();
         foreach (var comp in fm.ShiftFilter)
         {
             short _compID = Convert.ToInt16(comp.ID);
             _TempView.AddRange(_View.Where(aa => aa.ShiftID == _compID).ToList());
         }
         _View = _TempView.ToList();
     }
     if (fm.CrewFilter.Count > 0)
     {
         _TempView.Clear();
         foreach (var comp in fm.CrewFilter)
         {
             short _compID = Convert.ToInt16(comp.ID);
             _TempView.AddRange(_View.Where(aa => aa.CrewID == _compID).ToList());
         }
         _View = _TempView.ToList();
     }
     GridViewEmployee.DataSource = _View.Where(aa => aa.EmpName.ToUpper().Contains(search.ToUpper())
                                     || aa.EmpNo == search || aa.SectionName.ToUpper().Contains(search.ToUpper())).ToList();
     GridViewEmployee.DataBind();
 }