Exemplo n.º 1
0
        // GET: Keep/Edit
        public IActionResult Edit(string id, int page)
        {
            AppUserModel ur = _context.AppUsers.Where(u => u.UserName == this.User.Identity.Name).FirstOrDefault();

            ViewData["Page"] = page;
            if (!string.IsNullOrEmpty(id))
            {
                KeepModel keep = _context.Keeps.Find(id);
                if (keep == null)
                {
                    return(StatusCode(404));
                }
                if (userManager.IsInRole(User, "Admin") || userManager.IsInRole(User, "RepAdmin") ||
                    userManager.IsInRole(User, "RepMgr") || userManager.IsInRole(User, "CaPMgr") ||
                    userManager.IsInRole(User, "RepEngineer"))
                {
                    return(View(keep));
                }
                KeepFlowModel rf = _context.KeepFlows.Where(f => f.DocId == id && f.Status == "?").FirstOrDefault();
                if (rf != null)
                {
                    if (rf.UserId != ur.Id)
                    {
                        return(RedirectToAction("Index", "Home", new { Area = "" }));
                    }
                }
                return(View(keep));
            }
            return(StatusCode(404));
        }
        public async Task <IViewComponentResult> InvokeAsync(string docId)
        {
            var          keepEmps = _context.KeepEmps.ToList();
            KeepEmpModel emp      = keepEmps.Where(p => p.DocId == docId).FirstOrDefault();
            var          ur       = _userRepo.Find(us => us.UserName == this.User.Identity.Name).FirstOrDefault();

            if (emp == null)
            {
                emp        = new KeepEmpModel();
                emp.DocId  = docId;
                emp.UserId = ur.Id;
            }

            /* Get all engineers by role. */
            var allEngs = roleManager.GetUsersInRole("RepEngineer").ToList();
            List <SelectListItem> list = new List <SelectListItem>();
            SelectListItem        li   = new SelectListItem();

            foreach (string l in allEngs)
            {
                var u = _context.AppUsers.Where(a => a.UserName == l).FirstOrDefault();
                if (u != null)
                {
                    li       = new SelectListItem();
                    li.Text  = u.FullName;
                    li.Value = u.Id.ToString();
                    list.Add(li);
                }
            }
            ViewData["EmpList"] = new SelectList(list, "Value", "Text");

            KeepFlowModel rf = _context.KeepFlows.Where(f => f.DocId == docId)
                               .Where(f => f.Status == "?").FirstOrDefault();
            var isEngineer = _context.UsersInRoles.Where(u => u.AppRoles.RoleName == "RepEngineer" &&
                                                         u.UserId == ur.Id).FirstOrDefault();

            if (!(rf.Cls.Contains("工程師") && rf.UserId == ur.Id))    /* 流程 => 其他 */
            {
                if (rf.Cls.Contains("工程師") && isEngineer != null)   /* 流程 => 工程師,Login User => 非負責之工程師 */
                {
                    return(View(emp));
                }
                AppUserModel        appuser;
                List <KeepEmpModel> emps = keepEmps.Where(p => p.DocId == docId).ToList();
                emps.ForEach(rp =>
                {
                    rp.UserName = (appuser = _context.AppUsers.Find(rp.UserId)) == null ? "" : appuser.UserName;
                    rp.FullName = (appuser = _context.AppUsers.Find(rp.UserId)) == null ? "" : appuser.FullName;
                });
                return(View("Details", emps));
            }
            /* 流程 => 工程師,Login User => 負責之工程師 */
            return(View(emp));
        }
Exemplo n.º 3
0
        public IActionResult DeleteConfirmed(string id)
        {
            var           ur       = _userRepo.Find(u => u.UserName == this.User.Identity.Name).FirstOrDefault();
            KeepFlowModel keepflow = _context.KeepFlows.Where(f => f.DocId == id && f.Status == "?")
                                     .FirstOrDefault();

            keepflow.Status = "3";
            keepflow.Rtp    = ur.Id;
            keepflow.Rtt    = DateTime.Now;

            _context.SaveChanges();

            return(RedirectToAction("Index", "Home", new { Area = "" }));
        }
        public async Task <IViewComponentResult> InvokeAsync(string id)
        {
            KeepCostModel cost = new KeepCostModel();
            var           ur   = _userRepo.Find(u => u.UserName == this.User.Identity.Name).FirstOrDefault();

            /* Check the device's contract. */
            var keepDtl = _context.BMEDKeepDtls.Find(id);

            if (keepDtl.NotInExceptDevice == "Y") //該案件為統包
            {
                ViewData["HideCost"] = "Y";
            }
            else
            {
                ViewData["HideCost"] = "N";
            }

            int seqno = _context.BMEDKeepCosts.Where(c => c.DocId == id)
                        .Select(c => c.SeqNo).DefaultIfEmpty().Max();

            cost.DocId = id;
            cost.Qty   = 1; //Default value.
            cost.SeqNo = seqno + 1;
            KeepFlowModel rf = _context.BMEDKeepFlows.Where(f => f.DocId == id)
                               .Where(f => f.Status == "?").FirstOrDefault();
            var isEngineer = false;

            if (ur.DptId == "8420" || ur.DptId == "7084")
            {
                isEngineer = true;
            }
            if (!(rf.Cls.Contains("工程師") && rf.UserId == ur.Id))    /* 流程 => 其他 */
            {
                if (rf.Cls.Contains("工程師") && isEngineer == true)   /* 流程 => 工程師,Login User => 非負責之工程師 */
                {
                    return(View(cost));
                }
                if (rf.Cls.Contains("醫工主管") || rf.Cls.Contains("賀康主管")) /* 流程 => 醫工、賀康主管 */
                {
                    if (rf.UserId == ur.Id)
                    {
                        return(View(cost));
                    }
                }
                List <KeepCostModel> t = _context.BMEDKeepCosts.Include(r => r.TicketDtl).Where(c => c.DocId == id).ToList();
                return(View("List", t));
            }
            /* 流程 => 工程師,Login User => 負責之工程師 */
            return(View(cost));
        }
        public async Task <IViewComponentResult> InvokeAsync(string id = null)
        {
            KeepModel kp = _context.BMEDKeeps.Find(id);
            List <KeepFormatListVModel> kf = new List <KeepFormatListVModel>();
            KeepFormatModel             f;
            KeepRecordModel             r;

            if (kp != null)
            {
                AssetKeepModel ak = _context.BMEDAssetKeeps.Find(kp.AssetNo);
                if (ak != null)
                {
                    if (!string.IsNullOrEmpty(ak.FormatId))
                    {
                        _context.BMEDKeepFormatDtls.Where(d => d.FormatId == ak.FormatId)
                        .ToList()
                        .ForEach(d =>
                        {
                            kf.Add(new KeepFormatListVModel
                            {
                                Docid    = id,
                                FormatId = d.FormatId,
                                Plants   = (f = _context.BMEDKeepFormats.Find(d.FormatId)) == null ? "" :
                                           f.Plants,
                                Sno      = d.Sno,
                                Descript = d.Descript,
                                KeepDes  = (r = _context.BMEDKeepRecords.Find(id, d.FormatId, d.Sno)) == null ? "" :
                                           r.KeepDes
                            });
                        });
                    }
                }
                KeepFlowModel kf2 = _context.BMEDKeepFlows.Where(f2 => f2.DocId == id)
                                    .Where(f2 => f2.Status == "?").FirstOrDefault();
                if (kf2.Cls.Contains("工程師"))
                {
                    return(View(kf));
                }
                else
                {
                    return(View("Details", kf));
                }
            }
            return(Content("Page not found!"));  //ViewComponent can't return HTTP response (like as StatusCode() or BasRequest())
        }
Exemplo n.º 6
0
        public async Task <IViewComponentResult> InvokeAsync(string id)
        {
            KeepCostModel cost = new KeepCostModel();
            var           ur   = _userRepo.Find(u => u.UserName == this.User.Identity.Name).FirstOrDefault();

            /* Check the device's contract. */
            //var keepDtl = _context.KeepDtls.Find(id);
            //if (keepDtl.NotInExceptDevice == "Y") //該案件為統包
            //{
            //    ViewData["HideCost"] = "Y";
            //}
            //else
            //{
            //    ViewData["HideCost"] = "N";
            //}
            ViewData["HideCost"] = "N";
            int seqno = _context.KeepCosts.Where(c => c.DocId == id)
                        .Select(c => c.SeqNo).DefaultIfEmpty().Max();

            cost.DocId = id;
            cost.SeqNo = seqno + 1;
            KeepFlowModel rf = _context.KeepFlows.Where(f => f.DocId == id)
                               .Where(f => f.Status == "?").FirstOrDefault();
            var isEngineer = _context.UsersInRoles.Where(u => u.AppRoles.RoleName == "RepEngineer" &&
                                                         u.UserId == ur.Id).FirstOrDefault();

            if (!(rf.Cls.Contains("工程師") && rf.UserId == ur.Id))    /* 流程 => 其他 */
            {
                if (rf.Cls.Contains("工程師") && isEngineer != null)   /* 流程 => 工程師,Login User => 非負責之工程師 */
                {
                    return(View(cost));
                }
                List <KeepCostModel> t = _context.KeepCosts.Include(r => r.TicketDtl).Where(c => c.DocId == id).ToList();
                return(View("List", t));
            }
            /* 流程 => 工程師,Login User => 負責之工程師 */
            return(View(cost));
        }
Exemplo n.º 7
0
        // GET: Keep/PrintKeepDoc/5
        public IActionResult PrintKeepDoc(string DocId, int printType)
        {
            /* Get all print details according to the DocId. */
            KeepModel    keep = _context.Keeps.Find(DocId);
            KeepDtlModel dtl  = _context.KeepDtls.Find(DocId);
            KeepEmpModel emp  = _context.KeepEmps.Where(ep => ep.DocId == DocId).FirstOrDefault();

            /* Get the last flow. */
            string[]      s    = new string[] { "?", "2" };
            KeepFlowModel flow = _context.KeepFlows.Where(f => f.DocId == DocId)
                                 .Where(f => s.Contains(f.Status)).FirstOrDefault();
            KeepPrintVModel vm = new KeepPrintVModel();

            if (keep == null)
            {
                return(StatusCode(404));
            }
            else
            {
                vm.Docid       = DocId;
                vm.UserId      = keep.UserId;
                vm.UserName    = keep.UserName;
                vm.UserAccount = _context.AppUsers.Find(keep.UserId).UserName;
                vm.AccDpt      = keep.AccDpt;
                vm.SentDate    = keep.SentDate;
                vm.AssetNo     = keep.AssetNo;
                vm.AssetNam    = keep.AssetName;
                vm.Company     = _context.Departments.Find(keep.DptId).Name_C;
                vm.Amt         = 1;
                vm.Cycle       = keep.Cycle;
                vm.Contact     = keep.Ext;
                vm.PlaceLoc    = keep.PlaceLoc;

                if (dtl != null)
                {
                    vm.Result  = dtl.Result == null ? "" : _context.KeepResults.Find(dtl.Result).Title;
                    vm.Memo    = dtl.Memo;
                    vm.EndDate = dtl.EndDate;
                }
                //
                vm.AccDptNam = _context.Departments.Find(keep.AccDpt).Name_C;
                vm.Hour      = dtl.Hours == null ? 0 : dtl.Hours.Value;
                vm.InOut     = dtl.InOut == "0" ? "自行" :
                               dtl.InOut == "1" ? "委外" :
                               dtl.InOut == "2" ? "租賃" :
                               dtl.InOut == "3" ? "保固" : "";
                //vm.EngName = emp == null ? "" : _context.AppUsers.Find(emp.UserId).FullName;
                var lastFlowEng = _context.KeepFlows.Where(rf => rf.DocId == DocId)
                                  .Where(rf => rf.Cls.Contains("工程師"))
                                  .OrderByDescending(rf => rf.StepId).FirstOrDefault();
                AppUserModel EngTemp = _context.AppUsers.Find(lastFlowEng.UserId);
                if (EngTemp != null)
                {
                    vm.EngName = EngTemp.FullName + " (" + EngTemp.UserName + ")";
                }
                else
                {
                    vm.EngName = "";
                }

                var engMgr = _context.KeepFlows.Where(r => r.DocId == DocId)
                             .Where(r => r.Cls.Contains("工務主管") || r.Cls.Contains("營建主管"))
                             .Where(r => r.Opinions.Contains("[同意]")).ToList();
                if (engMgr.Count() != 0)
                {
                    engMgr = engMgr.GroupBy(e => e.UserId).Select(group => group.FirstOrDefault()).ToList();
                    foreach (var item in engMgr)
                    {
                        vm.EngMgr += item == null ? "" : _context.AppUsers.Find(item.UserId).FullName + "  ";
                    }
                }

                var engDirector = _context.KeepFlows.Where(r => r.DocId == DocId)
                                  .Where(r => r.Cls.Contains("工務主任") || r.Cls.Contains("營建主任"))
                                  .Where(r => r.Opinions.Contains("[同意]")).LastOrDefault();
                string firstString = "";
                if (engDirector != null)
                {
                    if (engDirector.Opinions != null)
                    {
                        var firstBracketIndex = engDirector.Opinions.IndexOf("]");
                        firstString = engDirector.Opinions.Substring(0, firstBracketIndex);
                    }
                }
                vm.EngDirector = engDirector == null ? "" : firstString + "]" + _context.AppUsers.Find(engDirector.UserId).FullName;

                var delivMgr = _context.RepairFlows.Where(r => r.DocId == DocId)
                               .Where(r => r.Cls.Contains("單位主管"))
                               .Where(r => r.Opinions.Contains("[同意]")).ToList();
                if (delivMgr.Count() != 0)
                {
                    delivMgr = delivMgr.GroupBy(e => e.UserId).Select(group => group.FirstOrDefault()).ToList();
                    foreach (var item in delivMgr)
                    {
                        vm.DelivMgr += item == null ? "" : _context.AppUsers.Find(item.UserId).FullName + "  ";
                    }
                }

                var delivDirector = _context.RepairFlows.Where(r => r.DocId == DocId)
                                    .Where(r => r.Cls.Contains("單位主任"))
                                    .Where(r => r.Opinions.Contains("[同意]")).LastOrDefault();
                vm.DelivDirector = delivDirector == null ? "" : _context.AppUsers.Find(delivDirector.UserId).FullName;

                var ViceSI = _context.RepairFlows.Where(r => r.DocId == DocId)
                             .Where(r => r.Cls.Contains("院長室主管") || r.Cls.Contains("副院長"))
                             .Where(r => r.Opinions.Contains("[同意]")).LastOrDefault();
                vm.ViceSuperintendent = ViceSI == null ? "" : _context.AppUsers.Find(ViceSI.UserId).FullName;

                if (flow != null)
                {
                    if (flow.Status == "2")
                    {
                        vm.CloseDate = flow.Rtt;
                        AppUserModel u = _context.AppUsers.Find(flow.UserId);
                        if (u != null)
                        {
                            vm.DelivEmp     = u.UserName;
                            vm.DelivEmpName = u.FullName;
                        }
                    }
                }
            }
            //if (printType != 0)
            //{
            //    return View("PrintRepairDoc2", vm);
            //}
            return(View(vm));
        }
Exemplo n.º 8
0
        public IActionResult Create(KeepModel keep)
        {
            AppUserModel ur = _context.AppUsers.Where(u => u.UserName == this.User.Identity.Name).FirstOrDefault();

            //if (string.IsNullOrEmpty(keep.AssetNo))
            //{
            //    throw new Exception("財產編號不可空白!!");
            //}
            string msg = "";

            try
            {
                if (ModelState.IsValid)
                {
                    //更新申請人的Email
                    if (string.IsNullOrEmpty(keep.Email))
                    {
                        throw new Exception("電子信箱不可空白!!");
                    }
                    AppUserModel a = _context.AppUsers.Find(keep.UserId);
                    a.Email = keep.Email;
                    _context.Entry(a).State = EntityState.Modified;
                    _context.SaveChanges();
                    //
                    AssetKeepModel kp = _context.AssetKeeps.Find(keep.DeviceNo);
                    AssetModel     at = _context.Assets.Find(keep.DeviceNo);
                    //
                    keep.AssetNo   = _context.Assets.Find(keep.DeviceNo).AssetNo;
                    keep.AssetName = _context.Assets.Find(keep.DeviceNo).Cname;
                    keep.EngId     = kp.KeepEngId;
                    //keep.AccDpt = at.AccDpt;
                    keep.SentDate = DateTime.Now;
                    keep.Cycle    = "手動出單";
                    keep.Src      = "M";
                    _context.Entry(keep).State = EntityState.Modified;

                    //
                    KeepDtlModel dl = new KeepDtlModel();
                    //var notInExceptDevice = _context.ExceptDevice.Find(keep.AssetNo);

                    /* If can find data in ExceptDevice table, the device is "not" 統包.
                     * It means if value is "Y", the device is 統包
                     */
                    //if (notInExceptDevice == null)
                    //{
                    //    dl.NotInExceptDevice = "Y";
                    //}
                    //else
                    //{
                    //    dl.NotInExceptDevice = "N";
                    //}
                    dl.DocId = keep.DocId;
                    switch (kp == null ? "自行" : kp.InOut)
                    {
                    case "自行":
                        dl.InOut = "0";
                        break;

                    case "委外":
                        dl.InOut = "1";
                        break;

                    case "租賃":
                        dl.InOut = "2";
                        break;

                    case "保固":
                        dl.InOut = "3";
                        break;

                    default:
                        dl.InOut = "0";
                        break;
                    }
                    _context.KeepDtls.Add(dl);
                    _context.SaveChanges();
                    //
                    KeepFlowModel kf = new KeepFlowModel();
                    kf.DocId  = keep.DocId;
                    kf.StepId = 1;
                    kf.UserId = ur.Id;
                    kf.Status = "1";
                    //rf.Role = Roles.GetRolesForUser().FirstOrDefault();
                    kf.Rtp = ur.Id;
                    kf.Rdt = null;
                    kf.Rtt = DateTime.Now;
                    kf.Cls = "申請者";
                    _context.KeepFlows.Add(kf);
                    //
                    kf        = new KeepFlowModel();
                    kf.DocId  = keep.DocId;
                    kf.StepId = 2;
                    kf.UserId = kp == null ? ur.Id : kp.KeepEngId;
                    kf.Status = "?";
                    AppUserModel u = _context.AppUsers.Find(kf.UserId);
                    if (u == null)
                    {
                        throw new Exception("無工程師資料!!");
                    }
                    //rf.Role = Roles.GetRolesForUser(u.UserName).FirstOrDefault();
                    kf.Rtp = null;
                    kf.Rdt = null;
                    kf.Rtt = DateTime.Now;
                    kf.Cls = "設備工程師";
                    _context.KeepFlows.Add(kf);
                    _context.SaveChanges();
                    //send mail
                    Tmail  mail = new Tmail();
                    string body = "";
                    u         = _context.AppUsers.Find(ur.Id);
                    mail.from = new System.Net.Mail.MailAddress(u.Email); //u.Email
                    //u = _context.AppUsers.Find(kp.KeepEngId);
                    mail.to = new System.Net.Mail.MailAddress(u.Email);   //u.Email
                    mail.message.Subject = "醫工工務智能保修系統[醫工保養案]:設備名稱: " + keep.AssetName;
                    body += "<p>表單編號:" + keep.DocId + "</p>";
                    body += "<p>送單日期:" + keep.SentDate.Value.ToString("yyyy/MM/dd") + "</p>";
                    body += "<p>申請人:" + keep.UserName + "</p>";
                    body += "<p>財產編號:" + keep.AssetNo + "</p>";
                    body += "<p>設備名稱:" + keep.AssetName + "</p>";
                    body += "<p>放置地點:" + keep.PlaceLoc + "</p>";
                    body += "<p><a href='http://dms.cch.org.tw/EDIS/Account/Login'" + "?docId=" + keep.DocId + "&dealType=KeepEdit" + ">處理案件</a></p>";
                    body += "<br/>";
                    body += "<h3>此封信件為系統通知郵件,請勿回覆。</h3>";
                    body += "<br/>";
                    body += "<h3 style='color:red'>如有任何疑問請聯絡工務部,分機3033或7033。<h3>";
                    mail.message.Body       = body;
                    mail.message.IsBodyHtml = true;
                    //mail.SendMail();

                    return(Ok(keep));
                }
                else
                {
                    msg = "";
                    foreach (var error in ViewData.ModelState.Values.SelectMany(modelState => modelState.Errors))
                    {
                        msg += error.ErrorMessage + Environment.NewLine;
                    }
                    throw new Exception(msg);
                }
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
            return(BadRequest(msg));
        }
        public async Task <IViewComponentResult> InvokeAsync(string id)
        {
            /* Get keep and flow details. */
            KeepModel     keep     = _context.Keeps.Find(id);
            KeepFlowModel keepFlow = _context.KeepFlows.Where(f => f.DocId == id && f.Status == "?")
                                     .FirstOrDefault();

            /* Insert values. */
            AssignModel assign = new AssignModel();

            assign.DocId = id;

            /* 根據當下流程的人員做額外的流程控管 */
            List <SelectListItem> listItem = new List <SelectListItem>();

            if (keepFlow != null)
            {
                assign.Cls = keepFlow.Cls;
                //if (repairFlow.Cls == "申請人")    //統一回申請人結案
                //{   /* 廢除選項在首頁 */
                //    listItem.Add(new SelectListItem { Text = "廢除", Value = "廢除" });
                //}
                if (keepFlow.Cls == "驗收人")    //統一回申請人=驗收人結案
                {
                    listItem.Add(new SelectListItem {
                        Text = "結案", Value = "結案"
                    });
                }
                if (keepFlow.Cls == "工務/營建工程師")            //工務/營建工程師自己為驗收人時
                {
                    if (keep.CheckerId == keepFlow.UserId) //驗收人為自己
                    {
                        listItem.Add(new SelectListItem {
                            Text = "結案", Value = "結案"
                        });
                    }
                }
            }

            listItem.Add(new SelectListItem {
                Text = "申請人", Value = "申請人"
            });
            listItem.Add(new SelectListItem {
                Text = "驗收人", Value = "驗收人"
            });
            listItem.Add(new SelectListItem {
                Text = "單位主管", Value = "單位主管"
            });
            listItem.Add(new SelectListItem {
                Text = "單位主任", Value = "單位主任"
            });
            listItem.Add(new SelectListItem {
                Text = "單位直屬院長室主管", Value = "單位直屬院長室主管"
            });
            listItem.Add(new SelectListItem {
                Text = "工務/營建工程師", Value = "工務/營建工程師"
            });
            listItem.Add(new SelectListItem {
                Text = "工務主管", Value = "工務主管"
            });
            listItem.Add(new SelectListItem {
                Text = "工務主任", Value = "工務主任"
            });
            listItem.Add(new SelectListItem {
                Text = "營建主管", Value = "營建主管"
            });
            listItem.Add(new SelectListItem {
                Text = "營建主任", Value = "營建主任"
            });
            listItem.Add(new SelectListItem {
                Text = "列管財產負責人", Value = "列管財產負責人"
            });
            listItem.Add(new SelectListItem {
                Text = "固資財產負責人", Value = "固資財產負責人"
            });
            listItem.Add(new SelectListItem {
                Text = "其他", Value = "其他"
            });

            ViewData["FlowCls"] = new SelectList(listItem, "Value", "Text", "");

            List <SelectListItem> listItem3 = new List <SelectListItem>();

            listItem3.Add(new SelectListItem {
                Text = "", Value = ""
            });
            ViewData["FlowUid"] = new SelectList(listItem3, "Value", "Text", "");

            assign.Hint = "";

            return(View(assign));
        }
        public async Task <IViewComponentResult> InvokeAsync(string id = null)
        {
            KeepModel kp = _context.Keeps.Find(id);
            List <KeepFormatListVModel> kf = new List <KeepFormatListVModel>();
            KeepFormatModel             f;
            KeepRecordModel             r;

            if (kp != null)
            {
                //AssetKeepModel ak = _context.AssetKeeps.Find(kp.DeviceNo);
                //if (ak != null)
                //{
                if (!string.IsNullOrEmpty(kp.FormatId))
                {
                    _context.KeepFormatDtls.Where(d => d.FormatId == kp.FormatId)
                    .ToList()
                    .ForEach(d =>
                    {
                        kf.Add(new KeepFormatListVModel
                        {
                            Docid    = id,
                            FormatId = d.FormatId,
                            Plants   = (f = _context.KeepFormats.Find(d.FormatId)) == null ? "" :
                                       f.Plants,
                            Sno          = d.Sno,
                            ListNo       = 1,
                            Descript     = d.Descript,
                            IsFunctional = (r = _context.KeepRecords.Find(id, d.FormatId, d.Sno, 1)) == null ? "" :
                                           r.IsFunctional,
                            KeepDes = (r = _context.KeepRecords.Find(id, d.FormatId, d.Sno, 1)) == null ? "" :
                                      r.KeepDes,
                            IsRequired = d.IsRequired
                        });
                    });
                }

                //}
                KeepFlowModel kf2 = _context.KeepFlows.Where(f2 => f2.DocId == id)
                                    .Where(f2 => f2.Status == "?").FirstOrDefault();
                var keepRecords = _context.KeepRecords.Where(kr => kr.DocId == id);
                if (keepRecords != null)
                {
                    var countList = keepRecords.Select(kr => kr.ListNo).Distinct().Count();
                    ViewData["CountList"] = countList;
                }
                if (kf2.Cls.Contains("工程師"))
                {
                    return(View(kf));
                }
                else
                {
                    // 處理多張保養紀錄
                    List <KeepFormatListVModel> kfl2 = new List <KeepFormatListVModel>();
                    //var keepRecords = _context.KeepRecords.Where(kr => kr.DocId == id);
                    if (keepRecords != null)
                    {
                        var countListNo = keepRecords.Select(kr => kr.ListNo).Distinct().Count();
                        //ViewData["CountList"] = countListNo;
                        if (countListNo >= 2)
                        {
                            keepRecords.Join(_context.KeepFormatDtls,
                                             kr => new { FormatId = kr.FormatId, Sno = kr.Sno },
                                             fd => new { FormatId = fd.FormatId, Sno = fd.Sno },
                                             (kr, fd) => new
                            {
                                keeprecords = kr,
                                formatdtls  = fd
                            }).ToList()
                            .ForEach(d =>
                            {
                                kfl2.Add(new KeepFormatListVModel
                                {
                                    Docid    = id,
                                    FormatId = d.formatdtls.FormatId,
                                    Plants   = (f = _context.KeepFormats.Find(d.formatdtls.FormatId)) == null ? "" :
                                               f.Plants,
                                    Sno          = d.keeprecords.Sno,
                                    ListNo       = d.keeprecords.ListNo,
                                    Descript     = d.keeprecords.Descript,
                                    IsFunctional = d.keeprecords.IsFunctional == null ? "" :
                                                   d.keeprecords.IsFunctional,
                                    KeepDes = d.keeprecords.KeepDes == null ? "" :
                                              d.keeprecords.KeepDes,
                                    IsRequired = d.formatdtls.IsRequired
                                });
                            });
                            kfl2 = kfl2.OrderBy(k => k.Sno).ThenBy(k => k.ListNo).ToList();
                            return(View("Detail2", kfl2));
                        }
                    }
                    return(View("Details", kf));
                }
            }
            return(Content("Page not found!"));  //ViewComponent can't return HTTP response (like as StatusCode() or BasRequest())
        }
Exemplo n.º 11
0
        public async Task <IActionResult> NextFlow(AssignModel assign)
        {
            var ur = _userRepo.Find(u => u.UserName == this.User.Identity.Name).FirstOrDefault();

            /* 工程師的流程控管 */
            if (assign.Cls == "設備工程師")
            {
                /* 如點選有費用、卻無輸入費用明細 */
                var isCharged = _context.BMEDKeepDtls.Where(d => d.DocId == assign.DocId).FirstOrDefault().IsCharged;
                if (isCharged == "Y")
                {
                    var CheckRepairCost = _context.BMEDKeepCosts.Where(c => c.DocId == assign.DocId).FirstOrDefault();
                    if (CheckRepairCost == null)
                    {
                        throw new Exception("尚未輸入費用明細!!");
                    }
                }
            }

            if (assign.FlowCls == "結案" || assign.FlowCls == "廢除")
            {
                assign.FlowUid = ur.Id;
            }
            if (ModelState.IsValid)
            {
                KeepFlowModel kf = _context.BMEDKeepFlows.Where(f => f.DocId == assign.DocId && f.Status == "?").FirstOrDefault();
                if (assign.FlowCls == "驗收人")
                {
                    if (_context.BMEDKeepEmps.Where(emp => emp.DocId == assign.DocId).Count() <= 0)
                    {
                        throw new Exception("沒有維修工程師紀錄!!");
                    }
                    else if (_context.BMEDKeepDtls.Find(assign.DocId).EndDate == null)
                    {
                        throw new Exception("沒有完工日!!");
                    }
                    if (_context.BMEDKeepDtls.Find(assign.DocId).Result == null)
                    {
                        throw new Exception("保養結果不可空白!!");
                    }
                    if (string.IsNullOrEmpty(_context.BMEDKeepDtls.Find(assign.DocId).InOut))
                    {
                        throw new Exception("保養方式不可空白!!");
                    }
                }
                if (assign.FlowCls == "結案")
                {
                    KeepDtlModel kd = _context.BMEDKeepDtls.Find(assign.DocId);
                    kd.CloseDate             = DateTime.Now;
                    kf.Opinions              = "[" + assign.AssignCls + "]" + Environment.NewLine + assign.AssignOpn;
                    kf.Status                = "2";
                    kf.UserId                = ur.Id;
                    kf.UserName              = _context.AppUsers.Find(ur.Id).FullName;
                    kf.Rtt                   = DateTime.Now;
                    kf.Rtp                   = ur.Id;
                    _context.Entry(kf).State = EntityState.Modified;
                    _context.Entry(kd).State = EntityState.Modified;

                    _context.SaveChanges();
                    // Save stock to ERP system.
                    //var ERPreponse = await SaveToERPAsync(assign.DocId);

                    //Send Mail
                    //To all users in this keep's flow.
                    Tmail        mail = new Tmail();
                    string       body = "";
                    string       sto  = "";
                    AppUserModel u;
                    KeepModel    keep = _context.BMEDKeeps.Find(assign.DocId);
                    mail.from = new System.Net.Mail.MailAddress(ur.Email); //u.Email
                    _context.BMEDKeepFlows.Where(f => f.DocId == assign.DocId)
                    .ToList()
                    .ForEach(f =>
                    {
                        u    = _context.AppUsers.Find(f.UserId);
                        sto += u.Email + ",";
                    });
                    mail.sto = sto.TrimEnd(new char[] { ',' });

                    mail.message.Subject = "醫工工務智能保修系統[醫工保養案-結案通知]:設備名稱: " + keep.AssetName;
                    body += "<p>表單編號:" + keep.DocId + "</p>";
                    body += "<p>送單日期:" + keep.SentDate.Value.ToString("yyyy/MM/dd") + "</p>";
                    body += "<p>申請人:" + keep.UserName + "</p>";
                    body += "<p>財產編號:" + keep.AssetNo + "</p>";
                    body += "<p>設備名稱:" + keep.AssetName + "</p>";
                    body += "<p>放置地點:" + keep.PlaceLoc + "</p>";
                    body += "<p>保養結果:" + kd.Result + "</p>";
                    body += "<p>保養描述:" + kd.Memo + "</p>";
                    body += "<p><a href='http://dms.cch.org.tw/EDIS/Account/Login'" + "?DocId=" + keep.DocId + "&dealType=BMEDKeepViews" + ">檢視案件</a></p>";
                    body += "<br/>";
                    body += "<h3>此封信件為系統通知郵件,請勿回覆。</h3>";
                    body += "<br/>";
                    //body += "<h3 style='color:red'>如有任何疑問請聯絡工務部,分機3033或7033。<h3>";
                    mail.message.Body       = body;
                    mail.message.IsBodyHtml = true;
                    mail.SendMail();
                }
                else if (assign.FlowCls == "廢除")
                {
                    kf.Opinions = "[廢除]" + Environment.NewLine + assign.AssignOpn;
                    kf.Status   = "3";
                    kf.Rtt      = DateTime.Now;
                    kf.Rtp      = ur.Id;
                    _context.Entry(kf).State = EntityState.Modified;
                    _context.SaveChanges();
                }
                else
                {
                    //轉送下一關卡
                    kf.Opinions = "[" + assign.AssignCls + "]" + Environment.NewLine + assign.AssignOpn;
                    kf.Status   = "1";
                    kf.Rtt      = DateTime.Now;
                    kf.Rtp      = ur.Id;
                    _context.Entry(kf).State = EntityState.Modified;
                    _context.SaveChanges();
                    //
                    KeepFlowModel flow = new KeepFlowModel();
                    flow.DocId    = assign.DocId;
                    flow.StepId   = kf.StepId + 1;
                    flow.UserId   = assign.FlowUid.Value;
                    flow.UserName = _context.AppUsers.Find(assign.FlowUid.Value).FullName;
                    flow.Status   = "?";
                    flow.Cls      = assign.FlowCls;
                    flow.Rtt      = DateTime.Now;
                    _context.BMEDKeepFlows.Add(flow);
                    _context.SaveChanges();

                    //Send Mail
                    //To user and the next flow user.
                    Tmail        mail = new Tmail();
                    string       body = "";
                    AppUserModel u;
                    KeepModel    keep = _context.BMEDKeeps.Find(assign.DocId);
                    mail.from = new System.Net.Mail.MailAddress(ur.Email); //ur.Email
                    u         = _context.AppUsers.Find(flow.UserId);
                    mail.to   = new System.Net.Mail.MailAddress(u.Email);  //u.Email
                                                                           //mail.cc = new System.Net.Mail.MailAddress("*****@*****.**");
                    mail.message.Subject = "醫工工務智能保修系統[醫工保養案]:設備名稱: " + keep.AssetName;
                    body += "<p>表單編號:" + keep.DocId + "</p>";
                    body += "<p>送單日期:" + keep.SentDate.Value.ToString("yyyy/MM/dd") + "</p>";
                    body += "<p>申請人:" + keep.UserName + "</p>";
                    body += "<p>財產編號:" + keep.AssetNo + "</p>";
                    body += "<p>設備名稱:" + keep.AssetName + "</p>";
                    body += "<p>放置地點:" + keep.PlaceLoc + "</p>";
                    body += "<p><a href='http://dms.cch.org.tw/EDIS/Account/Login'" + "?docId=" + keep.DocId + "&dealType=BMEDKeepEdit" + ">處理案件</a></p>";
                    body += "<br/>";
                    body += "<h3>此封信件為系統通知郵件,請勿回覆。</h3>";
                    body += "<br/>";
                    //body += "<h3 style='color:red'>如有任何疑問請聯絡工務部,分機3033或7033。<h3>";
                    mail.message.Body       = body;
                    mail.message.IsBodyHtml = true;
                    mail.SendMail();
                }

                return(new JsonResult(assign)
                {
                    Value = new { success = true, error = "" }
                });
            }
            else
            {
                string msg = "";
                foreach (var error in ViewData.ModelState.Values.SelectMany(modelState => modelState.Errors))
                {
                    msg += error.ErrorMessage + Environment.NewLine;
                }
                throw new Exception(msg);
            }
        }
Exemplo n.º 12
0
        public async Task <IViewComponentResult> InvokeAsync(string id)
        {
            var ur = _userRepo.Find(us => us.UserName == this.User.Identity.Name).FirstOrDefault();

            // InOut dropdown list's items.
            List <SelectListItem> listItem1 = new List <SelectListItem>();

            listItem1.Add(new SelectListItem {
                Text = "自行", Value = "0"
            });
            listItem1.Add(new SelectListItem {
                Text = "委外", Value = "1"
            });
            listItem1.Add(new SelectListItem {
                Text = "租賃", Value = "2"
            });
            listItem1.Add(new SelectListItem {
                Text = "保固", Value = "3"
            });
            ViewData["InOut"] = new SelectList(listItem1, "Value", "Text", "");

            // Result dropdown list's items.
            List <SelectListItem> listItem2 = new List <SelectListItem>();

            _context.BMEDKeepResults.Where(d => d.Flg == "Y")
            .ToList()
            .ForEach(d => {
                listItem2.Add(new SelectListItem {
                    Text = d.Title, Value = d.Id.ToString()
                });
            });
            ViewData["Result"] = new SelectList(listItem2, "Value", "Text", "");

            if (id == null)
            {
                KeepDtlModel dtl = new KeepDtlModel();
                dtl.IsCharged = "N";
                return(View(dtl));
            }

            KeepDtlModel  keepDtl = _context.BMEDKeepDtls.Find(id);
            KeepFlowModel kf      = _context.BMEDKeepFlows.Where(f => f.DocId == id)
                                    .Where(f => f.Status == "?").FirstOrDefault();

            /* Get CheckerName from Repair table. */
            var checkerId = _context.BMEDKeeps.Find(id).CheckerId;

            keepDtl.CheckerName = checkerId == 0 ? "" : _context.AppUsers.Find(checkerId).FullName;

            var isEngineer = _context.UsersInRoles.Where(u => u.AppRoles.RoleName == "MedEngineer" &&
                                                         u.UserId == ur.Id).FirstOrDefault();

            if (kf.Cls.Contains("工程師") && kf.UserId == ur.Id)  /* 流程 => 工程師,Login User => 負責之工程師 */
            {
                return(View(keepDtl));
            }
            else if (kf.Cls.Contains("工程師") && isEngineer != null)  /* 流程 => 工程師,Login User => 非負責之工程師 */
            {
                return(View(keepDtl));
            }
            else  /* 流程 => 其他 */
            {
                switch (keepDtl.InOut)
                {
                case "0":
                    keepDtl.InOut = "自行";
                    break;

                case "1":
                    keepDtl.InOut = "委外";
                    break;

                case "2":
                    keepDtl.InOut = "租賃";
                    break;

                case "3":
                    keepDtl.InOut = "保固";
                    break;
                }
                keepDtl.ResultTitle = keepDtl.Result == null ? "" : _context.BMEDKeepResults.Find(keepDtl.Result).Title;
                return(View("Details", keepDtl));
            }
        }
Exemplo n.º 13
0
        public async Task <IViewComponentResult> InvokeAsync(string id)
        {
            /* Get repair and flow details. */
            KeepModel     keep     = _context.BMEDKeeps.Find(id);
            KeepFlowModel keepFlow = _context.BMEDKeepFlows.Where(f => f.DocId == id && f.Status == "?")
                                     .FirstOrDefault();

            List <SelectListItem> listItem = new List <SelectListItem>();

            listItem.Add(new SelectListItem {
                Text = "申請人", Value = "申請人"
            });
            listItem.Add(new SelectListItem {
                Text = "驗收人", Value = "驗收人"
            });
            listItem.Add(new SelectListItem {
                Text = "單位主管", Value = "單位主管"
            });
            listItem.Add(new SelectListItem {
                Text = "維修工程師", Value = "維修工程師"
            });
            listItem.Add(new SelectListItem {
                Text = "設備工程師", Value = "設備工程師"
            });
            listItem.Add(new SelectListItem {
                Text = "醫工主管", Value = "醫工主管"
            });
            listItem.Add(new SelectListItem {
                Text = "設備主管", Value = "設備主管"
            });
            //listItem.Add(new SelectListItem { Text = "醫工主任", Value = "醫工主任" });
            listItem.Add(new SelectListItem {
                Text = "其他", Value = "其他"
            });

            /* Insert values. */
            AssignModel assign = new AssignModel();

            assign.DocId = id;

            /* 根據當下流程的人員做額外的流程控管 */
            if (keepFlow != null)
            {
                assign.Cls = keepFlow.Cls;

                if (keepFlow.Cls == "驗收人" || keepFlow.Cls == "醫工主管")    //驗收人 or 醫工主管結案
                {
                    listItem.Add(new SelectListItem {
                        Text = "結案", Value = "結案"
                    });
                }
            }
            ViewData["FlowCls"] = new SelectList(listItem, "Value", "Text", "");

            List <SelectListItem> listItem3 = new List <SelectListItem>();

            listItem3.Add(new SelectListItem {
                Text = "", Value = ""
            });
            ViewData["FlowUid"] = new SelectList(listItem3, "Value", "Text", "");

            assign.Hint = "";

            return(View(assign));
        }
Exemplo n.º 14
0
        public async Task <IViewComponentResult> InvokeAsync(string id)
        {
            /* Get repair and flow details. */
            KeepModel     keep     = _context.BMEDKeeps.Find(id);
            KeepDtlModel  keepDtl  = _context.BMEDKeepDtls.Find(id);
            KeepFlowModel keepFlow = _context.BMEDKeepFlows.Where(f => f.DocId == id && f.Status == "?")
                                     .FirstOrDefault();

            List <SelectListItem> listItem = new List <SelectListItem>();

            listItem.Add(new SelectListItem {
                Text = "申請人", Value = "申請人"
            });
            listItem.Add(new SelectListItem {
                Text = "驗收人", Value = "驗收人"
            });
            listItem.Add(new SelectListItem {
                Text = "單位主管", Value = "單位主管"
            });
            //listItem.Add(new SelectListItem { Text = "維修工程師", Value = "維修工程師" });
            listItem.Add(new SelectListItem {
                Text = "設備工程師", Value = "設備工程師"
            });
            listItem.Add(new SelectListItem {
                Text = "賀康主管", Value = "賀康主管"
            });
            //總、分院不同關卡
            if (keep.Loc == "總院")
            {
                listItem.Add(new SelectListItem {
                    Text = "醫工主管", Value = "醫工主管"
                });
            }
            else
            {
                listItem.Add(new SelectListItem {
                    Text = "醫工分院主管", Value = "醫工分院主管"
                });
                listItem.Add(new SelectListItem {
                    Text = "設備主管", Value = "設備主管"
                });
            }
            listItem.Add(new SelectListItem {
                Text = "其他", Value = "其他"
            });

            //額外流程控管 04/16
            //if (keepDtl.IsCharged == "Y" && keepDtl.NotInExceptDevice == "N")   //有費用 & 非統包
            //{
            //    var itemToRemove = listItem.SingleOrDefault(r => r.Value == "驗收人");  //移除驗收人關卡,只醫工主管可結案
            //    if (itemToRemove != null)
            //    {
            //        listItem.Remove(itemToRemove);
            //    }
            //}
            if (keepDtl.NotInExceptDevice == "N")                                    //非統包
            {
                var itemToRemove = listItem.SingleOrDefault(r => r.Value == "賀康主管"); //移除賀康主管關卡
                if (itemToRemove != null)
                {
                    listItem.Remove(itemToRemove);
                }
            }
            if (keepFlow.Cls == "驗收人" && keepDtl.IsCharged == "Y")  //有費用 & 關卡於驗收人,下一關只可給工程師
            {
                var itemToRemove = listItem.SingleOrDefault(r => r.Value == "醫工主管");
                if (itemToRemove != null)
                {
                    listItem.Remove(itemToRemove);
                }
                itemToRemove = listItem.SingleOrDefault(r => r.Value == "賀康主管");
                if (itemToRemove != null)
                {
                    listItem.Remove(itemToRemove);
                }
            }

            //Add New
            //有統包 有費用 關卡工程師
            //if (keepDtl.NotInExceptDevice == "Y" && keepFlow.Cls.Contains("工程師") && keepDtl.IsCharged == "Y")
            //{
            //    listItem.Add(new SelectListItem { Text = "賀康經辦", Value = "賀康經辦" });
            //    var itemToRemove = listItem.SingleOrDefault(r => r.Value == "賀康主管");  //移除賀康主管關卡
            //    if (itemToRemove != null)
            //    {
            //        listItem.Remove(itemToRemove);
            //    }
            //}

            /* Insert values. */
            AssignModel assign = new AssignModel();

            assign.DocId = id;

            /* 根據當下流程的人員做額外的流程控管 */
            if (keepFlow != null)
            {
                assign.Cls = keepFlow.Cls;

                if (keepFlow.Cls == "驗收人" || keepFlow.Cls == "醫工主管" ||
                    keepFlow.Cls == "賀康主管" || keepFlow.Cls == "設備主管")  //可結案人員
                {
                    listItem.Add(new SelectListItem {
                        Text = "結案", Value = "結案"
                    });
                }
                if (keepFlow.Cls == "驗收人" && keepDtl.IsCharged == "Y")  //有費用 & 關卡於驗收人,下一關只可給工程師
                {
                    var itemToRemove = listItem.SingleOrDefault(r => r.Value == "結案");
                    if (itemToRemove != null)
                    {
                        listItem.Remove(itemToRemove);
                    }
                }
                if (keepFlow.Cls == "驗收人")
                {
                    //2021/04/28 去除申請人
                    var itemToRemove = listItem.SingleOrDefault(r => r.Value == "申請人");
                    if (itemToRemove != null)
                    {
                        listItem.Remove(itemToRemove);
                    }
                }
                //無費用時單位主管可結案
                if (keepFlow.Cls == "單位主管")
                {
                    if (keepDtl != null)
                    {
                        if (keepDtl.IsCharged == "N")
                        {
                            listItem.Add(new SelectListItem {
                                Text = "結案", Value = "結案"
                            });
                        }
                    }
                }
            }
            ViewData["FlowCls"] = new SelectList(listItem, "Value", "Text", "");

            List <SelectListItem> listItem3 = new List <SelectListItem>();

            listItem3.Add(new SelectListItem {
                Text = "", Value = ""
            });
            ViewData["FlowUid"] = new SelectList(listItem3, "Value", "Text", "");

            assign.Hint = "申請者→負責工程師→使用單位→(若有費用)負責工程師→[醫工部主管、賀康主管]→結案";

            return(View(assign));
        }