예제 #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));
        }
예제 #2
0
        public IActionResult Update(KeepModel keepModel)
        {
            KeepModel keep = _context.Keeps.Find(keepModel.DocId);

            if (keep == null)
            {
                return(BadRequest("查無案件!"));
            }

            if (string.IsNullOrEmpty(keepModel.AccDpt))
            {
                return(BadRequest("成本中心不可空白!"));
            }

            keepModel.AccDpt = keepModel.AccDpt.Trim();
            var dpt = _context.Departments.Find(keepModel.AccDpt);

            if (dpt == null)
            {
                return(BadRequest("此編號查無部門!"));
            }
            keep.AccDpt = keepModel.AccDpt;
            _context.Entry(keep).State = EntityState.Modified;
            _context.SaveChanges();
            return(PartialView("Update", keep));
        }
예제 #3
0
        public ActionResult <Keep> AddKeep(KeepModel setKeep)
        {
            var userId = HttpContext.User.Identity.Name;

            setKeep.UserId = userId;
            return(Ok(_repo.AddKeep(setKeep)));
        }
        public async Task <IViewComponentResult> InvokeAsync(string id)
        {
            KeepModel kp = _context.BMEDKeeps.Find(id);

            kp.AccDptName  = kp.AccDpt == null ? "" : _context.Departments.Find(kp.AccDpt).Name_C;
            kp.CheckerName = kp.CheckerId == 0 ? "" : _context.AppUsers.Find(kp.CheckerId).FullName;

            return(View(kp));
        }
예제 #5
0
        // GET: Keep/Views
        public IActionResult Views(string id)
        {
            KeepModel keep = _context.Keeps.Find(id);

            if (keep == null)
            {
                return(StatusCode(404));
            }
            return(View(keep));
        }
예제 #6
0
        //add a keep
        public KeepModel AddKeep(KeepModel setKeep)
        {
            int id = _db.ExecuteScalar <int>($@"INSERT INTO Keeps (name, description, userId, isPrivate, img, views, saves)
      VALUES (@Name, @Description, @UserId, @IsPrivate, @Img, @Views, @Saves);
      SELECT LAST_INSERT_ID();", setKeep);

            if (id == 0)
            {
                return(null);
            }
            setKeep.Id = id;
            return(setKeep);
        }
예제 #7
0
        // GET: Keep/Delete/5
        public IActionResult Delete(string id)
        {
            // Find document.
            KeepModel keep = _context.Keeps.Find(id);

            keep.DptName     = _context.Departments.Find(keep.DptId).Name_C;
            keep.AccDptName  = _context.Departments.Find(keep.AccDpt).Name_C;
            keep.UserAccount = _context.AppUsers.Find(keep.UserId).UserName;

            if (keep == null)
            {
                return(StatusCode(404));
            }
            return(View(keep));
        }
        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())
        }
        public async Task <IViewComponentResult> InvokeAsync(int listNo, 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       = listNo,
                            Descript     = d.Descript,
                            IsFunctional = (r = _context.KeepRecords.Find(id, d.FormatId, d.Sno, listNo)) == null ? "" :
                                           r.IsFunctional,
                            KeepDes = (r = _context.KeepRecords.Find(id, d.FormatId, d.Sno, listNo)) == null ? "" :
                                      r.KeepDes,
                            IsRequired = d.IsRequired
                        });
                    });
                }

                //}
                return(View(kf));
            }
            return(Content("Page not found!"));  //ViewComponent can't return HTTP response (like as StatusCode() or BasRequest())
        }
예제 #10
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));
        }
예제 #11
0
        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.AssetNo);
                //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,
                            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
                        });
                    });
                }
                //}

                // 處理多張保養紀錄
                List <KeepFormatListVModel> kf2 = 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 =>
                        {
                            kf2.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
                            });
                        });
                        kf2 = kf2.OrderBy(k => k.Sno).ThenBy(k => k.ListNo).ToList();
                        return(View("Detail2", kf2));
                    }
                }
                return(View(kf));
            }
            return(Content("Page not found!"));  //ViewComponent can't return HTTP response (like as StatusCode() or BasRequest())
        }
예제 #12
0
        // GET: Keep/Create
        public IActionResult Create()
        {
            KeepModel    k  = new KeepModel();
            AppUserModel ur = _context.AppUsers.Where(u => u.UserName == this.User.Identity.Name).FirstOrDefault();

            k.Email = ur.Email == null ? "" : ur.Email;
            DepartmentModel d = _context.Departments.Find(ur.DptId);

            k.DocId       = GetID();
            k.UserId      = ur.Id;
            k.UserName    = ur.FullName;
            k.UserAccount = ur.UserName;
            k.SentDate    = DateTime.Now;
            k.DptId       = d == null ? "" : d.DptId;
            k.Company     = d == null ? "" : d.Name_C;
            k.AccDpt      = d == null ? "" : d.DptId;
            k.AccDptName  = d == null ? "" : d.Name_C;
            k.Ext         = ur.Ext == null ? "" : ur.Ext;
            k.CheckerId   = ur.Id;
            //
            _context.Keeps.Add(k);
            _context.SaveChanges();

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

            _context.Departments.ToList()
            .ForEach(dp =>
            {
                AccDpt.Add(new SelectListItem
                {
                    Value    = dp.DptId,
                    Text     = dp.Name_C,
                    Selected = false
                });
            });
            ViewData["AccDpt"] = AccDpt;

            //
            List <AssetModel> alist = null;

            if (ur.DptId != null)
            {
                alist = _context.Assets.Where(at => at.AccDpt == ur.DptId)
                        .Where(at => at.DisposeKind != "報廢").ToList();
            }
            else if (ur.VendorId > 0)
            {
                string s = Convert.ToString(ur.VendorId);
                alist = _context.Assets.Where(at => at.AccDpt == s)
                        .Where(at => at.DisposeKind != "報廢").ToList();
            }

            /* 擷取該使用者單位底下所有人員 */
            var dptUsers = _context.AppUsers.Where(a => a.DptId == ur.DptId).ToList();
            List <SelectListItem> dptMemberList = new List <SelectListItem>();

            foreach (var item in dptUsers)
            {
                dptMemberList.Add(new SelectListItem
                {
                    Text  = item.FullName,
                    Value = item.Id.ToString()
                });
            }
            ViewData["DptMembers"] = new SelectList(dptMemberList, "Value", "Text");

            return(View(k));
        }
        // GET: KeepRecord/GetRecordList
        public async Task <IActionResult> GetRecordList(int listNo, string docId = null)
        {
            KeepModel kp = _context.Keeps.Find(docId);
            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    = docId,
                            FormatId = d.FormatId,
                            Plants   = (f = _context.KeepFormats.Find(d.FormatId)) == null ? "" :
                                       f.Plants,
                            Sno      = d.Sno,
                            ListNo   = listNo,
                            Descript = d.Descript,
                            KeepDes  = (r = _context.KeepRecords.Find(docId, d.FormatId, d.Sno, listNo)) == null ? "" :
                                       r.KeepDes,
                            IsRequired = d.IsRequired
                        });
                    });

                    // 同步新增預設資料進DB.
                    KeepRecordModel keepRecord;
                    foreach (var item in kf)
                    {
                        keepRecord          = new KeepRecordModel();
                        keepRecord.DocId    = item.Docid;
                        keepRecord.FormatId = item.FormatId;
                        keepRecord.Sno      = item.Sno;
                        keepRecord.ListNo   = item.ListNo;
                        keepRecord.Descript = item.Descript;
                        keepRecord.KeepDes  = item.KeepDes;
                        _context.KeepRecords.Add(keepRecord);
                    }
                    if (listNo == 2)
                    {
                        // 新增第二筆紀錄時,如第一筆資料尚未新增,一併新增。
                        var findFirstData = _context.KeepRecords.Where(kr => kr.DocId == docId && kr.ListNo == 1);
                        if (findFirstData.Count() <= 0)
                        {
                            foreach (var item in kf)
                            {
                                keepRecord          = new KeepRecordModel();
                                keepRecord.DocId    = item.Docid;
                                keepRecord.FormatId = item.FormatId;
                                keepRecord.Sno      = item.Sno;
                                keepRecord.ListNo   = 1;
                                keepRecord.Descript = item.Descript;
                                keepRecord.KeepDes  = item.KeepDes;
                                _context.KeepRecords.Add(keepRecord);
                            }
                        }
                    }
                    _context.SaveChanges();
                }
                //}
                return(View(kf));
            }
            else
            {
                return(BadRequest());
            }
        }
예제 #14
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));
        }
예제 #15
0
        public ActionResult GetNextEmp(string cls, string docid /*, string vendor*/)
        {
            List <SelectListItem> list = new List <SelectListItem>();
            List <string>         s;
            SelectListItem        li;
            AppUserModel          u;
            KeepModel             k     = _context.BMEDKeeps.Find(docid);
            AssetModel            asset = _context.BMEDAssets.Where(a => a.AssetNo == k.AssetNo).FirstOrDefault();

            switch (cls)
            {
            case "維修工程師":
                roleManager.GetUsersInRole("Engineer").ToList()
                .ForEach(x =>
                {
                    u = _context.AppUsers.Where(ur => ur.UserName == x).FirstOrDefault();
                    if (u != null)
                    {
                        li       = new SelectListItem();
                        li.Text  = u.FullName;
                        li.Value = u.Id.ToString();
                        list.Add(li);
                    }
                });
                break;

            case "醫工主管":
                s    = roleManager.GetUsersInRole("MedMgr").ToList();
                list = new List <SelectListItem>();
                foreach (string l in s)
                {
                    u = _context.AppUsers.Where(ur => ur.UserName == l).FirstOrDefault();
                    if (!string.IsNullOrEmpty(u.DptId))
                    {
                        li       = new SelectListItem();
                        li.Text  = u.FullName + "(" + u.UserName + ")";
                        li.Value = u.Id.ToString();
                        list.Add(li);
                    }
                }
                break;

            case "設備主管":
                s    = roleManager.GetUsersInRole("MedAssetMgr").ToList();
                list = new List <SelectListItem>();
                foreach (string l in s)
                {
                    u = _context.AppUsers.Where(ur => ur.UserName == l).FirstOrDefault();
                    if (!string.IsNullOrEmpty(u.DptId))
                    {
                        li       = new SelectListItem();
                        li.Text  = u.FullName + "(" + u.UserName + ")";
                        li.Value = u.Id.ToString();
                        list.Add(li);
                    }
                }
                break;

            case "醫工主任":
                s    = roleManager.GetUsersInRole("MedDirector").ToList();
                list = new List <SelectListItem>();
                foreach (string l in s)
                {
                    u = _context.AppUsers.Where(ur => ur.UserName == l).FirstOrDefault();
                    if (!string.IsNullOrEmpty(u.DptId))
                    {
                        li       = new SelectListItem();
                        li.Text  = u.FullName + "(" + u.UserName + ")";
                        li.Value = u.Id.ToString();
                        list.Add(li);
                    }
                }
                break;

            case "醫工經辦":
                //list = new List<SelectListItem>();
                //u = _context.AppUsers.Where(ur => ur.UserName == "1814").FirstOrDefault();
                //if (!string.IsNullOrEmpty(u.DptId))
                //{
                //    li = new SelectListItem();
                //    li.Text = u.FullName;
                //    li.Value = u.Id.ToString();
                //    list.Add(li);
                //}
                break;

            case "單位主管":
            case "單位主任":
                //s = roleManager.GetUsersInRole("Manager").ToList();
                /* 擷取申請人單位底下所有人員 */
                //string c = _context.AppUsers.Find(r.UserId).DptId;
                //var dptUsers = _context.AppUsers.Where(a => a.DptId == c).ToList();
                //list = new List<SelectListItem>();
                //foreach (var item in dptUsers)
                //{
                //        li = new SelectListItem();
                //        li.Text = item.FullName;
                //        li.Value = item.Id.ToString();
                //        list.Add(li);
                //}
                break;

            case "單位副院長":
                s    = roleManager.GetUsersInRole("ViceSI").ToList();
                list = new List <SelectListItem>();
                foreach (string l in s)
                {
                    u = _context.AppUsers.Where(ur => ur.UserName == l).FirstOrDefault();
                    if (!string.IsNullOrEmpty(u.DptId))
                    {
                        li       = new SelectListItem();
                        li.Text  = u.FullName + "(" + u.UserName + ")";
                        li.Value = u.Id.ToString();
                        list.Add(li);
                    }
                }
                break;

            case "申請人":
                if (k != null)
                {
                    list     = new List <SelectListItem>();
                    li       = new SelectListItem();
                    li.Text  = k.UserName;
                    li.Value = k.UserId.ToString();
                    list.Add(li);
                }
                else
                {
                    list     = new List <SelectListItem>();
                    li       = new SelectListItem();
                    li.Text  = "宋大衛";
                    li.Value = "000";
                    list.Add(li);
                }
                break;

            case "驗收人":
                if (_context.BMEDKeepEmps.Where(emp => emp.DocId == docid).Count() <= 0)
                {
                    throw new Exception("沒有維修工程師紀錄!!");
                }
                else if (_context.BMEDKeepDtls.Find(docid).EndDate == null)
                {
                    throw new Exception("沒有完工日!!");
                }
                else if (_context.BMEDKeepDtls.Find(docid).Result == null ||
                         _context.BMEDKeepDtls.Find(docid).Result == null)
                {
                    throw new Exception("沒有保養結果!!");
                }
                if (k != null)
                {
                    /* 與驗收人同單位的成員(包括驗收人) */
                    var checkerDptId       = _context.AppUsers.Find(k.CheckerId).DptId;
                    List <AppUserModel> ul = _context.AppUsers.Where(f => f.DptId == checkerDptId)
                                             .Where(f => f.Status == "Y").ToList();
                    if (asset != null)
                    {
                        if (asset.DelivDpt != k.DptId)
                        {
                            ul.AddRange(_context.AppUsers.Where(f => f.DptId == asset.DelivDpt)
                                        .Where(f => f.Status == "Y").ToList());
                        }
                    }
                    /* 驗收人 */
                    var checker = _context.AppUsers.Find(k.CheckerId);
                    list     = new List <SelectListItem>();
                    li       = new SelectListItem();
                    li.Text  = checker.FullName + "(" + checker.UserName + ")";
                    li.Value = checker.Id.ToString();
                    list.Add(li);

                    foreach (AppUserModel l in ul)
                    {
                        /* 申請人以外的成員 */
                        if (l.Id != k.UserId)
                        {
                            li       = new SelectListItem();
                            li.Text  = l.FullName + "(" + l.UserName + ")";
                            li.Value = l.Id.ToString();
                            list.Add(li);
                        }
                    }
                }
                break;

            case "設備工程師":

                /* Get all engineers. */
                s = roleManager.GetUsersInRole("MedEngineer").ToList();
                var keepEngId = _context.BMEDAssetKeeps.Find(k.AssetNo).KeepEngId;
                var keepEng   = _context.AppUsers.Find(keepEngId);

                list = new List <SelectListItem>();
                /* 負責工程師 */
                li       = new SelectListItem();
                li.Text  = keepEng.FullName + "(" + keepEng.UserName + ")";
                li.Value = keepEng.Id.ToString();
                list.Add(li);
                /* 其他工程師 */
                foreach (string l in s)
                {
                    u = _context.AppUsers.Where(ur => ur.UserName == l).FirstOrDefault();
                    if (u != null && l != keepEng.UserName)
                    {
                        li       = new SelectListItem();
                        li.Text  = u.FullName + "(" + u.UserName + ")";
                        li.Value = u.Id.ToString();
                        list.Add(li);
                    }
                }
                break;

            case "列管財產負責人":
                //list = new List<SelectListItem>();
                //u = _context.AppUsers.Where(ur => ur.UserName == "181151").FirstOrDefault();
                //if (!string.IsNullOrEmpty(u.DptId))
                //{
                //    li = new SelectListItem();
                //    li.Text = u.FullName;
                //    li.Value = u.Id.ToString();
                //    list.Add(li);
                //}
                break;

            case "固資財產負責人":
                //list = new List<SelectListItem>();
                //u = _context.AppUsers.Where(ur => ur.UserName == "1814").FirstOrDefault();
                //if (!string.IsNullOrEmpty(u.DptId))
                //{
                //    li = new SelectListItem();
                //    li.Text = u.FullName;
                //    li.Value = u.Id.ToString();
                //    list.Add(li);
                //}
                break;

            default:
                list = new List <SelectListItem>();
                break;
            }
            return(Json(list));
        }
예제 #16
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);
            }
        }
예제 #17
0
        public ActionResult GetNextEmp(string cls, string docid/*, string vendor*/)
        {
            List<SelectListItem> list = new List<SelectListItem>();
            List<string> s;
            SelectListItem li;
            AppUserModel u;
            KeepModel k = _context.BMEDKeeps.Find(docid);
            AssetModel asset = _context.BMEDAssets.Where(a => a.AssetNo == k.AssetNo).FirstOrDefault();
            string[] locList;

            switch (cls)
            {
                case "維修工程師":  //Not Used
                    roleManager.GetUsersInRole("Engineer").ToList()
                        .ForEach(x =>
                        {
                            u = _context.AppUsers.Where(ur => ur.UserName == x).FirstOrDefault();
                            if (u != null)
                            {
                                li = new SelectListItem();
                                li.Text = u.FullName + "(" + u.UserName + ")";
                                li.Value = u.Id.ToString();
                                list.Add(li);
                            }
                        });
                    break;
                case "醫工主管":
                    s = roleManager.GetUsersInRole("MedMgr").ToList();
                    list = new List<SelectListItem>();
                    foreach (string l in s)
                    {
                        u = _context.AppUsers.Where(ur => ur.UserName == l).FirstOrDefault();
                        if (!string.IsNullOrEmpty(u.DptId))
                        {
                            li = new SelectListItem();
                            li.Text = u.FullName + "(" + u.UserName + ")";
                            li.Value = u.Id.ToString();
                            list.Add(li);
                        }
                    }
                    break;
                case "賀康主管":  //設備主管
                    s = roleManager.GetUsersInRole("MedAssetMgr").ToList();
                    list = new List<SelectListItem>();
                    foreach (string l in s)
                    {
                        u = _context.AppUsers.Where(ur => ur.UserName == l).FirstOrDefault();
                        if (!string.IsNullOrEmpty(u.DptId))
                        {
                            li = new SelectListItem();
                            li.Text = u.FullName + "(" + u.UserName + ")";
                            li.Value = u.Id.ToString();
                            list.Add(li);
                        }
                    }
                    if (k.Loc == "總院")
                    {
                        list.Remove(list.Single(x => x.Value == "1129"));
                    }
                    else
                    {
                        list.Remove(list.Single(x => x.Value == "12549"));
                    }
                    break;
                case "醫工主任":  //Not Used
                    s = roleManager.GetUsersInRole("MedDirector").ToList();
                    list = new List<SelectListItem>();
                    foreach (string l in s)
                    {
                        u = _context.AppUsers.Where(ur => ur.UserName == l).FirstOrDefault();
                        if (!string.IsNullOrEmpty(u.DptId))
                        {
                            li = new SelectListItem();
                            li.Text = u.FullName + "(" + u.UserName + ")";
                            li.Value = u.Id.ToString();
                            list.Add(li);
                        }
                    }
                    break;
                case "醫工經辦":  //Not Used
                    //list = new List<SelectListItem>();
                    //u = _context.AppUsers.Where(ur => ur.UserName == "1814").FirstOrDefault();
                    //if (!string.IsNullOrEmpty(u.DptId))
                    //{
                    //    li = new SelectListItem();
                    //    li.Text = u.FullName;
                    //    li.Value = u.Id.ToString();
                    //    list.Add(li);
                    //}
                    break;
                case "單位主管":
                    /* Get login user. */
                    u = _userRepo.Find(ur => ur.UserName == this.User.Identity.Name).FirstOrDefault();
                    /* Get login user's location. */
                    var urLocation = new DepartmentModel(_context).GetUserLocation(u);
                    if (urLocation != "總院")
                    {
                        s = roleManager.GetUsersInRole("Manager").OrderBy(x => x).ToList();
                        list = new List<SelectListItem>();
                        li = new SelectListItem();
                        li.Text = "請選擇";
                        li.Value = "請選擇";
                        list.Add(li);
                        //
                        locList = new[] { "K", "P", "C" };
                        if (k.Loc != "總院")
                        {
                            Array.Clear(locList, 0, locList.Length);
                            locList = new[] { k.Loc };
                        }
                        foreach (string l in s)
                        {
                            u = _context.AppUsers.Where(ur => !string.IsNullOrEmpty(ur.DptId))
                            .Join(_context.Departments, ur => ur.DptId, d => d.DptId, (ur, d) => new
                            {
                                appuser = ur,
                                dpt = d
                            })
                            .Where(d => locList.Contains(d.dpt.Loc))
                            .Where(ur => ur.appuser.UserName == l && ur.appuser.Status == "Y").Select(ur => ur.appuser).FirstOrDefault();
                            if (u != null)
                            {
                                li = new SelectListItem();
                                li.Text = u.FullName + "(" + u.UserName + ")";
                                li.Value = u.Id.ToString();
                                list.Add(li);
                            }
                        }
                    }
                    else
                    {
                        list = new List<SelectListItem>();
                        li = new SelectListItem();
                        li.Text = "請選擇";
                        li.Value = "請選擇";
                        list.Add(li);
                        //
                        _context.AppUsers.Where(ur => !string.IsNullOrEmpty(ur.DptId))
                        .Where(ur => ur.DptId == k.DptId)
                        .Where(ur => ur.Status == "Y")
                        .ToList()
                        .ForEach(ur => {
                            li = new SelectListItem();
                            li.Text = ur.FullName + "(" + ur.UserName + ")";
                            li.Value = ur.Id.ToString();
                            list.Add(li);
                        });
                    }
                    break;
                case "單位主任":  //Not Used
                    break;
                case "單位副院長":  //Not Used
                    s = roleManager.GetUsersInRole("ViceSI").ToList();
                    list = new List<SelectListItem>();
                    foreach (string l in s)
                    {
                        u = _context.AppUsers.Where(ur => ur.UserName == l).FirstOrDefault();
                        if (!string.IsNullOrEmpty(u.DptId))
                        {
                            li = new SelectListItem();
                            li.Text = u.FullName + "(" + u.UserName + ")";
                            li.Value = u.Id.ToString();
                            list.Add(li);
                        }
                    }
                    break;
                case "申請人":
                    if (k != null)
                    {
                        list = new List<SelectListItem>();
                        li = new SelectListItem();
                        li.Text = k.UserName;
                        li.Value = k.UserId.ToString();
                        list.Add(li);
                    }
                    else
                    {
                        list = new List<SelectListItem>();
                        li = new SelectListItem();
                        li.Text = "宋大衛";
                        li.Value = "000";
                        list.Add(li);
                    }
                    break;
                case "驗收人":
                    if (_context.BMEDKeepEmps.Where(emp => emp.DocId == docid).Count() <= 0)
                    {
                        throw new Exception("沒有維修工程師紀錄!!");
                    }
                    else if (_context.BMEDKeepDtls.Find(docid).EndDate == null)
                    {
                        throw new Exception("沒有完工日!!");

                    }
                    else if (_context.BMEDKeepDtls.Find(docid).Result == null ||
                        _context.BMEDKeepDtls.Find(docid).Result == null)
                    {
                        throw new Exception("沒有保養結果!!");
                    }
                    if (k != null)
                    {
                        if (k.Src != "M")// 非手動出單
                        {
                            /* 成本中心的成員 */
                            List<AppUserModel> ul = _context.AppUsers.Where(f => f.DptId == k.AccDpt)
                                                                     .Where(f => f.Status == "Y").ToList();
                            /* 驗收人列表 */
                            list = new List<SelectListItem>();
                            li = new SelectListItem();
                            li.Text = "請選擇";
                            li.Value = null;
                            list.Add(li);

                            foreach (AppUserModel l in ul)
                            {
                                li = new SelectListItem();
                                li.Text = l.FullName + "(" + l.UserName + ")";
                                li.Value = l.Id.ToString();
                                list.Add(li);
                            }
                        }
                        else
                        {
                            /* 與驗收人同單位的成員(包括驗收人) */
                            var checkerDptId = _context.AppUsers.Find(k.CheckerId).DptId;
                            List<AppUserModel> ul = _context.AppUsers.Where(f => f.DptId == checkerDptId)
                                                                     .Where(f => f.Status == "Y").ToList();
                            if (asset != null)
                            {
                                if (asset.DelivDpt != k.DptId)
                                {
                                    ul.AddRange(_context.AppUsers.Where(f => f.DptId == asset.DelivDpt)
                                                                 .Where(f => f.Status == "Y").ToList());
                                }
                            }
                            /* 驗收人 */
                            var checker = _context.AppUsers.Find(k.CheckerId);
                            list = new List<SelectListItem>();
                            li = new SelectListItem();
                            li.Text = checker.FullName + "(" + checker.UserName + ")";
                            li.Value = checker.Id.ToString();
                            list.Add(li);

                            foreach (AppUserModel l in ul)
                            {
                                /* 申請人以外的成員 */
                                if (l.Id != k.UserId)
                                {
                                    li = new SelectListItem();
                                    li.Text = l.FullName + "(" + l.UserName + ")";
                                    li.Value = l.Id.ToString();
                                    list.Add(li);
                                }
                            }
                        }
                    }
                    break;
                case "設備工程師":

                    /* Get all engineers. */
                    s = roleManager.GetUsersInRole("MedEngineer").OrderBy(x => x).ToList();
                    var keepEngId = _context.BMEDAssetKeeps.Find(k.AssetNo).KeepEngId;
                    var keepEng = _context.AppUsers.Find(keepEngId);

                    list = new List<SelectListItem>();
                    /* 負責工程師 */
                    li = new SelectListItem();
                    li.Text = keepEng.FullName + "(" + keepEng.UserName + ")";
                    li.Value = keepEng.Id.ToString();
                    list.Add(li);
                    /* 其他工程師 */
                    locList = new[] { "K", "P", "C" };
                    if (k.Loc != "總院")
                    {
                        Array.Clear(locList, 0, locList.Length);
                        locList = new[] { k.Loc };
                    }
                    foreach (string l in s)
                    {
                        u = _context.AppUsers.Where(ur => !string.IsNullOrEmpty(ur.DptId))
                            .Join(_context.Departments, ur => ur.DptId, d => d.DptId, (ur, d) => new
                            {
                                appuser = ur,
                                dpt = d
                            })
                            .Where(d => locList.Contains(d.dpt.Loc))
                            .Where(ur => ur.appuser.UserName == l && ur.appuser.Status == "Y").Select(ur => ur.appuser).FirstOrDefault();

                        if (u != null && l != keepEng.UserName)
                        {
                            li = new SelectListItem();
                            li.Text = u.FullName + "(" + u.UserName + ")";
                            li.Value = u.Id.ToString();
                            list.Add(li);
                        }
                    }
                    break;
                case "列管財產負責人":  //Not Used
                    //list = new List<SelectListItem>();
                    //u = _context.AppUsers.Where(ur => ur.UserName == "181151").FirstOrDefault();
                    //if (!string.IsNullOrEmpty(u.DptId))
                    //{
                    //    li = new SelectListItem();
                    //    li.Text = u.FullName;
                    //    li.Value = u.Id.ToString();
                    //    list.Add(li);
                    //}
                    break;
                case "固資財產負責人":  //Not Used
                    //list = new List<SelectListItem>();
                    //u = _context.AppUsers.Where(ur => ur.UserName == "1814").FirstOrDefault();
                    //if (!string.IsNullOrEmpty(u.DptId))
                    //{
                    //    li = new SelectListItem();
                    //    li.Text = u.FullName;
                    //    li.Value = u.Id.ToString();
                    //    list.Add(li);
                    //}
                    break;
                case "醫工分院主管":
                    s = roleManager.GetUsersInRole("MedBranchMgr").OrderBy(x => x).ToList();
                    list = new List<SelectListItem>();
                    locList = new[] { k.Loc };
                    foreach (string l in s)
                    {
                        u = _context.AppUsers.Where(ur => !string.IsNullOrEmpty(ur.DptId))
                            .Join(_context.Departments, ur => ur.DptId, d => d.DptId, (ur, d) => new
                            {
                                appuser = ur,
                                dpt = d
                            })
                            .Where(d => locList.Contains(d.dpt.Loc))
                            .Where(ur => ur.appuser.UserName == l && ur.appuser.Status == "Y").Select(ur => ur.appuser).FirstOrDefault();
                        if (u != null)
                        {
                            li = new SelectListItem();
                            li.Text = u.FullName + "(" + u.UserName + ")";
                            li.Value = u.Id.ToString();
                            list.Add(li);
                        }
                    }
                    break;
                case "設備主管":
                    s = roleManager.GetUsersInRole("DeviceMgr").OrderBy(x => x).ToList();
                    list = new List<SelectListItem>();
                    locList = new[] { "K", "P", "C" };
                    if (k.Loc != "總院")
                    {
                        Array.Clear(locList, 0, locList.Length);
                        locList = new[] { k.Loc };
                    }
                    foreach (string l in s)
                    {
                        u = _context.AppUsers.Where(ur => !string.IsNullOrEmpty(ur.DptId))
                            .Join(_context.Departments, ur => ur.DptId, d => d.DptId, (ur, d) => new
                            {
                                appuser = ur,
                                dpt = d
                            })
                            .Where(d => locList.Contains(d.dpt.Loc))
                            .Where(ur => ur.appuser.UserName == l && ur.appuser.Status == "Y").Select(ur => ur.appuser).FirstOrDefault();
                        if (u != null)
                        {
                            li = new SelectListItem();
                            li.Text = u.FullName + "(" + u.UserName + ")";
                            li.Value = u.Id.ToString();
                            list.Add(li);
                        }
                    }
                    break;
                default:
                    list = new List<SelectListItem>();
                    break;
            }
            return Json(list);
        }
예제 #18
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));
        }
        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));
        }
예제 #20
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));
        }