2022年7月18日 星期一

V120502 - ComboBox 加入選項 - ComboBox 加入本機 [印表機選項]

 


Combobox: 的選項,必需由 store提供

        //標籤ComboBox的下拉表單欄位值
        var store_LABELH = Ext.create("Ext.data.Store", {
            fields: ["Name", "Value"],
            data: [
                { Name: "40", Value: 40 },
                { Name: "60", Value: 60 },
                { Name: "70", Value: 70 },
            ]
        });


 {  //標籤高度
       xtype: "fieldcontainer", fieldLabel: "標籤高度", labelWidth: 60, layout: "hbox", flex: 10,
       items: [
                    {
          xtype: "combobox", id: "sub_LABELH", name: "sub_LABELH", width: 110, padding: "0 4 0 0",
          store: store_LABELH,   
          emptyText: "--請選擇--", displayField: "Name", valueField: "Value", queryMode: "local"},
                    ]
                            },  // end of 標籤高度       









Web V120502 - store 刪除資料

 


  var Tmp_sub_Grid = Ext.getCmp('sub_Grid');
                                    console.log("Tmp_sub_Grid:", Tmp_sub_Grid);
                                    var cur_recs;
                                    var cur_rec;
                                    cur_recs = Tmp_sub_Grid.selModel.getSelection();
                                    if (cur_recs.length == 0) {
                                        mywarnalert("請先選擇要刪除的資料");
                                        return;
                                    }
                                    else {
                                        cur_rec = cur_recs[0];
                                        console.log("cur_rec:", cur_rec);
                                        console.log("Tmp_sub_Grid.store:", Tmp_sub_Grid.store);
                                        Tmp_sub_Grid.store.remove(cur_rec);
                                        mysuccessalert("刪除資料完成 !!");
                                        return;
                                    }



2022年7月14日 星期四

Web V120502 - store 加入新資料(add)

目的: 在Grid(store) 加入資料 
問題:  1>如何在Grid(store)加入新資料

           2>如何判斷 store 有選擇資料
                --> 自行加入checkbox ,
                      勾選多行, 不可以 Ext.getCmp('grid_Single').selModel.getSelection();  判斷



Ans:
 var Tmp_Str = '';
        var Tmp_Grid = Ext.getCmp('grid_Single');
        var Tmp_store = Tmp_Grid.store;  //= gridstore        
        var Tmp_sub_Grid = Ext.getCmp('sub_Grid');
        var Tmp_sub_store = Tmp_sub_Grid.store;  //= gridstore        
        var Tmp_PageCnt = Tmp_store.getCount();
        console.log("分頁共 N  筆 , Tmp_PageCnt =", Tmp_PageCnt);
        var cur_rec, Tmp_AMMNO, Tmp_CHECK, Tmp_SAPNO, Tmp_PN, Tmp_QTY, Tmp_EOCND, Tmp_RMK ;
        var Tmp_OK = true;
        var np = {};
        for (i = 0; i < Tmp_PageCnt; i++) {
            //console.log("更新第 i  筆", i);
            //依目前 store的資料, 更新 AMM_FACDEPD.NWK , PK( DT+DEP+EMPLYID)
            cur_rec = Tmp_store.getAt(i);
            Tmp_AMMNO = cur_rec.data["AMMNO"];
            Tmp_CHECK = cur_rec.data["CHECK"];
            console.log("1 Tmp_AMMNO=", Tmp_AMMNO);
            console.log("1 Tmp_CHECK=", Tmp_CHECK);
            Tmp_SAPNO = cur_rec.data["SAPNO"];
            Tmp_PN = cur_rec.data["PN"];
            Tmp_QTY = cur_rec.data["QTY"];
            if (!checkisnull(cur_rec.data["ECNO"])) {
                Tmp_EOCND = cur_rec.data["ECNO"] + "+" + cur_rec.data["CNDPROCCODE"];
            }
            else {
                Tmp_EOCND = "";
            }
            Tmp_RMK = cur_rec.data["ACNO_"];
            //若主畫面資料有勾選,則加入 sub_store
            if (Tmp_CHECK) {
                var sub_Store_np = {
                    SAPNO: Tmp_SAPNO,
                    PN: Tmp_PN,
                    QTY: Tmp_QTY,
                    EOCND: Tmp_EOCND,
                    RMK: Tmp_RMK,                    
                }
                Tmp_sub_store.add(sub_Store_np);
            }

        }  // end of for i=
    }  // end of  function mySub2_OkBtn_click()

Web V120502 –選擇行 -加入checkbox 選擇Row , 行允許多選

目的 checkbox 選擇行且允許多選

問題: 1>如何在每一行開頭,加入checkbox (xtype: 'checkcolumn')

           2>依勾選資料處理(可多選) 


處理說明:

1>在每一行開頭,加入  checkbox

var J_columns = [
{ header: "", xtype: "rownumberer", width: 50, align: "center", sortable: false },
{
header: '勾選',
dataIndex: 'CHECK',
xtype: 'checkcolumn',
width: 60,
renderer: function (value, metadata, record, rowIndex, colIndex, store) {
var tempVal = '';
if ((value === 'Y') || (value === true)) { tempVal = 'checked'; }
var Tmp_Str = "<input  type='checkbox'  name=" + (record.get('AMMNO')) + "   " + tempVal + " >";
return Tmp_Str;
},
}, // end of  header='[ ]勾選'

{header:"AMM單號",dataIndex:"AMMNO",width:150,TMType:"string"},
{header:"AMM單況",dataIndex:"AMMSTS",width:75,TMType:"string"},
{header:"AMM單況說明",dataIndex:"AMMSTS_"},
{header:"工號",dataIndex:"SAPNO",width:120,TMType:"string"},
{header:"件號",dataIndex:"PN",width:150,TMType:"string"},
    :
];


2>依勾選資料處理(可多選)

        win.show();                
        var Tmp_Str = '';
        var Tmp_Grid = Ext.getCmp('grid_Single');
        var Tmp_store = Tmp_Grid.store;  //= gridstore        
        var Tmp_sub_Grid = Ext.getCmp('sub_Grid');
        var Tmp_sub_store = Tmp_sub_Grid.store;  //= gridstore        
        var Tmp_PageCnt = Tmp_store.getCount();  //store筆數
      
var cur_rec, Tmp_AMMNO, Tmp_CHECK, Tmp_SAPNO, Tmp_PN, Tmp_QTY, Tmp_EOCND, Tmp_RMK ;
        var Tmp_OK = true;
        var np = {};
        var sub_Store_np = {};
var Tmp_SelCnt = 0;
//將主畫面勾選的資料, 加入子視窗.DBGrid
        for (i = 0; i < Tmp_PageCnt; i++) {
            //console.log("更新第 i  筆", i);
            //依目前 store的資料, 更新 AMM_FACDEPD.NWK , PK( DT+DEP+EMPLYID)
            cur_rec = Tmp_store.getAt(i);
            Tmp_AMMNO = cur_rec.data["AMMNO"];
            Tmp_CHECK = cur_rec.data["CHECK"];
            //console.log("1 Tmp_AMMNO=", Tmp_AMMNO);
            //console.log("1 Tmp_CHECK=", Tmp_CHECK);
            Tmp_SAPNO = cur_rec.data["SAPNO"];
            Tmp_PN = cur_rec.data["PN"];
            Tmp_QTY = cur_rec.data["QTY"];
            if (!checkisnull(cur_rec.data["ECNO"])) {
                Tmp_EOCND = cur_rec.data["ECNO"] + "+" + cur_rec.data["CNDPROCCODE"];
            }
            else {
                Tmp_EOCND = "";
            }
            Tmp_RMK = cur_rec.data["ACNO_"];
            //若主畫面資料有勾選,則加入 sub_store , sub_store 不分頁
            if (Tmp_CHECK) {                
                sub_Store_np = {
                    SAPNO: Tmp_SAPNO,
                    PN: Tmp_PN,
                    QTY: Tmp_QTY,
                    EOCND: Tmp_EOCND,
                    RMK: Tmp_RMK,                    
                }
                Tmp_sub_store.add(sub_Store_np);
            }

}  // end of for i=         
        Tmp_SelCnt = Tmp_sub_store.getCount();
        if (Tmp_SelCnt == 0) {
            mywarnalert("請先選擇要列印的資料 !!");

            //console.log("Ext.getCmp('sub_Grid'):", Ext.getCmp('sub_Grid'));
            //Ext.getCmp('sub_Grid').up('window').close();
            //Ext.getCmp('sub_Grid').up('window').destroy();
            return;
}       

Web改版 - V120902- CheckBox欄位編輯處理

 Web改版V120902 – 出勤現況維護

目的: Checkbox編輯欄位值

問題: 1>如何在 Grid    Columns 加入 CheckBox

                    2>如何在後端讀取 CheckBox欄位值



Q1>如何在 Grid    Columns 加入 CheckBox

Ans:     1>於Grid的 Columns加入一欄位 : xtype: 'checkColumn',  

             {header: '缺勤',
                dataIndex: 'NWK',
                xtype: 'checkcolumn',
                          :
                }

                   2> checkColumn    renderer 時,  傳回  <input    type='checkbox'      checked/>
                           依欄位值 , 設定   checked   或空白
                          renderer: function (value, metadata, record, rowIndex, colIndex, store) {
                           var tempVal = '';
                           if ((value === 'Y') || (value === true)) { tempVal = 'checked'; }
                                   var Tmp_Str = "<input  type='checkbox'  name=" + DatetoStr(record.get('DT')) + "_" +                                                                                                            record.get('DEP') + "_" + record.get('EMPLYID') + "   " + tempVal + " >";
                              return Tmp_Str;
                },

              3>按[確定]鈕,  每筆 store 處理   [NWK]欄位值
                      var Tmp_Grid = Ext.getCmp('sub2_Grid');
                       var Tmp_store = Tmp_Grid.store;
                      var Tmp_TotalCnt = Tmp_store.getTotalCount();
for (i = 0; i < Tmp_TotalCnt; i++) {
                console.log("更新第 i  筆", i);
                //依目前 store的資料, 更新 AMM_FACDEPD.NWK , PK( DT+DEP+EMPLYID)
                cur_rec = Tmp_store.getAt(i);
                Tmp_DT = cur_rec.data["DT"];
                Tmp_DEP = cur_rec.data["DEP"];
                Tmp_EMPLYID = cur_rec.data["EMPLYID"];
                Tmp_LDMAN = cur_rec.data["LDMAN"];
                Tmp_NWK = cur_rec.data["NWK"];
                         : 
                          }

PS1:     加入  checkbox   欄位

 var sub2_Columns = [
            { header: "員工編號", dataIndex: "EMPLYID", width: 150, TMType: "string" },
            { header: "姓名", dataIndex: "EMPLYID_", width: 100, TMType: "string" },

            { header: "備註", dataIndex: "NOTE", width: 200, TMType: "string", },
            {
                header: '缺勤',
                dataIndex: 'NWK',
                xtype: 'checkcolumn',
                width: 60,
                editor: {
                    xtype: 'checkbox',
                    cls: 'x-grid-checkheader-editor',
                    inputValue: 'Y',
                    uncheckedValue: 'N'
                },
                //A renderer function used to return HTML markup for a cell given the cell's data value.
                renderer: function (value, metadata, record, rowIndex, colIndex, store) {
                    var tempVal = '';
                    if ((value === 'Y') || (value === true)) { tempVal = 'checked'; }
                    var Tmp_Str = "<input  type='checkbox'  name=" + DatetoStr(record.get('DT')) + "_" + record.get('DEP') + "_" + record.get('EMPLYID') + "   " + tempVal + " >";
                    return Tmp_Str;
                },
            }, // end of  header='缺勤1'
        ];

PS2:    renderer 時, 依[NWK]欄位值 , 設定 checked


 Q2>如何在後端讀取 CheckBox欄位值

Ans:

public HttpResponseMessage UPD_AMM_FACDEPD()
 string Tmp_NWK = nvc["Tmp_NWK"];
   if ((Tmp_NWK=="true") || (Tmp_NWK == "Y"))
                { Tmp_NWK_VAL = "Y"; }
                else
                { Tmp_NWK_VAL = "N"; }

 Tmp_Sql = "  UPDATE  AMM_FACDEPD  "
                                + "  SET          NWK=" + myfunc.AA(Tmp_NWK_VAL)+","
                                                         +"  NOTE=" + myfunc.AA(Tmp_NOTE)
                                + "  WHERE   DT= " + myfunc.AA(Tmp_DT)
                                + "   AND       DEP= " + myfunc.AA(Tmp_DEP)
                                + "   AND       EMPLYID= " + myfunc.AA(Tmp_EMPLYID);



2022年7月7日 星期四

Web改版 V120902 1>xls檔案未下載至前端Browser 2>TMGrid_高度設定_分頁控制Bar置於下方 3>主機下載檔案目錄權限設定

 1>[列印點名表] – 檔案下載至前端  -  standardSubmit: true, 且 必需以  form.submit, 不可用 Ext.Ajax


1>*.js

Ext.getCmp('mySubForm').submit({   

                url: '../../api/V120902API/DoPRNLIST',

                method: 'POST',

//  Ajax 的方式  //若要傳送檔案至前端, standardSubmit必需設為 true , 才會開新視窗,傳送 Binary檔案

//否則 Binary 檔案會放在原本的  Response

                standardSubmit: true,      

                params: np,             

        });

//顯示處理中..請稍待的訊息

var mask = new Ext.LoadMask(Ext.getBody(), {

                msg: '處理中,請稍待...'

        }); 

        mask.show();//使用 mask 需手動呼叫show() 方法下

        var timer = setInterval(function () {

                clearInterval(timer);

                mask.hide();

                timer = null;

                var r = r_cookies('EX_DFile');

                mysuccessalert(r);

        },1000);  //1000ms = 3sec

};  // end of function mySub1_OkBtn_click()







2>[缺點現況維護] -  TMGrid 的頁次未置於最下方 - Panel2 自動充滿畫面   - page


//panel2 的高度必需設定, 否則  panel2的高度會隨 Grid而變化
win.on('resize', function (me, width, height, eOpts) {
            //console.log("win.resize height=",height);
            var Tmp_okpanel_Height = Ext.getCmp('mySub2_OkBtn').getHeight() + 20;            
            var Tmp_rHeight = Ext.getCmp('mySubForm').getHeight() - Ext.getCmp('sub2_panel1').getHeight() - Tmp_okpanel_Height;            
            Ext.getCmp('sub2_panel2').setHeight(Tmp_rHeight);
            //console.log("win.resize Tmp_rHeight=", Tmp_rHeight);            
        });

// [缺勤記錄維護] - 開啟子視窗, 所有的變數在 子視窗開啟時, 要重新宣告,

    //                            --> 因為關閉子視窗時, 變數記憶體會被收回, 不重新宣告變數, 該變數會不存在

    function RollEditBtn_click() {

        var checkbox_id = 1;

        //按鈕 : [確認] [取消]  - [缺勤記錄維護]

        var mySub2_Btns = [

            {

                xtype: 'button', text: '確定', id: 'mySub2_OkBtn',

                listeners: {

                    click: function () {

                        mysuccessalert("mysub2_確定 ");

                        mySub2_OkBtn_click();

                    }

                }

            },

        ];

 

        var sub2_Columns = [

            { header: "員工編號", dataIndex: "EMPLYID", width: 150, TMType: "string" },

            { header: "姓名", dataIndex: "EMPLYID_", width: 100, TMType: "string" },

            { header: "缺勤", dataIndex: "NWK", width: 50, TMType: "string" },

            { header: "備註", dataIndex: "NOTE", width: 200, TMType: "string" },

            {

                header: '缺勤1',

                dataIndex: 'NWK',

                xtype: 'checkcolumn',               

                width: 60,

                editor: {

                    xtype: 'checkbox',

                    cls: 'x-grid-checkheader-editor',

                    inputValue: 'Y',

                    uncheckedValue: 'N'

                },           

                renderer: function (value, metadata, record, rowIndex, colIndex, store) {

                    console.log("1 renderer value:", value);

                    var tempVal = '';

                    if ((value === 'Y') || (value === true)) { tempVal = 'checked'; }     

                    var Tmp_Str = "<input  type='checkbox'  name=" + DatetoStr(record.get('DT')) + "_" + record.get('DEP') + "_" + record.get('EMPLYID') + "   " + tempVal + " >";

                    console.log("1 renderer return Tmp_Str:", Tmp_Str);

                    checkbox_id = checkbox_id + 1;

                    return Tmp_Str;

                },                               

                listeners: {

                    beforecheckchange: function (me, rowIndex, checked, eOpts) {

                        mysuccessalert("2 befoercheckchange !!");                       

                        console.log("2 befoercheckchange checked 1:", checked);                    

                        if (checked) { checked = false;checkVal = 'N'; }

                        else { checked = true; checkVal = 'Y'; }

                        Ext.getCmp('sub2_Grid').store.getAt(rowIndex).set('NWK', checkVal);

                        console.log("2 befoercheckchange checked 2:", checked);                    

                        return true;

                    },

                    click: function () { mysuccessalert("1 click event !!") }, 

                    // cellclick                   

                    checkchange: function (me, rowIndex, checked, eOpts) {

                         mysuccessalert("3 checkchange !!");

                        console.log(" 3 checkchange  checked :", checked);                           

                        var checkVal = '';

                        if (checked) {

                            checkVal = 'Y';                           

                            console.log("3  checkchange 目前 checked= Y !!  checkVal:", checkVal );

                        }

                        else {

                            checkVal = 'N';

                            console.log(" 3 checkchange 目前 checked= N !!  checkVal:", checkVal);

                        }                       

                        Ext.getCmp('sub2_Grid').store.getAt(rowIndex).set('NWK', checkVal);

                        console.log(" 4 checkchange Ext.getCmp(sub2_Grid).store.getat(rowIndex)", Ext.getCmp('sub2_Grid').store.getAt(rowIndex));                           

                        }

                    }

                },                               

        ];

 

 

        // [缺勤記錄維護]  - 子畫面欄位

        var mySub2 = [

            {

 type:'panel', bodyStyle: "background-color:transparent;", border: false, layout: { type: 'vbox', align: 'stretch' }, padding: "5",

                items: [

                    {

                        xtype: 'panel',

                        id: 'sub2_panel1',

                        layout: { type: 'hbox', align: 'stretch' },

                        flex: 5,

                        border: 1,

                        items: [

                        ]

                    },  //end of panel1                   

                    {

                        xtype: 'panel',

                        id: 'sub2_panel2',

                        //title: 'sub2_panel2',

                        layout: { type: 'vbox', align: 'stretch' },

                        //layout: 'fit',

                        flex: 10,

                        border: 1,                                               

                        items: [ sub2_Grid ]

                    },

                ] // end of   layout: "vbox", padding: "5", items: [

            }  //end of  my_Sub2 , items[{

        ]      //end of  my_Sub2 , items[

        var win = getMyWindow("缺勤記錄維護", mySub2, mySub2_Btns);       

        //Ext.getCmp('mySubForm').autoScroll = true;       

       

            var Tmp_Sql = " SELECT  EMPLYNM    "

                + "  FROM   HR_EMPLYM  "

                + " WHERE  EMPLYID=" + AA(Ext.getCmp('sub2_LDMAN').getValue());

            var Tmp_Str = SqlValue(Tmp_Sql);

            Ext.getCmp('sub2_LDMAN_').setValue(Tmp_Str);

        };

        //console.log("2  win: ", win);       

        win.width = 700;

        win.height = 400;

        win.show();

//Runtime 設定 Panel2 :  items[Sub2_Grid] 的高度, 以便充滿整個畫面

var Tmp_okpanel_Height = Ext.getCmp('mySub2_OkBtn').getHeight()+20;

var Tmp_rHeight =Ext.getCmp('mySubForm').getHeight()-Ext.getCmp('sub2_panel1').getHeight()-Tmp_okpanel_Height;

        Ext.getCmp('sub2_panel2').setHeight(Tmp_rHeight);

    };


3>V120902 – 在主機端無法正常下載檔案



Ans:    發佈至主機時,  web.config  檔案必需設定   user/password , 以便存取主機端的目錄
                    若沒設定,則無法存取主機端的目錄的權限,以致無法下載SS_FILES至主機目錄
1>web.config
 <system.web>
    <!--server端帳密,發行時請取消註解-->
    <!-- identity impersonate="true" userName="webadmin" password="Aidc@856+123" /-->
  -->  發佈至測試區/正式區時,  如上web.config 檔案   必需  remark 
<identity impersonate="true" userName="webadmin" password="Aidc@856+123" />

2022年3月17日 星期四

V120703 - 匯入格式下載 - SS_FILES - V120103

 V120703 - 匯入格式下載

目的: 提供使用者由資料庫下載匯入格式(SS_FILES. FNAME + FBODY)


1>[匯入格式下載]鈕      *.js

       {
            xtype: 'button', text: '匯入格式下載', id: 'DownFmtBtn',
            handler: function () {               
               document.location = "../api/VUTLAPI/dnloadSS_File?FNAME=V120503_匯入格式下載.xls  ";               
            }  // end of handler

     *.cs

       public bool dnloadSS_FileS(string FNAME)
        {
            string Strsql = "select FNAME,FBODY from SS_FILES where FNAME = '" + FNAME + "' ";
            try
            { downloadFile(Strsql, "FNAME", "FBODY"); }
            catch (Exception ex)
            { throw ex; }
            finally { }
            return true;
        }


 public byte[] downloadFile(string sql, string fileName, string fileBody)
        {
            setActionName();
            OracleConnection conn = new OracleConnection(DBService.ConnectionString(DBLINK));
            conn.Open();
            conn.ClientInfo = User.Identity.Name;
            conn.ModuleName = BaseSYS + "_" + BaseMODID;
            conn.ActionName = ActionName;
            OracleCommand cmd = new OracleCommand(sql, conn);
            OracleDataReader reader = cmd.ExecuteReader();
            byte[] file = null;
            if (reader.Read())
            {
                try
                {
                    //clearing the content
                    HttpContext.Current.Response.ClearContent();

                    // adding the headers to file stream
                    HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=\"" + HttpUtility.UrlEncode((string)reader[fileName], System.Text.Encoding.UTF8) + "\"");

                    //BinaryWriter bw = new BinaryWriter(HttpContext.Current.Response.OutputStream);
                    // converting data into bytes
                    file = (byte[])reader[fileBody];
                    //bw.Write(file);
                    //bw.Close();
                    HttpContext.Current.Response.BinaryWrite(file);
                    HttpContext.Current.Response.End();
                }
                finally
                {
                    reader.Close();
                    conn.Close();
                }
            }
            return file;
        }