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 list = new List(); #region 校验文件 try { dt = ExcelTool.GetExcelTableByOleDB(excelPath, "Sheet1"); if (dt != null && dt.Rows.Count > 1) { } else { ClientScript.RegisterStartupScript(this.GetType(), "tishi", ""); 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", ""); return; } string stockNo = dt.Rows[i][1].ToString(); if (stockNo == "") { ClientScript.RegisterStartupScript(this.GetType(), "tishi", ""); return; } string productName = dt.Rows[i][2].ToString(); if (productName == "") { ClientScript.RegisterStartupScript(this.GetType(), "tishi", ""); return; } string colorName = dt.Rows[i][3].ToString(); string partNo = dt.Rows[i][4].ToString(); if (partNo == "") { ClientScript.RegisterStartupScript(this.GetType(), "tishi", ""); 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(), "提示", ""); 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(), "提示", ""); 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(), "提示", ""); 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(), "提示", ""); } else { ClientScript.RegisterStartupScript(this.GetType(), "提示", ""); } } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); } #endregion } } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); } } } }