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.BasicInfo; using MESClassLibrary.BLL.Log; using MESClassLibrary.BLL.PunchAndWeld; using MESClassLibrary.EFModel; using MESWebSite.Tool; namespace MESWebSite.Manage { public partial class PunchBom : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_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 = 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; PunchAndStationBLL bll = new PunchAndStationBLL(); ProductBLL pbll = new ProductBLL(); StationBLL sbll=new StationBLL(); 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 zcPartNo = dt.Rows[i][0].ToString(); if (zcPartNo == "") { ClientScript.RegisterStartupScript(this.GetType(), "tishi", ""); return; } string partNo = dt.Rows[i][1].ToString(); if (partNo == "") { ClientScript.RegisterStartupScript(this.GetType(), "tishi", ""); return; } string partNo1 = dt.Rows[i][2].ToString(); string partNo2 = dt.Rows[i][3].ToString(); string partNo3 = dt.Rows[i][4].ToString(); string partNo4 = dt.Rows[i][5].ToString(); string partNo5 = dt.Rows[i][6].ToString(); string partNo6 = dt.Rows[i][7].ToString(); string stationNo = dt.Rows[i][8].ToString(); string partNo7 = dt.Rows[i][9].ToString(); string partNo8 = dt.Rows[i][10].ToString(); string partNo9 = dt.Rows[i][11].ToString(); string partNo10 = dt.Rows[i][12].ToString(); string partNo11 = dt.Rows[i][13].ToString(); string partNo12 = dt.Rows[i][14].ToString(); if (stationNo == "") { ClientScript.RegisterStartupScript(this.GetType(), "tishi", ""); return; } if (string.IsNullOrWhiteSpace(partNo1) && !string.IsNullOrWhiteSpace(partNo2)) { ClientScript.RegisterStartupScript(this.GetType(), "tishi", ""); return; } if (string.IsNullOrWhiteSpace(partNo2) && !string.IsNullOrWhiteSpace(partNo3)) { ClientScript.RegisterStartupScript(this.GetType(), "tishi", ""); return; } if (string.IsNullOrWhiteSpace(partNo1) && string.IsNullOrWhiteSpace(partNo2) && !string.IsNullOrWhiteSpace(partNo3)) { ClientScript.RegisterStartupScript(this.GetType(), "tishi", ""); return; } if (string.IsNullOrWhiteSpace(partNo4) && !string.IsNullOrWhiteSpace(partNo5)) { ClientScript.RegisterStartupScript(this.GetType(), "tishi", ""); return; } if (string.IsNullOrWhiteSpace(partNo5) && !string.IsNullOrWhiteSpace(partNo6)) { ClientScript.RegisterStartupScript(this.GetType(), "tishi", ""); return; } if (string.IsNullOrWhiteSpace(partNo4) && string.IsNullOrWhiteSpace(partNo5) && !string.IsNullOrWhiteSpace(partNo6)) { ClientScript.RegisterStartupScript(this.GetType(), "tishi", ""); return; } #endregion #region 业务逻辑校验 if (!string.IsNullOrEmpty(zcPartNo)) { DataTable sdt = pbll.SearchInfoByPartNo(zcPartNo); if (sdt != null && sdt.Rows.Count > 0) { zcPartNo = sdt.Rows[0]["ProductID"].ToString(); } else { ClientScript.RegisterStartupScript(this.GetType(), "提示", ""); return; } } if (!string.IsNullOrEmpty(partNo)) { DataTable sdt = pbll.SearchInfoByPartNo(partNo); if (sdt != null && sdt.Rows.Count > 0) { partNo = sdt.Rows[0]["ProductID"].ToString(); } else { ClientScript.RegisterStartupScript(this.GetType(), "提示", ""); return; } } if (!string.IsNullOrWhiteSpace(stationNo)) { DataTable sdt = sbll.SearchInfoByNo(stationNo); if (sdt != null && sdt.Rows.Count > 0) { stationNo = sdt.Rows[0]["StationID"].ToString(); } else { ClientScript.RegisterStartupScript(this.GetType(), "提示", ""); return; } } if (!string.IsNullOrEmpty(partNo1)) { DataTable sdt = pbll.SearchInfoByPartNo(partNo1); if (sdt != null && sdt.Rows.Count > 0) { partNo1 = sdt.Rows[0]["ProductID"].ToString(); } else { ClientScript.RegisterStartupScript(this.GetType(), "提示", ""); return; } } if (!string.IsNullOrEmpty(partNo2)) { DataTable sdt = pbll.SearchInfoByPartNo(partNo2); if (sdt != null && sdt.Rows.Count > 0) { partNo2 = sdt.Rows[0]["ProductID"].ToString(); } else { ClientScript.RegisterStartupScript(this.GetType(), "提示", ""); return; } } if (!string.IsNullOrEmpty(partNo3)) { DataTable sdt = pbll.SearchInfoByPartNo(partNo3); if (sdt != null && sdt.Rows.Count > 0) { partNo3 = sdt.Rows[0]["ProductID"].ToString(); } else { ClientScript.RegisterStartupScript(this.GetType(), "提示", ""); return; } } if (!string.IsNullOrEmpty(partNo7)) { DataTable sdt = pbll.SearchInfoByPartNo(partNo7); if (sdt != null && sdt.Rows.Count > 0) { partNo7 = sdt.Rows[0]["ProductID"].ToString(); } else { ClientScript.RegisterStartupScript(this.GetType(), "提示", ""); return; } } if (!string.IsNullOrEmpty(partNo8)) { DataTable sdt = pbll.SearchInfoByPartNo(partNo8); if (sdt != null && sdt.Rows.Count > 0) { partNo8 = sdt.Rows[0]["ProductID"].ToString(); } else { ClientScript.RegisterStartupScript(this.GetType(), "提示", ""); return; } } if (!string.IsNullOrEmpty(partNo9)) { DataTable sdt = pbll.SearchInfoByPartNo(partNo9); if (sdt != null && sdt.Rows.Count > 0) { partNo9 = sdt.Rows[0]["ProductID"].ToString(); } else { ClientScript.RegisterStartupScript(this.GetType(), "提示", ""); return; } } if (!string.IsNullOrEmpty(partNo4)) { DataTable sdt = pbll.SearchInfoByPartNo(partNo4); if (sdt != null && sdt.Rows.Count > 0) { partNo4 = sdt.Rows[0]["ProductID"].ToString(); } else { ClientScript.RegisterStartupScript(this.GetType(), "提示", ""); return; } } if (!string.IsNullOrEmpty(partNo5)) { DataTable sdt = pbll.SearchInfoByPartNo(partNo5); if (sdt != null && sdt.Rows.Count > 0) { partNo5= sdt.Rows[0]["ProductID"].ToString(); } else { ClientScript.RegisterStartupScript(this.GetType(), "提示", ""); return; } } if (!string.IsNullOrEmpty(partNo6)) { DataTable sdt = pbll.SearchInfoByPartNo(partNo6); if (sdt != null && sdt.Rows.Count > 0) { partNo6 = sdt.Rows[0]["ProductID"].ToString(); } else { ClientScript.RegisterStartupScript(this.GetType(), "提示", ""); return; } } if (!string.IsNullOrEmpty(partNo10)) { DataTable sdt = pbll.SearchInfoByPartNo(partNo10); if (sdt != null && sdt.Rows.Count > 0) { partNo10 = sdt.Rows[0]["ProductID"].ToString(); } else { ClientScript.RegisterStartupScript(this.GetType(), "提示", ""); return; } } if (!string.IsNullOrEmpty(partNo11)) { DataTable sdt = pbll.SearchInfoByPartNo(partNo11); if (sdt != null && sdt.Rows.Count > 0) { partNo11 = sdt.Rows[0]["ProductID"].ToString(); } else { ClientScript.RegisterStartupScript(this.GetType(), "提示", ""); return; } } if (!string.IsNullOrEmpty(partNo12)) { DataTable sdt = pbll.SearchInfoByPartNo(partNo12); if (sdt != null && sdt.Rows.Count > 0) { partNo12 = sdt.Rows[0]["ProductID"].ToString(); } else { ClientScript.RegisterStartupScript(this.GetType(), "提示", ""); return; } } #endregion tb_PunchAndStation md = new tb_PunchAndStation(); var info = Request.Cookies.Get("LoginUserInfo"); if (info != null) { //md.UserID = info["UserID"].ToUpper(); } md.ID = Guid.NewGuid().ToString(); md.StationID = stationNo; md.ProductID1 = zcPartNo; md.ProductID2 = partNo; md.ProductID3 = partNo1; md.ProductID4 = partNo2; md.ProductID5 = partNo3; md.ProductID6 = partNo4; md.ProductID7 = partNo5; md.ProductID8 = partNo6; md.ProductID9 = partNo7; md.ProductID10 = partNo8; md.ProductID11 = partNo9; md.ProductID12 = partNo10; md.ProductID13 = partNo11; md.ProductID14 = partNo12; 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()); } } } }