using Dapper; using Estsh.Core.Controllers; using Estsh.Core.Model.ExcelModel; using Estsh.Core.Model.Result; using Estsh.Core.Models; using Estsh.Core.Services.IServices; using Estsh.Core.Util; using Microsoft.AspNetCore.Mvc; using System.Collections; /*************************************************************************************************** * * 更新人:sitong.dong * 描述:配置管理 * 修改时间:2022.06.22 * 修改日志:系统迭代升级 * **************************************************************************************************/ namespace Estsh.Core.Web.Controllers { /// /// 配置管理 /// public class ModelPartController : BaseController { private IModelPartService service; public ModelPartController(IModelPartService _service) { service = _service; } public ActionResult Index() { return View(); } /// /// 获取配置管理列表数据 /// /// 菜单名称 /// 分页 /// 排序方式 /// 排序列 /// public ActionResult getModelPartListByPage(string cmbTypeName, string cmbModelName, Pager pager, String direction, String sort, String enabled = "Y") { Hashtable result = new Hashtable(); Hashtable dataHt = this.service.getModelPartListByPage(cmbTypeName, cmbModelName, enabled, pager, direction, sort); result.Add("rows", dataHt["dataList"]); result.Add("pager.totalRows", dataHt["totalCount"]); result.Add("sort", sort); result.Add("direction", direction); return Json(result); } /// /// 获取下拉列表数据 /// /// public ActionResult getSelectModelPart() { Hashtable result = new Hashtable(); List ModelPartList = this.service.getSelectModelPart(); result.Add("list", ModelPartList); return Json(result); } /// /// 保存数据 /// /// public ActionResult saveModelPart() { String editType = Request.Form["editType"].ToString(); String modelId = Request.Form["modelId"].ToString(); String modelCode = Request.Form["modelCode"].ToString(); String modelType = Request.Form["modelType"].ToString(); String modelName = Request.Form["modelName"].ToString(); String modelAlias = Request.Form["modelAlias"].ToString(); String modelDesc = Request.Form["modelDesc"].ToString(); String modelTypeId = Request.Form["modelTypeId"].ToString(); String pdline1 = Request.Form["pdline1"].ToString(); String pdline2 = Request.Form["pdline2"].ToString(); SysModel model = new SysModel(); model.ModelCode = modelCode; model.ModelType = modelType; model.ModelName = modelName; model.ModelAlias = modelAlias; model.ModelDesc = modelDesc; model.ModelTypeId = Convert.ToInt32(modelTypeId); model.Pdline1 =Convert.ToInt32( pdline1); model.Pdline2 = Convert.ToInt32(pdline2); SysPart partmodel = new SysPart(); partmodel.ModelName = modelName; String message = ""; string flag = ""; if (editType != null && editType.Trim().Equals("edit")) { try { model.ModelId =Convert.ToInt32( modelId); partmodel.ModelId = Convert.ToInt32(modelId); model.UpdateUserId = CurrentEmp.EmpId; int return_value =this.service.updateModelPart(model); if (return_value > 0) { partmodel.UpdateUserId = CurrentEmp.EmpId; this.service.updateModelPart_Sys_part(partmodel); message = "修改成功"; flag = "OK"; } else { message = "更新配置零件号失败"; flag = "Fail"; } } catch (Exception e) { message = "修改失败!"; flag = "Fail"; } } else { try { model.CreateUserId = CurrentEmp.EmpId; int return_value = this.service.saveModelPart(model); if (return_value > 0) { partmodel.CreateUserId = CurrentEmp.EmpId; this.service.saveModelPart_Sys_part(partmodel); message = "添加成功"; flag = "OK"; } else { message = "新增配置零件号失败"; flag = "Fail"; } } catch (Exception e) { message = "添加失败!"; flag = "Fail"; } } Hashtable result = new Hashtable(); result.Add("message", message); result.Add("flag", flag); return Json(result); } /// /// 查看详情 /// /// /// public ActionResult getModelPart(String ModelPart_id) { //List ModelPartInfo = this.service.getModelPart(ModelPart_id); ////Hashtable htModelPartInfo = (Hashtable)ModelPartInfo[0]; //ViewData.Add("partId", ModelPartInfo[0]["partId"]); //ViewData.Add("cust_order", htModelPartInfo["cust_order"]); //ViewData.Add("ship_unit", htModelPartInfo["ship_unit"]); return View("viewModelPart"); } /// /// 编辑 /// /// /// public ActionResult editModelPart(String modelId) { if (!string.IsNullOrEmpty(modelId)) { List ModelPartInfo = this.service.getModelPart(modelId); //Hashtable htModelPartInfo = (Hashtable)ModelPartInfo[0]; ViewData.Add("editType", "edit"); ViewData.Add("modelCode", ModelPartInfo[0].ModelCode); ViewData.Add("modelType", ModelPartInfo[0].ModelType); ViewData.Add("modelName", ModelPartInfo[0].ModelName); ViewData.Add("modelAlias", ModelPartInfo[0].ModelAlias); ViewData.Add("modelDesc", ModelPartInfo[0].ModelDesc); ViewData.Add("modelTypeId", ModelPartInfo[0].ModelTypeId); ViewData.Add("modelId", ModelPartInfo[0].ModelId); ViewData.Add("pdline1", ModelPartInfo[0].Pdline1); ViewData.Add("pdline2", ModelPartInfo[0].Pdline2); } else { ViewData.Add("editType", "new"); } return View("EditModelPart"); } /// /// 删除 /// /// /// public ActionResult deleteModelPart(String ids) { //String enabled = Request["enabled"].ToString(); //if (enabled == "1") //{ // return Json("该配置状态不能删除。"); //} int delCount = 0; try { delCount = this.service.deleteModelPart(ids); } catch (Exception e) { delCount = -1; } Hashtable result = new Hashtable(); result.Add("status", delCount); return Json(result); } /// /// 启用 /// /// /// public ActionResult onEnable(String ids) { int delCount = 0; try { delCount = this.service.EnableData(ids); } catch (Exception e) { delCount = -1; } Hashtable result = new Hashtable(); result.Add("status", delCount); return Json(result); } /// /// 禁用 /// /// /// public ActionResult onDisable(String ids) { int delCount = 0; try { delCount = this.service.DisableData(ids); } catch (Exception e) { delCount = -1; } Hashtable result = new Hashtable(); result.Add("status", delCount); return Json(result); } /// /// 变更状态 /// /// /// public ActionResult onState(String modelId , String enabled) { int delCount = 0; try { delCount = this.service.onState(modelId,enabled,CurrentEmp.EmpId.ToString()); } catch (Exception e) { delCount = -1; } Hashtable result = new Hashtable(); result.Add("status", delCount); return Json(result); } public ActionResult uploadFile() { return View("uploadFile"); } /// /// 车型 /// /// public ActionResult GetTypeName() { Hashtable ht = new Hashtable(); List alType = service.GetTypeName(); ht.Add("list", alType); return Json(ht); } /// /// 配置 /// /// /// public ActionResult GetModelName(string typeName) { Hashtable ht = new Hashtable(); List alModel = service.GetModelName(typeName); ht.Add("list", alModel); return Json(ht); } /// /// 导出数据到Excel /// /// /// /// /// /// /// public ActionResult exportData(string cmbTypeName, string cmbModelName, string txtEnabled, Pager pager, String sort, String direction, String isPage) { Boolean paging = false; if (isPage == null || "".Equals(isPage)) { paging = false; } else { if ("1".Equals(isPage.Trim())) { paging = true; } else { paging = false; } } Hashtable dataHt = this.service.getModelPartListByPage2(cmbTypeName, cmbModelName, txtEnabled, pager, direction, sort);//txtOrderNo, pager, direction, sort, paging List listHt = (List)dataHt["dataList"]; var memoryStream = ExcelHelper.ToExcel(listHt); return File(memoryStream.ToArray(), "application/ms-excel", "配置管理.xls"); } /// /// 导入Excel文件 /// /// public ActionResult importModelTypeInfo() { Hashtable result = new Hashtable(); IFormFile file = Request.Form.Files[0]; List data = ExcelHelper.GetList(file, 0); result = service.ImportExcel(data, CurrentEmp.EmpId); return Json(result); } } }