using Aspose.Cells; using Estsh.Core.Controllers; using Estsh.Core.Model.Result; using Estsh.Core.Models; using Estsh.Core.Services.IServices; using Estsh.Core.Util; using Microsoft.AspNetCore.Mvc; using NPOI.HSSF.UserModel; using System.Collections; /*************************************************************************************************** * * 更新人:sitong.dong * 描述:抽样模块控制类 * 修改时间:2022.06.22 * 修改日志:系统迭代升级 * **************************************************************************************************/ namespace Estsh.Core.Web.Controllers { /// /// 抽样模块控制类 /// public class SampleTestDefineController : BaseController { private ISampleTestDefineService service; public SampleTestDefineController(ISampleTestDefineService _service) { service = _service; } // // GET: /Menu/ public ActionResult Index() { return View(); } /// /// 获取抽样管理列表数据 /// /// /// /// /// /// public ActionResult GetListByPage(String typeName, String modelName, Pager pager, String direction, String sort) { Hashtable result = new Hashtable(); result.Add("pager.pageNo", pager.pageNo); Hashtable dataHt = this.service.GetListByPage(typeName, modelName, 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 GetSelectModelType() { Hashtable result = new Hashtable(); List list = this.service.GetSelectModelType(); result.Add("list", list); return Json(result); } /// /// 获取父节点抽样下拉列表数据 /// /// public ActionResult GetSelectModel() { Hashtable result = new Hashtable(); List list = this.service.GetSelectModel(); result.Add("list", list); return Json(result); } /// /// 保存抽样数据 /// /// public ActionResult Save() { String editType = Request.Form["editType"].ToString(); String testplanId = Request.Form["testplanId"].ToString(); String modelId = Request.Form["modelId"].ToString(); String startDate = Request.Form["startDate"].ToString(); String endDate = Request.Form["endDate"].ToString(); String lotQty = Request.Form["lotQty"].ToString(); String enabled = Request.Form["enabled"].ToString(); GAbTestplan gAbTestplan = new GAbTestplan(); gAbTestplan.ModelId = Convert.ToInt32(modelId); gAbTestplan.StartDate = startDate; gAbTestplan.EndDate = endDate; gAbTestplan.LotQty =Convert.ToInt32( lotQty); gAbTestplan.Enabled = enabled; String message = ""; if (editType != null && editType.Trim().Equals("edit")) { try { gAbTestplan.UpdateUserId = CurrentEmp.EmpId; gAbTestplan.TestplanId = Convert.ToInt32(testplanId); this.service.Update(gAbTestplan); message = "修改成功"; } catch (Exception e) { message = "修改失败!"; } } else { try { gAbTestplan.CreateUserId = CurrentEmp.EmpId; this.service.Insert(gAbTestplan); message = "添加成功"; } catch (Exception e) { message = "添加失败!"; } } Hashtable result = new Hashtable(); result.Add("message", message); return Json(result); } /// /// 查看抽样详情 /// /// /// public ActionResult GetDetail(String testplanId) { List Info = this.service.GetDetail(testplanId); ViewData.Add("typeName", Info[0].TypeName); ViewData.Add("modelName", Info[0].ModelName); ViewData.Add("startDate", Info[0].StartDate); ViewData.Add("endDate", Info[0].EndDate); ViewData.Add("lotQty", Info[0].LotQty); ViewData.Add("qty", Info[0].Qty); ViewData.Add("locationCounter", Info[0].LocationCounter); ViewData.Add("enabled", Info[0].Enabled); return View("viewSampleTestDefine"); } /// /// 编辑抽样 /// /// /// public ActionResult Edit(String testplanId) { if (!string.IsNullOrEmpty(testplanId)) { List Info = this.service.GetDetail(testplanId); ViewData.Add("editType", "edit"); ViewData.Add("testplanId", testplanId); ViewData.Add("modelId", Info[0].ModelId); ViewData.Add("startDate", Info[0].StartDate); ViewData.Add("endDate", Info[0].EndDate); ViewData.Add("lotQty", Info[0].LotQty); ViewData.Add("enabled", Info[0].Enabled); } else { ViewData.Add("editType", "new"); } return View("editSampleTestDefine"); } /// /// 删除抽样 /// /// /// public ActionResult Delete(String ids) { int delCount = 0; try { delCount = this.service.Delete(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); } /// /// 导出EXCEL /// /// public ActionResult ExportInfo(String typeName, String modelName) { Workbook workbook = this.service.ExportInfo(typeName, modelName); if (workbook != null) { ////直接导出 //Stream outputStream = Response.OutputStream; //workbook.Save(outputStream, FileFormatType.Default); //Response.Buffer = true; //Response.AppendHeader("Content-Disposition", "attachment;filename=BOMInfo.xls"); //Response.ContentEncoding = System.Text.Encoding.UTF8; //Response.ContentType = "application/vnd.ms-excel"; //Response.Flush(); } return Json(""); } } }