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

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();