using MESClassLibrary.BLL; using MESClassLibrary.BLL.BasicInfo; using MESClassLibrary.EFModel; using MESClassLibrary.Model; using MESWebSite.CommonClass; using MESWebSite.Export; using MESWebSite.Manage; using MESWebSite.Tool; using NPOI.XSSF.UserModel; using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Web; namespace MESWebSite.HttpHandlers { /// /// ZP_MK_PlanHandler 的摘要说明 /// public class ZP_MK_PlanHandler : BaseHandler { public ZP_MK_PlanHandler() : base() { RegisterAction(ExportExcel); } protected override void DelInfo() { string ID = GetParam("ID"); ZP_MK_PlanBLL bll = new ZP_MK_PlanBLL(); Response.Write(bll.DeleteInfo(new tb_ZP_MK_Plan() { ID = int.Parse(ID) }) ? ResponseResult.Success() : ResponseResult.Fail("删除失败")); Response.End(); } protected override void QueryList() { string StartTime = GetParam("StartTime"); string EndTime = GetParam("EndTime"); string PartNo = GetParam("PartNo"); int page = Page.To32Int(); int pageSize = Rows.To32Int(); ZP_MK_PlanBLL bll = new ZP_MK_PlanBLL(); string reslut = bll.SearchInfoAll(page, pageSize, StartTime, EndTime, PartNo); Response.Write(reslut); Response.End(); } protected override void SaveInfo() { string id = GetParam("ID"); //string stationID = GetParam("StationID"); string partNo = GetParam("PartNo"); int orderCount = GetParam("OrderCount").To32Int(); string orderName = GetParam("OrderName"); string line = GetParam("Line"); string station = GetParam("Station"); DateTime orderDate; if (!DateTime.TryParse(GetParam("OrderDate"), out orderDate)) { Response.Write(ResponseResult.Fail("装配日期错误!")); Response.End(); return; }; string lineName = ""; BasicBLL lineDB = new BasicBLL(); var lineList = lineDB.Search(p => p.LineName == line); if (lineList != null && lineList.Count > 0) { lineName = lineList[0].LineName; } if (string.IsNullOrEmpty(lineName)) { Response.Write(ResponseResult.Fail("产线不存在!")); Response.End(); return; } string stationNo = ""; BasicBLL stationDB = new BasicBLL(); var stationList = stationDB.Search(p => p.StationNo == station); if (stationList != null && stationList.Count > 0) { stationNo = stationList[0].StationNo; } if (string.IsNullOrEmpty(stationNo)) { Response.Write(ResponseResult.Fail("工位号不存在!")); Response.End(); return; } string partNo1 = ""; BasicBLL partNo1DB = new BasicBLL(); var partNo1List = partNo1DB.Search(p => p.PartNo1 == partNo); if (partNo1List != null && partNo1List.Count > 0) { partNo1 = partNo1List[0].StationNo; } if (string.IsNullOrEmpty(partNo1)) { Response.Write(ResponseResult.Fail(partNo + " 产品名称未在Bom中配置!")); Response.End(); return; } ZP_MK_PlanBLL bll = new ZP_MK_PlanBLL(); tb_ZP_MK_Plan zpp = new tb_ZP_MK_Plan { ID = int.Parse(id), PartNo = partNo, OrderDate = orderDate, OrderCount = orderCount, OrderName = orderName, Line = line, Station = station, }; //DataTable dt = bll.SearchOrderNo(DateTime.Now.ToString("yyyMMdd")); //if (dt != null && dt.Rows.Count > 0) //{ // string old = dt.Rows[0]["OrderNo"].ToString(); // zpp.OrderNo = DateTime.Now.ToString("yyyMMdd") + (Convert.ToInt32(old.Substring(old.Length - 4, 4))+1).ToString().PadLeft(4,'0'); //} //else //{ // zpp.OrderNo = DateTime.Now.ToString("yyyMMdd") + "0001"; //} if (id == "0") { Response.Write(bll.AddInfo(zpp) ? ResponseResult.Success() : ResponseResult.Fail("添加失败")); } else { string msg = string.Empty; Response.Write(bll.UpdateInfo(zpp, ref msg) ? ResponseResult.Success() : ResponseResult.Fail(msg)); } Response.End(); } public void ExportExcel() { string StartTime = GetParam("StartTime"); string EndTime = GetParam("EndTime"); string PartNo = GetParam("PartNo"); ZP_MK_PlanBLL bll = new ZP_MK_PlanBLL(); List result = bll.SearchByCreateTime(StartTime, EndTime, PartNo); ExcelTool excelTool = new ExcelTool(); XSSFWorkbook book = excelTool.Export(result, typeof(ExportZP_MK_Plan)); using (MemoryStream ms = new MemoryStream()) { book.Write(ms); Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}.xlsx", DateTime.Now.ToString("yyyyMMddHHmmssfff"))); Response.BinaryWrite(ms.ToArray()); Response.End(); } } } }