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
12 KiB
280 lines
12 KiB
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;
|
|
using MESClassLibrary.BLL.BasicInfo;
|
|
using MESClassLibrary.BLL.Log;
|
|
using MESClassLibrary.BLL.PunchAndWeld;
|
|
using MESClassLibrary.EFModel;
|
|
using NPOI.OpenXmlFormats.Wordprocessing;
|
|
|
|
namespace MESWebSite.Manage
|
|
{
|
|
public partial class Plan_Punch_new : System.Web.UI.Page
|
|
{
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
protected 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
|
|
|
|
PlanPunchNewBLL bll = new PlanPunchNewBLL();
|
|
StationBLL sbll=new StationBLL();
|
|
PunchAndStationBLL psbll=new PunchAndStationBLL();
|
|
List<tb_Plan_Punch_214> list = new List<tb_Plan_Punch_214>();
|
|
|
|
string[] no = null;
|
|
|
|
#region 校验数据
|
|
|
|
if (dt.Rows.Count > 0)
|
|
{
|
|
no = new string[dt.Rows.Count - 1];
|
|
for (int i = 1; i < dt.Rows.Count; i++)
|
|
{
|
|
#region 值校验
|
|
|
|
string orderNo = dt.Rows[i][0].ToString();
|
|
if (orderNo == "")
|
|
{
|
|
ClientScript.RegisterStartupScript(this.GetType(), "tishi", "<script type='text/javascript'>$.messager.alert('提示', '第" + i + "行,生产计划单号为空,故无法导入', 'warning');</script>");
|
|
return;
|
|
}
|
|
|
|
string item = dt.Rows[i][1].ToString();
|
|
if (item == "")
|
|
{
|
|
ClientScript.RegisterStartupScript(this.GetType(), "tishi", "<script type='text/javascript'>$.messager.alert('提示', '第" + i + "行,序号为空,故无法导入', 'warning');</script>");
|
|
return;
|
|
}
|
|
|
|
string partNo = dt.Rows[i][2].ToString();
|
|
if (partNo == "")
|
|
{
|
|
ClientScript.RegisterStartupScript(this.GetType(), "tishi", "<script type='text/javascript'>$.messager.alert('提示', '第" + i + "行,零件号为空,故无法导入', 'warning');</script>");
|
|
return;
|
|
}
|
|
string planCount = dt.Rows[i][3].ToString();
|
|
if (planCount == "")
|
|
{
|
|
ClientScript.RegisterStartupScript(this.GetType(), "tishi", "<script type='text/javascript'>$.messager.alert('提示', '第" + i + "行,计划数量为空,故无法导入', 'warning');</script>");
|
|
return;
|
|
}
|
|
|
|
string stationNo = dt.Rows[i][4].ToString();
|
|
if (stationNo == "")
|
|
{
|
|
ClientScript.RegisterStartupScript(this.GetType(), "tishi", "<script type='text/javascript'>$.messager.alert('提示', '第" + i + "行,工位号为空,故无法导入', 'warning');</script>");
|
|
return;
|
|
}
|
|
|
|
int int_item = 0;
|
|
if (!Int32.TryParse(item, out int_item))
|
|
{
|
|
ClientScript.RegisterStartupScript(this.GetType(), "tishi", "<script type='text/javascript'>$.messager.alert('提示', '第" + i + "行,序号不是整数,故无法导入', 'warning');</script>");
|
|
return;
|
|
}
|
|
int int_planCount = 0;
|
|
if (!Int32.TryParse(planCount, out int_planCount))
|
|
{
|
|
ClientScript.RegisterStartupScript(this.GetType(), "tishi", "<script type='text/javascript'>$.messager.alert('提示', '第" + i + "行,计划数量不是整数,故无法导入', 'warning');</script>");
|
|
return;
|
|
}
|
|
|
|
if (Array.IndexOf(no, partNo) != -1)
|
|
{
|
|
ClientScript.RegisterStartupScript(this.GetType(), "tishi", "<script type='text/javascript'>$.messager.alert('提示', '第" + i + "行,导入模板中存在多条相同零件的生产计划,故无法导入', 'warning');</script>");
|
|
return;
|
|
}
|
|
no[i - 1] = dt.Rows[i][2].ToString();
|
|
|
|
#endregion
|
|
|
|
#region 业务逻辑校验
|
|
|
|
if (bll.IsExist(orderNo, int_item))
|
|
{
|
|
ClientScript.RegisterStartupScript(this.GetType(), "tishi", "<script type='text/javascript'>$.messager.alert('提示', '第" + i + "行,生产计划单号中的序号已存在,故无法导入', 'warning');</script>");
|
|
return;
|
|
}
|
|
|
|
DataTable mdt = psbll.IsMath1(partNo, stationNo);
|
|
if (mdt != null && mdt.Rows.Count > 0)
|
|
{
|
|
}
|
|
else
|
|
{
|
|
ClientScript.RegisterStartupScript(this.GetType(), "tishi", "<script type='text/javascript'>$.messager.alert('提示', '第" + i + "行,工位和零件号不匹配,故无法导入', 'warning');</script>");
|
|
return;
|
|
}
|
|
|
|
#endregion
|
|
|
|
tb_Plan_Punch_214 md = new tb_Plan_Punch_214();
|
|
if (i == 1)
|
|
{
|
|
md.CreateTime = DateTime.Now;
|
|
}
|
|
else
|
|
{
|
|
md.CreateTime = list[i - 2].CreateTime.Value.AddSeconds(1);
|
|
}
|
|
|
|
md.ID = Guid.NewGuid().ToString();
|
|
md.LyCount = 0;
|
|
//md.CreateTime = DateTime.Now;
|
|
md.BadCount = 0;
|
|
md.CompleteCount = 0;
|
|
md.IsFinish = 0;
|
|
|
|
DataTable sdt = sbll.SearchInfoByNo(stationNo);
|
|
if (sdt != null && sdt.Rows.Count > 0)
|
|
{
|
|
md.StationId = sdt.Rows[0]["StationID"].ToString();
|
|
}
|
|
|
|
md.OrderNo = orderNo;
|
|
md.PartNo = partNo;
|
|
md.Des = "";
|
|
md.Item = int_item;
|
|
md.OrderCount = int_planCount;
|
|
list.Add(md);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 存储数据
|
|
try
|
|
{
|
|
if (list.Count > 0)
|
|
{
|
|
foreach (var item in list)
|
|
{
|
|
bll.AddInfo(item);
|
|
}
|
|
}
|
|
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|