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.
280 lines
9.1 KiB
280 lines
9.1 KiB
using MESClassLibrary.BLL;
|
|
using MESClassLibrary.BLL.BasicInfo;
|
|
using MESClassLibrary.EFModel;
|
|
using MESWebSite.CommonClass;
|
|
using NPOI.SS.UserModel;
|
|
using NPOI.XSSF.UserModel;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Web;
|
|
|
|
namespace MESWebSite.HttpHandlers
|
|
{
|
|
/// <summary>
|
|
/// Bom_MKHandler 的摘要说明
|
|
/// </summary>
|
|
public class Bom_MKHandler : 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 "QueryExcel":
|
|
QueryExcel();
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
public bool IsReusable
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
void QueryList()
|
|
{
|
|
string page = Request.Params["page"];
|
|
string pagesize = Request.Params["rows"];
|
|
string partNo1 = Request.Params["PartNo1"];
|
|
string partNo2 = Request.Params["PartNo2"];
|
|
string lineName = Request.Params["LineName"];
|
|
|
|
if (string.IsNullOrEmpty(page))
|
|
{
|
|
page = "0";
|
|
}
|
|
if (string.IsNullOrEmpty(pagesize))
|
|
{
|
|
pagesize = "15";
|
|
}
|
|
Bom_MKBLL bll = new Bom_MKBLL();
|
|
Response.Write(bll.SearchInfoAll(page, pagesize, partNo1, partNo2, lineName));
|
|
Response.End();
|
|
|
|
|
|
}
|
|
void SaveInfo()
|
|
{
|
|
string BomID = Request.Params["BomID"];
|
|
string PartNo1 = Request.Params["PartNo1"];
|
|
string PartNo2 = Request.Params["PartNo2"];
|
|
string IsChecked = Request.Params["IsChecked"];
|
|
string IsPartAssemble = Request.Params["IsPartAssemble"];
|
|
string StationNo = Request.Params["StationNo"];
|
|
string LineName = Request.Params["LineName"];
|
|
string LeftCount = Request.Params["LeftCount"];
|
|
string RightCount = Request.Params["RightCount"];
|
|
string ProductName1 = Request.Params["ProductName1"];
|
|
string ProductName2 = Request.Params["ProductName2"];
|
|
|
|
if(string.IsNullOrEmpty(LeftCount))
|
|
{
|
|
LeftCount = "0";
|
|
}
|
|
if (string.IsNullOrEmpty(RightCount))
|
|
{
|
|
RightCount = "0";
|
|
}
|
|
|
|
|
|
string lineName = "";
|
|
BasicBLL<tb_Line> lineNameDB = new BasicBLL<tb_Line>();
|
|
var lineNameList = lineNameDB.Search<tb_Line>(p => p.LineName == LineName);
|
|
if (lineNameList != null && lineNameList.Count > 0)
|
|
{
|
|
lineName = lineNameList[0].LineName;
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(lineName))
|
|
{
|
|
Response.Write(ResponseResult.Fail("产线不存在!"));
|
|
Response.End();
|
|
return;
|
|
}
|
|
|
|
string stationNo = "";
|
|
BasicBLL<tb_Station> stationDB = new BasicBLL<tb_Station>();
|
|
var stationList = stationDB.Search<tb_Station>(p => p.StationNo == StationNo);
|
|
if (stationList != null && stationList.Count > 0)
|
|
{
|
|
stationNo = stationList[0].StationNo;
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(stationNo))
|
|
{
|
|
Response.Write(ResponseResult.Fail("工位号不存在!"));
|
|
Response.End();
|
|
return;
|
|
}
|
|
|
|
//一个总成对应一个半成品
|
|
BasicBLL<tb_Bom_MK> partAssembleNum = new BasicBLL<tb_Bom_MK>();
|
|
int id_mk = int.Parse(BomID);
|
|
var partAssembleList = partAssembleNum.Search<tb_Bom_MK>(p => p.PartNo1 == PartNo1 && p.IsPartAssemble == 1 && p.BomID != id_mk);
|
|
if (partAssembleList != null && partAssembleList.Count == 1 && IsPartAssemble == "1")
|
|
{
|
|
Response.Write(ResponseResult.Fail("一个总成只能配置一个半成品!"));
|
|
Response.End();
|
|
return;
|
|
}
|
|
|
|
//查询产品描述
|
|
BasicBLL<tb_Product> productDesc = new BasicBLL<tb_Product>();
|
|
var productDescList = productDesc.Search<tb_Product>(p => p.PartNo == PartNo1);
|
|
if (productDescList != null && productDescList.Count >= 1 )
|
|
{
|
|
ProductName1 = productDescList[0].ProductName;
|
|
}
|
|
else
|
|
{
|
|
Response.Write(ResponseResult.Fail("总成零件号:" + PartNo1 +" 产品信息不存在"));
|
|
Response.End();
|
|
return;
|
|
}
|
|
|
|
productDescList = productDesc.Search<tb_Product>(p => p.PartNo == PartNo2);
|
|
if (productDescList != null && productDescList.Count >= 1)
|
|
{
|
|
ProductName2 = productDescList[0].ProductName;
|
|
}
|
|
else
|
|
{
|
|
Response.Write(ResponseResult.Fail("子零件号:" + PartNo2 + " 产品信息不存在"));
|
|
Response.End();
|
|
return;
|
|
}
|
|
|
|
|
|
Bom_MKBLL bll = new Bom_MKBLL();
|
|
tb_Bom_MK md = new tb_Bom_MK();
|
|
|
|
md.PartNo1 = PartNo1;
|
|
md.PartNo2 = PartNo2;
|
|
md.LineName = LineName;
|
|
md.StationNo = StationNo;
|
|
md.LeftCount = int.Parse(LeftCount);
|
|
md.RightCount = int.Parse(RightCount);
|
|
md.PartDesc1 = ProductName1;
|
|
md.PartDesc2 = ProductName2;
|
|
|
|
if (IsPartAssemble == "1")
|
|
{
|
|
md.IsPartAssemble = 1;
|
|
}
|
|
else
|
|
{
|
|
md.IsPartAssemble = 0;
|
|
}
|
|
|
|
if (IsChecked == "1")
|
|
{
|
|
md.IsChecked = true;
|
|
}
|
|
|
|
var info = Request.Cookies.Get("LoginUserInfo");
|
|
if (info != null)
|
|
{
|
|
md.UserID = info["UserID"].ToUpper();
|
|
}
|
|
|
|
if (BomID == "0")
|
|
{
|
|
BasicBLL<tb_Bom_MK> partNoBindDB = new BasicBLL<tb_Bom_MK>();
|
|
var partNo1List = partNoBindDB.Search<tb_Bom_MK>(p => p.PartNo1 == PartNo1 && p.PartNo2 == PartNo2 && p.LineName == LineName && p.StationNo == StationNo);
|
|
if (partNo1List != null && partNo1List.Count > 0)
|
|
{
|
|
Response.Write(ResponseResult.Fail("BOM总成零件号与子零件号绑定关系在系统中已存在"));
|
|
Response.End();
|
|
return;
|
|
}
|
|
|
|
//新增
|
|
//md.BomID = Guid.NewGuid().ToString();
|
|
Response.Write(bll.AddInfo(md) == true ? ResponseResult.Success() : ResponseResult.Fail("添加失败"));
|
|
}
|
|
else
|
|
{
|
|
//修改
|
|
md.BomID = int.Parse(BomID);
|
|
Response.Write(bll.UpdateInfo(md) == true ? ResponseResult.Success() : ResponseResult.Fail("更新失败"));
|
|
}
|
|
Response.End();
|
|
}
|
|
void DelInfo()
|
|
{
|
|
string BomID = Request.Params["BomID"];
|
|
|
|
Bom_MKBLL bll = new Bom_MKBLL();
|
|
tb_Bom_MK md = new tb_Bom_MK();
|
|
md.BomID = int.Parse(BomID);
|
|
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 QueryExcel()
|
|
{
|
|
string PartNo1 = Request.Params["PartNo1"];
|
|
string LineName = Request.Params["LineName"];
|
|
|
|
Bom_MKBLL bll = new Bom_MKBLL();
|
|
|
|
List<List<string>> list = bll.SearchForExcel(PartNo1, LineName);
|
|
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();
|
|
}
|
|
|
|
}
|
|
}
|