Example #1
0
        public ActionResult Index(int page = 1)
        {
            if (User.Identity.IsAuthenticated)
            {
                FormsIdentity             id     = (FormsIdentity)HttpContext.User.Identity;
                FormsAuthenticationTicket ticket = id.Ticket;
                int userdata = Convert.ToInt32(ticket.UserData);
                Session.Add("userdata", userdata);
                eid = userdata;
                PCGEntities db = new PCGEntities();

                var query = (from ad in db.Administrators
                             where ad.EmployeeID == userdata
                             select ad.Name).First();
                string name = query;
                Session.Add("Name", name);
            }
            else
            {
                Session.Add("Name", "Guset");
            }

            var query1 = _db.FacPopulation.OrderBy(x => x.FacID);
            var query2 = this.Att;

            int pageIndex = page < 1 ? 1 : page;

            var models = new AttMViewModel
            {
                SearchParaMeter = new AttMSearchViewModel(),
                PageIndex       = pageIndex,
                ZoneID          = new SelectList(this.ZoneID(eid), "ZoneID", "Country"),
                Factory         = new SelectList(this.Factory(0, eid), "FacID", "FacName"),
                Date            = new SelectList(this.Date(null), "Date", "Date"),
                Populations     = query1.ToPagedList(pageIndex, PageSize),
                AttMSearchList  = query2.ToPagedList(pageIndex, PageSize)
            };

            return(View(models));
        }
Example #2
0
        public ActionResult Index(AttMViewModel model)
        {
            int userdata = 0;

            if (User.Identity.IsAuthenticated)
            {
                FormsIdentity             id     = (FormsIdentity)HttpContext.User.Identity;
                FormsAuthenticationTicket ticket = id.Ticket;
                userdata = Convert.ToInt32(ticket.UserData);
                Session.Add("userdata", userdata);
                PCGEntities db = new PCGEntities();

                var query = (from ad in db.Administrators
                             where ad.EmployeeID == userdata
                             select ad.Name).First();
                string name = query;
                Session.Add("Name", name);
            }
            else
            {
                Session.Add("Name", "Guset");
            }
            eid = Convert.ToInt32(Session["userdata"]);
            var RS = from x in _db.FacPopulation
                     join y in _db.Factories on x.FacID equals y.FacID
                     join z in _db.Zone on y.ZoneID equals z.ZoneID
                     into joined
                     join w in _db.Permission on y.FacNo equals w.FacNo
                     from j in joined.DefaultIfEmpty()
                     orderby j.ZoneID
                     select new AttM {
                PopID = x.PopID, PopTotal = x.PopTotal, PopNew = x.PopNew, PopLeft = x.PopLeft, Date = x.Date, FacName = y.FacName, ZoneID = j.ZoneID, Country = j.Country, FacID = x.FacID, PopLeft3 = x.PopLeft3, EmployeeID = w.EmployeeID
            };

            var RS2 = from x in _db.FacPopulation
                      join y in _db.Factories on x.FacID equals y.FacID
                      join z in _db.Zone on y.ZoneID equals z.ZoneID
                      into joined
                      from j in joined.DefaultIfEmpty()
                      orderby j.ZoneID
                      select new AttM {
                PopID = x.PopID, PopTotal = x.PopTotal, PopNew = x.PopNew, PopLeft = x.PopLeft, Date = x.Date, FacName = y.FacName, ZoneID = j.ZoneID, Country = j.Country, FacID = x.FacID, PopLeft3 = x.PopLeft3
            };

            if (eid != 5)
            {
                RS.Where(x => x.EmployeeID == eid);
                if (model.SearchParaMeter.ZoneID != 0)
                {
                    RS = RS.Where(x => x.ZoneID == model.SearchParaMeter.ZoneID && x.EmployeeID == eid);
                }
                if (!string.IsNullOrWhiteSpace(model.SearchParaMeter.FacID))
                {
                    RS = RS.Where(x => x.FacID == model.SearchParaMeter.FacID.ToString());
                }
                if (!string.IsNullOrWhiteSpace(model.SearchParaMeter.Date))
                {
                    RS = RS.Where(x => x.Date == model.SearchParaMeter.Date);
                }
            }
            else
            {
                if (model.SearchParaMeter.ZoneID != 0)
                {
                    RS2 = RS2.Where(x => x.ZoneID == model.SearchParaMeter.ZoneID);
                }
                if (!string.IsNullOrWhiteSpace(model.SearchParaMeter.FacID))
                {
                    RS2 = RS2.Where(x => x.FacID == model.SearchParaMeter.FacID.ToString());
                }
                if (!string.IsNullOrWhiteSpace(model.SearchParaMeter.Date))
                {
                    RS2 = RS2.Where(x => x.Date == model.SearchParaMeter.Date);
                }
            }

            RS  = RS.OrderBy(x => x.ZoneID);
            RS2 = RS2.OrderBy(x => x.ZoneID);
            int pageIndex = model.PageIndex < 1 ? 1 : model.PageIndex;

            if (eid != 5)
            {
                var result = new AttMViewModel
                {
                    SearchParaMeter = model.SearchParaMeter,
                    ZoneID          = new SelectList(
                        items: this.ZoneID(eid),
                        dataValueField: "ZoneID",
                        dataTextField: "Country",
                        selectedValue: model.SearchParaMeter.ZoneID),
                    Factory = new SelectList(
                        items: this.Factory(model.SearchParaMeter.ZoneID, eid),
                        dataValueField: "FacID",
                        dataTextField: "FacName",
                        selectedValue: model.SearchParaMeter.FacID),
                    Date = new SelectList(
                        items: this.Date(model.SearchParaMeter.FacID),
                        dataValueField: "Date",
                        dataTextField: "Date",
                        selectedValue: model.SearchParaMeter.Date),
                    PageIndex      = model.PageIndex < 1 ? 1 : model.PageIndex,
                    AttMSearchList = RS.ToPagedList(pageIndex, PageSize)
                };
                return(View(result));
            }
            else
            {
                var result = new AttMViewModel
                {
                    SearchParaMeter = model.SearchParaMeter,
                    ZoneID          = new SelectList(
                        items: this.ZoneID(eid),
                        dataValueField: "ZoneID",
                        dataTextField: "Country",
                        selectedValue: model.SearchParaMeter.ZoneID),
                    Factory = new SelectList(
                        items: this.Factory(model.SearchParaMeter.ZoneID, eid),
                        dataValueField: "FacID",
                        dataTextField: "FacName",
                        selectedValue: model.SearchParaMeter.FacID),
                    Date = new SelectList(
                        items: this.Date(model.SearchParaMeter.FacID),
                        dataValueField: "Date",
                        dataTextField: "Date",
                        selectedValue: model.SearchParaMeter.Date),
                    PageIndex      = model.PageIndex < 1 ? 1 : model.PageIndex,
                    AttMSearchList = RS2.ToPagedList(pageIndex, PageSize)
                };
                return(View(result));
            }
        }