|
|
@@ -1,21 +1,17 @@
|
|
|
using System;
|
|
|
-using System.Data;
|
|
|
using System.IO;
|
|
|
using System.Windows.Forms;
|
|
|
using System.Text;
|
|
|
using NPOI.SS.UserModel;
|
|
|
using NPOI.XSSF.UserModel;
|
|
|
using Oracle.ManagedDataAccess.Client;
|
|
|
-using System.Reflection.Emit;
|
|
|
-using Microsoft.Office.Interop.Excel;
|
|
|
-using NPOI.SS.Formula.Functions;
|
|
|
|
|
|
namespace FileWatcher
|
|
|
{
|
|
|
public partial class UploadMakePlan : Form
|
|
|
{
|
|
|
|
|
|
- string connectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.3.7)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
|
|
|
+ string connectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.1.81.208)(PORT=11710)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
|
|
|
|
|
|
|
|
|
StringBuilder sql = new StringBuilder();
|
|
|
@@ -41,7 +37,10 @@ namespace FileWatcher
|
|
|
{
|
|
|
DateTime today = DateTime.Value;
|
|
|
string todayDate = today.ToString("MMdd");
|
|
|
- string code = dh.GetSerialNumberByCaller("MakePlan");
|
|
|
+ string code = "";
|
|
|
+ string[] param = new string[] { "MakePlan", "1", code };
|
|
|
+ dh.CallProcedure("SP_GETMAXNUMBER", ref param);
|
|
|
+ code = param[2];
|
|
|
string id = "";
|
|
|
System.Data.DataTable dt = (System.Data.DataTable)dh.ExecuteSql("select mp_id from MakePlan where to_char(mp_begintime,'yyyymmdd')='" + today.ToString("yyyyMMdd") + "'", "select");
|
|
|
if (dt.Rows.Count == 0)
|
|
|
@@ -65,13 +64,19 @@ namespace FileWatcher
|
|
|
{
|
|
|
ISheet sheet = workbook.GetSheetAt(i);
|
|
|
string sheetName = sheet.SheetName;
|
|
|
- if (sheetName.Contains(todayDate))
|
|
|
+
|
|
|
{
|
|
|
|
|
|
//Console.WriteLine($"Processing sheet: {sheetName}");
|
|
|
|
|
|
// 获取标题行(第4行)
|
|
|
- IRow headerRow = sheet.GetRow(3); // 第4行索引为3
|
|
|
+ string wccode = sheet.GetRow(2).GetCell(2).StringCellValue; // 第4行索引为3
|
|
|
+ if (wccode == "")
|
|
|
+ {
|
|
|
+ OperateResult.AppendText("工作中心不存在");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ IRow headerRow = sheet.GetRow(4); // 第4行索引为3
|
|
|
if (headerRow == null)
|
|
|
{
|
|
|
Console.WriteLine("Header row not found.");
|
|
|
@@ -79,7 +84,7 @@ namespace FileWatcher
|
|
|
}
|
|
|
|
|
|
// 获取标题列的索引
|
|
|
- int wccodeIndex = -1;
|
|
|
+ int dateIndex = -1;
|
|
|
int orderdetnoIndex = -1;
|
|
|
int ordercodeIndex = -1;
|
|
|
int planqtyIndex = -1;
|
|
|
@@ -92,11 +97,7 @@ namespace FileWatcher
|
|
|
if (cell != null)
|
|
|
{
|
|
|
string headerValue = cell.ToString().Trim().Replace("\r\n", "").Replace("\n", "").Replace("\r", "");
|
|
|
- if (headerValue == "工作中心")
|
|
|
- {
|
|
|
- wccodeIndex = colIndex;
|
|
|
- }
|
|
|
- else if (headerValue == "订单序号")
|
|
|
+ if (headerValue == "订单序号")
|
|
|
{
|
|
|
orderdetnoIndex = colIndex;
|
|
|
}
|
|
|
@@ -108,10 +109,14 @@ namespace FileWatcher
|
|
|
{
|
|
|
planqtyIndex = colIndex;
|
|
|
}
|
|
|
- else if (headerValue == "工序编号")
|
|
|
+ else if (headerValue == "工序")
|
|
|
{
|
|
|
stepcodeIndex = colIndex;
|
|
|
}
|
|
|
+ else if (headerValue == "日期")
|
|
|
+ {
|
|
|
+ dateIndex = colIndex;
|
|
|
+ }
|
|
|
else if (headerValue.Contains("备注") && !headerValue.Contains("生产异常备注"))
|
|
|
{
|
|
|
remarkIndex = colIndex;
|
|
|
@@ -119,7 +124,7 @@ namespace FileWatcher
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (wccodeIndex == -1 || orderdetnoIndex == -1 || ordercodeIndex == -1 || planqtyIndex == -1 || remarkIndex == -1 || stepcodeIndex == -1)
|
|
|
+ if (orderdetnoIndex == -1 || ordercodeIndex == -1 || planqtyIndex == -1 || remarkIndex == -1 || stepcodeIndex == -1)
|
|
|
{
|
|
|
OperateResult.AppendText("列头缺少,请检查表结构");
|
|
|
return;
|
|
|
@@ -128,22 +133,22 @@ namespace FileWatcher
|
|
|
using (OracleConnection conn = new OracleConnection(connectionString))
|
|
|
{
|
|
|
conn.Open();
|
|
|
- for (int rowIndex = 4; rowIndex <= sheet.LastRowNum; rowIndex++) // 从第5行开始解析数据
|
|
|
+ for (int rowIndex = 5; rowIndex <= sheet.LastRowNum; rowIndex++) // 从第5行开始解析数据
|
|
|
{
|
|
|
IRow row = sheet.GetRow(rowIndex);
|
|
|
if (row != null)
|
|
|
{
|
|
|
- string wccode = row.GetCell(wccodeIndex, MissingCellPolicy.CREATE_NULL_AS_BLANK).StringCellValue.ToString();
|
|
|
- if (wccode == "")
|
|
|
+ string date = row.GetCell(dateIndex, MissingCellPolicy.CREATE_NULL_AS_BLANK).ToString();
|
|
|
+ if (date == "")
|
|
|
{
|
|
|
- continue;
|
|
|
+ break;
|
|
|
}
|
|
|
string orderdetno = row.GetCell(orderdetnoIndex, MissingCellPolicy.CREATE_NULL_AS_BLANK).ToString();
|
|
|
string ordercode = row.GetCell(ordercodeIndex, MissingCellPolicy.CREATE_NULL_AS_BLANK).ToString();
|
|
|
string planqty = row.GetCell(planqtyIndex, MissingCellPolicy.CREATE_NULL_AS_BLANK).NumericCellValue.ToString();
|
|
|
string remark = row.GetCell(remarkIndex, MissingCellPolicy.CREATE_NULL_AS_BLANK).ToString();
|
|
|
string stepcode = row.GetCell(stepcodeIndex, MissingCellPolicy.CREATE_NULL_AS_BLANK).ToString();
|
|
|
- if (!string.IsNullOrEmpty(wccode) && !string.IsNullOrEmpty(orderdetno) && !string.IsNullOrEmpty(ordercode))
|
|
|
+ if (todayDate == date && !string.IsNullOrEmpty(wccode) && !string.IsNullOrEmpty(orderdetno) && !string.IsNullOrEmpty(ordercode))
|
|
|
{
|
|
|
string day = today.ToString("yyyy-MM-dd");
|
|
|
if (dh.CheckExist("MakePlanDetail left join makeplan on mpd_mpid=mp_id ", "trunc(mp_begintime)=to_date('" + day + "','yyyy-mm-dd') and mpd_orderdetno='" + orderdetno + "' and mpd_ordercode='" + ordercode + "' and mpd_wccode='" + wccode + "'"))
|
|
|
@@ -152,19 +157,21 @@ namespace FileWatcher
|
|
|
return;
|
|
|
}
|
|
|
//销售订单+订单序号存在ERP中,才允许上传
|
|
|
- if (!dh.CheckExist("saledetail@ERP left join sale@ERP on sa_id=sd_said", "SD_DETNO='" + orderdetno + "' and sa_code='" + ordercode + "'"))
|
|
|
- {
|
|
|
- OperateResult.AppendText(" 序号'" + orderdetno + "' 销售订单'" + ordercode + "'不存在");
|
|
|
- return;
|
|
|
- }
|
|
|
- if (dh.CheckExist("saledetail@ERP left join sale@ERP on sa_id=sd_said left join (select min(mpd_outqty)mpd_outqty, mpd_ordercode," +
|
|
|
- " mpd_orderdetno from(select mpd_stepcode,sum(mpd_outqty)mpd_outqty, mpd_ordercode, mpd_orderdetno from MakePlanDetail group by " +
|
|
|
- "mpd_ordercode, mpd_orderdetno,mpd_stepcode, MPD_WCCODE)group by mpd_ordercode, mpd_orderdetno,mpd_stepcode) on sa_code = mpd_ordercode and sd_detno" +
|
|
|
- " = mpd_orderdetno", "sd_qty<mpd_outqty+" + planqty + " and sa_code='" + ordercode + "' and sd_detno='" + orderdetno + "'"))
|
|
|
- {
|
|
|
- OperateResult.AppendText(" 序号'" + orderdetno + "' 销售订单'" + ordercode + "'工序" + stepcode + "累计排产数量超出");
|
|
|
- return;
|
|
|
- }
|
|
|
+ //if (!dh.CheckExist("saledetail@ERP left join sale@ERP on sa_id=sd_said", "SD_DETNO='" + orderdetno + "' and sa_code='" + ordercode + "'"))
|
|
|
+ //{
|
|
|
+ // OperateResult.AppendText(" 序号'" + orderdetno + "' 销售订单'" + ordercode + "'不存在");
|
|
|
+ // return;
|
|
|
+ //}
|
|
|
+ //dt = (System.Data.DataTable)dh.ExecuteSql("select * from saledetail@ERP left join sale@ERP on sa_id=sd_said left join " +
|
|
|
+ // "(select min(mpd_outqty)mpd_outqty, mpd_ordercode,mpd_orderdetno from(select mpd_stepcode,nvl(sum(mpd_outqty),0)mpd_outqty, " +
|
|
|
+ // "mpd_ordercode, mpd_orderdetno from MakePlanDetail where mpd_wccode='" + wccode + "' and nvl(mpd_stepcode,' ')='" + stepcode + "' group by mpd_ordercode, mpd_orderdetno,mpd_stepcode)group " +
|
|
|
+ // "by mpd_ordercode, mpd_orderdetno,mpd_stepcode) on sa_code = mpd_ordercode and sd_detno =mpd_orderdetno " +
|
|
|
+ // "where sd_qty<nvl(mpd_outqty,0)+" + planqty + " and sa_code='" + ordercode + "' and sd_detno='" + orderdetno + "'", "select");
|
|
|
+ //if (dt.Rows.Count > 0)
|
|
|
+ //{
|
|
|
+ // OperateResult.AppendText(" 序号'" + orderdetno + "' 销售订单'" + ordercode + "'工序" + stepcode + "累计排产数量超出");
|
|
|
+ // return;
|
|
|
+ //}
|
|
|
string insertQuery = "INSERT INTO MakePlanDetail (mpd_mpid,mpd_detno,mpd_id,mpd_wccode, mpd_orderdetno, mpd_ordercode,mpd_outqty,mpd_remark,mpd_stepcode) VALUES (" + id + "," + detno + ",MakePlanDetail_seq.nextval,:1, :2, :3,:4,:5,:6)";
|
|
|
using (OracleCommand cmd = new OracleCommand(insertQuery, conn))
|
|
|
{
|
|
|
@@ -184,7 +191,7 @@ namespace FileWatcher
|
|
|
dh.ExecuteSql("delete from MakePlanDetail where mpd_orderdetno is null", "delete");
|
|
|
OperateResult.AppendText($"Processing sheet: {sheetName}计划上传成功\n");
|
|
|
string Error = "";
|
|
|
- string[] param = new string[] { id, "0", Error };
|
|
|
+ param = new string[] { id, "0", Error };
|
|
|
dh.CallProcedure("USER_PLANSPLIT_COMMIT", ref param);
|
|
|
dh.CallProcedure("USER_PLANINSERT_WORK", ref param);
|
|
|
}
|