顯示具有 checkFormValue 標籤的文章。 顯示所有文章
顯示具有 checkFormValue 標籤的文章。 顯示所有文章

2022年10月25日 星期二

V20107 - Template存檔後,額外處理資料

 目的: V20107  - Template.存檔後,額外處理資料

處理說明: 1>Template.存檔後,額外處理資料 , 寫在V20107.btn_save.click ()

                      --> 即 Template 執行完存檔後,再執行 V20107.存檔  


1>*.js
//按[存檔], 若
Ext.getCmp('btn_save').on('click', function () {
        //若 checkFormValue 有問題,則 is_Keepgoing=false , 不往下執行
        if (is_keepgoing==false)
             return ;
         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);
                        is_Ok=true;
                    }
                    else {
                        var Tmp_Rtn_Msg = "自動新增4筆工作步序說明資料(AMM_WKSTPD)失敗<br>"
                            + "- 進廠檢測,拆檢,組裝,完工測試<br>"
                            + "請檢核!! <br>"
                            + Tmp_Obj["Rtn_Msg"];
                        mywarnalert(Tmp_Rtn_Msg);
                        is_Ok=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);
                    is_Ok=false;
                }
            })  //end of Ext.Ajax.Request        
           return is_OK;
        };  // end of callBackFunc(id)
    })  //Ext.getCmp('btn_save').on('click', function () {
    //檢核 AMM_WKSTPD 是否為空值, 若是,則傳回 true, 否則傳回 false
    function check_AMM_WKSTPD_isnull() {
        var np = {};
        var Tmp_MITM = Ext.getCmp("MITM").getValue();        
        np["MITM"] = Tmp_MITM;        
        var is_Ok = true;
        Ext.Ajax.request({
            url: '../../api/V20107API/check_AMM_WKSTPD_isnull',
            method: 'POST',
            async: false,
            params: np,
            success: function (response, opts) {
                console.log('0 check_AMM_WKSTPD_isnull 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_AMM_WKSTPD_isnull  true !!');
                    is_Ok = true;
                }
                else {
                    console.log(' 2 check_AMM_WKSTPD_isnull obj[sucess]  false !!');                    
                    is_Ok = false;
                }
            },
            failure: function (response, opts) {
                console.log(' 3 check_isnotDull failure !!');
                var obj = Ext.decode(response.responseText);
                console.log("obj:", obj);
                Tmp_Str = "檢核[工作步序說明(check_AMM_WKSTPD_isnull)]失敗!! <br>"
                    + obj["Rtn_Msg"];
                mywarnalert(Tmp_Str);
                is_Ok = false;
            } // end of failure 
        });  // end of Ext.Ajax
        return is_Ok;
    }

//btn_save.beforeInsert --> 實際寫入資料庫的處理
Ext.getCmp('btn_save').beforeInsert = function () {
        console.log(" 5 beforeInsert Ext.getCmp(btn_save).beforeInsert - MD_DB.doSave(Insert )");
        var isCheck = MD_DB.doSave('Insert');
        return isCheck;
    };



2>*.cs
//檢核 [AMM_WKSTPD] 是否為有資料,若無資料,則傳回 true, 否則傳回 false
        [HttpPost]
        public HttpResponseMessage check_AMM_WKSTPD_isnull()
        {
            HttpContext c = HttpContext.Current;
            NameValueCollection nvc = c.Request.Form;
            string Tmp_MITM = nvc["MITM"];           

            var response = this.Request.CreateResponse();
            string Tmp_Sql, Tmp_Str;
            int Tmp_cnt;
            Tmp_Sql = "  SELECT   count(*)  "
                            + "  FROM     AMM_WKSTPD "
                            + "  WHERE   MITM=" + myfunc.AA(Tmp_MITM);                            
            Tmp_Str = myfunc.SqlValue(Tmp_Sql);
            if (!myfunc.checkisnull(Tmp_Str))
            {
                Tmp_cnt = int.Parse(Tmp_Str);
                if (Tmp_cnt == 0)  //AMM_WKSTPD 無資料  of  MITM
                    Tmp_Str = "{success: true }";
                else
                    Tmp_Str = "{success: false }";
            }
            response.Content = new StringContent(Tmp_Str);    // 回應內容
            return response;  //若[WC+PN]不重覆 , 傳回 true, 否則傳回 false
        }

[HttpPost]
        public void Insert()
        {
            var c = System.Web.HttpContext.Current;
            NameValueCollection nvc = c.Request.Form;
            //excuteInsert(nvc, DBTable);
            NameValueCollection nvc1 = new NameValueCollection();
            foreach (string k in nvc.Keys)
            {
                nvc1[k] = nvc[k];
            }
            // ITM=MAX_ITM 改在前端 setFormValue, 設定, 不在後端設定, 因為  store 不 reload();
            //int Tmp_MAXITM = GET_MAX_ITM();
            //nvc1["MITM"] = 
            nvc1["ENER"] = LoginUserModel.LoginUserId;
            nvc1["ENDT"] = DateTime.Now.ToString("yyyy/MM/dd"); ;
            excuteInsert(nvc1, DBTable);
        }

 [HttpPost]
        public void Update()
        {
            var c = System.Web.HttpContext.Current;
            NameValueCollection nvc = c.Request.Form;
            string[] arrCondition = getPK();
            excuteUpdate(nvc, DBTable, arrCondition);
        }

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
        }