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.
256 lines
10 KiB
256 lines
10 KiB
using MESClassLibrary.BLL.BasicInfo;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using MESClassLibrary.BLL.Log;
|
|
using MESClassLibrary.EFModel;
|
|
using MESWebSite.Tool;
|
|
|
|
namespace MESWebSite.Manage
|
|
{
|
|
public partial class Product : System.Web.UI.Page
|
|
{
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
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)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
|
|
protected void Button1_OnClick(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 = 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;
|
|
|
|
ProductBLL bll = new ProductBLL();
|
|
List<tb_Product> list = new List<tb_Product>();
|
|
|
|
|
|
#region 校验文件
|
|
|
|
try
|
|
{
|
|
dt = ExcelTool.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)
|
|
{
|
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
|
return;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 校验数据
|
|
|
|
if (dt != null && dt.Rows.Count > 1)
|
|
{
|
|
for (int i = 1; i < dt.Rows.Count; i++)
|
|
{
|
|
#region 值校验
|
|
|
|
string productType = dt.Rows[i][0].ToString();
|
|
if (productType == "")
|
|
{
|
|
ClientScript.RegisterStartupScript(this.GetType(), "tishi",
|
|
"<script type='text/javascript'>$.messager.alert('提示', '第" + i.ToString() +
|
|
"行,产品类型为空,故无法导入', 'warning');</script>");
|
|
return;
|
|
}
|
|
|
|
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 productName = dt.Rows[i][2].ToString();
|
|
if (productName == "")
|
|
{
|
|
ClientScript.RegisterStartupScript(this.GetType(), "tishi",
|
|
"<script type='text/javascript'>$.messager.alert('提示', '第" + i.ToString() +
|
|
"行,产品名称为空,故无法导入', 'warning');</script>");
|
|
return;
|
|
}
|
|
|
|
string colorName = dt.Rows[i][3].ToString();
|
|
|
|
string partNo = dt.Rows[i][4].ToString();
|
|
if (partNo == "")
|
|
{
|
|
ClientScript.RegisterStartupScript(this.GetType(), "tishi",
|
|
"<script type='text/javascript'>$.messager.alert('提示', '第" + i.ToString() +
|
|
"行,零件号为空,故无法导入', 'warning');</script>");
|
|
return;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 业务逻辑校验
|
|
|
|
|
|
if (!string.IsNullOrEmpty(productType))
|
|
{
|
|
ProductTypeBLL ptbll = new ProductTypeBLL();
|
|
|
|
DataTable sdt = MESClassLibrary.Tool.ListToDataTable(ptbll.SearchAll()
|
|
.Where(p => p.ProductTypeNo.Equals(productType)).ToList());
|
|
if (sdt != null && sdt.Rows.Count > 0)
|
|
{
|
|
productType = sdt.Rows[0]["ProductTypeID"].ToString();
|
|
}
|
|
else
|
|
{
|
|
ClientScript.RegisterStartupScript(this.GetType(), "提示", "<script type='text/javascript'>$.messager.alert('提示', '第" + i.ToString() + "行,该产品类编号系统中不存在,故无法导入', 'warning');</script>");
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(stockNo))
|
|
{
|
|
DataTable sdt =
|
|
MESClassLibrary.Tool.ListToDataTable(bll.SearchAll()
|
|
.Where(p => p.StockNo == stockNo).ToList());
|
|
|
|
if (sdt != null && sdt.Rows.Count > 0)
|
|
{
|
|
ClientScript.RegisterStartupScript(this.GetType(), "提示", "<script type='text/javascript'>$.messager.alert('提示', '第" + i.ToString() + "行,该存货代码已存在,故无法导入', 'warning');</script>");
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(partNo))
|
|
{
|
|
DataTable sdt =
|
|
MESClassLibrary.Tool.ListToDataTable(bll.SearchAll()
|
|
.Where(p => p.PartNo == partNo).ToList());
|
|
|
|
if (sdt != null && sdt.Rows.Count > 0)
|
|
{
|
|
ClientScript.RegisterStartupScript(this.GetType(), "提示", "<script type='text/javascript'>$.messager.alert('提示', '第" + i.ToString() + "行,该零件号已存在,故无法导入', 'warning');</script>");
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
tb_Product md = new tb_Product();
|
|
|
|
var info = Request.Cookies.Get("LoginUserInfo");
|
|
if (info != null)
|
|
{
|
|
//md.UserID = info["UserID"].ToUpper();
|
|
}
|
|
|
|
md.ProductID = Guid.NewGuid().ToString();
|
|
md.ProductTypeID = productType;
|
|
md.StockNo = stockNo;
|
|
md.ProductName = productName;
|
|
md.ColorName = colorName;
|
|
md.PartNo = partNo;
|
|
|
|
list.Add(md);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 存储数据
|
|
|
|
try
|
|
{
|
|
bool flag = false;
|
|
if (list.Count > 0)
|
|
{
|
|
foreach (var item in list)
|
|
{
|
|
flag = bll.AddInfo(item);
|
|
}
|
|
}
|
|
if (flag)
|
|
{
|
|
ClientScript.RegisterStartupScript(this.GetType(), "提示", "<script type='text/javascript'>$.messager.alert('提示','导入成功!', 'warning');</script>");
|
|
}
|
|
else
|
|
{
|
|
ClientScript.RegisterStartupScript(this.GetType(), "提示", "<script type='text/javascript'>$.messager.alert('提示','导入失败!', 'warning');</script>");
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
|
}
|
|
}
|
|
}
|
|
}
|