public async Task <IViewComponentResult> InvokeAsync(string id) { RepairModel repair = _context.BMEDRepairs.Find(id); RepairDtlModel repdtl = _context.BMEDRepairDtls.Find(id); /* Get and set value for NotMapped fields. */ repair.DptName = _context.Departments.Find(repair.DptId).Name_C; repair.AccDptName = _context.Departments.Find(repair.AccDpt).Name_C; repair.CheckerName = _context.AppUsers.Find(repair.CheckerId).FullName; if (repair.AssetNo != null) { var asset = _context.BMEDAssets.Find(repair.AssetNo); if (asset != null) { if (asset.AccDate.HasValue) { repair.AssetAccDate = asset.AccDate.Value.ToString("yyyy/MM/dd"); } } } if (repdtl != null) { if (repdtl.NotInExceptDevice == "N") { repair.NotInExceptDevice = "否"; repair.Cost = repdtl.Cost; } else if (repdtl.NotInExceptDevice == "Y") { repair.NotInExceptDevice = "是"; } } return(View(repair)); }
public ActionResult Delete(string docid, string seqno) { try { RepairCostModel repairCost = _context.BMEDRepairCosts.Find(docid, Convert.ToInt32(seqno)); _context.BMEDRepairCosts.Remove(repairCost); _context.SaveChanges(); // RepairDtlModel dtl = _context.BMEDRepairDtls.Where(d => d.DocId == repairCost.DocId) .FirstOrDefault(); if (dtl != null) { dtl.Cost = _context.BMEDRepairCosts.Where(k => k.DocId == repairCost.DocId) .Select(k => k.TotalCost) .DefaultIfEmpty(0).Sum(); _context.Entry(dtl).State = EntityState.Modified; _context.SaveChanges(); } return(new JsonResult(repairCost) { Value = new { success = true, error = "" } }); } catch (Exception e) { throw new Exception(e.Message); } }
public async Task <IActionResult> Edit(RepairDtlModel repairDtl) { if (ModelState.IsValid) { try { _context.Entry(repairDtl).State = EntityState.Modified; _context.SaveChanges(); return(new JsonResult(repairDtl) { Value = new { success = true, error = "" } }); } catch (Exception e) { throw new Exception(e.Message); } } else { string msg = ""; foreach (var error in ViewData.ModelState.Values.SelectMany(modelState => modelState.Errors)) { msg += error.ErrorMessage + Environment.NewLine; } throw new Exception(msg); } }
public ActionResult Delete(string id, string uName) { var uid = _context.AppUsers.Where(u => u.UserName == uName).FirstOrDefault().Id; try { RepairEmpModel repairEmp = _context.BMEDRepairEmps.Find(id, uid); _context.BMEDRepairEmps.Remove(repairEmp); _context.SaveChanges(); // Recount the all repair time, and set value to RepairDtl. RepairDtlModel dtl = _context.BMEDRepairDtls.Where(d => d.DocId == repairEmp.DocId) .FirstOrDefault(); if (dtl != null) { int hr = _context.BMEDRepairEmps.Where(p => p.DocId == repairEmp.DocId) .Select(p => p.Hour) .DefaultIfEmpty(0).Sum(); decimal min = _context.BMEDRepairEmps.Where(p => p.DocId == repairEmp.DocId) .Select(p => p.Minute) .DefaultIfEmpty(0).Sum(); dtl.Hour = hr + Decimal.Round(min / 60m, 2); _context.Entry(dtl).State = EntityState.Modified; _context.SaveChanges(); } return(new JsonResult(repairEmp) { Value = new { success = true, error = "" } }); } catch (Exception e) { throw new Exception(e.Message); } }
public IActionResult Create(RepairEmpModel repairEmp) { if (ModelState.IsValid) { _context.BMEDRepairEmps.Add(repairEmp); _context.SaveChanges(); // Recount the all repair time, and set value to RepairDtl. RepairDtlModel dtl = _context.BMEDRepairDtls.Where(d => d.DocId == repairEmp.DocId) .FirstOrDefault(); if (dtl != null) { int hr = _context.BMEDRepairEmps.Where(p => p.DocId == repairEmp.DocId) .Select(p => p.Hour) .DefaultIfEmpty(0).Sum(); decimal min = _context.BMEDRepairEmps.Where(p => p.DocId == repairEmp.DocId) .Select(p => p.Minute) .DefaultIfEmpty(0).Sum(); dtl.Hour = hr + Decimal.Round(min / 60m, 2); _context.BMEDRepairDtls.Update(dtl); } return(RedirectToAction("Index")); } return(View(repairEmp)); }
public async Task <IActionResult> Create([Bind("DocId,DealState,DealDes,DealState2,FailFactor,FailFactor2,InOut,Hour,IsCharged,Cost,EndDate,CloseDate,ShutDate")] RepairDtlModel repairDtlModel) { if (ModelState.IsValid) { _context.Add(repairDtlModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(repairDtlModel)); }
public ActionResult Edit(RepairEmpModel repairEmp) { if (ModelState.IsValid) { //_context.RepairEmps.Add(repairEmp); //_context.SaveChanges(); var ExistRepairEmp = _context.RepairEmps.Find(repairEmp.DocId, repairEmp.UserId); if (ExistRepairEmp != null) { return(new JsonResult(repairEmp) { Value = new { isExist = true, error = "資料已存在!" } }); } else { _repempRepo.Create(repairEmp); } // Recount the all repair time, and set value to RepairDtl. RepairDtlModel dtl = _context.RepairDtls.Where(d => d.DocId == repairEmp.DocId) .FirstOrDefault(); if (dtl != null) { int hr = _context.RepairEmps.Where(p => p.DocId == repairEmp.DocId) .Select(p => p.Hour) .DefaultIfEmpty(0).Sum(); decimal min = _context.RepairEmps.Where(p => p.DocId == repairEmp.DocId) .Select(p => p.Minute) .DefaultIfEmpty(0).Sum(); dtl.Hour = hr + Decimal.Round(min / 60m, 2); _context.Entry(dtl).State = EntityState.Modified; _context.SaveChanges(); } // Return ViewComponent for ajax request. return(ViewComponent("RepEmpList", new { id = repairEmp.DocId })); } else { string msg = ""; foreach (var error in ViewData.ModelState.Values.SelectMany(modelState => modelState.Errors)) { msg += error.ErrorMessage + Environment.NewLine; } throw new Exception(msg); } }
public async Task <IViewComponentResult> InvokeAsync(string id) { RepairDtlModel repairDtl = _context.RepairDtls.Find(id); var ur = _userRepo.Find(us => us.UserName == this.User.Identity.Name).FirstOrDefault(); repairDtl.DealStateTitle = _context.DealStatuses.Find(repairDtl.DealState).Title; if (repairDtl.FailFactor == 0) { repairDtl.FailFactorTitle = "尚未處理"; } else { repairDtl.FailFactorTitle = _context.FailFactors.Find(repairDtl.FailFactor).Title; } return(View(repairDtl)); }
public IActionResult RepCostEdit(RepairCostModel repairCost) { var ur = _userRepo.Find(u => u.UserName == this.User.Identity.Name).FirstOrDefault(); if (repairCost.SignNo != null) { repairCost.SignNo = repairCost.SignNo.ToUpper(); } if (repairCost.StockType == "3") { ModelState.Remove("TicketDtl.SeqNo"); } if (ModelState.IsValid) { repairCost.Rtp = ur.Id; repairCost.Rtt = DateTime.Now; _context.Entry(repairCost).State = EntityState.Modified; _context.SaveChanges(); RepairDtlModel dtl = _context.RepairDtls.Where(d => d.DocId == repairCost.DocId) .FirstOrDefault(); if (dtl != null) { dtl.Cost = _context.RepairCosts.Where(k => k.DocId == repairCost.DocId) .Select(k => k.TotalCost) .DefaultIfEmpty(0).Sum(); _context.Entry(dtl).State = EntityState.Modified; _context.SaveChanges(); } return(new JsonResult(repairCost) { 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); } }
public async Task <IViewComponentResult> InvokeAsync(string id) { RepairDtlModel repairDtl = _context.BMEDRepairDtls.Find(id); var ur = _userRepo.Find(us => us.UserName == this.User.Identity.Name).FirstOrDefault(); /* Get CheckerName from Repair table. */ var checkerId = _context.BMEDRepairs.Find(id).CheckerId; repairDtl.CheckerName = checkerId == 0 ? "" : _context.AppUsers.Find(checkerId).FullName; repairDtl.DealStateTitle = _context.BMEDDealStatuses.Find(repairDtl.DealState).Title; if (repairDtl.FailFactor == 0) { repairDtl.FailFactorTitle = "尚未處理"; } else { repairDtl.FailFactorTitle = _context.BMEDFailFactors.Find(repairDtl.FailFactor).Title; } return(View(repairDtl)); }
public async Task <IActionResult> Edit(RepairDtlModel repairDtl) { if (ModelState.IsValid) { //if (string.IsNullOrEmpty(repairDtl.DealDes)) //{ // throw new Exception("請輸入[處理描述]!!"); //} try { if (repairDtl.IsCharged == "N") { //_context.BMEDRepairCosts.RemoveRange(_context.BMEDRepairCosts.Where(c => c.DocId == repairDtl.DocId)); repairDtl.Cost = 0; } else { repairDtl.Cost = _context.BMEDRepairCosts.Where(k => k.DocId == repairDtl.DocId) .Select(k => k.TotalCost) .DefaultIfEmpty(0).Sum(); int hr = _context.BMEDRepairEmps.Where(p => p.DocId == repairDtl.DocId) .Select(p => p.Hour) .DefaultIfEmpty(0).Sum(); decimal min = _context.BMEDRepairEmps.Where(p => p.DocId == repairDtl.DocId) .Select(p => p.Minute) .DefaultIfEmpty(0).Sum(); repairDtl.Hour = hr + Decimal.Round(min / 60m, 2); } _context.Entry(repairDtl).State = EntityState.Modified; /* Edit AssetNo if No exist. */ var repairModel = _context.BMEDRepairs.Find(repairDtl.DocId); repairModel.AssetNo = repairDtl.AssetNo; var tempAsset = _context.BMEDAssets.Where(a => a.AssetNo == repairDtl.AssetNo).FirstOrDefault(); if (tempAsset != null) { repairModel.AssetName = tempAsset.Cname; } _context.Entry(repairModel).State = EntityState.Modified; _context.SaveChanges(); return(new JsonResult(repairDtl) { Value = new { success = true, error = "" } }); } catch (Exception e) { throw new Exception(e.Message); } } else { string msg = ""; foreach (var error in ViewData.ModelState.Values.SelectMany(modelState => modelState.Errors)) { msg += error.ErrorMessage + Environment.NewLine; } throw new Exception(msg); } }
public IActionResult Edit2(RepairCostModel repairCost) { var ur = _userRepo.Find(u => u.UserName == this.User.Identity.Name).FirstOrDefault(); if (repairCost.TicketDtl.TicketDtlNo != null) { repairCost.TicketDtl.TicketDtlNo = repairCost.TicketDtl.TicketDtlNo.ToUpper(); } if (repairCost.SignNo != null) { repairCost.SignNo = repairCost.SignNo.ToUpper(); } if (repairCost.StockType == "3") { ModelState.Remove("TicketDtl.SeqNo"); } if (ModelState.IsValid) { if (repairCost.StockType != "3") { TicketModel t = _context.Tickets.Find(repairCost.TicketDtl.TicketDtlNo); if (t == null) { t = new TicketModel(); t.TicketNo = repairCost.TicketDtl.TicketDtlNo; t.TicDate = repairCost.AccountDate; t.ApplyDate = null; t.CancelDate = null; t.VendorId = repairCost.VendorId; t.VendorName = repairCost.VendorName; repairCost.TicketDtl.Ticket = t; _context.Tickets.Add(t); } TicketDtlModel ticketDtl = _context.TicketDtls.Find(repairCost.TicketDtl.TicketDtlNo, repairCost.TicketDtl.SeqNo); if (ticketDtl == null) { int i = _context.TicketDtls.Where(d => d.TicketDtlNo == repairCost.TicketDtl.TicketDtlNo) .Select(d => d.SeqNo).DefaultIfEmpty().Max(); repairCost.TicketDtl.SeqNo = i + 1; repairCost.TicketDtl.ObjName = repairCost.PartName; repairCost.TicketDtl.Qty = repairCost.Qty; repairCost.TicketDtl.Unite = repairCost.Unite; repairCost.TicketDtl.Price = repairCost.Price; repairCost.TicketDtl.Cost = repairCost.TotalCost; _context.TicketDtls.Add(repairCost.TicketDtl); } else { ticketDtl.ObjName = repairCost.PartName; ticketDtl.Qty = repairCost.Qty; ticketDtl.Unite = repairCost.Unite; ticketDtl.Price = repairCost.Price; ticketDtl.Cost = repairCost.TotalCost; _context.Entry(ticketDtl).State = EntityState.Modified; } } repairCost.Rtp = ur.Id; repairCost.Rtt = DateTime.Now; _context.Entry(repairCost).State = EntityState.Modified; _context.SaveChanges(); RepairDtlModel dtl = _context.RepairDtls.Where(d => d.DocId == repairCost.DocId) .FirstOrDefault(); if (dtl != null) { dtl.Cost = _context.RepairCosts.Where(k => k.DocId == repairCost.DocId) .Select(k => k.TotalCost) .DefaultIfEmpty(0).Sum(); _context.Entry(dtl).State = EntityState.Modified; _context.SaveChanges(); } return(RedirectToAction("Edit", "Repair", new { Area = "", id = repairCost.DocId, page = 4 })); } if (repairCost.StockType == "0") { ViewData["StockType"] = "庫存"; } else if (repairCost.StockType == "2") { ViewData["StockType"] = "發票(含收據)"; } else if (repairCost.StockType == "4") { ViewData["StockType"] = "零用金"; } else { ViewData["StockType"] = "簽單"; } return(View(repairCost)); }
public async Task <IActionResult> NextFlow(AssignModel assign) { var ur = _userRepo.Find(u => u.UserName == this.User.Identity.Name).FirstOrDefault(); var repairDtl = _context.BMEDRepairDtls.Find(assign.DocId); /* 工程師的流程控管 */ if (assign.Cls == "設備工程師") { /* 如點選有費用、卻無輸入費用明細 */ var isCharged = _context.BMEDRepairDtls.Where(d => d.DocId == assign.DocId).FirstOrDefault().IsCharged; if (isCharged == "Y") { var CheckRepairCost = _context.BMEDRepairCosts.Where(c => c.DocId == assign.DocId).FirstOrDefault(); if (CheckRepairCost == null) { throw new Exception("尚未輸入費用明細!!"); } } } // var repairDtl = _context.BMEDRepairDtls.Where(d => d.DocId == assign.DocId).FirstOrDefault(); // /* 3 = 已完成,4 = 報廢 */ // if (repairDtl.DealState == 3 || repairDtl.DealState == 4) // { // if(repairDtl.EndDate == null) // { // throw new Exception("報廢及已完成,需輸入完工日!!"); // } // } if (assign.FlowCls == "結案" || assign.FlowCls == "廢除") { assign.FlowUid = ur.Id; } if (ModelState.IsValid) { RepairFlowModel rf = _context.BMEDRepairFlows.Where(f => f.DocId == assign.DocId && f.Status == "?").FirstOrDefault(); if (assign.FlowCls == "驗收人") { if (_context.BMEDRepairEmps.Where(emp => emp.DocId == assign.DocId).Count() <= 0) { throw new Exception("沒有維修工程師紀錄!!"); } else if (_context.BMEDRepairDtls.Find(assign.DocId).EndDate == null) { throw new Exception("沒有完工日!!"); } else if (_context.BMEDRepairDtls.Find(assign.DocId).DealState == 0) { throw new Exception("處理狀態不可空值!!"); } if (_context.BMEDRepairDtls.Find(assign.DocId).FailFactor == 0) { throw new Exception("故障原因不可空白!!"); } if (string.IsNullOrEmpty(_context.BMEDRepairDtls.Find(assign.DocId).InOut)) { throw new Exception("維修方式不可空白!!"); } if (_context.BMEDRepairDtls.Find(assign.DocId).DealState == 3 || _context.BMEDRepairDtls.Find(assign.DocId).DealState == 4 || _context.BMEDRepairDtls.Find(assign.DocId).DealState == 8) { //Do nothing. //狀態為【已完成】、【報廢】、【退件】才可送至驗收人 } else { throw new Exception("送至驗收人處理狀態只可為【已完成】、【報廢】、【退件】!!"); } } if (assign.FlowCls == "結案") { if (assign.Cls == "驗收人" && repairDtl != null) { if (repairDtl.IsCharged == "Y") { throw new Exception("有費用之案件不可由驗收人直接結案!"); } } RepairDtlModel rd = _context.BMEDRepairDtls.Find(assign.DocId); rd.CloseDate = DateTime.Now; rf.Opinions = "[" + assign.AssignCls + "]" + Environment.NewLine + assign.AssignOpn; rf.Status = "2"; rf.UserId = ur.Id; rf.UserName = _context.AppUsers.Find(ur.Id).FullName; rf.Rtt = DateTime.Now; rf.Rtp = ur.Id; _context.Entry(rf).State = EntityState.Modified; _context.Entry(rd).State = EntityState.Modified; _context.SaveChanges(); // Save stock to ERP system. var ERPreponse = await SaveToERPAsync(assign.DocId); //Send Mail //To all users in this repair's flow. Tmail mail = new Tmail(); string body = ""; string sto = ""; AppUserModel u; RepairModel repair = _context.BMEDRepairs.Find(assign.DocId); mail.from = new System.Net.Mail.MailAddress(ur.Email); //u.Email _context.BMEDRepairFlows.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 = "醫工工務智能保修系統[醫工請修案-結案通知]:設備名稱: " + repair.AssetName; body += "<p>表單編號:" + repair.DocId + "</p>"; body += "<p>申請日期:" + repair.ApplyDate.ToString("yyyy/MM/dd") + "</p>"; body += "<p>申請人:" + repair.UserName + "</p>"; body += "<p>財產編號:" + repair.AssetNo + "</p>"; body += "<p>設備名稱:" + repair.AssetName + "</p>"; //body += "<p>請修地點:" + repair.PlaceLoc + " " + repair.BuildingName + " " + repair.FloorName + " " + repair.AreaName + "</p>"; body += "<p>放置地點:" + repair.PlaceLoc + "</p>"; body += "<p>故障描述:" + repair.TroubleDes + "</p>"; body += "<p>處理描述:" + rd.DealDes + "</p>"; body += "<p><a href='http://dms.cch.org.tw/EDIS/Account/Login'" + "?DocId=" + repair.DocId + "&dealType=BMEDRepViews" + ">檢視案件</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 == "廢除") { rf.Opinions = "[廢除]" + Environment.NewLine + assign.AssignOpn; rf.Status = "3"; rf.Rtt = DateTime.Now; rf.Rtp = ur.Id; _context.Entry(rf).State = EntityState.Modified; _context.SaveChanges(); } else { //轉送下一關卡 rf.Opinions = "[" + assign.AssignCls + "]" + Environment.NewLine + assign.AssignOpn; rf.Status = "1"; rf.Rtt = DateTime.Now; rf.Rtp = ur.Id; _context.Entry(rf).State = EntityState.Modified; _context.SaveChanges(); // RepairFlowModel flow = new RepairFlowModel(); flow.DocId = assign.DocId; flow.StepId = rf.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.BMEDRepairFlows.Add(flow); _context.SaveChanges(); //Send Mail //To user and the next flow user. Tmail mail = new Tmail(); string body = ""; AppUserModel u; RepairModel repair = _context.BMEDRepairs.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 = "醫工工務智能保修系統[醫工請修案]:設備名稱: " + repair.AssetName; body += "<p>表單編號:" + repair.DocId + "</p>"; body += "<p>申請日期:" + repair.ApplyDate.ToString("yyyy/MM/dd") + "</p>"; body += "<p>申請人:" + repair.UserName + "</p>"; body += "<p>財產編號:" + repair.AssetNo + "</p>"; body += "<p>設備名稱:" + repair.AssetName + "</p>"; body += "<p>故障描述:" + repair.TroubleDes + "</p>"; //body += "<p>請修地點:" + repair.PlaceLoc + " " + repair.BuildingName + " " + repair.FloorName + " " + repair.AreaName + "</p>"; body += "<p>放置地點:" + repair.PlaceLoc + "</p>"; body += "<p><a href='http://dms.cch.org.tw/EDIS/Account/Login'" + "?docId=" + repair.DocId + "&dealType=BMEDRepEdit" + ">處理案件</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); } }
public ActionResult NextFlow(AssignModel assign) { var ur = _userRepo.Find(u => u.UserName == this.User.Identity.Name).FirstOrDefault(); /* 工程師的流程控管 */ if (assign.Cls == "工務/營建工程師") { /* 如點選有費用、卻無輸入費用明細 */ var isCharged = _context.RepairDtls.Where(d => d.DocId == assign.DocId).FirstOrDefault().IsCharged; if (isCharged == "Y") { var CheckRepairCost = _context.RepairCosts.Where(c => c.DocId == assign.DocId).FirstOrDefault(); if (CheckRepairCost == null) { string msg = "尚未輸入費用明細!!"; return(BadRequest(msg)); } } var repairDtl = _context.RepairDtls.Where(d => d.DocId == assign.DocId).FirstOrDefault(); /* 3 = 已完成,4 = 報廢 */ if (repairDtl.DealState == 3 || repairDtl.DealState == 4) { if (repairDtl.EndDate == null) { string msg = "報廢及已完成,需輸入完工日!!"; return(BadRequest(msg)); } } /* 工程師做結案 */ if (assign.FlowCls == "結案") { if (_context.RepairEmps.Where(emp => emp.DocId == assign.DocId).Count() <= 0) { string msg = "沒有維修工程師紀錄!!"; return(BadRequest(msg)); } else if (_context.RepairDtls.Find(assign.DocId).EndDate == null) { string msg = "沒有完工日!!"; return(BadRequest(msg)); } else if (_context.RepairDtls.Find(assign.DocId).DealState == 0) { string msg = "處理狀態不可空值!!"; return(BadRequest(msg)); } if (_context.RepairDtls.Find(assign.DocId).FailFactor == 0) { string msg = "故障原因不可空白!!"; return(BadRequest(msg)); } if (string.IsNullOrEmpty(_context.RepairDtls.Find(assign.DocId).InOut)) { string msg = "維修方式不可空白!!"; return(BadRequest(msg)); } if (_context.RepairDtls.Find(assign.DocId).DealState == 1 || _context.RepairDtls.Find(assign.DocId).DealState == 2) { string msg = "處理狀態不可為處理中或未處理!!"; return(BadRequest(msg)); } } } if (assign.FlowCls == "結案" || assign.FlowCls == "廢除") { assign.FlowUid = ur.Id; } if (ModelState.IsValid) { RepairFlowModel rf = _context.RepairFlows.Where(f => f.DocId == assign.DocId && f.Status == "?").FirstOrDefault(); if (assign.FlowCls == "驗收人") { if (_context.RepairEmps.Where(emp => emp.DocId == assign.DocId).Count() <= 0) { //throw new Exception("沒有維修工程師紀錄!!"); string msg = "沒有維修工程師紀錄!!"; return(BadRequest(msg)); } else if (_context.RepairDtls.Find(assign.DocId).EndDate == null) { //throw new Exception("沒有完工日!!"); string msg = "沒有完工日!!"; return(BadRequest(msg)); } else if (_context.RepairDtls.Find(assign.DocId).DealState == 0) { //throw new Exception("處理狀態不可空值!!"); string msg = "處理狀態不可空值!!"; return(BadRequest(msg)); } if (_context.RepairDtls.Find(assign.DocId).FailFactor == 0) { //throw new Exception("故障原因不可空白!!"); string msg = "故障原因不可空白!!"; return(BadRequest(msg)); } if (string.IsNullOrEmpty(_context.RepairDtls.Find(assign.DocId).InOut)) { //throw new Exception("維修方式不可空白!!"); string msg = "維修方式不可空白!!"; return(BadRequest(msg)); } if (_context.RepairDtls.Find(assign.DocId).DealState == 1 || _context.RepairDtls.Find(assign.DocId).DealState == 2) { //throw new Exception("維修方式不可空白!!"); string msg = "處理狀態不可為處理中或未處理!!"; return(BadRequest(msg)); } } if (assign.FlowCls == "結案") { RepairDtlModel rd = _context.RepairDtls.Find(assign.DocId); rd.CloseDate = DateTime.Now; rf.Opinions = "[" + assign.AssignCls + "]" + Environment.NewLine + assign.AssignOpn; rf.Status = "2"; rf.UserId = ur.Id; rf.UserName = _context.AppUsers.Find(ur.Id).FullName; rf.Rtt = DateTime.Now; rf.Rtp = ur.Id; _context.Entry(rf).State = EntityState.Modified; _context.Entry(rd).State = EntityState.Modified; //If "結案", delete 1 dealing doc to the engineer. //var repairDoc = _context.Repairs.Find(assign.DocId); //var eng = _context.EngDealingDocs.Find(repairDoc.EngId); //eng.DealingDocs = eng.DealingDocs - 1; //_context.Entry(eng).State = EntityState.Modified; _context.SaveChanges(); //Send Mail //To all users in this repair's flow. //try //{ // Tmail mail = new Tmail(); // string body = ""; // string sto = ""; // AppUserModel u; // RepairModel repair = _context.Repairs.Find(assign.DocId); // if (repair.Building != null) // { // repair.BuildingName = _context.Buildings.Where(b => b.BuildingId == Convert.ToInt32(repair.Building)).FirstOrDefault().BuildingName; // repair.FloorName = _context.Floors.Where(f => f.BuildingId == Convert.ToInt32(repair.Building) && f.FloorId == repair.Floor).FirstOrDefault().FloorName; // repair.AreaName = _context.Places.Where(p => p.BuildingId == Convert.ToInt32(repair.Building) && p.FloorId == repair.Floor && p.PlaceId == repair.Area).FirstOrDefault().PlaceName; // } // else // { // repair.BuildingName = "(無資料)"; // repair.FloorName = ""; // repair.AreaName = ""; // } // mail.from = new System.Net.Mail.MailAddress(ur.Email); //u.Email // /* If is charged, send mail to all flow users. */ // if (rd.IsCharged == "Y") // { // _context.RepairFlows.Where(f => f.DocId == assign.DocId) // .ToList() // .ForEach(f => // { // u = _context.AppUsers.Find(f.UserId); // sto += u.Email + ","; // }); // } // else // { // _context.RepairFlows.Where(f => f.DocId == assign.DocId).Where(f => f.Cls.Contains("工程師") == false) // .ToList() // .ForEach(f => // { // u = _context.AppUsers.Find(f.UserId); // sto += u.Email + ","; // }); // } // var temp = _context.RepairFlows.Where(f => f.DocId == assign.DocId).Where(f => f.Cls.Contains("工程師") == false) // .ToList(); // mail.sto = sto.TrimEnd(new char[] { ',' }); // mail.message.Subject = "工務智能請修系統[請修案-結案通知]:設備名稱: " + repair.AssetName; // body += "<p>表單編號:" + repair.DocId + "</p>"; // body += "<p>申請日期:" + repair.ApplyDate.ToString("yyyy/MM/dd") + "</p>"; // body += "<p>申請人:" + repair.UserName + "</p>"; // body += "<p>財產編號:" + repair.AssetNo + "</p>"; // body += "<p>設備名稱:" + repair.AssetName + "</p>"; // body += "<p>請修地點:" + repair.PlaceLoc + " " + repair.BuildingName + " " + repair.FloorName + " " + repair.AreaName + "</p>"; // //body += "<p>放置地點:" + repair.PlaceLoc + "</p>"; // body += "<p>故障描述:" + repair.TroubleDes + "</p>"; // body += "<p>處理描述:" + rd.DealDes + "</p>"; // body += "<p><a href='http://dms.cch.org.tw/EDIS/Account/Login" + "?DocId=" + repair.DocId + "&dealType=Views'" + ">檢視案件</a></p>"; // body += "<br/>"; // body += "<p>使用IE瀏覽器注意事項:</p>"; // body += "<p>「工具」→「相容性檢視設定」→移除cch.org.tw</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(); //} //catch (Exception ex) //{ // throw new Exception(ex.Message); //} } else if (assign.FlowCls == "廢除") { rf.Opinions = "[廢除]" + Environment.NewLine + assign.AssignOpn; rf.Status = "3"; rf.Rtt = DateTime.Now; rf.Rtp = ur.Id; _context.Entry(rf).State = EntityState.Modified; _context.SaveChanges(); } else { //轉送下一關卡 rf.Opinions = "[" + assign.AssignCls + "]" + Environment.NewLine + assign.AssignOpn; rf.Status = "1"; rf.Rtt = DateTime.Now; rf.Rtp = ur.Id; _context.Entry(rf).State = EntityState.Modified; _context.SaveChanges(); // RepairFlowModel flow = new RepairFlowModel(); flow.DocId = assign.DocId; flow.StepId = rf.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.RepairFlows.Add(flow); _context.SaveChanges(); //Send Mail //To the next flow user. try { Tmail mail = new Tmail(); string body = ""; AppUserModel u; RepairModel repair = _context.Repairs.Find(assign.DocId); if (repair.Building != null) { repair.BuildingName = _context.Buildings.Where(b => b.BuildingId == Convert.ToInt32(repair.Building)).FirstOrDefault().BuildingName; repair.FloorName = _context.Floors.Where(f => f.BuildingId == Convert.ToInt32(repair.Building) && f.FloorId == repair.Floor).FirstOrDefault().FloorName; repair.AreaName = _context.Places.Where(p => p.BuildingId == Convert.ToInt32(repair.Building) && p.FloorId == repair.Floor && p.PlaceId == repair.Area).FirstOrDefault().PlaceName; } else { repair.BuildingName = "(無資料)"; repair.FloorName = ""; repair.AreaName = ""; } 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 = "工務智能請修系統[請修案]:設備名稱: " + repair.AssetName; body += "<p>表單編號:" + repair.DocId + "</p>"; body += "<p>申請日期:" + repair.ApplyDate.ToString("yyyy/MM/dd") + "</p>"; body += "<p>申請人:" + repair.UserName + "</p>"; body += "<p>財產編號:" + repair.AssetNo + "</p>"; body += "<p>設備名稱:" + repair.AssetName + "</p>"; body += "<p>故障描述:" + repair.TroubleDes + "</p>"; body += "<p>請修地點:" + repair.PlaceLoc + " " + repair.BuildingName + " " + repair.FloorName + " " + repair.AreaName + "</p>"; //body += "<p>放置地點:" + repair.PlaceLoc + "</p>"; body += "<p><a href='http://dms.cch.org.tw/EDIS/Account/Login" + "?docId=" + repair.DocId + "&dealType=Edit'" + ">處理案件</a></p>"; body += "<br/>"; body += "<p>使用IE瀏覽器注意事項:</p>"; body += "<p>「工具」→「相容性檢視設定」→移除cch.org.tw</p>"; body += "<br/>"; body += "<h3>此封信件為系統通知郵件,請勿回覆。</h3>"; body += "<br/>"; body += "<h3 style='color:red'>如有任何疑問請聯絡工務部,分機3033或7033。<h3>"; mail.message.Body = body; mail.message.IsBodyHtml = true; /* If next flow is not engineer, send mail. */ if (flow.Cls.Contains("工程師") == false) { mail.SendMail(); } } catch (Exception ex) { throw new Exception(ex.Message); } } 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); } }
public async Task <IViewComponentResult> InvokeAsync(string id) { RepairDtlModel repairDtl = _context.BMEDRepairDtls.Find(id); var ur = _userRepo.Find(us => us.UserName == this.User.Identity.Name).FirstOrDefault(); // Get dealstatuses for dropdownlist. List <SelectListItem> listItem = new List <SelectListItem>(); _context.BMEDDealStatuses.Where(d => d.Flg == "Y") .ToList() .ForEach(d => { listItem.Add(new SelectListItem { Text = d.Title, Value = d.Id.ToString() }); }); repairDtl.DealStates = listItem; // Get failfactors for dropdownlist. List <SelectListItem> listItem2 = new List <SelectListItem>(); _context.BMEDFailFactors.Where(d => d.Flg == "Y") .ToList() .ForEach(d => { listItem2.Add(new SelectListItem { Text = d.Title, Value = d.Id.ToString() }); }); repairDtl.FailFactors = listItem2; if (id == null) { RepairDtlModel dtl = new RepairDtlModel(); dtl.IsCharged = "N"; return(View(dtl)); } //if (repairDtl.InOut == null) // Set default value. //{ // repairDtl.InOut = "內修"; //} //if (repairDtl.IsCharged == null) // Set default value. //{ // repairDtl.IsCharged = "N"; //} /* Get assetNo, and set default value. */ repairDtl.AssetNo = _context.BMEDRepairs.Find(repairDtl.DocId).AssetNo; if (repairDtl.AssetNo != null) { var asset = _context.BMEDAssets.Where(a => a.AssetNo == repairDtl.AssetNo).FirstOrDefault(); if (asset != null) { repairDtl.AssetName = asset.Cname; if (asset.AccDate.HasValue) { repairDtl.AssetAccDate = asset.AccDate.Value.ToString("yyyy/MM/dd"); } } } /* Get CheckerName from Repair table. */ var checkerId = _context.BMEDRepairs.Find(id).CheckerId; repairDtl.CheckerName = checkerId == 0 ? "" : _context.AppUsers.Find(checkerId).FullName; RepairFlowModel rf = _context.BMEDRepairFlows.Where(f => f.DocId == id) .Where(f => f.Status == "?").FirstOrDefault(); var isEngineer = _context.UsersInRoles.Where(u => u.AppRoles.RoleName == "MedEngineer" && u.UserId == ur.Id).FirstOrDefault(); /* 流程 => 工程師,Login User => 負責之工程師 */ if (rf.Cls.Contains("工程師") && rf.UserId == ur.Id) { return(View(repairDtl)); } /* 流程 => 工程師,Login User => 非負責之工程師 */ else if (rf.Cls.Contains("工程師") && isEngineer != null) { return(View(repairDtl)); } /* 流程 => 其他 */ else { repairDtl.DealStateTitle = _context.BMEDDealStatuses.Find(repairDtl.DealState).Title; var failFactor = _context.BMEDFailFactors.Where(f => f.Id == repairDtl.FailFactor).FirstOrDefault(); if (failFactor != null) //防止工程師忘記輸入資訊就送出 { repairDtl.FailFactorTitle = failFactor.Title; } return(View("Details", repairDtl)); } }
public async Task <IViewComponentResult> InvokeAsync(string id) { /* Get repair and flow details. */ RepairModel repair = _context.BMEDRepairs.Find(id); RepairDtlModel repairDtl = _context.BMEDRepairDtls.Find(id); RepairFlowModel repairFlow = _context.BMEDRepairFlows.Where(f => f.DocId == id && f.Status == "?") .FirstOrDefault(); /* 增設流程 */ List <SelectListItem> listItem = new List <SelectListItem>(); if (repair.RepType == "增設") { 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 = "醫工主任" }); } else //維修流程 { 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 = "賀康主管" }); //額外流程控管 if (repairDtl.IsCharged == "Y" && repairDtl.NotInExceptDevice == "N") //有費用 & 非統包 { var itemToRemove = listItem.Single(r => r.Value == "驗收人"); listItem.Remove(itemToRemove); //只醫工、賀康主管可結案 } if (repairDtl.DealState == 4) //報廢 { var itemToRemove = listItem.Single(r => r.Value == "驗收人"); listItem.Remove(itemToRemove); //只醫工、賀康主管可結案 } if (repairDtl.IsCharged == "Y" && repairDtl.NotInExceptDevice == "Y") //有費用 & 統包 { var itemToRemove = listItem.Single(r => r.Value == "醫工主管"); listItem.Remove(itemToRemove); //移除醫工主管的選項 } if (repairFlow.Cls == "驗收人" && repairDtl.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); } } // } //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 (repairFlow != null) { assign.Cls = repairFlow.Cls; if (repairFlow.Cls == "驗收人" || repairFlow.Cls == "醫工主管" || repairFlow.Cls == "賀康主管") //可結案人員 { listItem.Add(new SelectListItem { Text = "結案", Value = "結案" }); } if (repairFlow.Cls == "驗收人" && repairDtl.IsCharged == "Y") //有費用 & 關卡於驗收人,下一關只可給工程師 { var itemToRemove = listItem.SingleOrDefault(r => r.Value == "結案"); if (itemToRemove != null) { listItem.Remove(itemToRemove); } } } 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", ""); /* Get Default Checker for MedEngineers to edit. */ List <SelectListItem> listItem4 = new List <SelectListItem>(); var defaultChecker = _context.AppUsers.Find(repair.CheckerId); listItem4.Add(new SelectListItem { Text = defaultChecker.FullName, Value = defaultChecker.Id.ToString() }); ViewData["DefaultChecker"] = new SelectList(listItem4, "Value", "Text", defaultChecker.Id.ToString()); /* 驗收人員所屬部門搜尋的下拉選單資料 */ var dptList = new[] { "K", "P", "C" }; //本院部門 var departments = _context.Departments.Where(d => dptList.Contains(d.Loc)).ToList(); List <SelectListItem> listItem5 = new List <SelectListItem>(); foreach (var item in departments) { listItem5.Add(new SelectListItem { Text = item.Name_C + "(" + item.DptId + ")", //show DptName(DptId) Value = item.DptId }); } ViewData["BMEDQRYDPT"] = new SelectList(listItem5, "Value", "Text"); //assign.Hint = "申請者→負責工程師→使用單位→[(若有費用及報廢)醫工部主管、賀康主管]→結案"; assign.Hint = "申請者→負責工程師→使用單位→(若有費用)負責工程師→[醫工部主管、賀康主管]→結案"; /* 於流程頁面顯示請修類型、及處理狀態*/ string hintRepType = repair.RepType; string hintRepState = ""; var repDtl = _context.BMEDRepairDtls.Where(dtl => dtl.DocId == id).FirstOrDefault(); if (repDtl != null) { hintRepState = _context.BMEDDealStatuses.Find(repDtl.DealState).Title; } ViewData["HintRepType"] = hintRepType + " / " + hintRepState; return(View(assign)); }
[Produces("application/xml")] //強制回傳設定格式 //[Consumes("application/xml")] //強制只接收設定格式 public async Task <IActionResult> Post([FromBody] Root root) { var userName = root.UsrID; AppUserModel ur = _context.AppUsers.Where(u => u.UserName == userName).FirstOrDefault(); if (ur != null) //Check is UserName exist { //string DESKey = "12345678"; //string userPW = DESDecrypt(root.Passwd, DESKey); //DES decrypt. Boolean CheckPassWord = true; //// WebApi to check password. //HttpClient client = new HttpClient(); //client.BaseAddress = new Uri("http://dms.cch.org.tw:8080/"); //string url = "WebApi/Accounts/CheckPasswdForCch?id=" + root.UsrID; //url += "&pwd=" + HttpUtility.UrlEncode(userPW, Encoding.GetEncoding("UTF-8")); //client.DefaultRequestHeaders.Accept.Clear(); //client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); //HttpResponseMessage response = await client.GetAsync(url); //string rstr = ""; //if (response.IsSuccessStatusCode) //{ // rstr = await response.Content.ReadAsStringAsync(); //} //client.Dispose(); //// //if (rstr.Contains("成功")) //彰基2000帳號WebApi登入 //{ // CheckPassWord = true; //} //else //外包帳號 or 值班帳號 //{ // /* Check and get external user. */ // var ExternalUser = _context.ExternalUsers.Where(ex => ex.UserName == root.UsrID).FirstOrDefault(); // if (ExternalUser != null && ExternalUser.Password == userPW) // { // CheckPassWord = true; // } //} if (CheckPassWord == true) //Check passed. { RepairModel repair = new RepairModel(); var dpt = _dptRepo.Find(d => d.DptId == "8410").FirstOrDefault(); var accdpt = _dptRepo.Find(d => d.DptId == "9390").FirstOrDefault(); var troDes = root.Building + root.Floor + root.Point + root.Area + "," + root.Name + root.Des; repair.DocId = GetID2(); repair.UserId = ur.Id; repair.UserName = ur.FullName; repair.UserAccount = ur.UserName; repair.DptId = dpt.DptId; repair.DptName = dpt.Name_C; repair.AccDpt = accdpt.DptId; repair.AccDptName = accdpt.Name_C; repair.ApplyDate = DateTime.Now; repair.LocType = "本單位"; repair.RepType = "請修"; repair.Ext = ur.Ext == null ? "" : ur.Ext; repair.TroubleDes = "【事件處理編號:" + root.SerNo + "】" + "\n" + troDes; repair.AssetNo = root.Point; repair.AssetName = root.Name; repair.Building = "6"; repair.Floor = "612"; repair.Area = "8410"; // 用XML傳入的工程師名稱尋找負責工程師ID var engs = roleManager.GetUsersInRole("RepEngineer").ToList(); int engId = _context.AppUsers.Where(a => a.UserName == "181316").FirstOrDefault().Id; foreach (string l in engs) { var u = _context.AppUsers.Where(a => a.UserName == l).FirstOrDefault(); if (u != null) { if (u.FullName == root.Manager) { engId = u.Id; } } } repair.EngId = engId; repair.CheckerId = ur.Id; /* 如有代理人,將工程師改為代理人*/ var subStaff = _context.EngSubStaff.SingleOrDefault(e => e.EngId == repair.EngId); if (subStaff != null) { int startDate = Convert.ToInt32(subStaff.StartDate.ToString("yyyyMMdd")); int endDate = Convert.ToInt32(subStaff.EndDate.ToString("yyyyMMdd")); int today = Convert.ToInt32(DateTime.UtcNow.AddHours(08).ToString("yyyyMMdd")); /* 如在代理期間內,將代理人指定為負責工程師 */ if (today >= startDate && today <= endDate) { repair.EngId = subStaff.SubstituteId; } } string msg = ""; try { // Create Repair Doc. repair.ApplyDate = DateTime.Now; _repRepo.Create(repair); // Create Repair Details. RepairDtlModel dtl = new RepairDtlModel(); dtl.DocId = repair.DocId; dtl.DealState = 1; // 處理狀態"未處理" _repdtlRepo.Create(dtl); //Create first Repair Flow. RepairFlowModel flow = new RepairFlowModel(); flow.DocId = repair.DocId; flow.StepId = 1; flow.UserId = ur.Id; flow.Status = "1"; // 流程狀態"已處理" flow.Rtp = ur.Id; flow.Rtt = DateTime.Now; flow.Cls = "申請人"; _repflowRepo.Create(flow); // Create next flow. flow = new RepairFlowModel(); flow.DocId = repair.DocId; flow.StepId = 2; flow.UserId = repair.EngId; flow.Status = "?"; // 狀態"未處理" flow.Rtt = DateTime.Now; flow.Cls = "工務/營建工程師"; _repflowRepo.Create(flow); Root successXML = new Root { Code = "0", Msg = "Success", SerNo = root.SerNo, Mno = repair.DocId }; return(Ok(successXML)); } catch (Exception ex) { msg = ex.Message; } Root errorXMLMsg = new Root { Code = "400", Msg = msg, SerNo = root.SerNo, Mno = "" }; return(BadRequest(errorXMLMsg)); } else { Root errorXMLMsg = new Root { Code = "400", Msg = "PassWord is incorrect.", SerNo = root.SerNo, Mno = "" }; return(BadRequest(errorXMLMsg)); } } else { Root errorXMLMsg = new Root { Code = "400", Msg = "UserID is not exist.", SerNo = root.SerNo, Mno = "" }; return(BadRequest(errorXMLMsg)); } }
public async Task <IViewComponentResult> InvokeAsync(string id) { RepairDtlModel repairDtl = _context.RepairDtls.Find(id); var ur = _userRepo.Find(us => us.UserName == this.User.Identity.Name).FirstOrDefault(); // Get dealstatuses for dropdownlist. List <SelectListItem> listItem = new List <SelectListItem>(); _context.DealStatuses.Where(d => d.Flg == "Y") .ToList() .ForEach(d => { listItem.Add(new SelectListItem { Text = d.Title, Value = d.Id.ToString() }); }); repairDtl.DealStates = listItem; // Get failfactors for dropdownlist. List <SelectListItem> listItem2 = new List <SelectListItem>(); _context.FailFactors.Where(d => d.Flg == "Y") .ToList() .ForEach(d => { listItem2.Add(new SelectListItem { Text = d.Title, Value = d.Id.ToString() }); }); repairDtl.FailFactors = listItem2; if (id == null) { RepairDtlModel dtl = new RepairDtlModel(); dtl.IsCharged = "N"; return(View(dtl)); } if (repairDtl.InOut == null) // Set default value. { repairDtl.InOut = "內修"; } if (repairDtl.IsCharged == null) // Set default value. { repairDtl.IsCharged = "N"; } /* Get assetNo, and set default value for hasAssetNo. */ repairDtl.AssetNo = _context.Repairs.Find(repairDtl.DocId).AssetNo; if (repairDtl.AssetNo == null) { repairDtl.HasAssetNo = "N"; } else { repairDtl.HasAssetNo = "Y"; var asset = _context.Assets.Where(a => a.AssetNo == repairDtl.AssetNo).FirstOrDefault(); if (asset != null) { repairDtl.AssetName = asset.Cname; if (asset.AccDate.HasValue) { repairDtl.AssetAccDate = asset.AccDate.Value.ToString("yyyy/MM/dd"); } } } RepairFlowModel rf = _context.RepairFlows.Where(f => f.DocId == id) .Where(f => f.Status == "?").FirstOrDefault(); var isEngineer = _context.UsersInRoles.Where(u => u.AppRoles.RoleName == "RepEngineer" && u.UserId == ur.Id).FirstOrDefault(); /* 查無處理中流程 => 已結案 或 已廢除 */ if (rf == null) { /* Role => 工務經辦 or Admin */ if (userManager.IsInRole(this.UserClaimsPrincipal, "RepToDo") == true || userManager.IsInRole(this.UserClaimsPrincipal, "Admin") == true) { return(View("Details", repairDtl)); } } /* 流程 => 工程師,Login User => 負責之工程師 */ if (rf.Cls.Contains("工程師") && rf.UserId == ur.Id) { return(View(repairDtl)); } /* 流程 => 工程師,Login User => 非負責之工程師 */ else if (rf.Cls.Contains("工程師") && isEngineer != null) { return(View(repairDtl)); } /* 流程 => 其他 */ else { repairDtl.DealStateTitle = _context.DealStatuses.Find(repairDtl.DealState).Title; var failFactor = _context.FailFactors.Where(f => f.Id == repairDtl.FailFactor).FirstOrDefault(); if (failFactor != null) //防止工程師忘記輸入資訊就送出 { repairDtl.FailFactorTitle = failFactor.Title; } return(View("Details", repairDtl)); } }
public IActionResult Edit(RepairCostModel repairCost) { var ur = _userRepo.Find(u => u.UserName == this.User.Identity.Name).FirstOrDefault(); /* Change to UpperCase.*/ if (repairCost.TicketDtl.TicketDtlNo != null) { repairCost.TicketDtl.TicketDtlNo = repairCost.TicketDtl.TicketDtlNo.ToUpper(); } if (repairCost.SignNo != null) { repairCost.SignNo = repairCost.SignNo.ToUpper(); } if (ModelState.IsValid) { try { if (repairCost.StockType == "2") { var dupData = _context.BMEDRepairCosts.Include(c => c.TicketDtl) .Where(c => c.DocId == repairCost.DocId && c.PartName == repairCost.PartName && c.Standard == repairCost.Standard && c.TicketDtl.TicketDtlNo == repairCost.TicketDtl.TicketDtlNo).FirstOrDefault(); if (dupData != null) { string msg = "資料重複儲存!!"; return(BadRequest(msg)); } } else { var dupData = _context.BMEDRepairCosts.Include(c => c.TicketDtl) .Where(c => c.DocId == repairCost.DocId && c.PartName == repairCost.PartName && c.Standard == repairCost.Standard && c.SignNo == repairCost.SignNo).FirstOrDefault(); if (dupData != null) { string msg = "資料重複儲存!!"; return(BadRequest(msg)); } } int seqno = _context.BMEDRepairCosts.Where(c => c.DocId == repairCost.DocId) .Select(c => c.SeqNo).DefaultIfEmpty().Max(); repairCost.SeqNo = seqno + 1; if (repairCost.StockType == "2") { if (string.IsNullOrEmpty(repairCost.TicketDtl.TicketDtlNo)) { //throw new Exception("發票號碼不可空白!!"); string msg = "發票號碼不可空白!!"; return(BadRequest(msg)); } if (repairCost.AccountDate == null) { //throw new Exception("發票日期不可空白!!"); string msg = "發票日期不可空白!!"; return(BadRequest(msg)); } int i = _context.BMEDTicketDtls.Where(d => d.TicketDtlNo == repairCost.TicketDtl.TicketDtlNo) .Select(d => d.SeqNo).DefaultIfEmpty().Max(); repairCost.TicketDtl.SeqNo = i + 1; repairCost.TicketDtl.ObjName = repairCost.PartName; repairCost.TicketDtl.Qty = repairCost.Qty; repairCost.TicketDtl.Unite = repairCost.Unite; repairCost.TicketDtl.Price = repairCost.Price; repairCost.TicketDtl.Cost = repairCost.TotalCost; TicketModel t = _context.BMEDTickets.Find(repairCost.TicketDtl.TicketDtlNo); if (t == null) { t = new TicketModel(); t.TicketNo = repairCost.TicketDtl.TicketDtlNo; t.TicDate = repairCost.AccountDate; t.ApplyDate = null; t.CancelDate = null; t.VendorId = repairCost.VendorId; t.VendorName = repairCost.VendorName; repairCost.TicketDtl.Ticket = t; _context.BMEDTickets.Add(t); } _context.BMEDTicketDtls.Add(repairCost.TicketDtl); } else { repairCost.AccountDate = repairCost.AccountDate == null ? DateTime.Now.Date : repairCost.AccountDate; repairCost.TicketDtl = null; } repairCost.Rtp = ur.Id; repairCost.Rtt = DateTime.Now; if (repairCost.StockType != "0") { repairCost.PartNo = ""; } _context.BMEDRepairCosts.Add(repairCost); _context.SaveChanges(); // RepairDtlModel dtl = _context.BMEDRepairDtls.Where(d => d.DocId == repairCost.DocId) .FirstOrDefault(); if (dtl != null) { dtl.Cost = _context.BMEDRepairCosts.Where(k => k.DocId == repairCost.DocId) .Select(k => k.TotalCost) .DefaultIfEmpty(0).Sum(); _context.Entry(dtl).State = EntityState.Modified; _context.SaveChanges(); } return(ViewComponent("BMEDRepCostList", new { id = repairCost.DocId, viewType = "Edit" })); } catch (Exception e) { throw new Exception(e.Message); } } else { string msg = ""; foreach (var error in ViewData.ModelState.Values.SelectMany(modelState => modelState.Errors)) { msg += error.ErrorMessage + Environment.NewLine; } throw new Exception(msg); } }
public async Task <IViewComponentResult> InvokeAsync(string id) { if (id == null) { RepairDtlModel dtl = new RepairDtlModel(); return(View(dtl)); } RepairDtlModel repairDtl = _context.RepairDtls.Find(id); var ur = _userRepo.Find(us => us.UserName == this.User.Identity.Name).FirstOrDefault(); // Get dealstatuses for dropdownlist. List <SelectListItem> listItem = new List <SelectListItem>(); listItem.Add(new SelectListItem { Text = "未處理", Value = "1" }); listItem.Add(new SelectListItem { Text = "處理中", Value = "2" }); repairDtl.DealStates = listItem; // Get failfactors for dropdownlist. List <SelectListItem> listItem2 = new List <SelectListItem>(); _context.FailFactors.Where(d => d.Flg == "Y") .ToList() .ForEach(d => { listItem2.Add(new SelectListItem { Text = d.Title, Value = d.Id.ToString() }); }); repairDtl.FailFactors = listItem2; // Set Default value if (repairDtl.EndDate == null) { repairDtl.EndDate = System.DateTime.UtcNow.AddHours(8); } RepairFlowModel rf = _context.RepairFlows.Where(f => f.DocId == id) .Where(f => f.Status == "?").FirstOrDefault(); var isEngineer = _context.UsersInRoles.Where(u => u.AppRoles.RoleName == "RepEngineer" && u.UserId == ur.Id).FirstOrDefault(); /* 流程 => 工程師,Login User => 負責之工程師 */ if (rf.Cls.Contains("工程師") && rf.UserId == ur.Id) { return(View(repairDtl)); } /* 流程 => 工程師,Login User => 非負責之工程師 */ else if (rf.Cls.Contains("工程師") && isEngineer != null) { return(View(repairDtl)); } /* 流程 => 其他 */ else { repairDtl.DealStateTitle = _context.DealStatuses.Find(repairDtl.DealState).Title; var failFactor = _context.FailFactors.Where(f => f.Id == repairDtl.FailFactor).FirstOrDefault(); if (failFactor != null) { repairDtl.FailFactorTitle = failFactor.Title; } return(View("Details", repairDtl)); } }