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.
377 lines
16 KiB
377 lines
16 KiB
2 months ago
|
using MESClassLibrary.BLL.BasicInfo;
|
||
|
using MESClassLibrary.BLL.Log;
|
||
|
using MESClassLibrary.BLL.Plan247;
|
||
|
using MESClassLibrary.EFModel;
|
||
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Data;
|
||
|
using System.Data.OleDb;
|
||
|
using System.IO;
|
||
|
using System.Linq;
|
||
|
using System.Reflection;
|
||
|
using System.Web;
|
||
|
using System.Web.UI;
|
||
|
using System.Web.UI.WebControls;
|
||
|
|
||
|
namespace MESWebSite.Manage
|
||
|
{
|
||
|
public partial class Product : System.Web.UI.Page
|
||
|
{
|
||
|
protected void Page_Load(object sender, EventArgs e)
|
||
|
{
|
||
|
if (Request.Cookies["LoginUserInfo"] == null)
|
||
|
{
|
||
|
Response.Write("<script language=javascript>alert('您的登录信息已过期,请重新登录!');top.location.href='../Login.aspx';</script>");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void ImportPDF_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
if (input02.PostedFile.ContentLength > 0)
|
||
|
{
|
||
|
string strUrl = "../PDF/";
|
||
|
if (Directory.Exists(Server.MapPath(strUrl)) == false)
|
||
|
{
|
||
|
Directory.CreateDirectory(Server.MapPath(strUrl));
|
||
|
}
|
||
|
String fileExtension = System.IO.Path.GetExtension(input02.PostedFile.FileName).ToLower();
|
||
|
String fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + fileExtension;
|
||
|
input02.PostedFile.SaveAs(Server.MapPath(strUrl) + fileName);
|
||
|
|
||
|
|
||
|
ProductBLL bll = new ProductBLL();
|
||
|
if (bll.UpdatePDF(this.lb_ID.Value, fileName))
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
}
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
public void ImportExcel_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
if (input01.PostedFile.ContentLength > 0)
|
||
|
{
|
||
|
string strUrl = "../Excel/";
|
||
|
if (Directory.Exists(Server.MapPath(strUrl)) == false)
|
||
|
{
|
||
|
Directory.CreateDirectory(Server.MapPath(strUrl));
|
||
|
}
|
||
|
String fileExtension = System.IO.Path.GetExtension(input01.PostedFile.FileName).ToLower();
|
||
|
String fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + fileExtension;
|
||
|
input01.PostedFile.SaveAs(Server.MapPath(strUrl) + fileName);
|
||
|
string excelPath = Server.MapPath(strUrl) + fileName;
|
||
|
DataTable dt = null;
|
||
|
#region 校验文件
|
||
|
try
|
||
|
{
|
||
|
|
||
|
dt = GetExcelTableByOleDB(excelPath, "Sheet1");
|
||
|
|
||
|
if (dt != null && dt.Rows.Count > 1)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ClientScript.RegisterStartupScript(this.GetType(), "tishi", "<script type='text/javascript'>$.messager.alert('提示', '模板内容为空', 'warning');</script>");
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
#endregion
|
||
|
ProductBLL bll = new ProductBLL();
|
||
|
List<tb_Product> list = new List<tb_Product>();
|
||
|
#region 校验数据
|
||
|
if (dt != null && dt.Rows.Count > 0)
|
||
|
{
|
||
|
for (int i = 1; i < dt.Rows.Count; i++)
|
||
|
{
|
||
|
#region 值校验
|
||
|
string StockNo = dt.Rows[i][1].ToString();
|
||
|
if (StockNo == "")
|
||
|
{
|
||
|
ClientScript.RegisterStartupScript(this.GetType(), "tishi", "<script type='text/javascript'>$.messager.alert('提示', '第" + i.ToString() + "行,存货代码为空,故无法导入', 'warning');</script>");
|
||
|
return;
|
||
|
}
|
||
|
string ProductTypeID = dt.Rows[i][0].ToString();
|
||
|
if (ProductTypeID == "")
|
||
|
{
|
||
|
ClientScript.RegisterStartupScript(this.GetType(), "tishi", "<script type='text/javascript'>$.messager.alert('提示', '第" + i.ToString() + "行,产品类型为空,故无法导入', 'warning');</script>");
|
||
|
return;
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 业务逻辑校验
|
||
|
string PartNo = dt.Rows[i][6].ToString();
|
||
|
if (bll.SearchIntByStockNoAndPartNo(StockNo, PartNo) > 0)
|
||
|
{
|
||
|
ClientScript.RegisterStartupScript(this.GetType(), "tishi", "<script type='text/javascript'>$.messager.alert('提示', '第" + i.ToString() + "行,该存货代码和零件号系统中已存在,故无法导入', 'warning');</script>");
|
||
|
return;
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
|
||
|
|
||
|
string CarTypeID = dt.Rows[i][2].ToString();
|
||
|
|
||
|
CarTypeBLL carTypeBLL = new CarTypeBLL();
|
||
|
DataTable dt_carType = carTypeBLL.SearchInfo(CarTypeID);
|
||
|
if (dt_carType != null && dt_carType.Rows.Count > 0)
|
||
|
{
|
||
|
CarTypeID = dt_carType.Rows[0]["ID"].ToString();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ClientScript.RegisterStartupScript(this.GetType(), "tishi", "<script type='text/javascript'>$.messager.alert('提示', '第" + i.ToString() + "行,车型无对应数据,故无法导入', 'warning');</script>");
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
|
||
|
ProductTypeBLL productTypeBll = new ProductTypeBLL();
|
||
|
var info_productType = productTypeBll.SearchInfoByName(ProductTypeID);
|
||
|
if (info_productType != null)
|
||
|
{
|
||
|
ProductTypeID = info_productType.ProductTypeID;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ClientScript.RegisterStartupScript(this.GetType(), "tishi", "<script type='text/javascript'>$.messager.alert('提示', '第" + i.ToString() + "行,产品类型无对应数据,故无法导入', 'warning');</script>");
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
string isImport = dt.Rows[i][3].ToString();
|
||
|
if (isImport == "是")
|
||
|
{
|
||
|
isImport = "1";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
isImport = "0";
|
||
|
}
|
||
|
string ProductName = dt.Rows[i][4].ToString();
|
||
|
string ColorName = dt.Rows[i][5].ToString();
|
||
|
string Rows = dt.Rows[i][7].ToString();
|
||
|
string Cols = dt.Rows[i][8].ToString();
|
||
|
string Layers = dt.Rows[i][9].ToString();
|
||
|
string Des = dt.Rows[i][10].ToString();
|
||
|
string PackCount = dt.Rows[i][11].ToString();
|
||
|
string OpenFailNum = dt.Rows[i][12].ToString();
|
||
|
string qLevel = dt.Rows[i][13].ToString();
|
||
|
string BackPlatingNum = dt.Rows[i][14].ToString();
|
||
|
string customerNo = dt.Rows[i][15].ToString();
|
||
|
string carModelCode = dt.Rows[i][16].ToString();
|
||
|
string colorCodeB = dt.Rows[i][17].ToString();
|
||
|
string isPrintOneTag = dt.Rows[i][18].ToString();
|
||
|
if (isPrintOneTag == "是")
|
||
|
{
|
||
|
isPrintOneTag = "1";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
isPrintOneTag = "0";
|
||
|
}
|
||
|
string isSupply = dt.Rows[i][19].ToString();
|
||
|
if (isSupply == "是")
|
||
|
{
|
||
|
isSupply = "1";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
isSupply = "0";
|
||
|
}
|
||
|
string isPrintPackList = dt.Rows[i][20].ToString();
|
||
|
if (isPrintPackList == "是")
|
||
|
{
|
||
|
isPrintPackList = "1";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
isPrintPackList = "0";
|
||
|
}
|
||
|
string isOneMore = dt.Rows[i][21].ToString();
|
||
|
if (isOneMore == "是")
|
||
|
{
|
||
|
isOneMore = "1";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
isOneMore = "0";
|
||
|
}
|
||
|
string IsSame = dt.Rows[i][22].ToString();
|
||
|
if (IsSame == "是")
|
||
|
{
|
||
|
IsSame = "1";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
IsSame = "0";
|
||
|
}
|
||
|
string isPlating = dt.Rows[i][23].ToString();
|
||
|
if (isPlating == "是")
|
||
|
{
|
||
|
isPlating = "1";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
isPlating = "0";
|
||
|
}
|
||
|
|
||
|
var info = Request.Cookies.Get("LoginUserInfo");
|
||
|
if (info != null)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
tb_Product md = new tb_Product();
|
||
|
md.ProductID = Guid.NewGuid().ToString();
|
||
|
md.ProductTypeID = ProductTypeID;
|
||
|
md.CarTypeID = CarTypeID;
|
||
|
md.StockNo = StockNo;
|
||
|
md.ProductName = ProductName;
|
||
|
md.ColorName = ColorName;
|
||
|
md.PartNo = PartNo;
|
||
|
md.Rows = Rows == "" ? 0 : Convert.ToInt32(Rows);
|
||
|
md.Cols = Cols == "" ? 0 : Convert.ToInt32(Cols);
|
||
|
md.Layers = Layers == "" ? 0 : Convert.ToInt32(Layers);
|
||
|
md.PackCount = PackCount == "" ? 0 : Convert.ToInt32(PackCount);
|
||
|
md.Des = Des;
|
||
|
md.isImport = isImport == "" ? 0 : Convert.ToInt32(isImport);
|
||
|
md.OpenFailNum = OpenFailNum == "" ? 0 : Convert.ToInt32(OpenFailNum);
|
||
|
md.QLevel = qLevel;
|
||
|
md.IsPrintOneTag = isPrintOneTag;
|
||
|
md.IsPrintPackList = isPrintPackList;
|
||
|
md.IsSupply = isSupply;
|
||
|
md.IsOneMore = isOneMore;
|
||
|
md.BackPlatingNum = BackPlatingNum == "" ? 0 : Convert.ToInt32(BackPlatingNum);
|
||
|
md.IsPlating = isPlating;
|
||
|
md.IsSame = IsSame == "" ? 0 : Convert.ToInt32(IsSame);
|
||
|
md.CustomerNo = customerNo;
|
||
|
md.CarModelCode = carModelCode;
|
||
|
md.ColorCodeB = colorCodeB;
|
||
|
md.UserID = info["UserID"].ToUpper();
|
||
|
list.Add(md);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 存储数据
|
||
|
try
|
||
|
{
|
||
|
bool flag = false;
|
||
|
if (list.Count > 0)
|
||
|
{
|
||
|
foreach (var item in list)
|
||
|
{
|
||
|
flag= bll.AddInfo(item);
|
||
|
}
|
||
|
}
|
||
|
if (flag == true)
|
||
|
{
|
||
|
ClientScript.RegisterStartupScript(this.GetType(), "tishi", "<script type='text/javascript'>$.messager.alert('提示','导入成功!', 'warning');</script>");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ClientScript.RegisterStartupScript(this.GetType(), "tishi", "<script type='text/javascript'>$.messager.alert('提示','导入失败!', 'warning');</script>");
|
||
|
}
|
||
|
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
}
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
public DataTable GetExcelTableByOleDB(string strExcelPath, string tableName)
|
||
|
{
|
||
|
OleDbConnection objConn = null;
|
||
|
try
|
||
|
{
|
||
|
DataTable dtExcel = new DataTable();
|
||
|
//数据表
|
||
|
DataSet ds = new DataSet();
|
||
|
//获取文件扩展名
|
||
|
string strExtension = System.IO.Path.GetExtension(strExcelPath);
|
||
|
string strFileName = System.IO.Path.GetFileName(strExcelPath);
|
||
|
//Excel的连接
|
||
|
|
||
|
switch (strExtension)
|
||
|
{
|
||
|
case ".xls":
|
||
|
objConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strExcelPath + ";" + "Extended Properties=\"Excel 8.0;HDR=NO;IMEX=1;\"");
|
||
|
break;
|
||
|
case ".xlsx":
|
||
|
objConn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strExcelPath + ";" + "Extended Properties=\"Excel 12.0;HDR=NO;IMEX=1;\"");
|
||
|
break;
|
||
|
|
||
|
default:
|
||
|
objConn = null;
|
||
|
break;
|
||
|
}
|
||
|
if (objConn == null)
|
||
|
{
|
||
|
return null;
|
||
|
}
|
||
|
try
|
||
|
{
|
||
|
objConn.Open();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
//获取Excel中所有Sheet表的信息
|
||
|
//System.Data.DataTable schemaTable = objConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);
|
||
|
//获取Excel的第一个Sheet表名
|
||
|
//string tableName = schemaTable.Rows[0][2].ToString().Trim();
|
||
|
string strSql = "select * from [" + tableName + "$]";
|
||
|
//获取Excel指定Sheet表中的信息
|
||
|
OleDbCommand objCmd = new OleDbCommand(strSql, objConn);
|
||
|
OleDbDataAdapter myData = new OleDbDataAdapter(strSql, objConn);
|
||
|
myData.Fill(ds, tableName);//填充数据
|
||
|
objConn.Close();
|
||
|
//dtExcel即为excel文件中指定表中存储的信息
|
||
|
dtExcel = ds.Tables[tableName];
|
||
|
return dtExcel;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
if (objConn != null)
|
||
|
{
|
||
|
objConn.Close();
|
||
|
}
|
||
|
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|