2022年9月6日 星期二

V20306 - 欄位值2Checkbox - 將資料庫欄位值顯示 在 checkbox

 目的: 將資料庫欄位值轉成 checkbox  &  將畫面checkbox值轉成資料庫欄位值

處理說明: 1>顯示資料 -  將資料庫欄位值轉成 checkbox (tab1.onShow event )

                  2>儲存資料 -  將畫面checkbox值轉成資料庫欄位值(按[存檔]鈕)




1>*.js 顯示資料 - 將資料庫欄位值轉成 checkbox (tab1.onShow event )

Ext.getCmp("tab1").on("show", function (me, eOpts) {
        //編輯畫面顯示,將欄位值反應至編輯畫面的 checkbox 選項             
        console.log("*** tab1 show event trigger");
        var sel_recs = Ext.getCmp('grid_Single').getView().getSelectionModel().getSelection();
        if (sel_recs.length > 0) {
            var sel_rec = sel_recs[0];
            console.log("sel_rec:" , sel_rec);
            if (checkisnull(sel_rec)) {
                return true;
            }
            var Tmp_WTLV = sel_rec.data["WTLV"].toString();
            var Tmp_ITPR = sel_rec.data["ITPR"].toString();
            setcheckbox_WTLV(Tmp_WTLV);
            setcheckbox_ITPR(Tmp_ITPR);            
        }

        function setcheckbox_WTLV(par_WTLV) {            
            let Tmp_Ary = ["A", "B", "C", "D"];
            //用  Arrary 用  in  不準, 改用 indexOf
            if (Tmp_Ary.indexOf(par_WTLV)==-1)
                return;


            var WTLV_id = "WTLV_" + par_WTLV;
            Ext.getCmp(WTLV_id).setValue(true);
        }

        //欄位值 par_ITPR: A/B/C/D/E/F/G:其他1
        function setcheckbox_ITPR(par_ITPR) {
            let Tmp_Ary = ["A", "B", "C", "D", "E", "F", "G"];
            let Tmp_ITPR1 = par_ITPR.substr(0, 1);
            if (Tmp_Ary.indexOf(Tmp_ITPR1) == -1)
                return;

            var par_ITPR_Ary = new Array;
            par_ITPR_Ary = par_ITPR.split(":");         
            //設定其他備註欄位  
            if (par_ITPR_Ary[0] == "G") {
                Ext.getCmp("ITPR1").setValue(par_ITPR_Ary[1]);
            }
            var ITPR_id = "ITPR_" + par_ITPR_Ary[0];                        

            //若為 G:其他1 , 則需特別處理
            var Tmp_ITPR_id = Ext.getCmp(ITPR_id).getValue();            
            Ext.getCmp(ITPR_id).setValue(true);            
        }
    });


     //修改的存檔, 重新顯示
    Ext.getCmp('btn_save').beforeEdit = function () {
        //執行後端 Upate 程式
        isCheck = S_DB.doSave('Update');
        //後端   Insert 後, store 重取
        if (isCheck)
           Ext.getCmp("btn_Show").fireHandler();
        return isCheck;
    };


2>*.cs 儲存資料 -  將畫面checkbox值轉成資料庫欄位值(按[存檔]鈕)

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

public NameValueCollection Proc_ITPR(NameValueCollection par_nvc1, NameValueCollection par_nvc)
        {
            //nvc 移除 radio開頭的 key
            var Tmp_key = "";
            foreach (string key in par_nvc.Keys)
            {
                if (!key.Contains("radio"))
                    par_nvc1[key] = par_nvc[key];
            }

            //若為[ITPR]若為'G', 其他則 nvc1[ITPR]=nvc1[ITPR]+":"+nvc1[ITPR1];
            //刪除 nvc1[ITRP1]
            if (par_nvc1["ITPR"] == "G")
                par_nvc1["ITPR"] = par_nvc1["ITPR"] + ":" + par_nvc1["ITPR1"];
            par_nvc1.Remove("ITPR1");
            return par_nvc1;
        }

 public void Insert()
        {
            var c = System.Web.HttpContext.Current;
            NameValueCollection nvc = c.Request.Form;
            NameValueCollection nvc1= new NameValueCollection();            
            nvc1 = Proc_ITPR(nvc1, nvc);        
            excuteInsert(nvc1, DBTable);
        }


3>V20306_JSON.js  - 畫面欄位設計  - checkbox


{
  xtype: 'radiogroup', fieldLabel: '重量等級', labelWidth: 160, layout: 'vbox',
id: 'WTLV',
items: [
{
boxLabel: '極重(木箱)',
name: 'WTLV', 
id: 'WTLV_A', 
inputValue: 'A',
border: 1,
width:300
}, {
boxLabel: '很重(七層紙箱)',
name: 'WTLV', 
id: 'WTLV_B', 
inputValue: 'B',
border: 1,
}, {
boxLabel: '重(五層紙箱)',
name: 'WTLV', 
id: 'WTLV_C', 
inputValue: 'C',
checked: true,
},
{
boxLabel: '一般(三層紙箱)',
name: 'WTLV', 
id: 'WTLV_D', 
inputValue: 'D',
}
]
}, // end of  WTLV重量等級
{
                xtype: 'radiogroup', fieldLabel: '內層包裝需求', labelWidth: 160, layout: 'vbox',
id: 'ITPR',
items: [
{
boxLabel: '旭化層',
name: 'ITPR', 
id: 'ITPR_A', 
inputValue: 'A',
}, {
boxLabel: '大氣泡布',
name: 'ITPR', 
id: 'ITPR_B', 
inputValue: 'B',
}, {
boxLabel: '小氣泡布',
name: 'ITPR', 
id: 'ITPR_C', 
inputValue: 'C',
checked: true,
},
{
boxLabel: '舒美布',
name: 'ITPR', 
id: 'ITPR_D', 
inputValue: 'D',
},
{
boxLabel: '牛皮紙',
name: 'ITPR', 
id: 'ITPR_E', 
inputValue: 'E',
},
{
boxLabel: '紙版',
name: 'ITPR', 
id: 'ITPR_F', 
inputValue: 'F',
},
                                         //用 panel - 包含 checkbox & TextField  
{
xtype: 'panel', layout: { type: 'hbox' }, border: 0,
items: [
{
xtype: 'radio', boxLabel: '其他', name: 'ITPR',
id: 'ITPR_G', 
inputValue: 'G',
},
{ xtype: 'textfield', id: 'ITPR1', width: 150, padding: "0 5 0 5" },
]
},
]
}, // end of  ITPR

沒有留言:

張貼留言