Exemple #1
0
 public override void Start()
 {
     IsRuning = synLock.IsLock("TJL5_DownLoadWO", SFCDB, DB_TYPE_ENUM.Oracle, out lockIp);
     if (IsRuning)
     {
         throw new Exception("TJL5 DownLoadWO interface is running on " + lockIp + ",Please try again later");
     }
     try
     {
         synLock.SYNC_Lock(BU, ip, "TJL5_DownLoadWO", "TJL5_DownLoadWO", "interface", SFCDB, DB_TYPE_ENUM.Oracle);
         SFCDB.CommitTrain();
         CallRFC();
     }
     catch (Exception ex)
     {
         SFCDB.RollbackTrain();
         throw new Exception("Start DownLoadWO Fail" + ex.Message);
     }
     synLock.SYNC_UnLock(BU, ip, "TJL5_DownLoadWO", "TJL5_DownLoadWO", "interface", SFCDB, DB_TYPE_ENUM.Oracle);
     SFCDB.CommitTrain();
 }
Exemple #2
0
        public override void Start()
        {
            //base.Start();
            IsRuning = synLock.IsLock("HWD_WOToMRBBackFlush", SFCDB, DB_TYPE_ENUM.Oracle, out lockIp);
            if (IsRuning)
            {
                throw new Exception("HWD WOToMRBBackFlush interface is running on " + lockIp + ",Please try again later");
            }

            try
            {
                synLock.SYNC_Lock(BU, ip, "HWD_WOToMRBBackFlush", "HWD_WOToMRBBackFlush", "interface", SFCDB, DB_TYPE_ENUM.Oracle);
                SFCDB.CommitTrain();
                DoMrbBackFlush();
            }
            catch (Exception ex)
            {
                SFCDB.RollbackTrain();
                throw new Exception("Start MrbBackFlush Fail" + ex.Message);
            }
            synLock.SYNC_UnLock(BU, ip, "HWD_WOToMRBBackFlush", "HWD_WOToMRBBackFlush", "interface", SFCDB, DB_TYPE_ENUM.Oracle);
            SFCDB.CommitTrain();
        }
Exemple #3
0
 public override void Start()
 {
     //判斷當前任務是否正在被執行:SELECT * From R_SYNC_LOCK where Lock_Name='{Section}'
     IsRuning = synLock.IsLock(Section, SFCDB, DB_TYPE_ENUM.Oracle, out lockIp);
     if (IsRuning)
     {
         throw new Exception(Section + " interface is running on " + lockIp + ",Please try again later");
     }
     try
     {
         //TEST();
         //寫一筆正在執行的記錄
         synLock.SYNC_Lock(BU, ip, Section, Section, "interface", SFCDB, DB_TYPE_ENUM.Oracle);
         SFCDB.CommitTrain();
         CallRFC();
     }
     catch (Exception ex)
     {
         SFCDB.RollbackTrain();
         throw new Exception("Start DownLoadWO Fail" + ex.Message);
     }
     synLock.SYNC_UnLock(BU, ip, Section, Section, "interface", SFCDB, DB_TYPE_ENUM.Oracle);
     SFCDB.CommitTrain();
 }
Exemple #4
0
 public void DoBackFlushGT(string clientip)
 {
     try
     {
         R_MRB_GT          = new T_R_MRB_GT(SFCDB, DB_TYPE_ENUM.Oracle);
         H_MRB_GT          = new T_H_MRB_GT(SFCDB, DB_TYPE_ENUM.Oracle);
         synLock           = new T_R_SYNC_LOCK(SFCDB, DB_TYPE_ENUM.Oracle);
         zrfc_sfc_nsg_0020 = new ZRFC_SFC_NSG_0020();
         zcpp_nsg_0091     = new ZCPP_NSBG_0091();
         IsRuning          = synLock.IsLock("HWD_MrbBackFlush", SFCDB, DB_TYPE_ENUM.Oracle, out lockIp);
         if (IsRuning)
         {
             throw new Exception("HWD MrbBackFlush interface is running on " + lockIp + ",Please try again later");
         }
         synLock.SYNC_Lock(BU, clientip, "HWD_MrbBackFlush", "HWD_MrbBackFlush", this.LoginUser.EMP_NO, SFCDB, DB_TYPE_ENUM.Oracle);
         DoMrbBackFlush();
         synLock.SYNC_UnLock(BU, clientip, "HWD_MrbBackFlush", "HWD_MrbBackFlush", this.LoginUser.EMP_NO, SFCDB, DB_TYPE_ENUM.Oracle);
     }
     catch (Exception ex)
     {
         synLock.SYNC_UnLock(BU, clientip, "HWD_MrbBackFlush", "HWD_MrbBackFlush", this.LoginUser.EMP_NO, SFCDB, DB_TYPE_ENUM.Oracle);
         throw new Exception("Start MrbBackFlush Fail" + ex.Message);
     }
 }
Exemple #5
0
        /// <summary>
        /// MRB 組裝退料拋賬
        /// </summary>
        /// <param name="requestValue"></param>
        /// <param name="Data"></param>
        /// <param name="StationReturn"></param>
        public void DoAssyToMrbBackFlush(JObject requestValue, JObject Data, MESStationReturn StationReturn)
        {
            try
            {
                SFCDB         = DBPools["SFCDB"].Borrow();
                R_MRB_GT      = new T_R_MRB_GT(SFCDB, DB_TYPE_ENUM.Oracle);
                H_MRB_GT      = new T_H_MRB_GT(SFCDB, DB_TYPE_ENUM.Oracle);
                synLock       = new T_R_SYNC_LOCK(SFCDB, DB_TYPE_ENUM.Oracle);
                zcpp_nsg_0091 = new ZCPP_NSBG_0091();
                MRBGTList     = new List <R_MRB_GT>();
                MRBTable      = new DataTable();

                if (Interface.IsMonthly(SFCDB, DB_TYPE_ENUM.Oracle))
                {
                    //月結不給拋賬
                    throw new Exception("This time is monthly,can't BackFlush");
                }

                IsRuning = synLock.IsLock("HWD_AssyToMrbBackFlush", SFCDB, DB_TYPE_ENUM.Oracle, out lockIp);
                if (IsRuning)
                {
                    throw new Exception("HWD AssyToMrbBackFlush interface is running on " + lockIp + ",Please try again later");
                }
                synLock.SYNC_Lock(BU, this.IP, "HWD_AssyToMrbBackFlush", "HWD_AssyToMrbBackFlush", this.LoginUser.EMP_NO, SFCDB, DB_TYPE_ENUM.Oracle);

                sql      = $@" select * from r_mrb_gt where sap_flag = 0 and zcpp_flag = 1 and sap_station_code is not null ";
                MRBTable = SFCDB.RunSelect(sql).Tables[0];
                if (MRBTable != null && MRBTable.Rows.Count > 0)
                {
                    foreach (DataRow row in MRBTable.Rows)
                    {
                        rowR_MRBGT = (Row_R_MRB_GT)R_MRB_GT.NewRow();
                        rowR_MRBGT.loadData(row);
                        MRBGTList.Add(rowR_MRBGT.GetDataObject());
                    }
                }
                postDate = Interface.GetPostDate(SFCDB);
                if (MRBGTList != null && MRBGTList.Count > 0)
                {
                    foreach (R_MRB_GT r_mrb_gt in MRBGTList)
                    {
                        rowR_MRBGT = null;
                        rowH_MRBGT = null;
                        logMessage = "";
                        zcpp_nsg_0091.SetValue("I_WERKS", "WDN1");
                        zcpp_nsg_0091.SetValue("I_MATNR", r_mrb_gt.SKUNO);
                        zcpp_nsg_0091.SetValue("I_LMNGA", r_mrb_gt.TOTAL_QTY.ToString());
                        zcpp_nsg_0091.SetValue("I_LGORT", r_mrb_gt.TO_STORAGE);
                        zcpp_nsg_0091.SetValue("I_AUFNR", r_mrb_gt.FROM_STORAGE);
                        zcpp_nsg_0091.SetValue("I_BUDAT", postDate);
                        rowR_MRBGT = (Row_R_MRB_GT)R_MRB_GT.GetObjByID(r_mrb_gt.ID, SFCDB);
                        try
                        {
                            zcpp_nsg_0091.CallRFC();
                            if (zcpp_nsg_0091.GetValue("O_MESSAGE").IndexOf("Material not exsit,pls check!") >= 0)
                            {
                                rowR_MRBGT.SAP_FLAG = "2";
                            }
                            else
                            {
                                rowR_MRBGT.SAP_FLAG = "1";
                            }
                        }
                        catch (Exception ex)
                        {
                            Interface.WriteIntoMESLog(SFCDB, BU, "MESStation", "MESStation.Interface.MrbBackFlush", "AssyToMrbBackFlush", r_mrb_gt.WORKORDERNO + ";" + this.IP + ";" + ex.ToString(), "", this.LoginUser.EMP_NO);
                            rowR_MRBGT.SAP_FLAG = "1";
                        }
                        SFCDB.ExecSQL(rowR_MRBGT.GetUpdateString(DB_TYPE_ENUM.Oracle));

                        logMessage                  = "M:" + zcpp_nsg_0091.GetValue("O_MESSAGE");
                        rowH_MRBGT                  = (Row_H_MRB_GT)H_MRB_GT.NewRow();
                        rowH_MRBGT.ID               = H_MRB_GT.GetNewID(BU, SFCDB);
                        rowH_MRBGT.WORKORDERNO      = r_mrb_gt.WORKORDERNO;
                        rowH_MRBGT.SAP_STATION_CODE = r_mrb_gt.SAP_STATION_CODE;
                        rowH_MRBGT.FROM_STORAGE     = r_mrb_gt.FROM_STORAGE;
                        rowH_MRBGT.TO_STORAGE       = r_mrb_gt.TO_STORAGE;
                        rowH_MRBGT.TOTAL_QTY        = r_mrb_gt.TOTAL_QTY;
                        rowH_MRBGT.CONFIRMED_FLAG   = r_mrb_gt.CONFIRMED_FLAG;
                        rowH_MRBGT.ZCPP_FLAG        = r_mrb_gt.ZCPP_FLAG;
                        rowH_MRBGT.SAP_FLAG         = r_mrb_gt.SAP_FLAG;
                        rowH_MRBGT.SKUNO            = r_mrb_gt.SKUNO;
                        rowH_MRBGT.SAP_MESSAGE      = logMessage;
                        rowH_MRBGT.EDIT_EMP         = this.LoginUser.EMP_NO;
                        rowH_MRBGT.EDIT_TIME        = Interface.GetDBDateTime(SFCDB, DB_TYPE_ENUM.Oracle);
                        SFCDB.ExecSQL(rowH_MRBGT.GetInsertString(DB_TYPE_ENUM.Oracle));
                    }
                }
                synLock.SYNC_UnLock(BU, this.IP, "HWD_AssyToMrbBackFlush", "HWD_AssyToMrbBackFlush", this.LoginUser.EMP_NO, SFCDB, DB_TYPE_ENUM.Oracle);
                if (SFCDB != null)
                {
                    DBPools["SFCDB"].Return(SFCDB);
                }
                StationReturn.Status = StationReturnStatusValue.Pass;
            }
            catch (Exception exception)
            {
                StationReturn.Status = StationReturnStatusValue.Fail;
                throw exception;
            }
        }
Exemple #6
0
        public void DoJobStockGT(JObject requestValue, JObject Data, MESStationReturn StationReturn)
        {
            OleExec SFCDB = DBPools["SFCDB"].Borrow();

            try
            {
                ZRFC_SFC_NSG_0020 zrfc_sfc_nsg_0020 = new ZRFC_SFC_NSG_0020(this.BU);
                string            lockIp            = "";
                string            postDate;
                string            o_flag     = "";
                string            o_flag1    = "";
                string            o_flag2    = "";
                string            o_message  = "";
                string            o_message1 = "";
                string            o_message2 = "";
                bool           IsRuning      = false;
                Row_R_STOCK_GT rowStockGT;
                DataTable      table = new DataTable();
                SFCDB.ThrowSqlExeception = true;
                T_R_SYNC_LOCK t_r_sync_lock = new T_R_SYNC_LOCK(SFCDB, DB_TYPE_ENUM.Oracle);
                T_R_STOCK_GT  t_r_stock_gt  = new T_R_STOCK_GT(SFCDB, DB_TYPE_ENUM.Oracle);
                T_R_STOCK     t_r_stock     = new T_R_STOCK(SFCDB, DB_TYPE_ENUM.Oracle);

                if (Interface.IsMonthly(SFCDB, DB_TYPE_ENUM.Oracle))
                {
                    //月結不給拋賬
                    //throw new Exception("This time is monthly,can't BackFlush");
                    throw new Exception(MESReturnMessage.GetMESReturnMessage("MSGCODE20180803152122", new string[] { }));
                }

                IsRuning = t_r_sync_lock.IsLock("JOBSTOCKGT", SFCDB, DB_TYPE_ENUM.Oracle, out lockIp);
                if (IsRuning)
                {
                    //throw new Exception("JOBSTOCKGT interface is running on " + lockIp + ",Please try again later");
                    throw new Exception(MESReturnMessage.GetMESReturnMessage("MSGCODE20180803152222", new string[] { lockIp }));
                }
                t_r_sync_lock.SYNC_Lock(BU, this.IP, "JOBSTOCKGT", "JOBSTOCKGT", this.LoginUser.EMP_NO, SFCDB, DB_TYPE_ENUM.Oracle);

                List <R_STOCK_GT> GTList = t_r_stock_gt.GetNotGTListByConfirmedFlag("0", SFCDB);

                postDate = Interface.GetPostDate(SFCDB);

                if (GTList != null && GTList.Count > 0)
                {
                    foreach (R_STOCK_GT r_stock_gt in GTList)
                    {
                        rowStockGT = null;
                        zrfc_sfc_nsg_0020.SetValue("I_AUFNR", r_stock_gt.WORKORDERNO);
                        zrfc_sfc_nsg_0020.SetValue("I_BUDAT", postDate);
                        zrfc_sfc_nsg_0020.SetValue("I_FLAG", r_stock_gt.CONFIRMED_FLAG);
                        zrfc_sfc_nsg_0020.SetValue("I_LGORT_TO", r_stock_gt.TO_STORAGE);
                        zrfc_sfc_nsg_0020.SetValue("I_LMNGA", r_stock_gt.TOTAL_QTY.ToString());
                        zrfc_sfc_nsg_0020.SetValue("I_STATION", r_stock_gt.SAP_STATION_CODE);
                        try
                        {
                            // zrfc_sfc_nsg_0020 中包含三個動作101,521,轉倉,flag,flag1,flag2 一次對應這三個動作
                            // flag,flag1,flag2 這幾個flag 0表示OK,1表示false
                            zrfc_sfc_nsg_0020.CallRFC();
                            o_flag     = zrfc_sfc_nsg_0020.GetValue("O_FLAG");
                            o_flag1    = zrfc_sfc_nsg_0020.GetValue("O_FLAG1");
                            o_flag2    = zrfc_sfc_nsg_0020.GetValue("O_FLAG2");
                            o_message  = zrfc_sfc_nsg_0020.GetValue("O_MESSAGE");
                            o_message1 = zrfc_sfc_nsg_0020.GetValue("O_MESSAGE1");
                            o_message2 = zrfc_sfc_nsg_0020.GetValue("O_MESSAGE2");

                            rowStockGT                = (Row_R_STOCK_GT)t_r_stock_gt.GetObjByID(r_stock_gt.ID, SFCDB);
                            rowStockGT.SAP_MESSAGE    = "101:" + o_message + ";521:" + o_message1 + ";311" + o_message2;
                            rowStockGT.BACKFLUSH_TIME = GetDBDateTime();
                            if (zrfc_sfc_nsg_0020.GetValue("O_FLAG") == "0")
                            {
                                rowStockGT.SAP_FLAG = "1";
                                t_r_stock.UpdateSapFlagByGTID(rowStockGT.ID, rowStockGT.SAP_FLAG, SFCDB);
                            }
                            else
                            {
                                rowStockGT.SAP_FLAG = "2";
                            }
                            SFCDB.ExecSQL(rowStockGT.GetUpdateString(DB_TYPE_ENUM.Oracle));
                        }
                        catch (Exception ex)
                        {
                            Interface.WriteIntoMESLog(SFCDB, BU, "MESStation", "MESStation.Interface.JobStockGT", "DoJobStockGT", r_stock_gt.WORKORDERNO + ";" + this.IP + ";" + ex.ToString(), "", this.LoginUser.EMP_NO);
                            r_stock_gt.SAP_FLAG = "2";
                        }
                    }
                }
                t_r_sync_lock.SYNC_UnLock(BU, this.IP, "JOBSTOCKGT", "JOBSTOCKGT", this.LoginUser.EMP_NO, SFCDB, DB_TYPE_ENUM.Oracle);
                if (SFCDB != null)
                {
                    DBPools["SFCDB"].Return(SFCDB);
                }
                StationReturn.Status = StationReturnStatusValue.Pass;
            }
            catch (Exception exception)
            {
                if (SFCDB != null)
                {
                    DBPools["SFCDB"].Return(SFCDB);
                }
                StationReturn.Status = StationReturnStatusValue.Fail;
                throw exception;
            }
        }
        public void CallRfcBackFlush()
        {
            if (!isRun)
            {
                sfcdb = new OleExec(DBName, false);
                //判斷是否有其他執行
                TR_SYNC_LOCK = new T_R_SYNC_LOCK(sfcdb, MESDataObject.DB_TYPE_ENUM.Oracle);
                string lockIP     = "";
                string sapMessage = "";
                bool   isLock     = TR_SYNC_LOCK.IsLock("BACKFLUSH", sfcdb, MESDataObject.DB_TYPE_ENUM.Oracle, out lockIP);
                if (isLock)
                {
                    throw new Exception("BackFlush Is Running,Please Wait!");
                }
                else
                {
                    TR_SYNC_LOCK.SYNC_Lock(BU, IP, "HWD", "BACKFLUSH", "Interface", sfcdb, MESDataObject.DB_TYPE_ENUM.Oracle);
                    isRun = true;
                }

                if (InterfacePublicValues.IsMonthly(sfcdb, MESDataObject.DB_TYPE_ENUM.Oracle))
                {
                    //月結不給拋賬
                    throw new Exception("This time is monthly,can't BackFlush");
                }


                if (setCtrlEnableDelegate != null)
                {
                    setCtrlEnableDelegate("btnCallRFC", false);
                    setCtrlEnableDelegate("btnStart", false);
                }
                try
                {
                    ZRFC_SFC_NSG_0009 RFC     = new ZRFC_SFC_NSG_0009(_BU);
                    ZRFC_SFC_NSG_0022 RW_RFC  = new ZRFC_SFC_NSG_0022(_BU);
                    string[]          ReWorks = REWORK.Split(new char[] { ',' });
                    int curCount = 0;
                    T_R_BACKFLUSH_HISTORY TR_BACKFLUSH_HISTORY = new T_R_BACKFLUSH_HISTORY(sfcdb, MESDataObject.DB_TYPE_ENUM.Oracle);
                    string ConfigPostDate = InterfacePublicValues.GetPostDate(sfcdb);
                    foreach (R_BACKFLUSH_CHECK item in bkList)
                    {
                        try
                        {
                            curCount++;
                            if (processRateDelegate != null)
                            {
                                processRateDelegate("BackFlushProgressBar", "labBackFlushProgress", bkList.Count, curCount);
                            }
                            if (item.DIFF_QTY > 0)
                            {
                                bool isRework = false;
                                for (int i = 0; i < ReWorks.Length; i++)
                                {
                                    if (item.WORKORDERNO.IndexOf(ReWorks[i]) == 0)
                                    {
                                        isRework = true;
                                        break;
                                    }
                                }
                                if (isRework)
                                {
                                    RW_RFC.SetValue(item.WORKORDERNO, ConfigPostDate, item.DIFF_QTY.ToString(), item.SAP_STATION);
                                    RW_RFC.CallRFC();
                                    MESDataObject.Module.R_BACKFLUSH_HISTORY his = new MESDataObject.Module.R_BACKFLUSH_HISTORY();
                                    his.WORKORDERNO   = item.WORKORDERNO;
                                    his.WORKORDER_QTY = (double?)item.WORKORDER_QTY;
                                    his.SFC_QTY       = (double?)item.SFC_QTY;
                                    his.SFC_STATION   = item.SFC_STATION;
                                    his.SKUNO         = item.SKUNO;
                                    his.SAP_STATION   = item.SAP_STATION;
                                    his.LAST_SFC_QTY  = (double?)item.LAST_SFC_QTY;
                                    his.DIFF_QTY      = (double?)item.DIFF_QTY;
                                    his.DIFF_QTY1     = (double?)item.DIFF_QTY1;
                                    his.BACK_DATE     = GetDBTime(sfcdb);
                                    his.TIMES         = 0;
                                    his.DIFF_QTY2     = (double?)item.DIFF_QTY2;
                                    his.MRB_QTY       = (double?)item.MRB_QTY;
                                    string resu = RW_RFC.GetValue("O_FLAG");
                                    if (resu == "0")
                                    {
                                        his.RESULT = "Y";
                                        resu       = RW_RFC.GetValue("O_FLAG1");
                                        if (resu == "1")
                                        {
                                            WriteLog.WriteIntoMESLog(sfcdb, _BU, "Interface",
                                                                     "MESInterface.HWD.BackFlush.BackFlushHelp",
                                                                     "CallRfcBackFlush", his.WORKORDERNO + ","
                                                                     + his.SAP_STATION + ",521 fail:" +
                                                                     RW_RFC.GetValue("O_MESSAGE1"), "", "System");
                                        }
                                    }
                                    else
                                    {
                                        his.RESULT = "N";
                                    }
                                    TR_BACKFLUSH_HISTORY.Add(his, sfcdb);
                                }
                                else
                                {
                                    RFC.SetValue(item.WORKORDERNO,
                                                 item.SAP_STATION,
                                                 item.DIFF_QTY.ToString(), ConfigPostDate);

                                    RFC.CallRFC();
                                    MESDataObject.Module.R_BACKFLUSH_HISTORY his = new MESDataObject.Module.R_BACKFLUSH_HISTORY();
                                    his.WORKORDERNO   = item.WORKORDERNO;
                                    his.WORKORDER_QTY = (double?)item.WORKORDER_QTY;
                                    his.SFC_QTY       = (double?)item.SFC_QTY;
                                    his.SFC_STATION   = item.SFC_STATION;
                                    his.SKUNO         = item.SKUNO;
                                    his.SAP_STATION   = item.SAP_STATION;
                                    his.LAST_SFC_QTY  = (double?)item.LAST_SFC_QTY;
                                    his.DIFF_QTY      = (double?)item.DIFF_QTY;
                                    his.DIFF_QTY1     = (double?)item.DIFF_QTY1;
                                    his.BACK_DATE     = GetDBTime(sfcdb);
                                    his.TIMES         = 0;
                                    his.DIFF_QTY2     = (double?)item.DIFF_QTY2;
                                    his.MRB_QTY       = (double?)item.MRB_QTY;
                                    string resu = RFC.GetValue("O_FLAG");
                                    if (resu == "0")
                                    {
                                        his.RESULT = "Y";
                                    }
                                    else
                                    {
                                        his.RESULT = "N";
                                        sapMessage = RFC.GetValue("O_MESSAGE");
                                        WriteLog.WriteIntoMESLog(sfcdb, _BU, "Interface", "MESInterface.HWD.BackFlush.BackFlushHelp", "CallRfcBackFlush",
                                                                 item.WORKORDERNO + "," + item.SAP_STATION + ":" + sapMessage, "", "System");
                                    }
                                    TR_BACKFLUSH_HISTORY.Add(his, sfcdb);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            WriteLog.WriteIntoMESLog(sfcdb, _BU, "Interface",
                                                     "MESInterface.HWD.BackFlush.BackFlushHelp",
                                                     "CallRfcBackFlush", item.WORKORDERNO + "," + item.SAP_STATION + ":" + ex.Message, "", "System");
                            continue;
                        }
                    }
                    isRun = false;
                    TR_SYNC_LOCK.SYNC_UnLock(BU, IP, "HWD", "BACKFLUSH", "Interface", sfcdb, MESDataObject.DB_TYPE_ENUM.Oracle);
                    if (setCtrlEnableDelegate != null)
                    {
                        setCtrlEnableDelegate("btnStart", true);
                    }
                }
                catch (Exception ex)
                {
                    WriteLog.WriteIntoMESLog(sfcdb, _BU, "Interface",
                                             "MESInterface.HWD.BackFlush.BackFlushHelp",
                                             "CallRfcBackFlush", ex.Message, "", "System");
                    isRun = false;
                    TR_SYNC_LOCK.SYNC_UnLock(BU, IP, "HWD", "BACKFLUSH", "Interface", sfcdb, MESDataObject.DB_TYPE_ENUM.Oracle);
                    if (setCtrlEnableDelegate != null)
                    {
                        setCtrlEnableDelegate("btnStart", true);
                    }
                }
            }
        }
        public void CallRFCBackFlush()
        {
            IsRuning = synLock.IsLock("HWD_StockInBackFlush", SFCDB, DB_TYPE_ENUM.Oracle, out lockIp);
            if (IsRuning)
            {
                throw new Exception("HWD StockInBackFlush interface is running on " + lockIp + ",Please try again later");
            }
            if (InterfacePublicValues.IsMonthly(SFCDB, DB_TYPE_ENUM.Oracle))
            {
                //月結不給拋賬
                throw new Exception("This time is monthly,can't BackFlush");
            }

            synLock.SYNC_Lock(BU, ip, "HWD_StockInBackFlush", "HWD_StockInBackFlush", "interface", SFCDB, DB_TYPE_ENUM.Oracle);
            SFCDB.CommitTrain();
            backFlushList = t_r_sap_temp.GetStockInBackFlushList(SFCDB);
            dateTimeNow   = DateTime.Parse(InterfacePublicValues.GetPostDate(SFCDB));
            if (backFlushList != null)
            {
                foreach (R_SAP_TEMP temp in backFlushList)
                {
                    logMsg     = "";
                    sapMsg     = "";
                    r_sap_temp = null;
                    zcmm_nsbg_0051.SetValue(Plant, temp.SKUNO, temp.FROM_STORAGE, temp.TO_STORAGE, temp.QTY.ToString(), temp.TYPE, dateTimeNow, "311");
                    zcmm_nsbg_0051.CallRFC();

                    r_sap_temp = (Row_R_SAP_TEMP)t_r_sap_temp.GetObjByID(temp.ID, SFCDB);
                    if (zcmm_nsbg_0051.GetValue("O_FLAG") == "1")
                    {
                        //失敗
                        sapMsg = " T:" + dateTimeNow.ToString("yyyy/MM/dd HH:mm:ss") + "M1:" + zcmm_nsbg_0051.GetValue("O_MESSAGE");
                        try
                        {
                            sapMsg += " M2:" + zcmm_nsbg_0051.GetTableValue("OUT_TAB").Rows[0]["MESSAGE"].ToString();
                        }
                        catch
                        {
                            sapMsg += " M2:null";
                        }
                        r_sap_temp.FAIL_COUNT = r_sap_temp.FAIL_COUNT + 1;
                        if (r_sap_temp.FAIL_COUNT >= 100)
                        {
                            r_sap_temp.SAP_FLAG = "3";
                        }
                        BackFlushOK = false;
                    }
                    else
                    {
                        //成功
                        sapMsg = "OK:" + zcmm_nsbg_0051.GetValue("O_MBLNR") + " T:" + dateTimeNow.ToString("yyyy/MM/dd HH:mm:ss");
                        r_sap_temp.EDIT_TIME = dateTimeNow;
                        r_sap_temp.SAP_FLAG  = "2";
                        BackFlushOK          = true;
                    }
                    SFCDB.ExecSQL(r_sap_temp.GetUpdateString(DB_TYPE_ENUM.Oracle));
                    logMsg = temp.SKUNO + ":" + temp.QTY.ToString() + ":" + sapMsg;
                    // write mes log
                    //WriteLog.WriteIntoMESLog(SFCDB, BU, "MESInterface", "MESInterface.HWD.StockInBackFlush", "CallRFCB", ip + ";" + logMsg, "", "interface");

                    // write r_saplog
                    try
                    {
                        r_saplog              = (Row_R_SAPLOG)t_r_saplog.NewRow();
                        r_saplog.ID           = t_r_saplog.GetNewID(BU, SFCDB);
                        r_saplog.WORKTIME     = temp.EDIT_TIME;
                        r_saplog.SKUNO        = temp.SKUNO;
                        r_saplog.QTY          = temp.QTY;
                        r_saplog.ERRORTYPE    = "STOCKIN";
                        r_saplog.ERRORMESSAGE = sapMsg;
                        SFCDB.ExecSQL(r_saplog.GetInsertString(DB_TYPE_ENUM.Oracle));
                        StockInBackFlush_UI.OutPutMessage(temp.SKUNO + ":" + temp.QTY.ToString(), sapMsg, BackFlushOK);
                    }
                    catch (Exception ex)
                    {
                        logMsg = temp.SKUNO + ":" + temp.QTY + ";insert into r_saplog fail" + ex.Message;
                        WriteLog.WriteIntoMESLog(SFCDB, BU, "MESInterface", "MESInterface.HWD.StockInBackFlush", "CallRFCB", ip + ";" + logMsg, "", "interface");
                    }
                    SFCDB.CommitTrain();
                }
            }
            synLock.SYNC_UnLock(BU, ip, "HWD_StockInBackFlush", "HWD_StockInBackFlush", "interface", SFCDB, DB_TYPE_ENUM.Oracle);
            SFCDB.CommitTrain();
        }