// GET: /LvShort/
        public ActionResult Index(string sortOrder, string searchString, string currentFilter, int? page)
        {
            User LoggedInUser = Session["LoggedUser"] as User;
            ViewBag.CurrentSort = sortOrder;
            ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            ViewBag.TypeSortParm = sortOrder == "LvType" ? "LvType_desc" : "LvType";
            ViewBag.DateSortParm = sortOrder == "Date" ? "Date_desc" : "Date";
            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }
            QueryBuilder qb = new QueryBuilder();
            string query = qb.QueryForUserAccess(LoggedInUser, qb.CheckForUserRole(LoggedInUser));

            DateTime dt1 = DateTime.Today;
            DateTime dt2 = new DateTime(dt1.Year, 1, 1);
            string date = dt2.Year.ToString() + "-" + dt2.Month.ToString() + "-" + dt2.Day.ToString() + " ";
            DataTable dt = qb.GetValuesfromDB("select * from ViewSLData where " + query);
            List<ViewSLData> lvapplications = dt.ToList<ViewSLData>();

            ViewBag.CurrentFilter = searchString;
            //var lvapplications = db.LvApplications.Where(aa=>aa.ToDate>=dt2).Include(l => l.Emp).Include(l => l.LvType1);
            if (!String.IsNullOrEmpty(searchString))
            {
                lvapplications = lvapplications.Where(s => s.EmpName.ToUpper().Contains(searchString.ToUpper())
                     || s.EmpNo.ToUpper().Contains(searchString.ToUpper())).ToList();
            }

            switch (sortOrder)
            {
                case "name_desc":
                    lvapplications = lvapplications.OrderByDescending(s => s.EmpName).ToList();
                    break;
                case "Date_desc":
                    lvapplications = lvapplications.OrderByDescending(s => s.DutyDate).ToList();
                    break;
                case "Date":
                    lvapplications = lvapplications.OrderBy(s => s.DutyDate).ToList();
                    break;
                default:
                    lvapplications = lvapplications.OrderBy(s => s.EmpName).ToList();
                    break;
            }
            int pageSize = 10;
            int pageNumber = (page ?? 1);
            return View(lvapplications.OrderByDescending(aa => aa.DutyDate).ToPagedList(pageNumber, pageSize));
        }
示例#2
0
        //
        // GET: /Zones/
        public ActionResult Index(string sortOrder, string searchString, string currentFilter, int? page)
        {
            ViewBag.CurrentSort = sortOrder;
            ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewBag.CurrentFilter = searchString;
            User LoggedInUser = HttpContext.Session["LoggedUser"] as User;
            QueryBuilder qb = new QueryBuilder();
            string query = qb.QueryForUserAccess(LoggedInUser, "Zone");
            DataTable dt = qb.GetValuesfromDB("Select * FROM Zone where " + query);
            var zone = dt.ToList<Zone>().AsQueryable();

            if (!String.IsNullOrEmpty(searchString))
            {
                zone = zone.Where(s => s.ZoneName.ToUpper().Contains(searchString.ToUpper()));
            }

            switch (sortOrder)
            {
                case "name_desc":
                    zone = zone.OrderByDescending(s => s.ZoneName);
                    break;
                default:
                    zone = zone.OrderBy(s => s.ZoneName);
                    break;
            }
            int pageSize = 8;
            int pageNumber = (page ?? 1);
            return View(zone.ToPagedList(pageNumber, pageSize));
        }