2023年4月16日 星期日

V80204 - 呼叫 WebService WS_ALS02_WBS - WebService 匯入及呼叫 - 1>參考 2>Connected Services - getWS_xxxx_

 目的: V80204  - 呼叫 WebService  WS_ALS02_WBS  - 取得 WBS+機號的報工工時

處理說明:  1>呼叫 WebSerivce 函式 = class.function
                       找出 WebService的  class 及 function
                   2>匯入 WebService 網址 - 找出 WS 的 class 及 function
                        [方案總管] --> [參考] -->[加入服務參考]
                        執行後 , [方案總管] --> [Connected Services]  --> 會新增一class
                   3>web.config 將重覆的 WebService名稱 remak ,
                       否則會有錯誤訊息  





1>*.cs
3>呼叫 WebService 函式的方法:  myfunc.getWS_ALS_WBSHR(string par_WBS, string par_ASN)
        //取得 WBS + ACNO.報工工時        
        //傳入參數:  par_WBS, par_ACNO , 若機號空白,則傳回該WBS的所有機號.工作小時
        //傳回參數:  工作小時
        //                     --> WS_ALS02 原本以分鐘傳回, 以小時為計算單位必需 /60 , 取小數2位        
        public static dynamic getWS_ALS_WBSHR(string par_WBS, string par_ASN)
        {
            string Tmp_hour = "0";
            string Tmp_Str = "";
            string Tmp_Str1 = "", Tmp_Str2 = "";
            double Tmp_double1 = 0;
            if (par_WBS != "")
            {
                ws_als_wbshour.ws_als_wbshourSoapClient wbshour_cls
                                       new ws_als_wbshour.ws_als_wbshourSoapClient();
                try
                {
                    Tmp_Str = wbshour_cls.wbshour(par_WBS, par_ASN);
                    //將 [分鐘]字串轉成[小時]字串
                    Tmp_Str1 = Min2Hr(Tmp_Str1);
                    Tmp_hour = Tmp_Str1;
                }
                catch (Exception ex)
                { }  //throw ex;  可能回傳 null
                finally
                { };
            }
            return Tmp_hour;
        }

2>*.js
{
                        xtype: 'button',
                        id: 'btn1_Show',
                        flex: 2,
                        border: 1,
                        text: '報工工時顯示',
                        iconCls: 'icon-search',
                        handler: function () {
                            //s1_form 的所有欄位均加入 np  - type=2
                   var np = s_JSON('s1_form', 2); //TMFunction.js, 組合form上的查詢條件為json參數傳遞
                            np['s1_WBS'] = Ext.getCmp('s1_WBS').getValue();
                            np['s1_ACNO'] = Ext.getCmp('s1_ACNO').getValue();
                            //因為 LoadMask 無作用,所以改用 label 來顯示訊息
                            //Ext.getCmp("waitlbl").setVisible(true);
                            //Ext.getCmp("waitlbl").update;
                            //Ext.getCmp("waitlbl").show();                            
                            var Proc_Msg;
                            try {
                                Proc_Msg = new Ext.LoadMask(Ext.getCmp("s1_PROCMSG"),
                                    { msg: 'WBS報工工時顯示處理中, 請稍候...', }
                                );
                                Proc_Msg.show();//使用 mask 需手動呼叫show() 方法下
                                //getGridData_M --> 轉工只有曾在於工作中心就會列入  , 後來改為  [目前工作中心]=xxxx , 才顯示
                                //gridstore.getProxy().url = '../api/V80205API/getGridData_M';

                                //2022/06/15 ..過濾條件若[目前工作中心]有值,則過濾 [目前工作中心]=xxxx, 其他 工作中心資料不顯示
                                // url 改為 getGridData_M_sub_WC --> 同 [過濾目前工作中心]鈕,的處理方法 ,                                 
                                //gridstore.getProxy().url = '../api/V120102API/getGridData_M';
                                //gridstore.getProxy().extraParams = np; //分頁OK,篩選條件OK
                                //console.log("1 reloadGridData - before");
                                //Ext.getCmp('grid_Single').reloadGridData();
                                //console.log("2 reloadGridData - after");
                                //取得  WBS+ACNO 的 WBS報工工時
                                Ext.Ajax.timeout = 600000; //如果有ajax timeout問題可以加上去       

                                Ext.Ajax.request({
                                    url: '../../api/V80204API/get_WBS_ALS_HR',  //myfunc.getWS_ALS_WBSHR
                                    method: 'POST',
                                    //async: false,
                                    async: true,
                                    timeout: 600000,
                                    //standardSubmit: true, // 非 Ajax 的方式  //若要傳送檔案至前端, standardSubmit必需設為 true 
                                    params: np,
                                    success: function (response, opts) {
                                        console.log('0 get_WBS_ALS_HR sucess!!');
                                        //console.log('0 opts:', opts);
                                        //console.log('0 response:', response);
                                        console.log("success response.responseText:", response.responseText);
                                        var obj = Ext.decode(response.responseText);
                                        var Tmp_WBSHR = "";
                                        //console.log("obj:", obj);
                                        if (obj["success"]) {
                                            Tmp_WBSHR = obj["WBSHR"];
                                            //mysuccessalert(Tmp_WBSHR);
                                            console.log("success=true , Tmp_WBSHR=", Tmp_WBSHR);
                                            Ext.getCmp("s1_WBS_HR").setValue(Tmp_WBSHR);
                                        }
                                        else {
                                            console.log(' 2 get_WBS_ALS_HR obj[sucess]  false !!');
                                            Tmp_Str = "[取得WBS報工工時]失敗 !! <br>"
                                                + obj["Rtn_Msg"];
                                            mysuccessalert(Tmp_Str);
                                        }
                                        Proc_Msg.hide();  //使用 mask 需手動呼叫hide() 方法下
                                        //Ext.getCmp("waitlbl").setVisible(false);                                        
                                    },
                                    failure: function (response, opts) {
                                        //console.log('uploadFileToDB failure !!');
                                        //console.log(" failure opts.response.responseText:", opts.response.responseText);
                                        console.log(' 3 get_WBS_ALS_HR failure !!');
                                        var obj = Ext.decode(response.responseText);
                                        console.log("obj:", obj);
                                        Tmp_Str = "[取得WBS報工工時]失敗!! <br>"
                                                         + obj["Rtn_Msg"];
                                        mywarnalert(Tmp_Str);
                                        //Ext.getCmp("waitlbl").setVisible(false);
                                        Proc_Msg.hide();  //使用 mask 需手動呼叫hide() 方法下
                                    } // end of failure 
                                });  // end of submit


                            }
                            finally {
                                //Proc_Msg.hide();  //使用 mask 需手動呼叫hide() 方法下
                            }

                        }
                    },  // end of 顯示資料



2>WebService 範例: WS_SAP12:  變更勾選工單之SAP工單狀態。

URLhttp://194.1.5.106/sapws/ZRFC_ZCO02.asmx  Method: PROCESS_TRANS_WEB_CO02



4>WebService – [加入服務參考]時 – 會將WebService 網址記錄在 web.config
--> AMM_PLM04可能會重覆 , 以致出現錯誤訊息(xx找到多個該合約的端點組態xx)
-->將其中一個 AMM_PLM04 刪除即可







沒有留言:

張貼留言