Ejemplo n.º 1
0
 public override void init()
 {
     try
     {
         //從Ini檔中獲取BU/Plant/DB/Cust/Count/ConvertWo/DownloadWO
         BU    = ConfigGet("BU");
         Plant = ConfigGet("PLANT");
         DB    = ConfigGet("DB");//與App.config中配置的匹配
         CUST  = ConfigGet("CUST");
         COUNT = ConfigGet("COUNT");
         //可以依工單前綴來確定哪種類型的工單需要自動轉,哪種需手動轉
         arrayConvertWO = ConfigGet("CONVERTWO").Split(',');
         _downloadWO    = ConfigGet("DOWNLOADWO");
         List <System.Net.IPAddress> temp = HWDNNSFCBase.HostInfo.IP.Where(ipv4 => ipv4.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).ToList();
         ip = temp[0].ToString();
         //創建DownloadWO_UI,并附值給輸入對象Output.UI
         Output.UI = new DownLoadWO_UI(this);
         //依據Ini檔配置的DB從ConnectionManager中獲取數據庫連接
         SFCDB = new OleExec(DB, false);
         //程序運行狀態表
         synLock = new T_R_SYNC_LOCK(SFCDB, DB_TYPE_ENUM.Oracle);
         //工單欄位對照表
         C_TAB_COLUMN_MAP = new T_C_TAB_COLUMN_MAP(SFCDB, DB_TYPE_ENUM.Oracle);
         //從SAP Download下來后分別存儲在以下三張表
         R_WO_HEADER = new T_R_WO_HEADER(SFCDB, DB_TYPE_ENUM.Oracle);
         R_WO_ITEM   = new T_R_WO_ITEM(SFCDB, DB_TYPE_ENUM.Oracle);
         R_WO_TEXT   = new T_R_WO_TEXT(SFCDB, DB_TYPE_ENUM.Oracle);
         //獲取料號/Route
         C_SKU       = new T_C_SKU(SFCDB, DB_TYPE_ENUM.Oracle);
         RouteDetail = new T_C_ROUTE_DETAIL(SFCDB, DB_TYPE_ENUM.Oracle);
         C_ROUTE     = new T_C_ROUTE(SFCDB, DB_TYPE_ENUM.Oracle);
         T_Series    = new T_C_SERIES(SFCDB, DB_TYPE_ENUM.Oracle);
         //工單類型及前綴信息
         WOType      = new T_R_WO_TYPE(SFCDB, DB_TYPE_ENUM.Oracle);
         Keypart     = new T_C_KEYPART(SFCDB, DB_TYPE_ENUM.Oracle);
         R_WO_BASE   = new T_R_WO_BASE(SFCDB, DB_TYPE_ENUM.Oracle);
         t_c_kp_list = new T_C_KP_LIST(SFCDB, DB_TYPE_ENUM.Oracle);
         //創建RFC類:建立SAP連接,建立RFC輸入輸出參數
         ZRFC_SFC_NSG_0001B = new ZRFC_SFC_NSG_0001B(BU);
     }
     catch (Exception e)
     {
         throw new Exception("Init DownLoadWO Fail" + e.Message);
     }
     //取得RFC的輸出參數Table對象,并附值給Output.Tables
     Output.Tables.Add(ZRFC_SFC_NSG_0001B.GetTableValue("ITAB"));
     Output.Tables.Add(ZRFC_SFC_NSG_0001B.GetTableValue("WO_HEADER"));
     Output.Tables.Add(ZRFC_SFC_NSG_0001B.GetTableValue("WO_ITEM"));
     Output.Tables.Add(ZRFC_SFC_NSG_0001B.GetTableValue("WO_TEXT"));
 }
Ejemplo n.º 2
0
 public override void init()
 {
     try
     {
         BU             = ConfigGet("BU");
         Plant          = ConfigGet("PLANT");
         DB             = ConfigGet("DB");
         CUST           = ConfigGet("CUST");
         COUNT          = ConfigGet("COUNT");
         arrayConvertWO = ConfigGet("CONVERTWO").Split(',');
         _downloadWO    = ConfigGet("DOWNLOADWO");
         List <System.Net.IPAddress> temp = HWDNNSFCBase.HostInfo.IP.Where(ipv4 => ipv4.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).ToList();
         ip                 = temp[0].ToString();
         Output.UI          = new DownLoadWO_UI(this);
         SFCDB              = new OleExec(DB, false);
         synLock            = new T_R_SYNC_LOCK(SFCDB, DB_TYPE_ENUM.Oracle);
         C_TAB_COLUMN_MAP   = new T_C_TAB_COLUMN_MAP(SFCDB, DB_TYPE_ENUM.Oracle);
         C_SKU              = new T_C_SKU(SFCDB, DB_TYPE_ENUM.Oracle);
         R_WO_HEADER        = new T_R_WO_HEADER(SFCDB, DB_TYPE_ENUM.Oracle);
         R_WO_ITEM          = new T_R_WO_ITEM(SFCDB, DB_TYPE_ENUM.Oracle);
         R_WO_TEXT          = new T_R_WO_TEXT(SFCDB, DB_TYPE_ENUM.Oracle);
         RouteDetail        = new T_C_ROUTE_DETAIL(SFCDB, DB_TYPE_ENUM.Oracle);
         WOType             = new T_R_WO_TYPE(SFCDB, DB_TYPE_ENUM.Oracle);
         Keypart            = new T_C_KEYPART(SFCDB, DB_TYPE_ENUM.Oracle);
         C_ROUTE            = new T_C_ROUTE(SFCDB, DB_TYPE_ENUM.Oracle);
         R_WO_BASE          = new T_R_WO_BASE(SFCDB, DB_TYPE_ENUM.Oracle);
         T_Series           = new T_C_SERIES(SFCDB, DB_TYPE_ENUM.Oracle);
         t_c_kp_list        = new T_C_KP_LIST(SFCDB, DB_TYPE_ENUM.Oracle);
         ZRFC_SFC_NSG_0001B = new ZRFC_SFC_NSG_0001B(BU);
     }
     catch (Exception e)
     {
         throw new Exception("Init DownLoadWO Fail" + e.Message);
     }
     Output.Tables.Add(ZRFC_SFC_NSG_0001B.GetTableValue("ITAB"));
     Output.Tables.Add(ZRFC_SFC_NSG_0001B.GetTableValue("WO_HEADER"));
     Output.Tables.Add(ZRFC_SFC_NSG_0001B.GetTableValue("WO_ITEM"));
     Output.Tables.Add(ZRFC_SFC_NSG_0001B.GetTableValue("WO_TEXT"));
 }
Ejemplo n.º 3
0
        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;
                }
            }
        }