顯示具有 Ext.Ajax 標籤的文章。 顯示所有文章
顯示具有 Ext.Ajax 標籤的文章。 顯示所有文章

2022年8月29日 星期一

V120103 - Ext.Ajax 1> async=true/false 的不同 2>Ext.Ajax 和 Form.submit 的不同 3>loadMask

 目的:  說明 Ext.Ajax  - async : true/false 的不同


處理說明: 1>async: true, 不等後端執行完,即往下執行
                       async: false, 等後端執行完,才往下執行
   
                  2>Ext.Ajax       : 由 response.responseText 取得傳回值
                      form.submit  : 由 opts.response.responseText 取得傳回值
            
                 3>LoadMask : 適用於 async: true 



1>*.js  async=true/false 的區別

function mySub1_OkBtn_click() {
//取得 [類別][匯入機號][拆移工場]
console.log('0 xlsToV120101 click -  mySub1_OkBtn_click !!');
//1 > 讀取子畫面的過濾條件
var np = {};
var Tmp_sub_CLS = Ext.getCmp("sub_CLS").getValue();
var Tmp_sub_ASN = Ext.getCmp("sub_ASN").getValue();
var Tmp_sub_FACWC = Ext.getCmp("sub_FACWC").getValue();
np["sub_CLS"] = Tmp_sub_CLS;
np["sub_ASN"] = Tmp_sub_ASN;
np["sub_FACWC"] = Tmp_sub_FACWC;

console.log('5  before show mask !!');
var Tmp_upPanel = Ext.getCmp("mySub1_OkBtn").up("panel");
//console.log("Tmp_upPanel:", Tmp_upPanel);
//var mask = new Ext.LoadMask(Ext.getBody(), {
var mask = new Ext.LoadMask(Tmp_upPanel, {
msg: '處理中,請稍待...'
});

mask.show();//使用 mask 需手動呼叫show() 方法下
//顯示結果訊息..
//console.log('5.5  mask.show() !!');
console.log('6  before timer !!');
var timer = setInterval(function () {
clearInterval(timer);
mask.hide();
console.log('6.5  mask.hide() - after 20 sec !!');
timer = null;
//var r = r_cookies('EX_DFile');
//console.log("r_cookies=", r);
//if (!checkisnull(r)) {
// mysuccessalert(r);
//}
}, 30000);  //5000ms = 5sec

        //Ext.getCmp('mySubForm').submit({
Ext.Ajax.request({
url: '../../api/V120103API/xlsToV120101',
method: 'POST',
async: false,
//standardSubmit: true, // 非 Ajax 的方式  //若要傳送檔案至前端, standardSubmit必需設為 true 
params: np,
success: function (response, opts) {
console.log('0 xlsToV120101 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 xlsToV120101 obj[sucess]  true !!');
Tmp_Str = "[匯入]完成 !! <br>"
           + obj["Rtn_Msg"];
mysuccessalert(Tmp_Str);
console.log("success=true , Tmp_Str=", Tmp_Str);
Ext.getCmp('mySub1_OkBtn').up("window").close();
Ext.getCmp('mySub1_OkBtn').up("window").destroy();
Ext.getCmp('btn_Show').fireHandler();
}
else {
console.log(' 2 xlsToV120101 obj[sucess]  false !!');
Tmp_Str = "[匯入]失敗 !! <br>"
            +obj["Rtn_Msg"];
mysuccessalert(Tmp_Str);
}
            },
            failure: function (response, opts) {
                //console.log('uploadFileToDB failure !!');
                //console.log(" failure opts.response.responseText:", opts.response.responseText);
console.log(' 3 xlsToV120101 failure !!');
                var obj = Ext.decode(response.responseText);
                console.log("obj:", obj);
Tmp_Str = "[匯入]失敗!! <br>"
+ obj["Rtn_Msg"];
                mywarnalert(Tmp_Str);                
            } // end of failure 
});  // end of submit
console.log('7  Ext.Ajax finished !!');
};  // end of function mySub1_OkBtn_click()


2>success: function (response, opts) {

     1>>若 Ext.Ajax 則由 response.responseText

             var obj = Ext.decode(response.responseText);

     2>>若 Form.submit 則由 opts.response.responseText

            var obj = Ext.decode(opts.response.responseText);



3>Loadmask的用法:  適用於 async : true



2022年8月8日 星期一

V120103 - Ext.Ajax.reqest : AJAX Sample - getUrlStr(Tmp_url, np, "加入資料");

1>*.js
   //檢核是否 CLS+DITM 已存在 AMM_FRO3F16STD
/檢核欄位值是否正確
    Ext.getCmp('btn_save').checkFormValue = function () {

        var np = {};
        np["CLS"] = Tmp_CLS;
        np["DITM"] = Tmp_DITM;
        var isOk = true;
        Ext.Ajax.request({
            method: "POST",
            url: '../../api/V120103API/CHECK_CLS_DITM',
            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"] == false) {
                    var Tmp_Rtn_Msg = "類別(" + Tmp_CLS + ")排序項次(" + Tmp_DITM + ")已存在拆挪管制標準檔(AMM_FRO3F16STD)<br>"
                        + "請檢核<br>"
                        + Tmp_Obj["Rtn_Msg"];
                    mywarnalert(Tmp_Rtn_Msg);
                    isOk = false;
                }
            },  //end of success                
            failure: function (response, opts) {
                var Tmp_Obj = Ext.decode(response.responseText);
                var Tmp_Rtn_Msg = "類別(" + Tmp_CLS + ")排序項次(" + Tmp_DITM + ")已存在拆挪管制標準檔(AMM_FRO3F16STD)<br>"
                    + "請檢核<br>"
                    + Tmp_Obj["Rtn_Msg"];
                mywarnalert(Tmp_Rtn_Msg);
                isOk = false;
            }
        })  //end of Ext.Ajax.Request        
        if (isOk == true) {
            mysuccessalert("包裝完成確認成功!!");
            //資料更新完成, 重新顯示資料
            Ext.getCmp("btn_Show").fireHandler();
        }

    } // end of  checkFormValue 

2>*.cs
using TLSWEB_AMM.Service;
using TLSWEB_AMM.Models;

//檢查 CLS_DITM 是否重複(AMM_FRO3F16STD)
        [HttpPost]          
        public HttpResponseMessage CHECK_CLS_DITM()
        {
            var c = HttpContext.Current;
            NameValueCollection nvc = c.Request.Form;
            string Tmp_CLS = nvc["CLS"];
            string Tmp_DITM = nvc["DITM"];            
            OracleConnection conn = new OracleConnection(DBService.ConnectionString(DBLINK));//
            OracleCommand cmd = new OracleCommand();
            OracleDataReader reader;
            var response = this.Request.CreateResponse();

            conn.Open();
            conn.ClientInfo = User.Identity.Name;
            conn.ModuleName = BaseSYS + "_" + BaseMODID;
            conn.ActionName = ActionName;
            cmd.Connection = conn;
            string Tmp_Sql = "";
            string Tmp_Str = "";
            string Tmp_RtnMsg;
            int Tmp_CNT = 0;
            try
            {
                Tmp_Sql = " SELECT    COUNT(*) AS CNT"
                               + "  FROM      AMM_FRO3F16STD "
                                + "  WHERE   CLS= " + myfunc.AA(Tmp_CLS)
                                + "   AND        DITM=" + myfunc.AA(Tmp_DITM);
                cmd.CommandText = Tmp_Sql;
                reader = cmd.ExecuteReader();
                if (reader.Read())
                {
                    Tmp_CNT = int.Parse(reader["CNT"].ToString());
                    if (Tmp_CNT > 0)
                    {
                        Tmp_RtnMsg = "類別(" + Tmp_CLS + ")排序項次(" + Tmp_DITM + ")已存在<br>"
                                                +" 不可重複!!<br>"
                                                + "請檢核<br>";
                        //將傳回值加入  JSON String
                        Tmp_Str = "{success: false,Rtn_Msg:" + myfunc.AA(Tmp_RtnMsg) + ","                                                                 
                                        + " }";                     
                    }
                    else
                    {
                        Tmp_RtnMsg = "類別(" + Tmp_CLS + ")排序項次(" + Tmp_DITM + ")未重複!!<br>";                                         
                        //將傳回值加入  JSON String
                        Tmp_Str = "{success: true,Rtn_Msg:" + myfunc.AA(Tmp_RtnMsg) + ","
                                        + " }";                        
                    }
                    response.Content = new StringContent(Tmp_Str);    // 回應內容
                    return response;
                }                // if reader.Read()                
            }  // end of try
            catch (Exception e)
            {
                var Tmp_ErrMsg = myfunc.Get1ORA(e.Message);
                Tmp_RtnMsg = "取得[類別][排序項次]的資料失敗 (CHECK_CLS_DITM) !!  <br> "
                                         + Tmp_ErrMsg;
                response.Content = new StringContent("{'success': false , failure: true , 'Rtn_Msg':'" + Tmp_RtnMsg + "' }");    // 回應內容
                return response;
            }
            finally
            {
                conn.Close();
            }
            return response;
        }  // end function CHECK_CLS_DITM() 


3>V120402C.cs  UPDATE 資料
// 更新 - UDPATE_AMM_TMDWGD  - 更新[借閱記錄(AMM_TMDWGD)].BRDAY
        [HttpPost]
        public HttpResponseMessage UPDATE_AMM_TMDWGD()
        {
            //取得參數值
            var c = HttpContext.Current;
            NameValueCollection nvc = c.Request.Form;

            string Tmp_TMNO = nvc["TMNO"];
            string Tmp_RtnMsg = "";

            string n = funId + "_UPDATE_AMM_TMDWGD";
            OracleConnection conn = new OracleConnection(DBService.ConnectionString(DBLINK));
            OracleCommand cmd = new OracleCommand();
            var response = Request.CreateResponse();
            try
            {
                conn.Open();
                conn.ClientInfo = User.Identity.Name;
                conn.ModuleName = BaseSYS + "_" + BaseMODID;
                conn.ActionName = ActionName;
                cmd.BindByName = true;
                cmd.Connection = conn;
                string Tmp_Sql;
                Tmp_Sql = "  UPDATE  AMM_TMDWGD   "
                               + "  SET  BRDAY=nvl(BRDAY,0)+10 "
                               + "   WHERE   TMNO=" + myfunc.AA(Tmp_TMNO)
                               + "   AND       (TMNO,ITM)  IN  ( SELECT    TMNO,MAX(ITM)  "
                                                                                   +" FROM     AMM_TMDWGD  "
                                                                                   +"  WHERE  TMNO=" + myfunc.AA(Tmp_TMNO)
                                                                                   + " group by  TMNO) ";
                cmd.CommandText = Tmp_Sql;
                cmd.ExecuteNonQuery();
                response.StatusCode = HttpStatusCode.OK;
                Tmp_RtnMsg = "條碼編號(" + Tmp_TMNO + ")<br>"
                                         + "[續借登記]成功 !!  <br>";
                response.Content = new StringContent("{'success': true,'Rtn_Msg':'" + Tmp_RtnMsg + "'}");    // 回應內容

                return response;
                //excuteSQLTran
            }  //try
            catch (Exception e)
            {
                string Tmp_msg;
                Tmp_msg = myfunc.Get1ORA(e.Message);
                Tmp_RtnMsg = "借閱登記失敗 !!  <br>"
                                         + Tmp_msg;
                response.Content = new StringContent("{'success': false,'Rtn_Msg':'" + Tmp_RtnMsg + "'}");    // 回應內容
                return response;
            }
            finally
            {
                conn.Close();
            }
        }


3>V120202D -getUrlStr - 傳回ds  -
{ //加入資料
xtype: "button", text: "加入資料", width: 120, border: 2, margin: { left: 10, },
hidden: true,
id: "sub_btn_Add",
handler: function () {
console.log("insider handler of sub_btn_Add");
var Tmp_APNO = Ext.getCmp("sub_APNO").getValue();
var Tmp_Str = "";
if (checkisnull(Tmp_APNO)) {
Tmp_Str = "請先輸入[申請單號] !!"
mywarnalert(Tmp_Str);
return;
}
var np = {};
np["sub_APNO"] = Tmp_APNO;
var Tmp_url = "../../api/V120202DAPI/get_sub_data1";

//取得挑選資料的 dt2JSON 字串 
//getUrlStr : 必需傳回字串( dt.JSON字串) , 非 ds
var rtn_Str = getUrlStr(Tmp_url, np, "加入資料");

console.log("rtn_Str:", rtn_Str);

if (checkRtnOK(rtn_Str)) {
var Tmp_recs = Ext.decode(rtn_Str);
var Tmp_rec;
for (i = 0; i < Tmp_recs.length; i++) {
Tmp_rec = Tmp_recs[0];
console.log("Tmp_rec:", Tmp_rec);
if (Ext.getCmp("sub_Grid").store.find("APNO", Tmp_rec["APNO"]) == -1) {
console.log("add store Tmp_rec:", Tmp_rec);
Ext.getCmp("sub_Grid").store.add(Tmp_rec);
Ext.getCmp("sub_APNO").setValue("");
}
} //end of for
console.log("store :", Ext.getCmp("sub_Grid").store);
} // end of if (checkRtnOK(rtn_Str)) {
} // end of handler
}, // end of 加入資料

//開啟畫面
var win1 = getMyWindow("領料登記", sub_V120202D_Flds, sub_V120202D_Btns, "D");
    win1.x = 100;
    win1.setWidth(500);
    win1.setHeight(400);
    var np = {};
    //np["sub_APNO"] = Ext.getCmp("sub_APNO").getValue();
    var Tmp_url = "../../api/V120202DAPI/get_sub_data";  //
    Ext.getCmp("sub_Grid").store.getProxy().url = Tmp_url;
    Ext.getCmp("sub_Grid").store.getProxy().extraParams = np; //分頁OK,篩選條件OK    
    Ext.getCmp("sub_Grid").store.load();
    win1.show();

2022年8月3日 星期三

V120103 - 判斷目前編輯的模式(1:新增, 2:編輯,0:瀏覽,..) buttonModel.modelType

1>TMSingleViewEdit.js

var buttonModel = function () {
    this.modelType = 0; //預設檢視模式
    this.getModelType = function () {
        return this.modelType;
    }
}

Ext.define('G_buttonModel', {
getModelType: function () {
return buttonModel.modelType;
},
setModelType: function (type_num) {
buttonModel.modelType = type_num;
}
});


2>V120103.js 

Ext.onReady(function () {
     var TMSingleViewEdit = Ext.create('TMSingleViewEdit');
     var gridstore = Ext.getCmp('grid_Single').store;
     var buttonModel = Ext.create('G_buttonModel'); 
                         :
               Ext.getCmp('btn_save').setFormValue = function () {
               //要判斷 buttonModel 的編輯模式時, 才即時去抓 modelType
               var modelType = buttonModel.getModelType();

               console.log("setFormValue modelType=", modelType);
               //若非[新增]模式,則不設定欄位值
               if (!(modelType == 1))    
                   return true;

        var isOk = true;
        var Tmp_MAX_ITM = "";       
        np = {};
        np["CLS"] = Ext.getCmp('CLS').getValue();        
        Ext.Ajax.request({
            method: "POST",
            url: '../../api/V120103API/GET_MAXITM',
            params: np,
            async: false,
            success: function (response, opts) {
                var Tmp_Obj = Ext.decode(response.responseText);       
                if (Tmp_Obj["success"]) {
                    Tmp_MAX_ITM = Tmp_Obj['MAX_ITM'];
                    Ext.getCmp("ITM").setValue(Tmp_MAX_ITM);
                }
            }, // end of  success 
            failure: function (response, opts) {
                isOk = false;
            }
        });  // end of Ext.Ajax               
       return isOk;

}