/// <summary> /// 從dtWOItem表中查詢指定的工單信息,并寫入R_WO_Item表中 /// </summary> protected void SaveWOItem(DataRow[] rowDownloadItem) { for (int m = 0; m < rowDownloadItem.Length; m++) { sql = ""; woIsExist = false; try { //判斷工單Item是否已經存在,如果存在則先刪除(如果autoDownLoad=false) woIsExist = R_WO_ITEM.CheckWoItemByWo(rowDownloadItem[m]["AUFNR"].ToString(), rowDownloadItem[m]["MATNR"].ToString(), autoDownLoad, SFCDB); if (woIsExist) { continue; } Row_R_WO_ITEM rowRWOItem = (Row_R_WO_ITEM)R_WO_ITEM.NewRow(); rowRWOItem.ID = R_WO_ITEM.GetNewID(BU, SFCDB); rowRWOItem.AUFNR = rowDownloadItem[m]["AUFNR"].ToString(); rowRWOItem.POSNR = rowDownloadItem[m]["POSNR"].ToString(); rowRWOItem.MATNR = rowDownloadItem[m]["MATNR"].ToString(); rowRWOItem.PARTS = rowDownloadItem[m]["PARTS"].ToString(); rowRWOItem.KDMAT = rowDownloadItem[m]["KDMAT"].ToString(); rowRWOItem.BDMNG = rowDownloadItem[m]["BDMNG"].ToString(); rowRWOItem.MEINS = rowDownloadItem[m]["MEINS"].ToString(); rowRWOItem.REVLV = rowDownloadItem[m]["REVLV"].ToString(); rowRWOItem.BAUGR = rowDownloadItem[m]["BAUGR"].ToString(); rowRWOItem.REPNO = rowDownloadItem[m]["REPNO"].ToString(); rowRWOItem.REPPARTNO = rowDownloadItem[m]["REPPARTNO"].ToString(); rowRWOItem.AUART = rowDownloadItem[m]["AUART"].ToString(); rowRWOItem.AENAM = rowDownloadItem[m]["AENAM"].ToString(); rowRWOItem.AEDAT = rowDownloadItem[m]["AEDAT"].ToString(); rowRWOItem.MAKTX = rowDownloadItem[m]["MAKTX"].ToString(); rowRWOItem.MATKL = rowDownloadItem[m]["MATKL"].ToString(); rowRWOItem.WGBEZ = rowDownloadItem[m]["WGBEZ"].ToString(); rowRWOItem.ALPOS = rowDownloadItem[m]["ALPOS"].ToString(); rowRWOItem.ABLAD = rowDownloadItem[m]["ABLAD"].ToString(); rowRWOItem.MVGR3 = rowDownloadItem[m]["MVGR3"].ToString(); rowRWOItem.RGEKZ = rowDownloadItem[m]["RGEKZ"].ToString(); rowRWOItem.LGORT = rowDownloadItem[m]["LGORT"].ToString(); rowRWOItem.ENMNG = rowDownloadItem[m]["ENMNG"].ToString(); rowRWOItem.DUMPS = rowDownloadItem[m]["DUMPS"].ToString(); rowRWOItem.BISMT = rowDownloadItem[m]["BISMT"].ToString(); rowRWOItem.XLOEK = rowDownloadItem[m]["XLOEK"].ToString(); rowRWOItem.SHKZG = rowDownloadItem[m]["SHKZG"].ToString(); rowRWOItem.CHARG = rowDownloadItem[m]["CHARG"].ToString(); rowRWOItem.RSPOS = rowDownloadItem[m]["RSPOS"].ToString(); rowRWOItem.VORNR = rowDownloadItem[m]["VORNR"].ToString(); sql = rowRWOItem.GetInsertString(DB_TYPE_ENUM.Oracle); SFCDB.ExecSQL(sql); SFCDB.CommitTrain(); } catch (Exception ex) { WriteLog.WriteIntoMESLog(SFCDB, BU, "MESInterface", "MESInterface.MBD.DownLoadWO", "SaveWOItem", ip + ";" + rowDownloadItem[m]["AUFNR"].ToString() + "; Download r_wo_item fail," + ex.Message.ToString(), sql, "interface"); continue; } } }
public void Download(string ItemName, string Date) { string StrSql = ""; OleExec sfcdb; DataTable RFC_Table = new DataTable(); T_C_TAB_COLUMN_MAP C_TAB_COLUMN_MAP; DataObjectBase Row; T_R_WO_HEADER R_WO_HEADER; T_R_WO_ITEM R_WO_ITEM; T_R_WO_TEXT R_WO_TEXT; T_R_WO_BASE R_WO_BASE; T_C_SKU C_SKU; T_C_PARAMETER C_PARAMETER; Row_C_PARAMETER Row_PARAMETER; Dictionary <string, string> DicPara = new Dictionary <string, string>(); string StrColumn = ""; string StrValue = ""; string[] StrColumn_Name; string[] StrColumn_Value; string StrWo = ""; bool Exist_WO_Flag = false; bool Exist_WO_Base_Flag = false; bool Exist_SKU_Flag = false; bool DownLoad_Auto = false; if (string.IsNullOrEmpty(StrWo)) { DownLoad_Auto = true; } sfcdb = this.DBPools["SFCDB"].Borrow(); C_PARAMETER = new T_C_PARAMETER(sfcdb, DB_TYPE_ENUM.Oracle); DicPara = C_PARAMETER.Get_Interface_Parameter_2(ItemName, sfcdb, DB_TYPE_ENUM.Oracle); this.DBPools["SFCDB"].Return(sfcdb); ZRFC_SFC_NSG_0001B Zrfc_SFC_NSG_001B = new ZRFC_SFC_NSG_0001B(StrWo); Zrfc_SFC_NSG_001B.SetValue("PLANT", DicPara["PLANT"]);//NHGZ,WDN1//WDN1,WSL3 Zrfc_SFC_NSG_001B.SetValue("SCHEDULED_DATE", Date); Zrfc_SFC_NSG_001B.SetValue("RLDATE", Date); Zrfc_SFC_NSG_001B.SetValue("COUNT", DicPara["COUNT"]); Zrfc_SFC_NSG_001B.SetValue("CUST", DicPara["CUST"]); Zrfc_SFC_NSG_001B.SetValue("IN_CNF", DicPara["IN_CNF"]); //IN_CNF=0,Download WO not Confirmed Zrfc_SFC_NSG_001B.CallRFC(); for (int i = 0; i < Zrfc_SFC_NSG_001B.ReturnDatatableByIndex.Count; i++) { string ErrorMessage = ""; switch (Zrfc_SFC_NSG_001B.ReturnDatatableByIndex[i].TableName.ToString().ToUpper()) { case "ITAB": if (Zrfc_SFC_NSG_001B.ReturnDatatableByIndex[0].Rows.Count > 0) { ErrorMessage = Zrfc_SFC_NSG_001B.ReturnDatatableByIndex[0].Rows[0][1].ToString(); throw new Exception(ErrorMessage); } break; case "WO_HEADER": sfcdb = this.DBPools["SFCDB"].Borrow(); C_TAB_COLUMN_MAP = new T_C_TAB_COLUMN_MAP(sfcdb, DB_TYPE_ENUM.Oracle); Row = C_TAB_COLUMN_MAP.GetTableColumnMap("R_WO_HEADER", sfcdb, DB_TYPE_ENUM.Oracle); StrColumn = Row["TAB_COLUMN"].ToString(); StrValue = ""; StrColumn_Name = StrColumn.Split(','); StrColumn_Value = new string[StrColumn_Name.Count()]; RFC_Table = (DataTable)Zrfc_SFC_NSG_001B.ReturnDatatableByIndex[i]; for (int m = 0; m < RFC_Table.Rows.Count; m++) { R_WO_BASE = new T_R_WO_BASE(sfcdb, DB_TYPE_ENUM.Oracle); Exist_WO_Base_Flag = R_WO_BASE.CheckDataExist(RFC_Table.Rows[m]["AUFNR"].ToString(), sfcdb); R_WO_HEADER = new T_R_WO_HEADER(sfcdb, DB_TYPE_ENUM.Oracle); Exist_WO_Flag = R_WO_HEADER.CheckWoHeadByWo(RFC_Table.Rows[m]["AUFNR"].ToString(), DownLoad_Auto, StrColumn, sfcdb, DB_TYPE_ENUM.Oracle); C_SKU = new T_C_SKU(sfcdb, DB_TYPE_ENUM.Oracle); Exist_SKU_Flag = C_SKU.CheckSku(RFC_Table.Rows[m][3].ToString(), sfcdb); if (!Exist_WO_Flag && Exist_SKU_Flag && !Exist_WO_Base_Flag) { string StrID = C_TAB_COLUMN_MAP.GetNewID(BU, sfcdb); for (int j = 0; j < StrColumn_Name.Count(); j++) { //StrColumn_Value[j] = ReplaceSpecialChar(RFC_Table.Rows[m][StrColumn_Name[j]].ToString()); StrColumn_Value[j] = RFC_Table.Rows[m][StrColumn_Name[j]].ToString(); if (j == 0) { StrValue = "'" + StrColumn_Value[j].ToString() + "'"; } else { StrValue = StrValue + ",'" + StrColumn_Value[j].ToString() + "'"; } } StrSql = " insert into R_WO_HEADER(" + StrColumn + ",ID " + ") values(" + StrValue + ",'" + StrID + "'" + ");"; R_WO_HEADER = new T_R_WO_HEADER(sfcdb, DB_TYPE_ENUM.Oracle); R_WO_HEADER.EditWoHead(StrSql, sfcdb, DB_TYPE_ENUM.Oracle); } } this.DBPools["SFCDB"].Return(sfcdb); break; case "WO_ITEM": StrSql = ""; sfcdb = this.DBPools["SFCDB"].Borrow(); C_TAB_COLUMN_MAP = new T_C_TAB_COLUMN_MAP(sfcdb, DB_TYPE_ENUM.Oracle); Row = C_TAB_COLUMN_MAP.GetTableColumnMap("R_WO_ITEM", sfcdb, DB_TYPE_ENUM.Oracle); StrColumn = Row["TAB_COLUMN"].ToString(); StrValue = ""; StrColumn_Name = StrColumn.Split(','); StrColumn_Value = new string[StrColumn_Name.Count()]; RFC_Table = (DataTable)Zrfc_SFC_NSG_001B.ReturnDatatableByIndex[i]; for (int m = 0; m < RFC_Table.Rows.Count; m++) { R_WO_BASE = new T_R_WO_BASE(sfcdb, DB_TYPE_ENUM.Oracle); Exist_WO_Base_Flag = R_WO_BASE.CheckDataExist(RFC_Table.Rows[m]["AUFNR"].ToString(), sfcdb); R_WO_ITEM = new T_R_WO_ITEM(sfcdb, DB_TYPE_ENUM.Oracle); Exist_WO_Flag = R_WO_ITEM.CheckWoItemByWo(RFC_Table.Rows[m]["AUFNR"].ToString(), RFC_Table.Rows[m]["MATNR"].ToString(), DownLoad_Auto, StrColumn, sfcdb, DB_TYPE_ENUM.Oracle); C_SKU = new T_C_SKU(sfcdb, DB_TYPE_ENUM.Oracle); Exist_SKU_Flag = C_SKU.CheckSku(RFC_Table.Rows[m][8].ToString(), sfcdb); if (!Exist_WO_Flag && Exist_SKU_Flag && !Exist_WO_Base_Flag) { string StrID = C_TAB_COLUMN_MAP.GetNewID(BU, sfcdb); for (int j = 0; j < StrColumn_Name.Count(); j++) { //StrColumn_Value[j] = ReplaceSpecialChar(RFC_Table.Rows[m][StrColumn_Name[j]].ToString()); StrColumn_Value[j] = RFC_Table.Rows[m][StrColumn_Name[j]].ToString(); if (j == 0) { StrValue = "'" + StrColumn_Value[j].ToString() + "'"; } else { StrValue = StrValue + ",'" + StrColumn_Value[j].ToString() + "'"; } } StrSql = "insert into R_WO_ITEM(" + StrColumn + ",ID " + ") values(" + StrValue + ",'" + StrID + "'" + ");\n"; R_WO_ITEM = new T_R_WO_ITEM(sfcdb, DB_TYPE_ENUM.Oracle); R_WO_ITEM.EditWoItem(StrSql, sfcdb, DB_TYPE_ENUM.Oracle); } } this.DBPools["SFCDB"].Return(sfcdb); break; case "WO_TEXT": StrSql = ""; sfcdb = this.DBPools["SFCDB"].Borrow(); C_TAB_COLUMN_MAP = new T_C_TAB_COLUMN_MAP(sfcdb, DB_TYPE_ENUM.Oracle); Row = C_TAB_COLUMN_MAP.GetTableColumnMap("R_WO_TEXT", sfcdb, DB_TYPE_ENUM.Oracle); StrColumn = Row["TAB_COLUMN"].ToString(); StrValue = ""; StrColumn_Name = StrColumn.Split(','); StrColumn_Value = new string[StrColumn_Name.Count()]; RFC_Table = (DataTable)Zrfc_SFC_NSG_001B.ReturnDatatableByIndex[i]; for (int m = 0; m < RFC_Table.Rows.Count; m++) { R_WO_BASE = new T_R_WO_BASE(sfcdb, DB_TYPE_ENUM.Oracle); Exist_WO_Base_Flag = R_WO_BASE.CheckDataExist(RFC_Table.Rows[m]["AUFNR"].ToString(), sfcdb); R_WO_TEXT = new T_R_WO_TEXT(sfcdb, DB_TYPE_ENUM.Oracle); Exist_WO_Flag = R_WO_TEXT.CheckWoTextByWo(RFC_Table.Rows[m]["AUFNR"].ToString(), DownLoad_Auto, StrColumn, sfcdb, DB_TYPE_ENUM.Oracle); R_WO_HEADER = new T_R_WO_HEADER(sfcdb, DB_TYPE_ENUM.Oracle); Exist_SKU_Flag = R_WO_HEADER.CheckWoHeadByWo(RFC_Table.Rows[m]["AUFNR"].ToString(), true, StrColumn, sfcdb, DB_TYPE_ENUM.Oracle); if (!Exist_WO_Flag && !Exist_WO_Base_Flag && Exist_SKU_Flag) { string StrID = C_TAB_COLUMN_MAP.GetNewID(BU, sfcdb); for (int j = 0; j < StrColumn_Name.Count(); j++) { StrColumn_Value[j] = RFC_Table.Rows[m][StrColumn_Name[j]].ToString(); if (j == 0) { StrValue = "'" + StrColumn_Value[j].ToString() + "'"; } else { StrValue = StrValue + ",'" + StrColumn_Value[j].ToString() + "'"; } } StrSql = "insert into R_WO_TEXT(" + StrColumn + ",ID " + ") values(" + StrValue + ",'" + StrID + "'" + ");"; R_WO_TEXT = new T_R_WO_TEXT(sfcdb, DB_TYPE_ENUM.Oracle); R_WO_TEXT.EditWoText(StrSql, sfcdb, DB_TYPE_ENUM.Oracle); } } this.DBPools["SFCDB"].Return(sfcdb); break; } } }