一厂MES,含注塑,喷涂,冲孔
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

304 lines
9.5 KiB

3 months ago
using MESClassLibrary.BLL.BasicInfo;
using MESClassLibrary.EFModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
namespace MESWebSite.HttpHandlers
{
/// <summary>
/// ModelInfoHandler 的摘要说明
/// </summary>
public class ModelInfoHandler : IHttpHandler
{
HttpRequest Request = null;
HttpResponse Response = null;
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
Request = context.Request;
Response = context.Response;
string method = Request.Params["method"];
switch (method)
{
case "QueryList":
QueryList();
break;
case "SaveInfo":
SaveInfo();
break;
case "DelInfo":
DelInfo();
break;
case "QueryUpdateList":
QueryUpdateList();
break;
case "SaveUpdateInfo":
SaveUpdateInfo();
break;
case "DelUpdateInfo":
DelUpdateInfo();
break;
case "QueryForCombobox":
QueryForCombobox();
break;
case "GetComboboxDataForModelNo":
GetComboboxDataForModelNo();
break;
case "QueryExcel":
QueryExcel();
break;
case "QueryExcel1":
QueryExcel1();
break;
default:
break;
}
}
public bool IsReusable
{
get
{
return false;
}
}
void QueryList()
{
string page = Request.Params["page"];
string pagesize = Request.Params["rows"];
string ModelNo = Request.Params["ModelNo"];
if (string.IsNullOrEmpty(page))
{
page = "0";
}
if (string.IsNullOrEmpty(pagesize))
{
pagesize = "15";
}
ModelInfoBLL bll = new ModelInfoBLL();
Response.Write(bll.SearchInfoAll(page, pagesize, ModelNo));
Response.End();
}
void SaveInfo()
{
string ID = Request.Params["ID"];
string ModelName = Request.Params["ModelName"];
string ModelNo = Request.Params["ModelNo"];
string PermanentAssetsNo = Request.Params["PermanentAssetsNo"];
string Tonnage = Request.Params["Tonnage"];
string ServiceLife = Request.Params["ServiceLife"];
string Supplier = Request.Params["Supplier"];
string PartWeight = Request.Params["PartWeight"];
string InjectionPeriod = Request.Params["InjectionPeriod"];
string LocatingRingSize = Request.Params["LocatingRingSize"];
string OutForm = Request.Params["OutForm"];
string ModelWeight = Request.Params["ModelWeight"];
string RunnerForm = Request.Params["RunnerForm"];
string ModelCavityNo = Request.Params["ModelCavityNo"];
string ModelSize = Request.Params["ModelSize"];
ModelInfoBLL bll = new ModelInfoBLL();
tb_ModelInfo md = new tb_ModelInfo();
md.ModelName = ModelName;
md.ModelNo = ModelNo;
md.PermanentAssetsNo = PermanentAssetsNo;
md.Tonnage = Tonnage;
md.ServiceLife = ServiceLife;
md.Supplier = Supplier;
md.PartWeight = PartWeight;
md.InjectionPeriod = InjectionPeriod;
md.LocatingRingSize = LocatingRingSize;
md.OutForm = OutForm;
md.ModelWeight = ModelWeight;
md.RunnerForm = RunnerForm;
md.ModelCavityNo = ModelCavityNo;
md.ModelSize = ModelSize;
var info = Request.Cookies.Get("LoginUserInfo");
if (info != null)
{
md.UserID = info["UserID"].ToUpper();
}
if (ID == "0")
{
//新增
md.ID = Guid.NewGuid().ToString();
Response.Write(bll.AddInfo(md) == true ? "true" : "false");
}
else
{
//修改
md.ID = ID;
Response.Write(bll.UpdateInfo(md) == true ? "true" : "false");
}
Response.End();
}
void DelInfo()
{
string ID = Request.Params["ID"];
ModelInfoBLL bll = new ModelInfoBLL();
tb_ModelInfo md = new tb_ModelInfo();
md.ID = ID;
var info = Request.Cookies.Get("LoginUserInfo");
if (info != null)
{
md.UserID = info["UserID"].ToUpper();
}
Response.Write(bll.DeleteInfo(md) == true ? "true" : "false");
Response.End();
}
void QueryUpdateList()
{
string page = Request.Params["page"];
string pagesize = Request.Params["rows"];
string ModelID = Request.Params["ModelID"];
if (string.IsNullOrEmpty(page))
{
page = "0";
}
if (string.IsNullOrEmpty(pagesize))
{
pagesize = "15";
}
ModelUpdateBLL bll = new ModelUpdateBLL();
Response.Write(bll.SearchInfoAll(page, pagesize, ModelID));
Response.End();
}
void SaveUpdateInfo()
{
string ModelID = Request.Params["ModelID"];
string Purpose = Request.Params["Purpose"];
string State = Request.Params["State"];
string Supplier = Request.Params["Supplier_u"];
string Remarks = Request.Params["Remarks"];
string AddTime = Request.Params["AddTime"];
ModelUpdateBLL bll = new ModelUpdateBLL();
tb_Model_Update md = new tb_Model_Update();
md.ModelID = ModelID;
md.Purpose = Purpose;
md.State = State;
md.Supplier = Supplier;
md.Remarks = Remarks;
md.AddTime = AddTime != null ? Convert.ToDateTime(AddTime) : DateTime.Now;
//新增
md.ID = Guid.NewGuid().ToString();
Response.Write(bll.AddUpdateInfo(md) == true ? "true" : "false");
Response.End();
}
void DelUpdateInfo()
{
string ID = Request.Params["ID"];
ModelUpdateBLL bll = new ModelUpdateBLL();
tb_Model_Update md = new tb_Model_Update();
md.ID = ID;
Response.Write(bll.DeleteInfo(md) == true ? "true" : "false");
Response.End();
}
void QueryForCombobox()
{
ModelInfoBLL bll = new ModelInfoBLL();
Response.Write(bll.GetComboboxData());
Response.End();
}
void GetComboboxDataForModelNo()
{
ModelInfoBLL bll = new ModelInfoBLL();
Response.Write(bll.GetComboboxDataForModelNo());
Response.End();
}
void QueryExcel()
{
//string page = Request.Params["page"];
//string pagesize = Request.Params["rows"];
string ProductName = Request.Params["ProductName"];
string ModelNo = Request.Params["ModelNo"];
ModelProductBLL bll=new ModelProductBLL();
List<List<string>> list = bll.SearchForExcel(ProductName, ModelNo);
XSSFWorkbook book = new XSSFWorkbook();
ISheet sheet = book.CreateSheet("Sheet1");
for (int i = 0; i < list.Count; i++)
{
IRow row = sheet.CreateRow(i);
for (int k = 0; k < list[i].Count; k++)
{
row.CreateCell(k).SetCellValue(list[i][k].ToString());
}
}
// 写入到客户端
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());
book = null;
ms.Close();
ms.Dispose();
}
void QueryExcel1()
{
string ModelNo = Request.Params["ModelNo"];
ModelInfoBLL bll = new ModelInfoBLL();
List<List<string>> list = bll.SearchForExcel( ModelNo);
XSSFWorkbook book = new XSSFWorkbook();
ISheet sheet = book.CreateSheet("Sheet1");
for (int i = 0; i < list.Count; i++)
{
IRow row = sheet.CreateRow(i);
for (int k = 0; k < list[i].Count; k++)
{
row.CreateCell(k).SetCellValue(list[i][k].ToString());
}
}
// 写入到客户端
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());
book = null;
ms.Close();
ms.Dispose();
}
}
}