public void AutoConvert() { T_R_WO_HEADER R_WO_HEADER; T_R_WO_BASE R_WO_BASE; T_C_SKU C_SKU; T_C_ROUTE C_ROUTE; OleExec Sfcdb; string Rows_ID = ""; Sfcdb = this.DBPools["SFCDB"].Borrow(); R_WO_HEADER = new T_R_WO_HEADER(Sfcdb, DB_TYPE_ENUM.Oracle); DataTable dt = R_WO_HEADER.GetConvertWoList(Sfcdb, DB_TYPE_ENUM.Oracle); if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { R_WO_BASE = new T_R_WO_BASE(Sfcdb, DB_TYPE_ENUM.Oracle); Rows_ID = R_WO_BASE.GetNewID(BU, Sfcdb); Row_R_WO_BASE Rows = (Row_R_WO_BASE)R_WO_BASE.NewRow(); C_SKU = new T_C_SKU(Sfcdb, DB_TYPE_ENUM.Oracle); Row_C_SKU Rows_SKU = (Row_C_SKU)C_SKU.GetSku(dr["MATNR"].ToString(), Sfcdb, DB_TYPE_ENUM.Oracle); C_ROUTE = new T_C_ROUTE(Sfcdb, DB_TYPE_ENUM.Oracle); Row_C_ROUTE Rows_Route = (Row_C_ROUTE)C_ROUTE.GetRouteBySkuno(dr["MATNR"].ToString(), Sfcdb, DB_TYPE_ENUM.Oracle); if (Rows != null && Rows_SKU != null && Rows_Route != null) { Rows.ID = Rows_ID; Rows.WORKORDERNO = dr["AUFNR"].ToString(); Rows.SKUNO = dr["MATNR"].ToString(); Rows.CUSTOMER_NAME = Rows_SKU.CUST_SKU_CODE; Rows.CUST_PN = Rows_SKU.CUST_PARTNO; Rows.WORKORDER_QTY = Convert.ToDouble(dr["GAMNG"]); Rows.SKU_VER = dr["REVLV"].ToString(); Rows.SKU_NAME = Rows_SKU.SKU_NAME; Rows.SKU_DESC = Rows_SKU.DESCRIPTION; Rows.ROHS = dr["ROHS_VALUE"].ToString(); Rows.ROUTE_ID = Rows_Route.ID; //路由應該加版本//Rows.KP_LIST_ID Rows.CLOSED_FLAG = "0"; Rows.EDIT_EMP = "LLF"; string str = Sfcdb.ExecSQL(Rows.GetInsertString(DB_TYPE_ENUM.Oracle)); } } } }
/// <summary> /// convert wo /// </summary> protected void ConvertWO() { if (_downloadWO != "") { dtConvertWO = R_WO_HEADER.GetConvertWoTableByWO(SFCDB, DB_TYPE_ENUM.Oracle, _downloadWO); } else { dtConvertWO = R_WO_HEADER.GetConvertWoTable(SFCDB, DB_TYPE_ENUM.Oracle, arrayConvertWO); } if (dtConvertWO.Rows.Count > 0) { foreach (DataRow row in dtConvertWO.Rows) { rowSku = null; rowRoute = null; rowWOBase = null; rowWOType = null; routeDetailList = null; keypartList = null; keypartIDList = null; linkStationList = null; C_Series = null; sql = ""; try { rowSku = (Row_C_SKU)C_SKU.GetSku(row["MATNR"].ToString(), SFCDB, DB_TYPE_ENUM.Oracle); if (rowSku == null) { throw new Exception(" sku " + row["MATNR"].ToString() + " can't exist"); } //if (!string.Equals(rowSku.VERSION.ToString(), row["REVLV"].ToString())) //{ // throw new Exception(" The sku version is not the same," + rowSku.VERSION.ToString() + "," + row["REVLV"].ToString()); //} C_Series = T_Series.GetDetailById(SFCDB, rowSku.C_SERIES_ID); if (C_Series == null) { throw new Exception(" the series of " + row["MATNR"].ToString() + " can't exist"); } rowWOType = WOType.GetWOTypeByWO(SFCDB, row["AUART"].ToString()); if (rowWOType == null) { throw new Exception("get wo type fail"); } rowRoute = (Row_C_ROUTE)C_ROUTE.GetRouteBySkuno(rowSku.ID, SFCDB, DB_TYPE_ENUM.Oracle); if (rowRoute == null) { throw new Exception(" the route of " + row["MATNR"].ToString() + " can't exist"); } routeDetailList = RouteDetail.GetByRouteIdOrderBySEQASC(rowRoute.ID, SFCDB); if (routeDetailList == null || routeDetailList.Count == 0) { throw new Exception("get route detail fail by " + rowRoute.ID); } keypartIDList = t_c_kp_list.GetListIDBySkuno(rowSku.SKUNO, SFCDB); if (keypartIDList.Count > 0 && keypartIDList.Count != 1) { throw new Exception("skuno:" + row["MATNR"].ToString() + " have more keypart id"); } //HWD的邏輯 //linkStationList = routeDetailList.Where(link => link.STATION_NAME == "LINK").ToList(); //if (linkStationList != null && linkStationList.Count > 0) //{ // keypartList = Keypart.GetKeypartListBySkuVersion(SFCDB, row["MATNR"].ToString(), row["REVLV"].ToString()); // keypartIDList = keypartList.Select(id => id.KEYPART_ID).Distinct().ToList(); // if (keypartIDList == null || keypartIDList.Count != 1) // { // throw new Exception("get keypart id fail by skuno:" + row["MATNR"].ToString() + " and version:" + row["REVLV"].ToString()); // } //} rowWOBase = (Row_R_WO_BASE)R_WO_BASE.NewRow(); rowWOBase.ID = R_WO_BASE.GetNewID(BU, SFCDB); rowWOBase.WORKORDERNO = row["AUFNR"].ToString(); rowWOBase.PLANT = row["WERKS"].ToString(); rowWOBase.RELEASE_DATE = InterfacePublicValues.GetDBDateTime(SFCDB, DB_TYPE_ENUM.Oracle); rowWOBase.DOWNLOAD_DATE = InterfacePublicValues.GetDBDateTime(SFCDB, DB_TYPE_ENUM.Oracle); rowWOBase.PRODUCTION_TYPE = "BTO";//HWD原有邏輯寫死 rowWOBase.WO_TYPE = rowWOType.WORKORDER_TYPE; rowWOBase.SKUNO = row["MATNR"].ToString(); rowWOBase.SKU_VER = row["REVLV"].ToString(); rowWOBase.SKU_SERIES = C_Series.SERIES_NAME; rowWOBase.SKU_NAME = rowSku.SKU_NAME; rowWOBase.SKU_DESC = rowSku.DESCRIPTION; rowWOBase.CUST_PN = rowSku.CUST_PARTNO; rowWOBase.CUST_PN_VER = ""; rowWOBase.CUSTOMER_NAME = rowSku.CUST_SKU_CODE; rowWOBase.ROUTE_ID = rowRoute.ID; rowWOBase.START_STATION = routeDetailList[0].STATION_NAME; rowWOBase.KP_LIST_ID = (keypartIDList != null && keypartIDList.Count > 0) ? keypartIDList[0] : ""; rowWOBase.CLOSED_FLAG = "0"; rowWOBase.WORKORDER_QTY = Convert.ToDouble(row["GAMNG"]); rowWOBase.INPUT_QTY = 0; rowWOBase.FINISHED_QTY = 0; rowWOBase.SCRAPED_QTY = 0; rowWOBase.STOCK_LOCATION = row["LGORT"].ToString(); rowWOBase.PO_NO = ""; rowWOBase.CUST_ORDER_NO = row["ABLAD"].ToString(); rowWOBase.ROHS = row["ROHS_VALUE"].ToString(); rowWOBase.EDIT_EMP = "interface"; rowWOBase.EDIT_TIME = InterfacePublicValues.GetDBDateTime(SFCDB, DB_TYPE_ENUM.Oracle); SFCDB.ThrowSqlExeception = true; sql = rowWOBase.GetInsertString(DB_TYPE_ENUM.Oracle); SFCDB.ExecSQL(rowWOBase.GetInsertString(DB_TYPE_ENUM.Oracle)); SFCDB.CommitTrain(); } catch (Exception ex) { WriteLog.WriteIntoMESLog(SFCDB, BU, "MESInterface", "MESInterface.HWD.DownLoadWO", "ConvertWO", ip + ";" + row["AUFNR"].ToString() + ";ConvertWO fail," + ex.Message.ToString(), sql, "interface"); } } } }
/// <summary> /// convert wo /// </summary> protected void ConvertWO() { if (_downloadWO != "") { //如果指定了工單Download,且工單不存在于R_WO_BASE表中,則返回該工單R_WO_Header記錄 dtConvertWO = R_WO_HEADER.GetConvertWoTableByWO(SFCDB, DB_TYPE_ENUM.Oracle, _downloadWO); } else { //否則抓取所有不存在于R_WO_BASE表中工單,并結合CONVERTWO=00251的設定返回工單R_WO_Header記錄 //MBD 正常工單類型,且ModelType不包含094的才轉 dtConvertWO = R_WO_HEADER.GetConvertWoTableForMBD(SFCDB, DB_TYPE_ENUM.Oracle, arrayConvertWO); } if (dtConvertWO.Rows.Count > 0) { //循環所有待轉工單 foreach (DataRow row in dtConvertWO.Rows) { rowSku = null; rowRoute = null; rowWOBase = null; rowWOType = null; routeDetailList = null; keypartList = null; keypartIDList = null; linkStationList = null; C_Series = null; sql = ""; try { //判斷料號是否存在 rowSku = (Row_C_SKU)C_SKU.GetSku(row["MATNR"].ToString(), SFCDB, DB_TYPE_ENUM.Oracle); if (rowSku == null) { throw new Exception(" sku " + row["MATNR"].ToString() + " not exist"); } if (rowSku.C_SERIES_ID == null) { throw new Exception(" the series of " + row["MATNR"].ToString() + " can not be null "); } //從C_Series表中獲取系列信息 C_Series = T_Series.GetDetailById(SFCDB, rowSku.C_SERIES_ID); if (C_Series == null) { throw new Exception(" the series of " + row["MATNR"].ToString() + " not exist"); } //從R_WO_TYPE表中獲取工單類型:這張表需要事先設定 rowWOType = WOType.GetWOTypeByWO(SFCDB, row["AUART"].ToString()); if (rowWOType == null) { throw new Exception("get wo type fail"); } //從R_Sku_Route&C_Route表中獲取默認路由 rowRoute = (Row_C_ROUTE)C_ROUTE.GetDefaultRouteBySkuno(rowSku.ID, SFCDB, DB_TYPE_ENUM.Oracle); if (rowRoute == null) { throw new Exception(" the route of " + row["MATNR"].ToString() + " not exist"); } //從C_Route_Detail表中獲取路由 routeDetailList = RouteDetail.GetByRouteIdOrderBySEQASC(rowRoute.ID, SFCDB); if (routeDetailList == null || routeDetailList.Count == 0) { throw new Exception("get route detail fail by " + rowRoute.ID); } //???KeyParts如何轉 keypartIDList = t_c_kp_list.GetListIDBySkuno(rowSku.SKUNO, SFCDB); if (keypartIDList.Count > 0 && keypartIDList.Count != 1) { throw new Exception("skuno:" + row["MATNR"].ToString() + " have more keypart id"); } rowWOBase = (Row_R_WO_BASE)R_WO_BASE.NewRow(); rowWOBase.ID = R_WO_BASE.GetNewID(BU, SFCDB); rowWOBase.WORKORDERNO = row["AUFNR"].ToString(); rowWOBase.PLANT = row["WERKS"].ToString(); rowWOBase.RELEASE_DATE = InterfacePublicValues.GetDBDateTime(SFCDB, DB_TYPE_ENUM.Oracle); rowWOBase.DOWNLOAD_DATE = InterfacePublicValues.GetDBDateTime(SFCDB, DB_TYPE_ENUM.Oracle); rowWOBase.PRODUCTION_TYPE = "BTO";//原有邏輯寫死 rowWOBase.WO_TYPE = rowWOType.WORKORDER_TYPE; rowWOBase.SKUNO = row["MATNR"].ToString(); rowWOBase.SKU_VER = row["REVLV"].ToString(); rowWOBase.SKU_SERIES = C_Series.SERIES_NAME; rowWOBase.SKU_NAME = rowSku.SKU_NAME; rowWOBase.SKU_DESC = rowSku.DESCRIPTION; rowWOBase.CUST_PN = rowSku.CUST_PARTNO; rowWOBase.CUST_PN_VER = ""; rowWOBase.CUSTOMER_NAME = rowSku.CUST_SKU_CODE; rowWOBase.ROUTE_ID = rowRoute.ID; rowWOBase.START_STATION = routeDetailList[0].STATION_NAME; //?????? rowWOBase.KP_LIST_ID = (keypartIDList != null && keypartIDList.Count > 0) ? keypartIDList[0] : ""; rowWOBase.CLOSED_FLAG = "0"; rowWOBase.WORKORDER_QTY = Convert.ToDouble(row["GAMNG"]); rowWOBase.INPUT_QTY = 0; rowWOBase.FINISHED_QTY = 0; rowWOBase.SCRAPED_QTY = 0; rowWOBase.STOCK_LOCATION = row["LGORT"].ToString(); rowWOBase.PO_NO = ""; rowWOBase.CUST_ORDER_NO = row["ABLAD"].ToString(); rowWOBase.ROHS = row["ROHS_VALUE"].ToString(); rowWOBase.EDIT_EMP = "interface"; rowWOBase.EDIT_TIME = InterfacePublicValues.GetDBDateTime(SFCDB, DB_TYPE_ENUM.Oracle); SFCDB.ThrowSqlExeception = true; sql = rowWOBase.GetInsertString(DB_TYPE_ENUM.Oracle); SFCDB.ExecSQL(rowWOBase.GetInsertString(DB_TYPE_ENUM.Oracle)); SFCDB.CommitTrain(); } catch (Exception ex) { WriteLog.WriteIntoMESLog(SFCDB, BU, "MESInterface", "MESInterface.MBD.DownLoadWO", "ConvertWO", ip + ";" + row["AUFNR"].ToString() + ";ConvertWO fail," + ex.Message.ToString(), sql, "interface"); } } } }
public void SubmitWoInfo(JObject requestValue, JObject Data, MESStationReturn StationReturn) { //wo string wo = Data["wo"].ToString(); if (string.IsNullOrEmpty(wo)) { //StationReturn.Status = StationReturnStatusValue.Fail; //StationReturn.MessageCode = "MES00000006"; //StationReturn.MessagePara = new List<object>() { "Skuno" }; //StationReturn.Data = ""; //return; throw new Exception(MESReturnMessage.GetMESReturnMessage("MES00000006", new string[] { "WO" })); } OleExec sfcdb = DBPools["SFCDB"].Borrow(); T_R_WO_BASE t_wo = new T_R_WO_BASE(sfcdb, DB_TYPE_ENUM.Oracle); if (!t_wo.CheckDataExist(wo, sfcdb)) { throw new Exception(MESReturnMessage.GetMESReturnMessage("MES00000008", new string[] { wo })); } R_WO_HEADER wo_header = new T_R_WO_HEADER(sfcdb, DB_TYPE_ENUM.Oracle).GetDetailByWo(sfcdb, wo); //sku info string skuno = Data["skuno"].ToString();//wo_header.MATNR if (string.IsNullOrEmpty(skuno)) { throw new Exception(MESReturnMessage.GetMESReturnMessage("MES00000006", new string[] { "SKUNO" })); } string skuver = Data["sku_ver"].ToString();//wo_header.REVLV C_SKU c_sku = new T_C_SKU(sfcdb, DB_TYPE_ENUM.Oracle).GetSku(skuno, sfcdb, DB_TYPE_ENUM.Oracle).GetDataObject(); if (c_sku == null) { throw new Exception(MESReturnMessage.GetMESReturnMessage("MES00000007", new string[] { skuno })); } //route exchange from name string route_name = Data["route_name"].ToString(); if (string.IsNullOrEmpty(route_name)) { throw new Exception(MESReturnMessage.GetMESReturnMessage("MES00000006", new string[] { "ROUTE" })); } C_ROUTE c_route = new T_C_ROUTE(sfcdb, DB_TYPE_ENUM.Oracle).GetByRouteName(route_name, sfcdb); if (c_route == null) { throw new Exception(MESReturnMessage.GetMESReturnMessage("MES00000007", new string[] { route_name })); } //station route check string station_name = Data["station"].ToString(); if (string.IsNullOrEmpty(station_name)) { throw new Exception(MESReturnMessage.GetMESReturnMessage("MES00000006", new string[] { "STATION" })); } List <C_ROUTE_DETAIL> c_route_detail = new T_C_ROUTE_DETAIL(sfcdb, DB_TYPE_ENUM.Oracle).GetByRouteIdOrderBySEQASC(c_route.ID, sfcdb); if (c_route_detail != null && c_route_detail.Count > 0) { C_ROUTE_DETAIL check = c_route_detail.Find(t => t.STATION_NAME == station_name); if (check == null) { throw new Exception(MESReturnMessage.GetMESReturnMessage("MES00000007", new string[] { station_name })); } } else { throw new Exception(MESReturnMessage.GetMESReturnMessage("MES00000007", new string[] { route_name })); } //data record Row_R_WO_BASE row_wobase = (Row_R_WO_BASE)t_wo.NewRow(); row_wobase.ID = t_wo.GetNewID(this.BU, sfcdb); row_wobase.WORKORDERNO = wo; row_wobase.PLANT = Data["factory"].ToString(); row_wobase.RELEASE_DATE = DateTime.Now; row_wobase.DOWNLOAD_DATE = Convert.ToDateTime(Data["date"].ToString()); row_wobase.PRODUCTION_TYPE = "BTO"; row_wobase.WO_TYPE = Data["wo_type"].ToString(); row_wobase.SKUNO = skuno; row_wobase.SKU_VER = skuver; row_wobase.SKU_NAME = c_sku.SKU_NAME; //row_wobase.SKU_SERIES = null; //row_wobase.SKU_DESC = null; row_wobase.CUST_PN = c_sku.CUST_PARTNO; row_wobase.ROUTE_ID = c_route.ID; row_wobase.START_STATION = station_name; row_wobase.KP_LIST_ID = Data["kp_list_id"].ToString(); row_wobase.CLOSED_FLAG = "0"; row_wobase.WORKORDER_QTY = Convert.ToDouble(Data["qty"].ToString()); row_wobase.STOCK_LOCATION = wo_header.LGORT; row_wobase.CUST_ORDER_NO = wo_header.ABLAD; row_wobase.EDIT_EMP = this.LoginUser.EMP_NO; row_wobase.EDIT_TIME = DateTime.Now; string sql = row_wobase.GetInsertString(DB_TYPE_ENUM.Oracle); try { int res = sfcdb.ExecSqlNoReturn(sql, null); if (res == 0) { throw new Exception(MESReturnMessage.GetMESReturnMessage("MES00000021", new string[] { wo })); } if (sfcdb != null) { DBPools["SFCDB"].Return(sfcdb); } } catch (Exception ex) { if (sfcdb != null) { DBPools["SFCDB"].Return(sfcdb); } throw ex; } }