Ejemplo n.º 1
0
        public ActionResult InEvaluate(string docid = null)
        {
            BuyFlowModel buyflow = _context.BuyFlows.Where(b => b.DocId == docid)
                                   .Where(b => b.Status == "?").FirstOrDefault();

            if (buyflow == null)
            {
                return(NotFound());
            }
            else
            {
                buyflow.Status = "E";
                buyflow.Rtt    = DateTime.Now;
                _context.Entry(buyflow).State = EntityState.Modified;
                //
                BuyEvaluateModel e = _context.BuyEvaluates.Find(docid);
                BuySFlowModel    s = new BuySFlowModel();
                s.DocId  = docid;
                s.DocSid = buyflow.DocId + "_1";
                s.StepId = 2;
                s.Status = "?";
                s.Rtp    = buyflow.UserId;
                s.Rtt    = DateTime.Now;
                _context.BuySFlows.Add(s);
                BuySFlowModel s2 = new BuySFlowModel();
                s2.DocId  = docid;
                s2.DocSid = buyflow.DocId + "_2";
                s2.StepId = 2;
                s2.Status = "?";
                s2.Rtp    = buyflow.UserId;
                s2.Rtt    = DateTime.Now;
                _context.BuySFlows.Add(s2);
                //
                BuyFlowModel bf  = new BuyFlowModel();
                BuyFlowModel bf2 = new BuyFlowModel();
                bf.DocId   = buyflow.DocId + "_1";
                bf2.DocId  = buyflow.DocId + "_2";
                bf.StepId  = 1;
                bf2.StepId = 1;
                bf.UserId  = buyflow.UserId;
                bf2.UserId = buyflow.UserId;
                bf.Status  = "1";
                bf2.Status = "1";
                bf.Cls     = "採購人員";
                bf2.Cls    = "採購人員";
                bf.Rtp     = buyflow.UserId;
                bf2.Rtp    = buyflow.UserId;
                bf.Rtt     = DateTime.Now;
                bf2.Rtt    = DateTime.Now;
                _context.Entry(buyflow).State = EntityState.Modified;
                _context.BuyFlows.Add(bf);
                _context.BuyFlows.Add(bf2);
                //
                bf.StepId  = 2;
                bf2.StepId = 2;
                bf.UserId  = e.UserId;
                bf2.UserId = e.EngId;
                bf.Status  = "?";
                bf2.Status = "?";
                bf.Cls     = "申請者";
                bf2.Cls    = "維修工程師";
                bf.Rtp     = buyflow.UserId;
                bf2.Rtp    = buyflow.UserId;
                bf.Rtt     = DateTime.Now;
                bf2.Rtt    = DateTime.Now;
                _context.BuyFlows.Add(bf);
                _context.BuyFlows.Add(bf2);
                _context.SaveChanges();
            }
            return(RedirectToAction("Index", "Home", new { Area = "" }));
        }
Ejemplo n.º 2
0
        public ActionResult NextFlow(BuyFlowModel BuyFlow)
        {
            // Get Login User's details.
            var loginUser = _userRepo.Find(ur => ur.UserName == User.Identity.Name).FirstOrDefault();

            if (ModelState.IsValid)
            {
                if (BuyFlow.SelOpin == "其他" && string.IsNullOrEmpty(BuyFlow.Opinions))
                {
                    throw new Exception("請填寫意見欄!!");
                }
                BuyFlowModel        rf     = _context.BuyFlows.Where(f => f.DocId == BuyFlow.DocId && f.Status == "?").FirstOrDefault();
                List <BuyFlowModel> rflist = _context.BuyFlows.Where(f => f.DocId == BuyFlow.DocId).ToList();
                BuyEvaluateModel    r;
                BuySFlowModel       s = _context.BuySFlows.Where(b => b.DocSid == BuyFlow.DocId).FirstOrDefault();
                if (s != null)
                {
                    r = _context.BuyEvaluates.Find(s.DocId);
                }
                else
                {
                    r = _context.BuyEvaluates.Find(BuyFlow.DocId);
                }
                AppUserModel u;
                Tmail        mail;
                string       body = "";
                string       sto  = "";
                if (BuyFlow.Cls == "結案")
                {
                    rf.Opinions = BuyFlow.SelOpin + Environment.NewLine + BuyFlow.Opinions;
                    rf.Status   = "2";
                    rf.Rtt      = DateTime.Now;
                    rf.Rtp      = loginUser.Id;
                    if (s != null)
                    {
                        s.Status = "2";
                        s.Rtt    = DateTime.Now;
                        s.Rtp    = loginUser.Id;
                        _context.Entry(s).State = EntityState.Modified;
                    }
                    _context.Entry(rf).State = EntityState.Modified;
                    _context.SaveChanges();
                    //
                    if (s != null) //會簽
                    {
                        List <BuySFlowModel> sf = _context.BuySFlows.Where(bs => bs.DocId == s.DocId)
                                                  .Where(bs => bs.Status == "?").ToList();
                        if (sf.Count() == 0)
                        {
                            BuyFlowModel f = _context.BuyFlows.Where(bf => bf.DocId == s.DocId)
                                             .Where(bf => bf.Status == "E").FirstOrDefault();
                            if (f != null)
                            {
                                f.Status = "?";
                                _context.Entry(f).State = EntityState.Modified;
                                _context.SaveChanges();
                                //
                                mail      = new Tmail();
                                u         = _context.AppUsers.Find(loginUser.Id);
                                mail.from = new System.Net.Mail.MailAddress(u.Email); //u.Email
                                mail.to   = new System.Net.Mail.MailAddress(_context.AppUsers.Find(f.UserId).Email);
                                //mail.cc = new System.Net.Mail.MailAddress("*****@*****.**");
                                mail.message.Subject = "醫工智能保修系統[採購評估案-會簽完成通知]:儀器名稱: " + r.PlantCnam;
                                body += "<p>申請人:" + r.UserName + "</p>";
                                body += "<p>儀器名稱:" + r.PlantCnam + "</p>";
                                body += "<br/>";
                                body += "<h3>此封信件為系統通知郵件,請勿回覆。</h3>";
                                mail.message.Body       = body;
                                mail.message.IsBodyHtml = true;
                                mail.SendMail();
                            }
                        }
                    }
                    else
                    {
                        mail      = new Tmail();
                        u         = _context.AppUsers.Find(loginUser.Id);
                        mail.from = new System.Net.Mail.MailAddress(u.Email); //u.Email
                        foreach (BuyFlowModel rr in rflist)
                        {
                            u    = _context.AppUsers.Find(rr.UserId);
                            sto += u.Email + ",";
                        }
                        mail.sto = sto.TrimEnd(new char[] { ',' });
                        //mail.cc = new System.Net.Mail.MailAddress("*****@*****.**");
                        mail.message.Subject = "醫工智能保修系統[採購評估案-結案通知]:儀器名稱: " + r.PlantCnam;
                        body += "<p>申請人:" + r.UserName + "</p>";
                        body += "<p>儀器名稱:" + r.PlantCnam + "</p>";
                        body += "<p><a href='http://dms.cch.org.tw/BMED/Account/Login'>前往網站檢視</a></p>";
                        body += "<br/>";
                        body += "<h3>此封信件為系統通知郵件,請勿回覆。</h3>";
                        mail.message.Body       = body;
                        mail.message.IsBodyHtml = true;
                        mail.SendMail();
                    }
                    return(new JsonResult(BuyFlow)
                    {
                        Value = new { success = true, error = "" },
                    });
                }
                else if (BuyFlow.Cls == "廢除")
                {
                    rf.Opinions = BuyFlow.SelOpin + Environment.NewLine + BuyFlow.Opinions;
                    rf.Status   = "3";
                    rf.Rtt      = DateTime.Now;
                    rf.Rtp      = loginUser.Id;
                    _context.Entry(rf).State = EntityState.Modified;
                    _context.SaveChanges();
                    //
                    mail      = new Tmail();
                    u         = _context.AppUsers.Find(loginUser.Id);
                    mail.from = new System.Net.Mail.MailAddress(u.Email); //u.Email
                    foreach (BuyFlowModel rr in rflist)
                    {
                        u    = _context.AppUsers.Find(rr.UserId);
                        sto += u.Email + ",";
                    }
                    mail.sto = sto.TrimEnd(new char[] { ',' });
                    //mail.cc = new System.Net.Mail.MailAddress("*****@*****.**");
                    mail.message.Subject = "醫工智能保修系統[採購評估案-廢除通知]:儀器名稱: " + r.PlantCnam;
                    body += "<p>申請人:" + r.UserName + "</p>";
                    body += "<p>儀器名稱:" + r.PlantCnam + "</p>";
                    body += "<br/>";
                    body += "<h3>此封信件為系統通知郵件,請勿回覆。</h3>";
                    mail.message.Body       = body;
                    mail.message.IsBodyHtml = true;
                    mail.SendMail();
                    return(new JsonResult(BuyFlow)
                    {
                        Value = new { success = true, error = "" },
                    });
                }
                BuyFlow.StepId = rf.StepId + 1;
                BuyFlow.Rtt    = DateTime.Now;
                switch (BuyFlow.Cls)
                {
                case "申請者":
                    BuyFlow.UserId = r.UserId;
                    break;

                case "設備經辦":

                    break;
                }
                BuyFlow.Status = "?";
                u                        = _context.AppUsers.Find(BuyFlow.UserId);
                BuyFlow.Role             = roleManager.GetRolesForUser(u.Id).FirstOrDefault();
                rf.Opinions              = BuyFlow.SelOpin + Environment.NewLine + BuyFlow.Opinions;
                rf.Status                = "1";
                rf.Rtp                   = loginUser.Id;
                BuyFlow.Opinions         = null;
                _context.Entry(rf).State = EntityState.Modified;
                _context.BuyFlows.Add(BuyFlow);
                _context.SaveChanges();
                //
                mail      = new Tmail();
                body      = "";
                u         = _context.AppUsers.Find(loginUser.Id);
                mail.from = new System.Net.Mail.MailAddress(u.Email); //u.Email
                u         = _context.AppUsers.Find(BuyFlow.UserId);
                mail.to   = new System.Net.Mail.MailAddress(u.Email); //u.Email
                //mail.cc = new System.Net.Mail.MailAddress("*****@*****.**");
                mail.message.Subject = "醫工智能保修系統[採購評估案]:儀器名稱: " + r.PlantCnam;
                body += "<p>申請人:" + r.UserName + "</p>";
                body += "<p>儀器名稱:" + r.PlantCnam + "</p>";
                body += "<p><a href='http://dms.cch.org.tw/BMED/Account/Login'>處理案件</a></p>";
                body += "<br/>";
                body += "<h3>此封信件為系統通知郵件,請勿回覆。</h3>";
                mail.message.Body       = body;
                mail.message.IsBodyHtml = true;
                mail.SendMail();

                return(new JsonResult(BuyFlow)
                {
                    Value = new { success = true, error = "" },
                });
            }

            return(View(BuyFlow));
        }
Ejemplo n.º 3
0
        public List <BuyEvaluateListVModel> GetList(string cls = null)
        {
            // Get Login User's details.
            var user = _userRepo.Find(ur => ur.UserName == User.Identity.Name).FirstOrDefault();
            List <BuyEvaluateListVModel> rv = new List <BuyEvaluateListVModel>();
            List <BuyFlowModel>          rf = new List <BuyFlowModel>();
            List <BuyFlowModel>          rf2;

            switch (cls)
            {
            case "已處理":
                rf2 = _context.BuyFlows.Where(bf => bf.Status == "?")
                      .Where(m => m.UserId != user.Id).ToList();
                foreach (BuyFlowModel f in rf2)
                {
                    if (_context.BuyFlows.Where(m => m.DocId == f.DocId).Where(m => m.UserId == user.Id).Count() > 0)
                    {
                        rf.Add(f);
                    }
                }
                break;

            case "已結案":
                rf2 = _context.BuyFlows.Where(bf => bf.Status == "2").ToList();
                foreach (BuyFlowModel f in rf2)
                {
                    if (_context.BuyFlows.Where(m => m.DocId == f.DocId).Where(m => m.UserId == user.Id).Count() > 0)
                    {
                        rf.Add(f);
                    }
                }
                break;

            case "查詢":
                rf2 = _context.BuyFlows.Where(bf => bf.Status == "?").ToList();
                AppUserModel     p = user;
                DepartmentModel  c = _context.Departments.Find(p.DptId);
                BuyEvaluateModel r;
                foreach (BuyFlowModel f in rf2)
                {
                    r = _context.BuyEvaluates.Find(f.DocId);
                    rf.Add(f);
                }
                break;

            default:
                rf = _context.BuyFlows.Where(bf => bf.Status == "?")
                     .Where(m => m.UserId == user.Id).ToList();
                break;
            }
            rf.OrderByDescending(m => m.Rtt);
            BuyEvaluateListVModel i;
            BuyEvaluateModel      r2;

            foreach (BuyFlowModel f in rf)
            {
                i = new BuyEvaluateListVModel();
                BuySFlowModel s = _context.BuySFlows.Where(bs => bs.DocSid == f.DocId).FirstOrDefault();
                if (s != null)
                {
                    r2       = _context.BuyEvaluates.Find(s.DocId);
                    i.DocSid = f.DocId;
                }
                else
                {
                    r2 = _context.BuyEvaluates.Find(f.DocId);
                }
                AppUserModel    p = _context.AppUsers.Find(r2.UserId);
                DepartmentModel c = _context.Departments.Find(p.DptId);
                i.DocType  = "評估";
                i.DocId    = r2.DocId;
                i.UserId   = r2.UserId;
                i.UserName = r2.UserName;
                if (p != null && p.DptId != null)
                {
                    i.CustId  = p.DptId;
                    i.CustNam = c.Name_C;
                }
                i.PlantCnam = r2.PlantCnam;
                i.PlantEnam = r2.PlantEnam;
                i.PlantType = r2.PlantType;
                i.Days      = DateTime.Now.Subtract(r2.Rtt.GetValueOrDefault()).Days;
                if (f.Status == "2")
                {
                    i.Flg = "2";
                    List <DeliveryModel>  dv = _context.Deliveries.Where(v => v.PurchaseNo == f.DocId).ToList();
                    List <DelivFlowModel> df;
                    DelivFlowModel        w;
                    foreach (DeliveryModel d in dv)
                    {
                        df = _context.DelivFlows.Where(g => g.DocId == d.DocId).ToList();
                        w  = df.Where(g => g.Status == "?").FirstOrDefault();
                        if (w != null)
                        {
                            i.Flg = "E";
                        }
                        w = df.Where(g => g.Status == "2").FirstOrDefault();
                        if (w != null)
                        {
                            i.Flg = "E";
                        }
                    }
                }
                else
                {
                    i.Flg = f.Status;
                }
                i.FlowUid   = f.UserId;
                i.FlowUname = _context.AppUsers.Find(f.UserId).FullName;
                rv.Add(i);
            }
            return(rv);
        }