Beispiel #1
0
        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));
        }
Beispiel #2
0
        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));
        }
Beispiel #3
0
        public ActionResult CreatePo(string id)
        {
            ViewBag.Title = "新增職稱";
            ViewBag.Mode  = "Create";
            jobPo model = new jobPo();

            model.depNo = id;
            return(View(model));
        }
Beispiel #4
0
        public ActionResult EditPo(string id)
        {
            ViewBag.Title = "編輯職稱";
            ViewBag.Mode  = "Edit";
            ViewBag.id    = id;
            var   context = new ApplicationDbContext();
            jobPo model   = context.jobPos.Where(x => x.poNo == id).FirstOrDefault();

            return(View("CreatePo", model));
        }
Beispiel #5
0
        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));
        }
        public ActionResult Details(string id, string FlowPageType = "", string ReturnAction = "")
        {
            var  store       = new UserStore <ApplicationUser>(ctx);
            var  manager     = new UserManager <ApplicationUser>(store);
            var  user        = manager.FindByName(User.Identity.Name);
            var  roleStore   = new RoleStore <ApplicationRole>(ctx);
            var  roleManager = new RoleManager <ApplicationRole>(roleStore);
            bool isAdmin     = false;

            FlowMain fmain = ctx.FlowMainList.Where(x => x.id == id).FirstOrDefault();

            ViewBag.flowMain = fmain;
            vwEmployee employee = ctx.getUserByWorkNo(fmain.senderNo);

            ViewBag.Employee = employee;

            foreach (var role in roleManager.Roles)
            {
                if (user.Roles.Where(x => x.RoleId == role.Id && role.Name.ToUpper() == "ADMIN").Count() > 0)
                {
                    isAdmin = true;
                    break;
                }
            }

            if (!isAdmin && fmain.defId != "EventSchedule")
            {
                if (ctx.FlowSubList.Where(x => x.pid == id && x.workNo == User.Identity.Name).Count() == 0)
                {
                    return(RedirectToAction("AccessDenied", "Account"));
                }
            }

            if (ctx.FlowSubList.Where(x => x.pid == id && x.workNo == User.Identity.Name && x.signType == 701).Count() > 0)
            {
                FlowPageType = "HRCheck";
            }

            if (FlowPageType == "")
            {
                FlowPageType = fmain.defId == "EventSchedule" ? "EventSchedule" : "";
            }

            var context = new ApplicationDbContext();

            ViewBag.FlowPageType = FlowPageType;
            ViewBag.ReturnAction = ReturnAction;

            List <vwFlowSub> list     = new List <vwFlowSub>();
            List <FlowSub>   fsubList = context.FlowSubList.Where(x => x.pid == id).OrderBy(x => x.seq).ToList <FlowSub>();

            foreach (FlowSub sitem in fsubList)
            {
                var       signResultObj = context.signResultList().Where(x => x.id == sitem.signResult).FirstOrDefault();
                var       signTypeObj   = context.signTypeList().Where(x => x.id == sitem.signType).FirstOrDefault();
                var       signUser      = context.Users.Where(x => x.workNo == sitem.workNo).FirstOrDefault();
                vwFlowSub item          = new vwFlowSub
                {
                    id         = sitem.id,
                    seq        = sitem.seq,
                    signDate   = sitem.signDate,
                    signResult = signResultObj == null ? "" : signResultObj.nm,
                    signType   = signTypeObj == null ? "會簽" : signTypeObj.nm,
                    signer     = signUser == null ? "" : signUser.workNo + "-" + signUser.cName,
                    comment    = sitem.comment
                };
                list.Add(item);
            }


            #region "非工作時間廠務申請單"
            if (fmain.defId == "OverTime")
            {
                fmain.flowName += "(P016A1)";
                ReqOverTime   reqOverTimeObj   = context.reqOverTimeList.Where(x => x.flowId == id).FirstOrDefault();
                vwReqOverTime vwReqOverTimeObj = null;
                if (reqOverTimeObj != null)
                {
                    vwReqOverTimeObj = new vwReqOverTime
                    {
                        billNo  = fmain.billNo,
                        dtBegin = reqOverTimeObj.dtBegin,
                        dtEnd   = reqOverTimeObj.dtEnd,
                        hours   = reqOverTimeObj.hours,
                        sMemo   = reqOverTimeObj.sMemo
                    };
                    JObject jobjext = null;
                    try
                    {
                        jobjext = JObject.Parse(reqOverTimeObj.jext);
                        vwReqOverTimeObj.sType      = jobjext["stype"] == null ? "" : jobjext["stype"].ToString();
                        vwReqOverTimeObj.place      = jobjext["place"] == null ? "" : jobjext["place"].ToString();
                        vwReqOverTimeObj.otherPlace = jobjext["otherPlace"] == null ? "" : jobjext["otherPlace"].ToString();
                        vwReqOverTimeObj.prjId      = jobjext["prjId"] == null ? "" : jobjext["prjId"].ToString();

                        vwReqOverTimeObj.sMemo2 = jobjext["sMemo2"] == null ? "" : jobjext["sMemo2"].ToString();
                        vwReqOverTimeObj.worker = jobjext["worker"] == null ? "" : jobjext["worker"].ToString();
                        vwReqOverTimeObj.depNo  = jobjext["depNo"] == null ? "" : jobjext["depNo"].ToString();

                        vwReqOverTimeObj.poNo = jobjext["poNo"] == null ? "" : jobjext["poNo"].ToString();
                        vwReqOverTimeObj.poNm = jobjext["poNo"] == null ? "" : context.jobPos.Where(x => x.poNo.Equals(vwReqOverTimeObj.poNo)).FirstOrDefault().poNm;

                        jobPo  poObj = context.jobPos.Where(x => x.poNo == vwReqOverTimeObj.poNo).First();
                        string depNo = poObj.depNo;
                        string depNm = context.getParentDeps(depNo, context) + " : " + poObj.poNm;
                        vwReqOverTimeObj.depNm = depNm;
                    }
                    catch (Exception ex)
                    {
                    }
                }
                ViewBag.SubModel = vwReqOverTimeObj;
                return(View(list));
            }
            #endregion

            #region "加班單"
            if (fmain.defId == "RealOverTime")
            {
                fmain.flowName += "(P017A1)";
                ReqOverTime    reqOverTimeObj   = context.reqOverTimeList.Where(x => x.flowId == id).FirstOrDefault();
                vwRealOverTime vwReqOverTimeObj = null;
                if (reqOverTimeObj != null)
                {
                    vwReqOverTimeObj = new vwRealOverTime
                    {
                        user    = ctx.getUserByWorkNo(fmain.senderNo),
                        billNo  = fmain.billNo,
                        dtBegin = reqOverTimeObj.dtBegin,
                        dtEnd   = reqOverTimeObj.dtEnd,
                        hours   = reqOverTimeObj.hours,
                        sMemo   = reqOverTimeObj.sMemo
                    };
                    JObject jobjext = null;
                    try
                    {
                        jobjext = JObject.Parse(reqOverTimeObj.jext);
                        vwReqOverTimeObj.sMemo2 = jobjext["sMemo2"] == null ? "" : jobjext["sMemo2"].ToString();
                    }
                    catch (Exception ex)
                    {
                    }
                }
                ViewBag.SubModel = vwReqOverTimeObj;
                return(View(list));
            }
            #endregion

            #region "請假單"
            if (fmain.defId == "DayOff")
            {
                fmain.flowName += "(P018A1)";
                vwDayOffForm subModel  = new vwDayOffForm();
                dayOff       dayOffObj = ctx.dayOffList.Where(x => x.flowId == fmain.id).FirstOrDefault();
                subModel.dayOffForm = new vwdayOff
                {
                    id       = dayOffObj.id,
                    billNo   = fmain.billNo,
                    dtBegin  = dayOffObj.dtBegin,
                    dtEnd    = dayOffObj.dtEnd,
                    hours    = dayOffObj.hours,
                    dType    = dayOffObj.dType,
                    sMemo    = dayOffObj.sMemo,
                    jobAgent = dayOffObj.jobAgent
                };
                ViewBag.SubModel = subModel;
                return(View("Details", list));
            }
            #endregion

            #region "外出申請單"
            if (fmain.defId == "PublicOut")
            {
                fmain.flowName += "(P019A1)";
                publicOut   publicOutObj = ctx.publicOutList.Where(x => x.flowId == fmain.id).FirstOrDefault();
                vwPublicOut subModel     = new vwPublicOut
                {
                    id          = publicOutObj.id,
                    billNo      = fmain.billNo,
                    user        = ctx.getUserByWorkNo(fmain.senderNo),
                    requestDate = publicOutObj.requestDate,
                    dtBegin     = publicOutObj.dtBegin,
                    dtEnd       = publicOutObj.dtEnd,
                    subject     = publicOutObj.subject,
                    destination = publicOutObj.destination,
                    transport   = publicOutObj.transport
                };
                ViewBag.SubModel = subModel;
                return(View("Details", list));
            }

            #endregion

            #region "訪客申請單"
            if (fmain.defId == "GuestForm")
            {
                fmain.flowName += "(P011A1)";
                guestForm   formObj  = ctx.guestFormList.Where(x => x.flowId == fmain.id).FirstOrDefault();
                vwGuestForm subModel = new vwGuestForm
                {
                    id          = formObj.id,
                    user        = ctx.getUserByWorkNo(fmain.senderNo),
                    requestDate = formObj.requestDate,
                    dtBegin     = formObj.dtBegin,
                    dtEnd       = formObj.dtEnd,
                    subject     = formObj.subject,
                    to          = formObj.to,
                    toDep       = formObj.toDep,
                    guestCmp    = formObj.guestCmp,
                    guestName   = formObj.guestName,
                    guestCnt    = formObj.guestCnt,
                    cellPhone   = formObj.cellPhone,
                    area1       = formObj.area1,
                    area2       = formObj.area2,
                    area21      = formObj.area21,
                    area3       = formObj.area3,
                    area4       = formObj.area4,
                    area41      = formObj.area41,
                    sMemo       = formObj.sMemo
                };
                ViewBag.SubModel = subModel;
                return(View("Details", list));
            }
            #endregion

            #region "廠務派工及總務需求申請單"
            if (fmain.defId == "ReqInHouse")
            {
                fmain.flowName += "(P020A1)";
                ReqInHouse   formObj  = ctx.reqInHouseList.Where(x => x.flowId == fmain.id).FirstOrDefault();
                vwReqInHouse subModel = new vwReqInHouse
                {
                    id       = formObj.id,
                    user     = ctx.getUserByWorkNo(fmain.senderNo),
                    billDate = fmain.billDate,
                    contact  = formObj.contact,
                    depNo    = formObj.depNo,
                    reqLimit = formObj.reqLimit,
                    reqMemo  = formObj.reqMemo,
                    sMemo    = formObj.sMemo
                };
                ViewBag.SubModel = subModel;
                return(View("Details", list));
            }
            #endregion

            #region "公司行程規劃表"
            if (fmain.defId == "EventSchedule")
            {
                fmain.flowName += "(B001A1)";
                EventSchedule   formObj  = ctx.eventScheduleList.Where(x => x.flowId == fmain.id).FirstOrDefault();
                vwEventSchedule subModel = new vwEventSchedule
                {
                    id        = formObj.id,
                    user      = ctx.getUserByWorkNo(fmain.senderNo),
                    billDate  = fmain.billDate,
                    beginHH   = formObj.beginHH,
                    beginMM   = formObj.beginMM,
                    subject   = formObj.subject,
                    location  = formObj.location,
                    eventType = formObj.eventType,
                    sMemo     = formObj.sMemo
                };
                ViewBag.SubModel = subModel;
                return(View("Details", list));
            }
            #endregion

            return(View(list));
        }