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)); } }
public ActionResult EditPermissionsubmit(FormCollection chk, string FacID, string Name, string Character, string Email, string Account, string Password) { PCGEntities db = new PCGEntities(); SqlConnection CN = new SqlConnection("server=pcgdb.c45myfrybea8.ap-northeast-1.rds.amazonaws.com;user=PCGdb;database=PCG;password=12345678;"); int ZoneID = 0; string[] values = chk.GetValues("HaveSelect");//取得要的權限的工廠名字 string[] FacIDvalues = chk.GetValues("FacID"); string[] EmployeeIDvalues = chk.GetValues("EmployeeID"); int EmployeeIDdel = Convert.ToInt32(EmployeeIDvalues[0]); string FacID2 = FacIDvalues[0]; CN.Open(); SqlCommand SCSelFacID = new SqlCommand("select zoneID from Factories where FacID = '" + FacID2 + "'", CN); SqlDataReader SR = SCSelFacID.ExecuteReader(); while (SR.Read()) { ZoneID = SR.GetInt32(0); } CN.Close(); //刪除權限 CN.Open(); SqlCommand SCDEL = new SqlCommand("delete Permission where EmployeeID = " + EmployeeIDdel, CN); SCDEL.ExecuteReader(); CN.Close(); ////加入權限 for (int i = 0; i < values.Count(); i++) { CN.Open(); SqlCommand SCADD = new SqlCommand("insert into Permission(EmployeeID, ZoneID, FacNo)VALUES(" + EmployeeIDdel + ", " + ZoneID + ", " + values[i] + ")", CN); SCADD.ExecuteReader(); CN.Close(); } CN.Open(); SqlCommand SCEditAD = new SqlCommand("update Administrators set FacID = '" + FacID + "', name = N'" + Name + "',[Character] = N'" + Character + "', Email = '" + Email + "', Account = '" + Account + "',[Password] = '" + Password + "'where EmployeeID = " + EmployeeIDdel, CN); SCEditAD.ExecuteReader(); CN.Close(); //for (var i = 0; i < values.Count(); i++) //{ // int FacNo = Convert.ToInt32(values[i]); // int EmployeeID = Convert.ToInt32(EmployeeIDvalues[i]); // var queryzoneID = from f in db.Factories //查出挑出一項的ZoneID // where f.FacNo == FacNo // select f.ZoneID; // var queryFacNo = from f in db.Factories //查出挑出一項的FacNo // where f.FacNo == FacNo // select f.FacNo; // //查現在是哪一個EmployeeID // int IntFacNo = queryFacNo.First(); // int IntZone = (int)queryzoneID.First(); // Permission per = new Permission(); // per.EmployeeID = EmployeeID; // per.ZoneID = IntZone; // per.FacNo = IntFacNo; // db.Entry(per).State = EntityState.Added; // db.SaveChanges(); return(RedirectToAction("PMSTART")); }
public ActionResult ADDAD(PersonInformation ad, FormCollection chk) { TempData["Name"] = ad.Name; TempData["Character"] = ad.Character; TempData["Email"] = ad.Email; TempData["Account"] = ad.Account; TempData["Password"] = ad.Password; if (string.IsNullOrEmpty(ad.Name)) { this.ModelState.AddModelError("Name", "Nmae不可為空白"); TempData["Nameerror"] = "Name不可為空白"; } if (string.IsNullOrEmpty(ad.Character)) { this.ModelState.AddModelError("Charactererror", "Character不可為空白"); TempData["Charactererror"] = "Character不可為空白"; } if (string.IsNullOrEmpty(ad.Email)) { this.ModelState.AddModelError("Emailerror", "Email不可為空白"); TempData["Emailerror"] = "Email不可為空白"; } if (string.IsNullOrEmpty(ad.Account)) { this.ModelState.AddModelError("Account", "Account不可為空白"); TempData["Accounterror"] = "Account不可為空白"; } if (string.IsNullOrEmpty(ad.Password)) { this.ModelState.AddModelError("Password", "Password不可為空白"); TempData["Passworderror"] = "Password不可為空白"; } if (ModelState.IsValid) { PCGEntities db = new PCGEntities(); Administrators ad2 = new Administrators(); ad2.FacID = ad.FacID; ad2.Character = ad.Character; ad2.Name = ad.Name; ad2.Email = ad.Email; ad2.Account = ad.Account; ad2.Password = ad.Password; db.Entry(ad2).State = EntityState.Added; db.SaveChanges(); string[] values = chk.GetValues("HaveSelect");//取得要的權限的工廠名字 for (var i = 0; i < values.Count(); i++) { int FacNo = Convert.ToInt32(values[i]); var queryzoneID = from f in db.Factories //查出挑出一項的zoneID where f.FacNo == FacNo select f.ZoneID; var queryFacNo = from f in db.Factories //查出挑出一項的zoneID where f.FacNo == FacNo select f.FacNo; var queryemp = (from em in db.Administrators orderby em.EmployeeID descending select em.EmployeeID).Take(1); //查出現在最高值 var maxstringemp = queryemp; //取得新增之後的emp名 int MaxIntEmp = maxstringemp.First(); int IntFacNo = queryFacNo.First(); int IntZone = (int)queryzoneID.First(); Permission per = new Permission(); per.EmployeeID = MaxIntEmp; per.ZoneID = IntZone; per.FacNo = IntFacNo; db.Entry(per).State = EntityState.Added; db.SaveChanges(); } TempData["Name"] = null; TempData["Character"] = null; TempData["Email"] = null; TempData["Account"] = null; TempData["Password"] = null; return(RedirectToAction("PMSTART")); } return(Redirect("ADDAD")); }
public ActionResult PMSTART() {// 取得現在的使用者 int userdata = 0; PCGEntities db = new PCGEntities(); if (User.Identity.IsAuthenticated) { FormsIdentity id = (FormsIdentity)HttpContext.User.Identity; FormsAuthenticationTicket ticket = id.Ticket; userdata = Convert.ToInt32(ticket.UserData); Session.Add("userdata", userdata); 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"); } int PromissionID = Convert.ToInt32(userdata);//取得員工ID if (PromissionID == 5) { //如果是superuser List <PersonInformation> model = new List <PersonInformation>(); var query = from z in db.Zone //不限定條件 select new PersonInformation { ZoneID = z.ZoneID, Country = z.Country }; foreach (var item in query) //retrieve each item and assign to model { model.Add(new PersonInformation() { ZoneID = item.ZoneID, Country = item.Country }); } return(View(model)); } else //其他使用者 { List <PersonInformation> model = new List <PersonInformation>(); var query = from z in db.Zone//根據地區限定條件 join per in db.Permission on z.ZoneID equals per.ZoneID where per.ZoneID == z.ZoneID && per.EmployeeID == userdata select new PersonInformation { ZoneID = z.ZoneID, Country = z.Country }; query = query.Distinct(); foreach (var item in query) //retrieve each item and assign to model { model.Add(new PersonInformation() { ZoneID = item.ZoneID, Country = item.Country }); } return(View(model)); } //var query = from z in db.Zone // join Fac in db.Factories // on z.ZoneID equals Fac.ZoneID // join per in db.Permission // on z.ZoneID equals per.ZoneID // where per.EmployeeID == PromissionID // select new PersonInformation // { // ZoneID = z.ZoneID, // Country = z.Country // }; //query = query.GroupBy(x =>x.FacName).Select(x => x.First()); }
public ActionResult PM(int ZoneID) { PCGEntities db = new PCGEntities(); 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); 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"); } ZoneID = Convert.ToInt32(Request["ZoneID"]); //挑出地區名稱後做廠別篩選 List <PersonInformation> model = new List <PersonInformation>(); if (userdata != 5)//不是管理者 { var query = from per in db.Permission join f in db.Factories on per.FacNo equals f.FacNo where per.ZoneID == ZoneID join ad in db.Administrators on f.FacID equals ad.FacID where ad.EmployeeID == userdata select new PersonInformation { ZoneID = f.ZoneID, FacName = f.FacName, FacNo = f.FacNo, Character = ad.Character, EmployeeID = ad.EmployeeID, Name = ad.Name }; query = query.Distinct(); foreach (var item in query) //retrieve each item and assign to model { model.Add(new PersonInformation() { ZoneID = item.ZoneID, FacName = item.FacName, FacNo = item.FacNo, Character = item.Character, EmployeeID = item.EmployeeID, Name = item.Name //FacNo用來作為 地區下拉式選單的value廠別的下拉式選單篩選條件,千萬別刪掉 }); } return(Json(new { model })); } else //管理者 { var query = from f in db.Factories join ad in db.Administrators on f.FacID equals ad.FacID where f.ZoneID == ZoneID orderby ad.EmployeeID select new PersonInformation { ZoneID = f.ZoneID, FacName = f.FacName, FacNo = f.FacNo, Character = ad.Character, EmployeeID = ad.EmployeeID, Name = ad.Name }; foreach (var item in query) //retrieve each item and assign to model { model.Add(new PersonInformation() { ZoneID = item.ZoneID, FacName = item.FacName, FacNo = item.FacNo, Character = item.Character, EmployeeID = item.EmployeeID, Name = item.Name //FacNo用來作為 地區下拉式選單的value廠別的下拉式選單篩選條件,千萬別刪掉 }); } return(Json(new { model })); } }
public ActionResult Index(int page = 1) { //登入時取得session empolyeeID if (User.Identity.IsAuthenticated) { FormsIdentity id = (FormsIdentity)HttpContext.User.Identity; FormsAuthenticationTicket ticket = id.Ticket; int userdata = Convert.ToInt32(ticket.UserData); Session.Add("EmployeeID", userdata); PCGEntities db = new PCGEntities(); var queryname = (from ad in db.Administrators where ad.EmployeeID == userdata select ad.Name).First(); string name = queryname; Session.Add("Name", name); } else { Session.Add("Name", "Guset"); } int empID; string xxx = ""; if (Session["EmployeeID"] != null) { xxx = Session["EmployeeID"].ToString(); } int.TryParse(xxx, out empID); //int empID = Convert.ToInt32(Session["EmployeeID"].ToString()); //.Where(y=> y.EmployeeID == empID); var querry = this.Att(empID).OrderBy(x => x.ZoneID); var query = _db.Factories.OrderBy(x => x.ZoneID); //var qry = from gu in _db.Factories // from cu in _db.Zone // where gu.ZoneID == cu.ZoneID // select new { cu, gu }; int pageIndex = page < 1 ? 1 : page; var model = new FactoryListViewModel { SearchParaMeter = new FactorySearchViewModel(), PageIndex = pageIndex, Factory = new SelectList(this.Factory(null), "FacNo", "FacName"), ZoneID = new SelectList(this.ZoneID(empID), "ZoneID", "Country"), 廠別s = query.ToPagedList(pageIndex, PageSize), AttSearchList = querry.ToPagedList(pageIndex, PageSize) }; //if (id == null) //{ // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); //} //Factories factories = _db.Factories.Find(id); //if (factories == null) //{ // return HttpNotFound(); //} //ViewBag.Supervisor = new SelectList(_db.Administrators, "EmployeeID", "Name", factories.Supervisor); //ViewBag.ZoneID = new SelectList(_db.Zone, "ZoneID", "Country", factories.ZoneID); return(View(model)); }