|
|
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;
|
|
|
using System.Text;
|
|
|
using System.Text.Json;
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
/***************************************************************************************************
|
|
|
*
|
|
|
* 更新人:sitong.dong
|
|
|
* 描述:关键数据管理
|
|
|
* 修改时间:2022.06.22
|
|
|
* 修改日志:系统迭代升级
|
|
|
*
|
|
|
**************************************************************************************************/
|
|
|
namespace Estsh.Core.Web.Controllers
|
|
|
{
|
|
|
public class KeyDataDefineController : BaseController
|
|
|
{
|
|
|
|
|
|
private IKeyDataDefineService service;
|
|
|
public KeyDataDefineController(IKeyDataDefineService _service)
|
|
|
{
|
|
|
service = _service;
|
|
|
}
|
|
|
|
|
|
//
|
|
|
// GET: /Menu/
|
|
|
public ActionResult Index()
|
|
|
{
|
|
|
return View();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取关键数据管理列表数据
|
|
|
/// </summary>
|
|
|
/// <param name="menuName"></param>
|
|
|
/// <param name="pager"></param>
|
|
|
/// <param name="direction"></param>
|
|
|
/// <param name="sort"></param>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult getKeyDataListByPage(String keydata_name_search, Pager pager, String direction, String sort, String enabled_search="Y")
|
|
|
{
|
|
|
Hashtable result = new Hashtable();
|
|
|
result.Add("pager.pageNo", pager.pageNo);
|
|
|
Hashtable dataHt = this.service.getKeyDataListByPage(keydata_name_search, enabled_search, 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);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 保存菜单数据
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult saveKeyData()
|
|
|
{
|
|
|
Hashtable result = new Hashtable();
|
|
|
String message = "";
|
|
|
string flag = "";
|
|
|
String editType = Request.Form["editType"].ToString();
|
|
|
|
|
|
String keydataId = Request.Form["keydataId"].ToString();
|
|
|
String keydataName = Request.Form["keydataName"].ToString();
|
|
|
String keydataDesc = Request.Form["keydataDesc"].ToString();
|
|
|
String maxValue = Request.Form["maxValue"].ToString();
|
|
|
String minValue = Request.Form["minValue"].ToString();
|
|
|
String maxTolerance = Request.Form["maxTolerance"].ToString();
|
|
|
String minTolerance = Request.Form["minTolerance"].ToString();
|
|
|
String enabled = Request.Form["enabled"].ToString();
|
|
|
|
|
|
SysKeydata model = new SysKeydata();
|
|
|
model.KeydataName = keydataName;
|
|
|
model.KeydataDesc = keydataDesc;
|
|
|
model.MaxValue =Convert.ToInt32( maxValue);
|
|
|
model.MinValue = Convert.ToInt32(minValue);
|
|
|
model.MaxTolerance = Convert.ToInt32(maxTolerance);
|
|
|
model.MinTolerance = Convert.ToInt32(minTolerance);
|
|
|
model.Enabled = enabled;
|
|
|
|
|
|
model.UpdateUserId = CurrentEmp.EmpId;
|
|
|
model.CreateUserId = CurrentEmp.EmpId;
|
|
|
|
|
|
if (editType != null && editType.Trim().Equals("edit"))
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
model.UpdateUserId = CurrentEmp.EmpId;
|
|
|
model.KeydataId =Convert.ToInt32( keydataId);
|
|
|
this.service.updateKeyData(model);
|
|
|
message = "修改成功";
|
|
|
flag = "OK";
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
message = "修改失败!";
|
|
|
flag = "NO";
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
model.CreateUserId = CurrentEmp.EmpId;
|
|
|
this.service.saveKeyData(model);
|
|
|
message = "添加成功";
|
|
|
flag = "OK";
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
message = "添加失败!";
|
|
|
flag = "NO";
|
|
|
}
|
|
|
}
|
|
|
result.Add("message", message);
|
|
|
result.Add("flag",flag);
|
|
|
return Json(result) ;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 查看菜单详情
|
|
|
/// </summary>
|
|
|
/// <param name="keydataId"></param>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult getKeyDataDetail(String keydataId)
|
|
|
{
|
|
|
Hashtable ht = this.service.getKeyDataDetail(keydataId);
|
|
|
ViewData.Add("keydataId",ht["keydataId"]);
|
|
|
ViewData.Add("keydataName", ht["keydataName"]);
|
|
|
ViewData.Add("keydataDesc", ht["keydataDesc"]);
|
|
|
ViewData.Add("maxValue", ht["maxValue"]);
|
|
|
ViewData.Add("minValue", ht["minValue"]);
|
|
|
ViewData.Add("maxTolerance", ht["maxTolerance"]);
|
|
|
ViewData.Add("minTolerance", ht["minTolerance"]);
|
|
|
ViewData.Add("enabled", ht["enabled"]);
|
|
|
return View("ViewKeyDataDefine");
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 编辑菜单
|
|
|
/// </summary>
|
|
|
/// <param name="keydataId"></param>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult editKeyData(String keydataId)
|
|
|
{
|
|
|
|
|
|
if (!string.IsNullOrEmpty(keydataId))
|
|
|
{
|
|
|
Hashtable ht = this.service.getKeyDataDetail(keydataId);
|
|
|
ViewData.Add("editType", "edit");
|
|
|
|
|
|
ViewData.Add("keydataId", ht["keydataId"]);
|
|
|
ViewData.Add("keydataName", ht["keydataName"]);
|
|
|
ViewData.Add("keydataDesc", ht["keydataDesc"]);
|
|
|
ViewData.Add("maxValue", ht["maxValue"]);
|
|
|
ViewData.Add("minValue", ht["minValue"]);
|
|
|
ViewData.Add("maxTolerance", ht["maxTolerance"]);
|
|
|
ViewData.Add("minTolerance", ht["minTolerance"]);
|
|
|
ViewData.Add("enabled", ht["enabled"]);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ViewData.Add("editType", "new");
|
|
|
}
|
|
|
|
|
|
return View("EditKeyDataDefine");
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除菜单
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult deleteKeyData(String ids)
|
|
|
{
|
|
|
int delCount = 0;
|
|
|
try
|
|
|
{
|
|
|
delCount = this.service.deleteKeyData(ids);
|
|
|
}
|
|
|
catch(Exception e)
|
|
|
{
|
|
|
delCount = -1;
|
|
|
}
|
|
|
Hashtable result = new Hashtable();
|
|
|
result.Add("status", delCount);
|
|
|
return Json(result);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 启用
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
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);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 禁用
|
|
|
/// </summary>
|
|
|
/// <param name="ids"></param>
|
|
|
/// <returns></returns>
|
|
|
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);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取 站点 信息
|
|
|
/// BY NOAH
|
|
|
/// </summary>
|
|
|
/// <rehuoturns></returns>
|
|
|
public ActionResult getTerminalName()
|
|
|
{
|
|
|
Hashtable result = new Hashtable();
|
|
|
List<KeyValueResult> menuList = this.service.getTerminalName();
|
|
|
result.Add("list", menuList);
|
|
|
return Json(result);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 获取 产线 信息
|
|
|
/// BY NOAH
|
|
|
/// </summary>
|
|
|
/// <rehuoturns></returns>
|
|
|
public ActionResult getBoardName()
|
|
|
{
|
|
|
Hashtable result = new Hashtable();
|
|
|
List<KeyValueResult> menuList = this.service.getBoardName();
|
|
|
result.Add("list", menuList);
|
|
|
return Json(result);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 判断是否为数字类型
|
|
|
/// BY NOAH
|
|
|
/// </summary>
|
|
|
/// <param name="s"></param>
|
|
|
/// <returns></returns>
|
|
|
public bool isNum(string s)
|
|
|
{
|
|
|
string pattern = "^[0-9]*$";
|
|
|
Regex rx = new Regex(pattern);
|
|
|
return rx.IsMatch(s);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 导出数据到Excel
|
|
|
/// BY NOAH
|
|
|
/// </summary>
|
|
|
/// <param name="pager"></param>
|
|
|
/// <param name="txtOrderNo"></param>
|
|
|
/// <param name="sort"></param>
|
|
|
/// <param name="direction"></param>
|
|
|
/// <param name="isPage"></param>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult exportData(String keydata_name_search, String enabled_search, 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.getTableListByPage(keydata_name_search, enabled_search, pager, direction, sort, paging);//txtOrderNo, pager, direction, sort, paging
|
|
|
|
|
|
List<KeyDataDefine> listHt = (List<KeyDataDefine>)dataHt["dataList"];
|
|
|
var memoryStream = ExcelHelper.ToExcel(listHt);
|
|
|
return File(memoryStream.ToArray(), "application/ms-excel", "关键数据管理.xls");
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 导入Excel文件
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult importKeyData()
|
|
|
{
|
|
|
Hashtable result = new Hashtable();
|
|
|
IFormFile file = Request.Form.Files[0];
|
|
|
List<KeyDataDefine> data = ExcelHelper.GetList<KeyDataDefine>(file, 0);
|
|
|
result = service.ImportExcel(data, CurrentEmp.EmpId);
|
|
|
return Json(result);
|
|
|
}
|
|
|
}
|
|
|
}
|