diff --git a/AMESCoreStudio.Web/Controllers/BASController.cs b/AMESCoreStudio.Web/Controllers/BASController.cs index 587e8157..725ae55c 100644 --- a/AMESCoreStudio.Web/Controllers/BASController.cs +++ b/AMESCoreStudio.Web/Controllers/BASController.cs @@ -144,6 +144,18 @@ namespace AMESCoreStudio.Web.Controllers ViewBag.FlowRuleList = FlowRuleItems; } + private async Task GetFlowRuleListByUnit(string unit_no) + { + var result = await _basApi.GetFlowRulesByUnit(unit_no); + + var FlowRuleItems = new List(); + for (int i = 0; i < result.Count; i++) + { + FlowRuleItems.Add(new SelectListItem(result[i].UnitNo + result[i].FlowRuleName, result[i].FlowRuleID.ToString())); + } + ViewBag.FlowRuleList = FlowRuleItems; + } + private async Task GetStationList() { var result = await _basApi.GetStationses(); @@ -1027,6 +1039,23 @@ namespace AMESCoreStudio.Web.Controllers return View(model); } + public async Task BAS009Copy(string id) + { + await GetUnitList(); + await GetFlowRuleListByUnit(id); + + var model = new FlowRule(); + if (id != null) + { + if (id != "") + { + model.UnitNo = id; + } + } + + return View(model); + } + //修改页面 [HttpGet] public async Task BAS009UAsync(int id) @@ -1108,6 +1137,47 @@ namespace AMESCoreStudio.Web.Controllers return View("BAS009U", model); } + //頁面提交,id=0 添加,id>0 修改 + [HttpPost] + public async Task BAS009CopySaveAsync(FlowRule model) + { + IResultModel result; + + var userID = ""; + HttpContext.Request.Cookies.TryGetValue("UserID", out userID); + int user_id = 0; + if (userID != null) + { + if (int.Parse(userID.ToString()) >= 0) + { + user_id = int.Parse(userID.ToString()); + } + } + model.CreateUserId = user_id; + + result = await _basApi.PostFlowRuleCopy(model.FlowRuleID, JsonConvert.SerializeObject(model)); + + + if (result.Success) + { + var _msg = "複製成功!"; + return RedirectToAction("Refresh", "Home", new { msg = _msg }); + } + else + { + if (result.Errors.Count > 0) + { + ModelState.AddModelError(result.Errors[0].Id, result.Errors[0].Msg); + } + else + { + ModelState.AddModelError("error", result.Msg); + } + } + + return View("BAS009Copy", model); + } + [ResponseCache(Duration = 0)] [HttpGet] public async Task GetFlowRulesAsync() diff --git a/AMESCoreStudio.Web/HttpApis/IBAS.cs b/AMESCoreStudio.Web/HttpApis/IBAS.cs index 603fe10c..30c38542 100644 --- a/AMESCoreStudio.Web/HttpApis/IBAS.cs +++ b/AMESCoreStudio.Web/HttpApis/IBAS.cs @@ -325,6 +325,13 @@ namespace AMESCoreStudio.Web [WebApiClient.Attributes.HttpPost("api/FlowRules")] ITask> PostFlowRule([FromBody, RawJsonContent] string model); + /// + /// 複製流程 + /// + /// + [WebApiClient.Attributes.HttpPost("api/FlowRules/{id}")] + ITask> PostFlowRuleCopy(int id,[FromBody, RawJsonContent] string model); + /// /// 更新流程 /// diff --git a/AMESCoreStudio.Web/Views/BAS/BAS009.cshtml b/AMESCoreStudio.Web/Views/BAS/BAS009.cshtml index 6bfb7ea3..0aaadeba 100644 --- a/AMESCoreStudio.Web/Views/BAS/BAS009.cshtml +++ b/AMESCoreStudio.Web/Views/BAS/BAS009.cshtml @@ -190,7 +190,17 @@ //alert(id); hg.open('新增流程', '/BAS/BAS009C/' + id, 600, 400); } - } + }, { + text: '複製', + layuiicon: '', + class: 'layui-btn-normal', + handler: function () { + var id = unitNo.value; + //alert(unitNo.value); + //alert(id); + hg.open('複製流程', '/BAS/BAS009Copy/' + id, 600, 400); + } + } ]; diff --git a/AMESCoreStudio.Web/Views/BAS/BAS009Copy.cshtml b/AMESCoreStudio.Web/Views/BAS/BAS009Copy.cshtml new file mode 100644 index 00000000..33e4ae6b --- /dev/null +++ b/AMESCoreStudio.Web/Views/BAS/BAS009Copy.cshtml @@ -0,0 +1,56 @@ +@model AMESCoreStudio.WebApi.Models.BAS.FlowRule + + +@{ ViewData["Title"] = "BAS009Copy"; + Layout = "~/Views/Shared/_FormLayout.cshtml"; } + + + +
+
+
+
+ +
+ + + +
+
+ + + +
+
+ + + +
+ @Html.ValidationMessage("error") +
+ +
+ +
+
+
+ +@section Scripts { + @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_FileinputScriptsPartial"); } + + + + +} diff --git a/AMESCoreStudio.WebApi/Controllers/BAS/FlowRulesController.cs b/AMESCoreStudio.WebApi/Controllers/BAS/FlowRulesController.cs index 9fa6860c..7cbbba8b 100644 --- a/AMESCoreStudio.WebApi/Controllers/BAS/FlowRulesController.cs +++ b/AMESCoreStudio.WebApi/Controllers/BAS/FlowRulesController.cs @@ -173,6 +173,92 @@ namespace AMESCoreStudio.WebApi.Controllers.BAS return result; + } + + /// + /// 複製流程資料 + /// + /// + /// + /// + // POST: api/FlowRules + // To protect from overposting attacks, enable the specific properties you want to bind to, for + // more details, see https://go.microsoft.com/fwlink/?linkid=2123754. + [HttpPost("{id}")] + public async Task> PostFlowRuleCopy(int id,[FromBody] FlowRule flowRule) + { + ResultModel result = new ResultModel(); + + var copyFlowRule = await _context.FlowRules.Where(p => p.FlowRuleID.Equals(id)).FirstOrDefaultAsync(); + + IQueryable q = _context.RuleStations; + + q = q.Where(p => p.FlowRuleID.Equals(id)); + + var copyRuleStation = await q.ToListAsync(); + + Helper helper = new Helper(_context); + flowRule.FlowRuleID = helper.GetIDKey("FLOW_RULE_ID").Result; + flowRule.FlowStatus = copyFlowRule.FlowStatus; + flowRule.FlowType = copyFlowRule.FlowType; + flowRule.ProcessTypeNo = copyFlowRule.ProcessTypeNo; + flowRule.SysType = copyFlowRule.SysType; + flowRule.UnitNo = copyFlowRule.UnitNo; + flowRule.CreateDate = DateTime.Now; + + _context.FlowRules.Add(flowRule); + try + { + await _context.SaveChangesAsync(); + + for (int i = 0; i < copyRuleStation.Count; i++) + { + int copyRuleStationId = copyRuleStation[i].RuleStationID; + int ruleStationId = helper.GetIDKey("RULE_STATION_ID").Result; + + RuleStation ruleStation = new RuleStation(); + ruleStation = copyRuleStation[i]; + ruleStation.RuleStationID = ruleStationId; + ruleStation.FlowRuleID = flowRule.FlowRuleID; + ruleStation.CreateDate = DateTime.Now; + ruleStation.CreateUserId = flowRule.CreateUserId; + ruleStation.UpdateDate = DateTime.Now; + + + _context.RuleStations.Add(ruleStation); + await _context.SaveChangesAsync(); + + IQueryable q1 = _context.Ruleses; + + q1 = q1.Where(p => p.RuleStationID.Equals(copyRuleStationId)); + + var copyRules = await q1.ToListAsync(); + + for (int j = 0; j < copyRules.Count; j++) + { + Rules rules = new Rules(); + rules = copyRules[j]; + rules.RuleStationID = ruleStationId; + rules.CreateDate = DateTime.Now; + rules.CreateUserId = flowRule.CreateUserId; + rules.UpdateDate = DateTime.Now; + + _context.Ruleses.Add(rules); + await _context.SaveChangesAsync(); + } + } + + result.Success = true; + result.Msg = "OK"; + } + catch (Exception ex) + { + result.Success = false; + result.Msg = ex.InnerException.Message; + } + return result; + + } ///