public ActionResult Gm() { var ctx = new ApplicationDbContext(); dep model = ctx.deps.Where(x => x.depNo == "001").Count() == 0 ? new dep() : ctx.deps.Where(x => x.depNo == "001").First(); return(View(model)); }
public ActionResult Gm(dep Model) { var ctx = new ApplicationDbContext(); dep tModel = null; tModel = ctx.deps.Where(x => x.depNo == "001").Count() == 0 ? null : ctx.deps.Where(x => x.depNo == "001").First(); if (tModel == null) { tModel = new dep { depNo = "001", sort = 1 }; ctx.deps.Add(tModel); } tModel.depNm = Model.depNm; tModel.parentDepNo = ""; tModel.depLevel = 0; ctx.SaveChanges(); TempData["saveok"] = "Y"; return(View(tModel)); }
public ActionResult Create(int depLevel = 1, string pId = "001") { switch (depLevel) { case 1: ViewBag.Title = "新增-處級"; break; case 2: ViewBag.Title = "新增-部門"; break; case 3: ViewBag.Title = "新增-課別"; break; } ViewBag.Mode = "Create"; ViewBag.depLevel = depLevel; dep model = new dep { parentDepNo = pId, depLevel = depLevel }; return(View(model)); }
public ActionResult Index(string Id = "") { ApplicationDbContext context = new ApplicationDbContext(); var store = new UserStore <ApplicationUser>(context); var manager = new UserManager <ApplicationUser>(store); List <ApplicationUser> users = store.Users.Where(x => x.status == 1 && x.UserName.ToLower().Contains("sadmin") == false).OrderBy(x => x.workNo).ToList <ApplicationUser>(); List <vwEmployee> model = new List <vwEmployee>(); foreach (var usr in users) { context.Entry(usr).Collection(x => x.poList).Load(); List <vwPoNo> poNoList = new List <vwPoNo>(); List <string> usrTitle = new List <string>(); foreach (var po in usr.poList) { jobPo poObj = context.jobPos.Where(x => x.poNo == po.poNo).FirstOrDefault(); dep depObj = poObj == null ? null : context.deps.Where(x => x.depNo == poObj.depNo).FirstOrDefault <dep>(); if (depObj != null) { string depNm = depObj.depNm; dep depObj2 = context.deps.Where(x => x.depNo == depObj.parentDepNo).FirstOrDefault <dep>(); if (depObj2 != null && depObj2.depNo != "001") { depNm = depObj2.depNm + "-" + depNm; dep depObj3 = context.deps.Where(x => x.depNo == depObj2.parentDepNo).FirstOrDefault <dep>(); if (depObj3 != null && depObj3.depNo != "001") { depNm = depObj3.depNm + "-" + depNm; } } poNoList.Add(new vwPoNo { poNo = poObj.poNo, poNm = poObj.poNm, depNo = poObj.depNo, depNm = depObj.depNm }); usrTitle.Add(depNm + ":" + poObj.poNm); } } //if (manager.GetRoles(usr.Id).Where(x=>x=="Admin").Count()==0) { model.Add(new vwEmployee { Id = usr.Id, workNo = usr.workNo, UserCName = usr.cName, UserEName = usr.eName, Title = string.Join(",", usrTitle.ToArray()) }); } ViewBag.testList = usr.poList; } return(View(model)); }
public ActionResult CreatePo(jobPo model) { if (string.IsNullOrEmpty(model.poNm)) { ModelState.AddModelError("poNm", "不可為空值"); return(View(model)); } var context = new ApplicationDbContext(); if (string.IsNullOrEmpty(model.poNo)) { dep depObj = context.deps.Where(x => x.depNo == model.depNo).FirstOrDefault(); if (context.jobPos.Where(x => x.poNm == model.poNm && x.depNo == model.depNo).Count() > 0) { ModelState.AddModelError("poNm", "部門職稱名稱重複"); } try { model.poNo = Guid.NewGuid().ToString(); if (ModelState.IsValid) { context.jobPos.Add(model); context.SaveChanges(); return(RedirectToAction("Details", "Dep", new { id = model.depNo })); } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); } } else { dep depObj = context.deps.Where(x => x.depNo == model.depNo).FirstOrDefault(); if (context.jobPos.Where(x => x.poNm == model.poNm && x.depNo == model.depNo && x.poNo.Equals(model.poNo) == false).Count() > 0) { ModelState.AddModelError("poNm", "部門職稱名稱重複"); } try { if (ModelState.IsValid) { jobPo saveModel = context.jobPos.Where(x => x.poNo == model.poNo).FirstOrDefault(); saveModel.poNm = model.poNm; saveModel.isFormSigner = model.isFormSigner; context.SaveChanges(); return(RedirectToAction("Details", "Dep", new { id = model.depNo })); } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); } } return(View(model)); }
public ActionResult Create(dep model) { var context = new ApplicationDbContext(); if (string.IsNullOrEmpty(model.depNo)) { if (context.deps.Where(x => x.depNm == model.depNm && x.depLevel == model.depLevel).Count() > 0) { ModelState.AddModelError("depNm", "名稱重複"); } try { model.depNo = Guid.NewGuid().ToString(); if (ModelState.IsValid) { context.deps.Add(model); context.SaveChanges(); return(RedirectToAction("Index", new { depLevel = model.depLevel, pId = model.parentDepNo })); } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); } } else { if (context.deps.Where(x => x.depNm == model.depNm && x.depLevel == model.depLevel && x.depNo.Equals(model.depNo) == false).Count() > 0) { ModelState.AddModelError("depNm", "名稱重複"); } try { if (ModelState.IsValid) { dep saveModel = context.deps.Where(x => x.depNo == model.depNo).FirstOrDefault(); saveModel.sort = model.sort; saveModel.depNm = model.depNm; saveModel.depLevel = model.depLevel; context.SaveChanges(); return(RedirectToAction("Index", new { depLevel = model.depLevel, pId = model.parentDepNo })); } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); } } return(View(model)); }
Tuple <List <string>, List <vwPoNo> > getUserTitle(ApplicationUser user, ApplicationDbContext ctx) { ctx.Entry(user).Collection(x => x.poList).Load(); List <string> userTitle = new List <string>(); List <vwPoNo> poNoList = new List <vwPoNo>(); foreach (var po in user.poList) { jobPo poObj = ctx.jobPos.Where(x => x.poNo == po.poNo).FirstOrDefault(); dep depObj = poObj == null ? null : ctx.deps.Where(x => x.depNo == poObj.depNo).FirstOrDefault <dep>(); if (depObj != null) { poNoList.Add(new vwPoNo { poNo = poObj.poNo, poNm = poObj.poNm, depNo = poObj.depNo, depNm = depObj.depNm }); userTitle.Add(depObj.depNm + "-" + poObj.poNm); } } return(Tuple.Create(userTitle, poNoList)); }
=> GetDependants(module).Where(dep => FindInjectableModule(dep, module.Status) is null);
foreach (var(dep, version) in dependencies)
public async Task <ActionResult> reqInHouse(vwReqInHouse Model) { Model.user = ctx.getCurrentUser(User.Identity.Name); ViewBag.userList = ctx.getUserList(); ViewBag.depList = ctx.getDepList(); #region "checkinput" List <string> errList = new List <string>(); var context = new ApplicationDbContext(); if (!ModelState.IsValid) { return(View(Model)); } #endregion #region "FlowWork" string FlowDefKey = "ReqInHouse"; FlowMain fmain = new FlowMain(); List <FlowSub> fsublist = new List <FlowSub>(); FlowDefMain fDefMain = context.FlowDefMainList.Where(x => x.enm == FlowDefKey).FirstOrDefault(); List <FlowDefSub> fDefSubList = new List <FlowDefSub>(); if (fDefMain != null) { fDefSubList = context.FlowDefSubList.Where(x => x.pid == fDefMain.id).OrderBy(x => x.seq).ToList <FlowDefSub>(); } var sender = context.Users.Where(x => x.UserName == User.Identity.Name).FirstOrDefault(); fmain.billNo = ctx.genBillNo(FlowDefKey); fmain.id = Guid.NewGuid().ToString(); fmain.defId = FlowDefKey; fmain.flowName = fDefMain.nm; fmain.flowStatus = 1; fmain.senderNo = sender.workNo; fmain.billDate = context.getLocalTiime(); context.FlowMainList.Add(fmain); ReqInHouse fmObj = new ReqInHouse { contact = Model.contact, depNo = Model.depNo, reqLimit = Model.reqLimit, reqMemo = Model.reqMemo, id = Guid.NewGuid().ToString(), flowId = fmain.id }; context.reqInHouseList.Add(fmObj); int flowSeq = 1; dbHelper dbh = new dbHelper(); string senderPoNo = dbh.sql2Str("select poNo from PoUsers where UserId='" + sender.workNo + "' and ApplicationUser_Id is not null"); string senderMgrNo = ""; List <string> signerList = new List <string>(); if (!string.IsNullOrEmpty(senderPoNo)) { string senderDepNo = dbh.sql2Str("select depNo from jobPoes where poNo='" + senderPoNo + "'"); if (!string.IsNullOrEmpty(senderDepNo)) { dep depObj = context.deps.Where(x => x.depNo == senderDepNo).FirstOrDefault(); signerList = getDepSigner(context, depObj, sender.workNo, signerList); } } foreach (string signer in signerList) { FlowSub fsub = new FlowSub(); fsub.pid = fmain.id; fsub.id = Guid.NewGuid().ToString(); fsub.seq = flowSeq; fsub.workNo = signer; fsub.signType = 1; fsub.signResult = 0; flowSeq++; context.FlowSubList.Add(fsub); } foreach (FlowDefSub defItem in fDefSubList) { if (defItem.workNo != senderMgrNo && signerList.Where(x => x == defItem.workNo).Count() == 0 && defItem.workNo != sender.workNo) { FlowSub fsub = new FlowSub(); fsub.pid = fmain.id; fsub.id = Guid.NewGuid().ToString(); fsub.seq = flowSeq; fsub.workNo = defItem.workNo; fsub.signType = defItem.signType; fsub.signResult = 0; flowSeq++; context.FlowSubList.Add(fsub); signerList.Add(defItem.workNo); } } #endregion try { context.SaveChanges(); StringBuilder sb = new StringBuilder(); sb.Append("您好," + "<br/><br/>"); sb.Append(sender.workNo + " " + sender.cName + " 送出廠務派工及總務需求申請單:" + fmain.billNo + "<br/><br/>"); sb.AppendFormat("<a href='{0}'>{1}</a><br/>", Url.Action("Details", "FormMgr", new RouteValueDictionary(new { id = fmain.id }), HttpContext.Request.Url.Scheme, HttpContext.Request.Url.Authority), "單據網址" ); sb.Append("<br/>此信件為系統發出,請勿直接回信<br/>"); foreach (string signer in signerList) { vwEmployee emp = ctx.getUserByWorkNo(signer); if (!string.IsNullOrEmpty(emp.Email)) { List <EmailAddress> mailList = new List <EmailAddress>(); mailList.Add(new EmailAddress { Email = emp.Email, Name = emp.workNo + " " + emp.UserCName }); await SendGridSrv.sendEmail(mailList, "廠務派工及總務需求申請單", sb.ToString()); } } return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(View(Model)); } }
public async Task <ActionResult> eventSchedule(vwEventSchedule model) { model.user = ctx.getCurrentUser(User.Identity.Name); prepareEventScheduleViewBag(); if (!ModelState.IsValid) { return(View(model)); } try { DateTime _dt = Convert.ToDateTime(model.billDate); } catch (Exception ex) { ModelState.AddModelError("billDate", "請輸入正確日期格式"); return(View(model)); } var sender = ctx.Users.Where(x => x.UserName == User.Identity.Name).FirstOrDefault(); FlowMain fmain = new FlowMain(); if (string.IsNullOrEmpty(model.id)) { #region "FlowWork" string FlowDefKey = "EventSchedule"; List <FlowSub> fsublist = new List <FlowSub>(); FlowDefMain fDefMain = ctx.FlowDefMainList.Where(x => x.enm == FlowDefKey).FirstOrDefault(); List <FlowDefSub> fDefSubList = new List <FlowDefSub>(); if (fDefMain != null) { fDefSubList = ctx.FlowDefSubList.Where(x => x.pid == fDefMain.id).OrderBy(x => x.seq).ToList <FlowDefSub>(); } fmain.billNo = ctx.genBillNo(FlowDefKey); fmain.id = Guid.NewGuid().ToString(); fmain.defId = FlowDefKey; fmain.flowName = fDefMain.nm; fmain.flowStatus = 1; fmain.senderNo = sender.workNo; fmain.billDate = model.billDate; ctx.FlowMainList.Add(fmain); EventSchedule fmObj = new EventSchedule { id = Guid.NewGuid().ToString(), flowId = fmain.id, subject = model.subject, location = model.location, beginHH = model.beginHH, beginMM = model.beginMM, endHH = model.endHH, endMM = model.endMM, beginDate = model.beginDate, endDate = model.endDate, eventType = model.eventType, sMemo = model.sMemo, colorTag = model.colorTag }; ctx.eventScheduleList.Add(fmObj); int flowSeq = 1; dbHelper dbh = new dbHelper(); string senderPoNo = dbh.sql2Str("select poNo from PoUsers where UserId='" + sender.workNo + "' and ApplicationUser_Id is not null"); string senderMgrNo = ""; List <string> signerList = new List <string>(); if (!string.IsNullOrEmpty(senderPoNo)) { string senderDepNo = dbh.sql2Str("select depNo from jobPoes where poNo='" + senderPoNo + "'"); if (!string.IsNullOrEmpty(senderDepNo)) { dep depObj = ctx.deps.Where(x => x.depNo == senderDepNo).FirstOrDefault(); signerList = getDepSigner(ctx, depObj, sender.workNo, signerList); } } foreach (string signer in signerList) { FlowSub fsub = new FlowSub(); fsub.pid = fmain.id; fsub.id = Guid.NewGuid().ToString(); fsub.seq = flowSeq; fsub.workNo = signer; fsub.signType = 1; fsub.signResult = 0; flowSeq++; ctx.FlowSubList.Add(fsub); } foreach (FlowDefSub defItem in fDefSubList) { if (defItem.workNo != senderMgrNo && signerList.Where(x => x == defItem.workNo).Count() == 0 && defItem.workNo != sender.workNo) { FlowSub fsub = new FlowSub(); fsub.pid = fmain.id; fsub.id = Guid.NewGuid().ToString(); fsub.seq = flowSeq; fsub.workNo = defItem.workNo; fsub.signType = defItem.signType; fsub.signResult = 0; flowSeq++; ctx.FlowSubList.Add(fsub); signerList.Add(defItem.workNo); } } #endregion try { ctx.SaveChanges(); StringBuilder sb = new StringBuilder(); sb.Append("您好," + "<br/><br/>"); if (model.eventType == 1) { sb.Append(sender.workNo + " " + sender.cName + " 送出業務拜訪行程:" + fmain.billNo + "<br/><br/>"); } else { sb.Append(sender.workNo + " " + sender.cName + " 送出公司行程/活動:" + fmain.billNo + "<br/><br/>"); } sb.AppendFormat("<a href='{0}'>{1}</a><br/>", Url.Action("Details", "FormMgr", new RouteValueDictionary(new { id = fmain.id }), HttpContext.Request.Url.Scheme, HttpContext.Request.Url.Authority), "單據網址" ); sb.Append("<br/>此信件為系統發出,請勿直接回信<br/>"); foreach (string signer in signerList) { vwEmployee emp = ctx.getUserByWorkNo(signer); if (!string.IsNullOrEmpty(emp.Email)) { List <EmailAddress> mailList = new List <EmailAddress>(); mailList.Add(new EmailAddress { Email = emp.Email, Name = emp.workNo + " " + emp.UserCName }); await SendGridSrv.sendEmail(mailList, "公司行程規劃通知", sb.ToString()); } } return(RedirectToAction("ListEventSchedule")); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(View(model)); } } else { fmain = ctx.FlowMainList.Where(x => x.id == model.flowId).FirstOrDefault(); EventSchedule eventObj = ctx.eventScheduleList.Where(x => x.id == model.id).FirstOrDefault(); eventObj.subject = model.subject; eventObj.location = model.location; eventObj.beginHH = model.beginHH; eventObj.beginMM = model.beginMM; eventObj.endHH = model.endHH; eventObj.endMM = model.endMM; eventObj.beginDate = model.beginDate; eventObj.endDate = model.endDate; eventObj.eventType = model.eventType; eventObj.sMemo = model.sMemo; eventObj.colorTag = model.colorTag; ctx.SaveChanges(); return(RedirectToAction("Details", "Form", new { @id = model.flowId })); } }