2022年10月25日 星期二

V20107 – 檢核編輯欄位值是否正確 - checkFormValue()

 目的: V20107 – 檢核編輯欄位值是否正確  - checkFormValue()

處理說明: 1>宣告 var  is_Ok ; 若 checkFormValue()  正確,則傳回 true, 否則傳回 false
                       不是由 success: function(response,opts) 傳回值
                        var is_OK=true;
                        Ext.getCmp('btn_save').checkFormValue = function () {
                        var buttonModel = Ext.create('G_buttonModel'); 
                        var modelType = buttonModel.getModelType();
                        is_Ok = true;
                       //若[新增]模式,則檢核 [工作中心]+[件號] 不可重複,
                       if (modelType == 1) { 
                            Ext.Ajax.request({
                                     url: '../../api/V20107API/check_isnotDual',
                                     method: 'POST',
                                     async: false,
                                     params: np,
                                     success: function (response, opts) {
                                         is_Ok=true;
                                     failure: function(response, opts) {
                                         is_Ok=false;
                                  })
                         return is_Ok;  

                       });


1>*.js

//[新增]時,檢核 [工作中心]+[件號] 不可重複,
    //若重複, 則顯示訊息資料重複,請重新輸入
    var is_keepgoing = true;
    
    Ext.getCmp('btn_save').checkFormValue = function () {
        console.log("checkFormValue of V20107 ");
        var buttonModel = Ext.create('G_buttonModel'); 
        var modelType = buttonModel.getModelType();
        console.log("checkFormValue modelType=", modelType);
        is_Ok = true;
        //若[新增]模式,則檢核 [工作中心]+[件號] 不可重複,
        if (modelType == 1) {
            var np = {};
            var Tmp_WC = Ext.getCmp("WC").getValue();
            var Tmp_PN = Ext.getCmp("PN").getValue();
            np["WC"] = Tmp_WC;
            np["PN"] = Tmp_PN;
            Ext.Ajax.request({
                url: '../../api/V20107API/check_isnotDual',
                method: 'POST',
                async: false,
                params: np,
                success: function (response, opts) {
                    console.log('0 check_isnotDual sucess!!');
                    //console.log('0 opts:', opts);
                    //console.log('0 response:', response);
                    console.log("success response.responseText:", response.responseText);
                    var obj = Ext.decode(response.responseText);
                    //console.log("obj:", obj);
                    if (obj["success"]) {
                        console.log(' 1 check_isnotDual  true !!');
                        is_Ok = true;
                        return true;
                    }
                    else {
                        console.log(' 2 check_isnotDull obj[sucess]  false !!');
                        Tmp_Str = "工作中心(" + Tmp_WC + ")件號(" + Tmp_PN + ") 不可重覆<br>"
                            + " 請檢核 !!<br>"
                        mywarnalert(Tmp_Str);
                        is_Ok = false;
                        return false;
                    }
                },
                failure: function (response, opts) {
                    console.log(' 3 check_isnotDull failure !!');
                    var obj = Ext.decode(response.responseText);
                    console.log("obj:", obj);
                    Tmp_Str = "檢核[工作中心]+[件號]是否重覆失敗!! <br>"
                        + obj["Rtn_Msg"];
                    mywarnalert(Tmp_Str);
                    is_Ok = false;
                    return false;
                } // end of failure 
            });  // end of Ext.Ajax
        }// if modeltype==1        
        is_keepgoing = is_Ok;
        return is_Ok;
    };  // end of  Ext.getCmp('btn_save').checkFormValue = function () 


//按[存檔], 額外自行處理的部份,若  checkFormValue()=false (is_keepgoing=false), 則不往下執行
    Ext.getCmp('btn_save').on('click', function () {
        //若 checkFormValue 有問題,則 is_Keepgoing=false , 不往下執行
        if (is_keepgoing==false)
            return ;
        console.log('step 1 click_btn_save of V20107');
        if (!check_AMM_WKSTPD_isnull()) {
            console.log("if !check_AMM_WKSTPD_isnull() , return ");
            return ;   // AMM_WKSTPD 已有資料,不新增 4筆資料
        }
        //若 AMM_WKSTPD 為空值,則詢問是否為系統件維修,
        //若是,則  INSERT_AMM_WKSTPD4  ,寫入 4筆資料
        console.log("3 詢問是否為系統件維修嗎?");
        var Tmp_Msg = "本交修件是否為系統件維修嗎 ?";
        Ext.Msg.confirm('確認', Tmp_Msg, callBackFunc);
        function callBackFunc(id) {
            console.log("1 callBackFunc : 本交修件是否為系統件維修嗎 ?");
            if (id == 'no')
                return;
            //insert 四筆資料   AMM_WKSTPD
            var np = {};
            np["MITM"] = Ext.getCmp("MITM").getValue();
            np["PN"] = Ext.getCmp("PN").getValue();
            np["DEPID"] = Ext.getCmp("DEPID").getValue();
            np["WC"] = Ext.getCmp("WC").getValue();
            var isOk = true;
            Ext.Ajax.request({
                method: "POST",
                url: '../../api/V20107API/DO_Ins_AMM_WKSTPD4',
                params: np,
                async: false,
                success: function (response, opts) {
                    console.log("0 response.responseText=", response.responseText);
                    var Tmp_Obj = Ext.decode(response.responseText);
                    console.log("1  Tmp_Obj=", Tmp_Obj);
                    if (Tmp_Obj["success"] == true) {
                        var Tmp_Rtn_Msg = "自動新增4筆工作步序說明資料(AMM_WKSTPD)<br>"
                            + "- 進廠檢測,拆檢,組裝,完工測試<br>";
                        + Tmp_Obj["Rtn_Msg"];
                        mysuccessalert(Tmp_Rtn_Msg);
                        return true;
                    }
                    else {
                        var Tmp_Rtn_Msg = "自動新增4筆工作步序說明資料(AMM_WKSTPD)失敗<br>"
                            + "- 進廠檢測,拆檢,組裝,完工測試<br>"
                            + "請檢核!! <br>"
                            + Tmp_Obj["Rtn_Msg"];
                        mywarnalert(Tmp_Rtn_Msg);
                        return false;
                    }
                },  //end of success                
                failure: function (response, opts) {
                    var Tmp_Obj = Ext.decode(response.responseText);
                    var Tmp_Rtn_Msg = "新增4筆工作步序說明資料(AMM_WKSTPD)失敗<br>"
                        + "請檢核<br>"
                        + Tmp_Obj["Rtn_Msg"];
                    mywarnalert(Tmp_Rtn_Msg);
                    return false;
                }
            })  //end of Ext.Ajax.Request        
        };  // end of callBackFunc(id)
    })  //Ext.getCmp('btn_save').on('click', function () {


2>*.cs

//檢核 [工作中心]+[件號] 是否重覆, 若不重覆,則 success=true, 若重覆, 則 success=false

[HttpPost]
public HttpResponseMessage check_isnotDual()
{
            HttpContext c = HttpContext.Current;
            NameValueCollection nvc = c.Request.Form;
            string Tmp_WC = nvc["WC"];   
            string Tmp_PN = nvc["PN"];
            var response = this.Request.CreateResponse();
            string Tmp_Sql, Tmp_Str;
            int Tmp_cnt;
            Tmp_Sql = "  SELECT   count(*)  "
                            + "  FROM     AMM_WKSTP "
                            + "  WHERE   WC=" + myfunc.AA(Tmp_WC)
                            +"   AND         PN=" + myfunc.AA(Tmp_PN);
            Tmp_Str= myfunc.SqlValue(Tmp_Sql);
            if (!myfunc.checkisnull(Tmp_Str))
            {
                Tmp_cnt = int.Parse(Tmp_Str);
                if (Tmp_cnt == 0)  //不重覆                
                    Tmp_Str = "{success: true }";
                else
                    Tmp_Str = "{success: false }";
            }
                response.Content = new StringContent(Tmp_Str);    // 回應內容
                return response;  //若[WC+PN]不重覆 , 傳回 true, 否則傳回 false
        }


沒有留言:

張貼留言