static void createFlowDef(ApplicationDbContext ctx) { int idx = 6; if (ctx.FlowDefMainList.Where(x => x.code == "P020A1").Count() == 0) { FlowDefMain defObj = new FlowDefMain { id = Guid.NewGuid().ToString(), code = "P020A1", nm = "廠務派工及總務需求申請單", seq = 6, enm = "ReqInHouse" }; ctx.FlowDefMainList.Add(defObj); ctx.SaveChanges(); } if (ctx.FlowDefMainList.Where(x => x.code == "B001A1").Count() == 0) { FlowDefMain defObj = new FlowDefMain { id = Guid.NewGuid().ToString(), code = "B001A1", nm = "公司行程規劃表", seq = 7, enm = "EventSchedule" }; ctx.FlowDefMainList.Add(defObj); ctx.SaveChanges(); } }
void getFlowMainData(ApplicationDbContext context, string id) { ViewBag.FlowDefId = id; FlowDefMain main = context.FlowDefMainList.Where(x => x.id == id).FirstOrDefault(); ViewBag.FlowDefName = main.nm; }
public ActionResult Create(FlowDefMain Model) { if (!ModelState.IsValid) { return(View(Model)); } var context = new ApplicationDbContext(); if (context.FlowDefMainList.Where(x => x.nm == Model.nm).Count() > 0) { ModelState.AddModelError("nm", "表單名稱不可重複"); return(View(Model)); } Model.id = Guid.NewGuid().ToString(); context.FlowDefMainList.Add(Model); context.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult AddDefSub(FlowDefSub model) { dbHelper dbh = new dbHelper(); if (string.IsNullOrEmpty(model.id)) { ViewBag.EditMode = "Create"; model.id = Guid.NewGuid().ToString(); FlowDefMain fmain = ctx.FlowDefMainList.Where(x => x.id == model.pid).FirstOrDefault(); if (fmain.enm == "RealOverTime" && model.signType != 3 && model.signType != 4) { ModelState.AddModelError("signType", "加班單限定為串簽或直接許可"); } if (fmain.enm == "DayOff" && model.signType != 3 && model.signType != 4) { ModelState.AddModelError("signType", "請假單限定為串簽或直接許可"); } if (!string.IsNullOrEmpty(model.workNo)) { int iuser = dbh.sql2count( "select count(workNo) cnt from FlowDefSub where workNo='" + model.workNo + "' and pid='" + model.pid + "'" ); if (iuser > 0) { ModelState.AddModelError("workNo", "工號重複"); } } if (model.signType == 2) { int iSign1 = dbh.sql2count("select count(workNo) cnt from FlowDefSub where signType=1 and pid='" + model.pid + "'"); ModelState.AddModelError("signType", "已有設定【1.會簽】,不允許【2.會簽-全部同意】"); } } else { ViewBag.EditMode = "Edit"; } if (model.signType == 0) { ModelState.AddModelError("signType", "請選擇簽核類別"); } if (!ModelState.IsValid) { getUserList(new ApplicationDbContext()); return(View(model)); } else { ApplicationDbContext context = new ApplicationDbContext(); try { context.FlowDefSubList.Add(model); context.SaveChanges(); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); getUserList(new ApplicationDbContext()); return(View(model)); } return(RedirectToAction("SetupFLow", new { id = model.pid })); } }
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 })); } }