顯示具有 子視窗 標籤的文章。 顯示所有文章
顯示具有 子視窗 標籤的文章。 顯示所有文章

2023年3月10日 星期五

V80204A: - 匯出時,不分頁,資料全取 ,[工作中心報工匯出]鈕 – c# 子視窗呼叫 Master的函式(*.cs)

 目的: V80204: [工作中心報工匯出] – c# 子視窗呼叫 Master的函式(*.cs)

處理說明: 1>*.cs 
          //匯出時, 不分頁(par_paging=false), 資料全取 
            V80204APIController V80204 = new V80204APIController();
            DataSet ds = V80204.getGridData_M(false);



1>*.cs
 [HttpPost]
        public void WC_ALS_OutFile()
        {
            var c = HttpContext.Current;
            NameValueCollection nvc = c.Request.Form;

            //匯出時, 不分頁(par_paging=false), 資料全取 
            V80204APIController V80204 = new V80204APIController();
            DataSet ds = V80204.getGridData_M(false);
            //DataSet ds = null;

            string Tmp_FName = nvc["FName"];   //含 *.xls
            string Tmp_sub1_WC = nvc["sub1_WC"];
            //string fName = Tmp_FNAME + ".xlsx";
            string fName = Tmp_FName;
            Workbook wk = null;
            MemoryStream stream = new MemoryStream();
            string Tmp_Str = "";
            string Tmp_Sql = "";
            int Tmp_Cnt = 0;
            try
            {
                wk = new Workbook();
                Worksheet sheet1 = wk.Worksheets[0];//獲取第一個工作表
                //共 9 欄
                //AMM單號 工號  件號 件號名稱    製程 製程資料內容  WBS 工單類型    數量 單位  EOECN 專案  機號 起始值 情況處理碼 工單報工統計(小時)  工作中心 工作中心報工統計(小時)    版本
                string[] outFieldArray = { "項次","AMM單號","工號", "件號", "件號名稱", "製程",
                                                             "製程資料內容", " WBS", "工單類型", "數量", "單位",
                                                             "EOECN", "專案","機號","起始值","情況處理碼",
                                          "工單報工統計(小時)","工作中心","工作中心報工統計(小時)"," 版本" };
                for (int i = 0; i < outFieldArray.Length; i++)
                {
                    sheet1.Range[myfunc.GetExcelPos(i, 0)].Text = outFieldArray[i];
                }
                DataTable dt = ds.Tables[1];
                Tmp_Cnt = dt.Rows.Count;
                //Tmp_Str = "已匯出完成!!  ("+Tmp_Cnt.ToString() +"筆) ";
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    sheet1.Range[myfunc.GetExcelPos(0, i + 1)].Text = String.Format("{0:d}", i + 1);
                    //sheet1.Range[myfunc.GetExcelPos(1, i + 1)].Text = String.Format("{0:yyyy/MM/dd}", DateTime.Parse(dt.Rows[i]["DT"].ToString())); };
                    // "AMM單號","工號", "件號", "件號名稱", "製程",
                    sheet1.Range[myfunc.GetExcelPos(1, i + 1)].Text = dt.Rows[i]["AMMNO"].ToString();
                    sheet1.Range[myfunc.GetExcelPos(2, i + 1)].Text = dt.Rows[i]["SAPNO"].ToString();
                    sheet1.Range[myfunc.GetExcelPos(3, i + 1)].Text = dt.Rows[i]["PN"].ToString();
                    sheet1.Range[myfunc.GetExcelPos(4, i + 1)].Text = dt.Rows[i]["PNNAME"].ToString();
                    sheet1.Range[myfunc.GetExcelPos(5, i + 1)].Text = dt.Rows[i]["MKNO"].ToString();
                    //"製程資料內容", " WBS", "工單類型", "數量", "單位",
                    sheet1.Range[myfunc.GetExcelPos(6, i + 1)].Text = dt.Rows[i]["MKDESCPT"].ToString();
                    sheet1.Range[myfunc.GetExcelPos(7, i + 1)].Text = dt.Rows[i]["WBS"].ToString();
                    sheet1.Range[myfunc.GetExcelPos(8, i + 1)].Text = dt.Rows[i]["SROTP"].ToString();
                    sheet1.Range[myfunc.GetExcelPos(9, i + 1)].Text = dt.Rows[i]["QTY"].ToString();
                    sheet1.Range[myfunc.GetExcelPos(10, i + 1)].Text = dt.Rows[i]["UNIT"].ToString();
                    //"EOECN", "專案","機號","起始值","情況處理碼",
                    sheet1.Range[myfunc.GetExcelPos(11, i + 1)].Text = dt.Rows[i]["ECNO"].ToString();
                    sheet1.Range[myfunc.GetExcelPos(12, i + 1)].Text = dt.Rows[i]["PROJID"].ToString();
                    sheet1.Range[myfunc.GetExcelPos(13, i + 1)].Text = dt.Rows[i]["ACNO_"].ToString();
                    sheet1.Range[myfunc.GetExcelPos(14, i + 1)].Text = dt.Rows[i]["STARTVAL"].ToString();
                    sheet1.Range[myfunc.GetExcelPos(15, i + 1)].Text = dt.Rows[i]["CNDPROCCODE"].ToString();
                    // "工單報工統計(小時)","工作中心","工作中心報工統計(小時)"," 版本" 
                    sheet1.Range[myfunc.GetExcelPos(16, i + 1)].Text = dt.Rows[i]["ALS_HR_"].ToString();
                    //sheet1.Range[myfunc.GetExcelPos(17, i + 1)].Text = dt.Rows[i]["CURR_ARBPL_"].ToString(); //目前工作中心
                    sheet1.Range[myfunc.GetExcelPos(17, i + 1)].Text = Tmp_sub1_WC; //子視窗.工作中心                    
                    //工作中心報工統計(小時)
                    Tmp_Sql = "  SELECT round((sum(HOUR_WORK)+sum(HOUR_OT))/60,2)  WCHR  "
                                     + "  FROM   "
                                     + "  (  "
                                     + "    SELECT  JCN, ACT, WC, HOUR_WORK, work_ID, HOUR_OT FROM  HOUR.ALS_HOUR_COMP@ALS_HOUR WHERE WC = " + myfunc.AA(Tmp_sub1_WC) + "   AND JCN = '0000' || " + myfunc.AA(dt.Rows[i]["SAPNO"].ToString())
                                     + "    union all   "
                                    + "     SELECT  JCN, ACT, WC, HOUR_WORK, work_ID, HOUR_OT FROM HOUR.ALS_HOUR_COMP_HISTORY@ALS_HOUR WHERE WC = " + myfunc.AA(Tmp_sub1_WC) + "   AND JCN = '0000' || " + myfunc.AA(dt.Rows[i]["SAPNO"].ToString())
                                    + "   )   "
                                    + "  GROUP BY JCN,WC   ";
                    Tmp_Str = myfunc.SqlValue(Tmp_Sql);
                    sheet1.Range[myfunc.GetExcelPos(18, i + 1)].Text = Tmp_Str; //工作中心報工統計(小時)                   
                    //版本
                    Tmp_Sql = "  SELECT  ED   "
                                   + "   FROM    AMM_EDLST  "
                                   + "   WHERE (AMMNO, ITM) in (select AMMNO, max(to_number(ITM)) from AMM_EDLST group by AMMNO )  "
                                   + "   AND AMMNO = " + myfunc.AA(dt.Rows[i]["AMMNO"].ToString());
                    Tmp_Str = myfunc.SqlValue(Tmp_Sql);
                    sheet1.Range[myfunc.GetExcelPos(19, i + 1)].Text = Tmp_Str; //版本


                    // end of for 
                }  // end of   for (int i = 0; i < dt.Rows.Count; i++)
                sheet1.AllocatedRange.AutoFitColumns();
                wk.SaveToStream(stream, FileFormat.Version2007);
            } //end of try
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
            finally
            {
                wk.Dispose();
            }

            //Tmp_Cnt = 6;
            Tmp_Str = "已匯出完成!!  (" + Tmp_Cnt.ToString() + "筆) <br>"
                            + "檔案名稱(" + Tmp_FName + ")";
            HttpCookie MyCookie = new HttpCookie("EX_DFile", HttpUtility.UrlEncode(Tmp_Str));
            HttpContext.Current.Response.Cookies.Add(MyCookie);
            HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=\"" + HttpUtility.UrlEncode(fName, System.Text.Encoding.UTF8) + "\"");
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
            HttpContext.Current.Response.BinaryWrite(stream.ToArray());
            HttpContext.Current.Response.End();
        }    // end of ExportdFile


2>*.js
//工作中心報工匯出
function WC_ALS_OutFile() {
    var np = s_JSON('s_form'); //TMFunction.js, 組合form上的查詢條件為json參數傳遞
    np["FName"] = "V80204_工作中心報表匯出.xlsx";
    np["sub1_WC"] = Ext.getCmp("sub1_WC").getValue();
    console.log("np:", np);
    console.log("FName: ", np.FName);
    f_downloadFile('EX_DFile', '../api/V80204AAPI/WC_ALS_OutFile', np, 'POST', function () {
        var r = r_cookies('EX_DFile');
        mysuccessalert(r);
    });
};

2022年12月12日 星期一

V80201 – 生工OSM查詢 – 開啟子視窗 - layout:'border' - 顯示子件資料 - 子畫面

 目的: V80201 – 生工OSM查詢 開啟子視窗

處理說明:







1>*.js 開啟子視窗的 source

1>> V80201A.js

Ext.Loader.loadScript({
    url: '../JsFunction/V80201A1.js'
});

//[顯示子件資料]鈕 - 子視窗
function ShowPNBtn_click() {
console.log(" ShowPNBtn_click  step1");
    //按鈕 : [確認] [取消]  - [顯示子件資料]鈕
    var sub_ShowPN_Btns = [
        {
            xtype: 'button', text: '確定', id: 'sub_ShowPN_OkBtn',
            listeners: {
                click: function () {
                    //mysuccessalert("mysub2_確定 ");
                    ShowPNGridDetail();
                }
            }
        },        


2>>V80201A1.js
//[顯示子件明細資料]鈕 - 子視窗Grid
function ShowPNGridDetail() {

    //按鈕 : [確認] [取消]  - [顯示子件資料]鈕
    var sub_ShowPNDetail_Btns = [
        {
            xtype: 'button', text: '瀏覽參考文件', id: 'sub_ShowRef_OkBtn',
            listeners: {
                click: function () {
                    //mysuccessalert("mysub2_確定 ");
                    ShowRefDetail();
                }
            }
        },        
        {
            xtype: 'button', text: '離開', id: 'sub_ShowRef_CancelBtn',
            listeners: {
                click: function () {
                    //mysuccessalert("mysub2_取消");
                    var Tmp_win = this.up("window");
                    if (Tmp_win == undefined) {
                        Ext.Msg.alert("取消時未取到Window Object");
                    }
                    this.up("window").close();
                    this.up("window").destroy();
                }
            }
        },
    ];

// [顯示子件資料]鈕  - Grid子畫面欄位
    var sub_Columns = [
        { header: "", xtype: "rownumberer", width: 50, align: "center", sortable: false },
        { header: "子件件號", dataIndex: "cmp_id", width: 100, TMType: "string" },
        { header: "件號名稱", dataIndex: "itm_name", width: 150, TMType: "string" },
        { header: "數量", dataIndex: "qty", width: 80, TMType: "string" },
        { header: "單位", dataIndex: "units", width: 60, TMType: "string" },
        { header: "製程", dataIndex: "mroutingtype", width: 80, TMType: "string" },
        { header: "製程名稱", dataIndex: "mroutingtype_name", width: 100, TMType: "string" },
        //{ header: "替代件號", dataIndex: "SPN", width: 100, TMType: "string" },
        //{ header: "參考文件", dataIndex: "FLNM", width: 100, TMType: "string" },        
    ];

    var sub_model = [
        { name: "cmp_id" },
        { name: "itm_name" },
        { name: "qty" },
        { name: "units" },
        { name: "mroutingtype" },
        { name: "mroutingtype_name" },
        //{ name: "SPN" },
        //{ name: "FLNM" },        
    ];

    console.log(" ShowPNGridDetail  step2");
    //子件明細 Grid
    var sub_Grid = Ext.create('TMGrid', {
        grid_id: 'sub_Grid',
        columns: sub_Columns,
        autoScroll: true,
        flex: 1,
        store: Ext.create('gridstore', { model: sub_model }),
    });

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

var sub_ShowPNDetail_Flds = [
        {
            type: 'panel', bodyStyle: "background-color:transparent;", border: 5, padding: "1",            
            layout: 'border',            
            items: [
                {
                    xtype: 'panel',
                    id: 'sub_panel1',
                    region: 'north',
                    layout: { type: 'hbox', align: 'stretch' },
                    items: [                      
                        {
                            xtype: "fieldcontainer", fieldLabel: "專案別", labelWidth: 80, flex: 5, border: 2,
                            items: [
                                { id: "sub_PROJID1", name: "sub_PROJID1", xtype: "textfield", width: 80, padding: "0 4 0 0", },
                            ]
                        },
                        {
                            xtype: "button", text: "顯示明細資料", labelWidth: 120, flex: 2, border: 2,
                            handler: function () {
                                var np = {};
                                Ext.getCmp('sub_Grid').store.getProxy().url = '../api/V80201A1API/getsubData';
                                Ext.getCmp('sub_Grid').store.getProxy().extraParams = np; //分頁OK,篩選條件OK
                                Ext.getCmp('sub_Grid').store.load();
                            }                           
                        },

                    ],
                },//end of 專案別
                {
                    xtype: 'panel',
                    id: 'sub_panel2',                    
                    region: 'center',        //自動填滿剩餘空間
                    layout: 'fit',  //如此 Grid 才會充滿 panel2
                    flex: 5,
                    border: 1,
                    items: [sub_Grid]
                },                
] // end of   layout: "vbox", padding: "5", items: [
}  //end of  sub_ShowPN_Flds , items[{
]      //end of  var sub_ShowPN_Flds 

    //"A1" : 區分不同 window_id
    var win1 = getMyWindow("顯示子件明細資料", sub_ShowPNDetail_Flds, sub_ShowPNDetail_Btns, "A1");
    win1.x = 450;
win1.setWidth(400);
    win1.setHeight(300);
    //顯示 sub Grid 資料
    var np = {};
    np["sub_BRP"] = "";
    
    Ext.getCmp('sub_Grid').store.on("load", function (me, records, successful, eOpts) {        
        if (successful) {
            console.log("successful");
            console.log("Ext.getCmp('sub_Grid').store.data", Ext.getCmp('sub_Grid').store.data);
            win1.show();
        }
    }
    );
    Ext.getCmp('sub_Grid').store.getProxy().url = '../api/V80201A1API/getsubData';
    Ext.getCmp('sub_Grid').store.getProxy().extraParams = np; //分頁OK,篩選條件OK
   //Ext.getCmp('sub_Grid').store.clearOnPageLoad = true;
    //Ext.getCmp('sub_Grid').reloadGridData();
    Ext.getCmp('sub_Grid').store.load();
    console.log(" STEP 1 Ext.getCmp('sub_Grid').store.load() ");
//Ext.getCmp('sub_Grid_ptb').hide();

};  // end of function ShowPNBtn_click() {

2022年12月7日 星期三

V120501– 顯示子畫面 - [新增領用登記] - Form - 子視窗

目的: V120501– 開啟子視窗 - [新增領用登記]  - Form

處理說明: 1>開啟子視窗 - 
                       var win = getMyWindow("新增領用登記", J_formFields_Sub1mySub1_Btns);        
                  2>定義子視窗_button
                      var mySub1_Btns = [
                         {
                            xtype: 'button', text: '確定', id: 'OkBtn_mySub1',
                           listeners: {
                               click: function () {  ..  }
                           
                  3>定義子視窗_欄位
                      var J_formFields_Sub1 = [
                  {
                           bodyStyle: "background-color:transparent;", border: false, layout: "vbox", padding: "5", items: [
                  {        



1>*.js

 //按鈕 : [新增領用登記] [掃描登記][查詢領用記錄]
    var BtnAry = [
        {
            xtype: 'button', text: '新增領用登記', id: 'UseRegBtn',
            listeners: {
                click: function () {
                    AddRegBtn_click();                    
                }
            }
        },

//新增 [新增領用登記]鈕    
    function AddRegBtn_click() {
        console.log(" 1 inside - AddRegBtn_Click 新增領用登記: ");
        //1>檢核資料是否正確 - 是否有選擇資料        
        var cur_recs = Ext.getCmp('grid_Single').getSelectionModel().getSelection(); //grid select指向選擇的第一筆        
        var cur_rec = cur_recs[0];
        console.log("cur_rec[raw][QTY]:", cur_rec["raw"]["QTY"]);
        var np1 = {};
        np1["CPNO"] = cur_rec["raw"]["CPNO"];
        np1["MATNR"] = cur_rec["raw"]["MATNR"];
        np1["WH"] = cur_rec["raw"]["WH"];
        np1["SP"] = cur_rec["raw"]["SP"];        
        np1["QTY"] = cur_rec["raw"]["QTY"];
        np1["RQTY"] = cur_rec["raw"]["RQTY"];
        np1["UNIT"] = cur_rec["raw"]["UNIT"];
        np1["CHARG"] = cur_rec["raw"]["CHARG"];        
        np1["NOTE"] = cur_rec["raw"]["NOTE"];
        np1["COMPER"] = loginInfo.id;        
        np1["PQTY"] = "";
        //2>顯示子畫面 - [新增領用登記]
        var mySub1_Btns = [
            {
                xtype: 'button', text: '確定', id: 'OkBtn_mySub1',
                listeners: {
                    click: function () {
                        //1>更新資料庫資料(AMM_COMPQTY)
                        var Tmp_Str = "";
                        if (checkisnull(Ext.getCmp("sub1_PQTY").getValue())){
                            Tmp_Str = "領用數量不可空白<br>"
                                            + " 敬請檢核 !!";
                            mywarnalert(Tmp_Str);
                            return;
                        }
                        if (Number(Ext.getCmp("sub1_PQTY").getValue()) > Number(Ext.getCmp("sub1_RQTY").getValue())) {
                            Tmp_Str = "領用數量(" + Ext.getCmp("sub1_PQTY").getValue() + ")不可大於剩餘數量(" + Ext.getCmp("sub1_RQTY").getValue() + ")<br>"
                                + " 敬請檢核 !!";
                            mywarnalert(Tmp_Str);
                            return;
                        }
                        np1["PQTY"] = Ext.getCmp("sub1_PQTY").getValue();
                        np1["SAPNO"] = Ext.getCmp("sub1_SAPNO").getValue();
                        np1["NOTE"] = Ext.getCmp("sub1_NOTE").getValue();
                        np1["COMPER"] = Ext.getCmp("sub1_COMPER").getValue();
                        np1["COMPDT"] = cnow();                      
                        Ext.Ajax.request({
                            method: 'POST',
                            params: np1,
                            async: false, //將非同步功能關閉
                            url: '../../api/V120501API/Add_AMMCOMPQTY_1',
                            success: function (response, opts) {
                                var obj = Ext.decode(response.responseText);
                                var Tmp_Str = obj["Rtn_Msg"];
                                var Tmp_success = obj["success"];
                                if (Tmp_success) {
                                    Tmp_Str = "[新增領用登記]成功 !!<br>"
                                                    + Tmp_Str;
                                    mysuccessalert(Tmp_Str);                                    
                                }
                                else {
                                    Tmp_Str = "[新增領用登記]失敗 !! <BR> "
                                                     + Tmp_Str;
                                    mywarnalert(Tmp_Str);                                    
                                }
                            },
                            failure: function (response, opts) {
                                var obj = Ext.decode(response.responseText);
                                var Tmp_Str = obj["Rtn_Msg"];
                                Tmp_Str = "[新增領用登記]失敗 !!<br>"                                    
                                                + Tmp_Str;
                                mywarnalert(Tmp_Str);                                
                                return;
                            }
                        });  // end of  Ext.Ajax.Request  for Email
                        //2> close windows
                        this.up("window").close();
                        this.up("window").destroy();
                        //3>重新更新 MDBGrid
                        Ext.getCmp("btn_Show").fireHandler();                        
                    }
                }
            },
            {
                xtype: 'button', text: '取消', id: 'CancelBtn_mySub1',
                listeners: {
                    click: function () {
                        this.up("window").close();
                        this.up("window").destroy();
                    }
                }
            },
        ];
        
        var win = getMyWindow("新增領用登記", J_formFields_Sub1, mySub1_Btns);        
        win.onshow = Sub1_onShow(np1);
        win.width = 600;
        win.height = 450;        
        win.show();
    };

2>V120201_json.js  -  子畫面欄位
// [新增領用登記]鈕  
var J_formFields_Sub1 = [
{
bodyStyle: "background-color:transparent;", border: false, layout: "vbox", padding: "5", items: [
{
xtype: "fieldcontainer", fieldLabel: "編號", labelWidth: 100, layout: "hbox", items: [
{ id: "sub1_CPNO", name: "sub1_CPNO", xtype: "textfield", width: 100, padding: "0 4 0 0", readOnly: true, fieldCls: "readonly", },
]
},  //end of 編號
{
xtype: "fieldcontainer", fieldLabel: "件號", labelWidth: 100, layout: "hbox", items: [
{ id: "sub1_MATNR", name: "sub1_MATNR", xtype: "textfield", width: 100, padding: "0 4 0 0", readOnly: true, fieldCls: "readonly", },
]
},   // end of 件號
{
xtype: "fieldcontainer", fieldLabel: "庫房", labelWidth: 100, layout: "hbox", items: [
{ id: "sub1_WH", name: "sub1_WH", xtype: "textfield", width: 100, padding: "0 4 0 0", readOnly: true, fieldCls: "readonly", },
]
}, // end of 庫房
{
xtype: "fieldcontainer", fieldLabel: "數量", labelWidth: 100, layout: "hbox", items: [
{ id: "sub1_QTY", name: "sub1_QTY", xtype: "textfield", width: 100, padding: "0 4 0 0", readOnly: true, fieldCls: "readonly",},
]
},  // end of 數量
{
xtype: "fieldcontainer", fieldLabel: "剩餘數量", labelWidth: 100, layout: "hbox", items: [
{ id: "sub1_RQTY", name: "sub1_RQTY", xtype: "textfield", width: 100, padding: "0 4 0 0", readOnly: true, fieldCls: "readonly", },
]
},  // end of 剩餘數量
{
xtype: "fieldcontainer", fieldLabel: "單位", labelWidth: 100, layout: "hbox", items: [
{ id: "sub1_UNIT", name: "sub1_UNIT", xtype: "textfield", width: 100, padding: "0 4 0 0", readOnly: true,fieldCls: "readonly", },
]
}, // end of 單位
{
xtype: "fieldcontainer", fieldLabel: "批次", labelWidth: 100, layout: "hbox", items: [
{ id: "sub1_CHARG", name: "sub1_CHARG", xtype: "textfield", width: 100, padding: "0 4 0 0", readOnly: true, fieldCls: "readonly", },
] // end of 批次.items
}, // end of 批次
{
xtype: "fieldcontainer", fieldLabel: "儲存位置", labelWidth: 100, layout: "hbox", items: [
{ id: "sub1_SP", name: "sub1_SP", xtype: "textfield", width: 100, padding: "0 4 0 0", readOnly: true, fieldCls: "readonly", },
]
}, // end of 儲存位置
{
xtype: "fieldcontainer", fieldLabel: "領用數量", labelWidth: 100, layout: "hbox", items: [
{ id: "sub1_PQTY", name: "sub1_PQTY", xtype: "textfield", width: 100, padding: "0 4 0 0", fieldCls: "required",  },
]
}, // end of 領用數量
{
xtype: "fieldcontainer", fieldLabel: "領用人員", labelWidth: 100, layout: "hbox", items: [
{ id: "sub1_COMPER", name: "sub1_COMPER", xtype: "textfield", width: 100, padding: "0 4 0 0", fieldCls: "required", },
{ id: "sub1_COMPER_", name: "sub1_COMPER_", xtype: "textfield", width: 100, padding: "0 4 0 0", fieldCls: "readonly", },
{
id: "btn_sub1_COMPER", name: "btn_sub1_COMPER", xtype: "button", text: "...",
//員工編號挑選 , TreeView 挑選    
handler: function () {
console.log(" btn_sub1_COMPER on click");
var treepanel = Ext.create('EmployeeTree', {
id: 'myEmployeeTree',
listeners: {
itemclick: function (view, record, item, index, e) {
if (record.raw.leaf) {
var info = record.raw.text;
var newStr = info.split(":");
Ext.getCmp('sub1_COMPER').setValue(newStr[0]);
Ext.getCmp('sub1_COMPER_').setValue(newStr[1]);
win_tree.close();
}
}
}
});
var win_tree = getWindow('領用人員挑選', treepanel);
win_tree.height = 400;
win_tree.show();
} // end of handler of  btn_sub1_comper
},
]
}, // end of 領用人員
{
xtype: "fieldcontainer", fieldLabel: "領用工號", labelWidth: 100, layout: "hbox", items: [
{ id: "sub1_SAPNO", name: "sub1_SAPNO", xtype: "textfield", width: 100, padding: "0 4 0 0",  },
]
}, // end of 領用工號
{
xtype: "fieldcontainer", fieldLabel: "備註(使用架次)", labelWidth: 100, layout: "hbox", items: [
{ id: "sub1_NOTE", name: "sub1_NOTE", xtype: "textarea", width: 200, padding: "0 4 0 0",  },
]
}, // end of 備註
] // end of   layout: "vbox", padding: "5", items: [
}  //end of  J_formFields_Sub1 , items[{
]      //end of  J_formFields_Sub1 , items[

2022年9月28日 星期三

V120402B -[歸還登記]鈕 - 顯示子畫面,子視窗 - Grid

目的: V120402B  -[歸還登記]鈕  -開啟子視窗,顯示子畫面 - 含Grid

處理說明: 1>var win = getMyWindow("借閱登記", sub_LendFlds, sub_LendFlds_Btns);
                       win.show();      
                  2>設定子畫面下方處理按鈕(sub_LendFlds_Btns)
                  3>設定子畫面上方過濾條件 & Grid
                  4>子畫面     layout: 'border'
                                      [過濾條件: region: 'north',]  [Grid: region: 'center',] []


1>*.js  - 開啟子視窗

 //按鈕 : [借閱登記] [歸還登記][續借登記][查詢借閱記錄][報表]
    var BtnAry = [
        {
            xtype: 'button', text: '借閱登記', id: 'LendBtn',
            listeners: {
                click: function () {
                    LendBtn_click();
                }
            }
        },
        {
            xtype: 'button', text: '歸還登記', id: 'BackBtn',
            listeners: {
                click: function () {
                    //console.log(" 1 inside 缺勤記錄維護: ");
                    BackBtn_click();
                }
            }
        },
         :
]

//於單檔下方新增 Button
 Ext.getCmp('grid_D').insertBtn(BtnAry);

//[借閱登記]鈕 - 子視窗
    function LendBtn_click() {
        console.log("step1");        

        //按鈕 : [確認] [取消]  - [借閱登記]鈕
        var sub_LendFlds_Btns = [
            {
                xtype: 'button', text: '確定', id: 'sub_LendFlds_OkBtn',
                listeners: {
                    click: function () {
                        //mysuccessalert("mysub2_確定 ");
                        sub_LendFlds_OkBtn();
                    }
                }
            },
            {
                xtype: 'button', text: '刪除', id: 'sub_LendFlds_DelBtn',
                listeners: {
                    click: function () {
                        //mysuccessalert("mysub2_確定 ");
                        //sub_LendFlds_DelBtn();
                        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;
                        }
                    }
                }
            },
            {
                xtype: 'button', text: '取消', id: 'sub_LendFlds_CancelBtn',
                listeners: {
                    click: function () {
                        //mysuccessalert("mysub2_取消");
                        var Tmp_win = this.up("window");
                        if (Tmp_win == undefined) {
                            Ext.Msg.alert("取消時未取到Window Object");
                        }
                        this.up("window").close();
                        this.up("window").destroy();
                    }
                }
            },
        ];

        console.log("step2");

        var sub_Columns = [
            { header: "", xtype: "rownumberer", width: 50, align: "center", sortable: false },
            { header: "條碼編號", dataIndex: "TMNO", width: 100, TMType: "string" },
            { header: "技令編號", dataIndex: "TMNOXX", width: 150, TMType: "string" },
            { header: "文件編號", dataIndex: "DOCNO", width: 100, TMType: "string" },
            { header: "最近版期", dataIndex: "VNDTXY_", width: 100, TMType: "string" },
            { header: "最近版別", dataIndex: "VNTPXD_", width: 100, TMType: "string" },
            { header: "頁次", dataIndex: "SHT", width: 100, TMType: "string" },
            { header: "版本", dataIndex: "REV", width: 100, TMType: "string" },
            { header: "文件名稱", dataIndex: "DOCTLE", width: 200, TMType: "string" },
            { header: "儲位", dataIndex: "STLCT", width: 100, TMType: "string" },
            { header: "冊號", dataIndex: "VOL", width: 100, TMType: "string" },
            { header: "管制現況", dataIndex: "STAT", width: 80, TMType: "string" },
            { header: "管制現況說明", dataIndex: "STAT_", width: 100, TMType: "string" },
            { header: "預期借閱天數", dataIndex: "BRDAY_", width: 100, TMType: "string" },
            { header: "備註", dataIndex: "REMARK_", width: 100, TMType: "string" },
        ];

        var sub_Fields = [
            { name: "TMNO" },
            { name: "TMNOXX" },
            { name: "DOCNO" },
            { name: "VNTPXD_" },
            { name: "VNDTXY_" },
            { name: "SHT" },
            { name: "REV" },
            { name: "DOCTLE" },
            { name: "STLCT" },
            { name: "VOL" },
            { name: "STAT" },
            { name: "STAT_" },
            { name: "BRDAY_" },
            { name: "REMARK_" },
        ];

        //借閱登記 Grid
        var sub_Grid = Ext.create('TMGrid', {
            grid_id: 'sub_Grid',
            columns: sub_Columns,
            autoScroll: true,
            flex: 1,
            store: Ext.create('gridstore', { model: sub_Fields }),
        });

        console.log("step2.5");

        // [缺勤記錄維護]鈕  - 子畫面欄位
        var sub_LendFlds = [
            {
                type: 'panel', bodyStyle: "background-color:transparent;", border: 0, padding: "5",
                flex: 100,
                layout: 'border',
                items: [
                    {  //sub_panel1 : 過濾條件 panel
                        xtype: 'panel',
                        id: 'sub_panel1',
                        region: 'north',
                        layout: { type: 'hbox', align: 'stretch' },
                        //flex: 0,
                        //border: 1,
                        items: [
                            {
                                xtype: 'panel',
                                id: 'sub_panel11',
                                layout: { type: 'vbox', align: 'stretch' },
                                flex: 15,
                                border: 0,
                                items: [{
                                    xtype: "fieldcontainer", fieldLabel: "借閱人員", labelWidth: 60, layout: "hbox", flex: 2,
                                    items: [{
                                        xtype: "textfield", id: "sub_BRP", name: "sub_BRP", width: 100, padding: "0 4 0 0", fieldCls: "required", 
                                        listeners: {
                                            change: function (textfield, newValue, oldValue) {
                                                if (newValue.length == 10) {
                                                    getVcardInfo(newValue);
                                                }0
                                            }
                                        }
                                    },
                                        { xtype: "textfield", id: "sub_BRP_", name: "sub_BRP_", width: 100, padding: "0 4 0 0", readOnly: true, fieldCls: "readonly", },
                                    {
                                        xtype: "button", id: "sub_BRP_btn", name: "sub_BRP_btn", width: 100, padding: "0 4 0 0", text: "借閱人員變更",
                                        handler: function () {
                                            Ext.getCmp("sub_BRP").setValue("");
                                        }
                                    },
                                    ]
                                }, // end of s_借閱人員
                                {  //QRCODE 
                                    xtype: "fieldcontainer", fieldLabel: "QR CODE", labelWidth: 60, layout: "hbox", flex: 2,
                                    items: [
                                        {
                                            xtype: "textfield", id: "sub_TMNO", name: "sub_TMNO", width: 200, padding: "0 4 0 0", fieldCls: "required", 
                                            listeners: {
                                                blur: function (obj, event, opts) {
                                                    //1>檢核 TMNO 是否存在 AMM_TMDWG
                                                    //2>檢核 TMNO 存在 AMM_TMDWG 是否可借閱(STAT='A')
                                                    var Tmp_TMNO = "";
                                                    var isOk = true;
                                                    Tmp_TMNO = Ext.getCmp("sub_TMNO").getValue();
                                                    var np = {};
                                                    np["TMNO"] = Tmp_TMNO;
                                                    Ext.Ajax.request({
                                                        method: "POST",
                                                        url: '../../api/V120402API/CHECK_TMNO',
                                                        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_TMNO + ")錯誤訊息如下:<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_TMNO + ")錯誤訊息如下:<br>"                                                                
                                                                + Tmp_Obj["Rtn_Msg"];
                                                            mywarnalert(Tmp_Rtn_Msg);
                                                            isOk = false;
                                                        }
                                                    })  //end of Ext.Ajax.Request              
                                                    //若 ok ,才可按 [加入資料]
                                                    if (isOk == true) {
                                                        console.log("isOk:", isOk);
                                                        if (!checkisnull(Ext.getCmp("sub_btn_add")))
                                                            Ext.getCmp("sub_btn_add").setDisabled(false);
                                                    }
                                                    else {
                                                        if (!checkisnull(Ext.getCmp("sub_btn_add")))
                                                            Ext.getCmp("sub_btn_add").setDisabled(true);
                                                    }
                                                        

                                                    //3>加入 sub_store
                                                    console.log("1 sub_btn_add.fireHandler()");
                                                    Ext.getCmp("sub_btn_Add").fireHandler();
                                                    //Ext.getCmp("sub_btn_Add").fireEvent("click");
                                                    //console.log("2 sub_btn_add.fireEvent(click)");

                                                }  // end of blur event
                                            }  // end of Listener
                                        },  // end of sub_TMNO
                                    ]       // end of QR_CODE.ITEMS
                                },
                                ]
                            }, //end of sub2_panel11 , flex:20   
                            {
                                //xtype: 'toolbar',
                                xtype: 'panel',
                                id: 'sub_panel12',
                                layout: { type: 'vbox', align: 'right' },
                                flex: 5,
                                border: 0,
                                items: [
                                    {
                                        xtype: 'button',
                                        id: 'sub_btn_Show',
                                        hidden: true,
                                        flex: 2,
                                        border: 1,
                                        text: '資料顯示',  //sub2
                                        iconCls: 'icon-search',
                                        handler: function () {
                                            //--> 需改為將 TMNO 的[AMM_TMDWG]資料加入 store 
                                            var np = {};
                                            np["sub_BRP"] = Ext.getCmp("sub_BRP").getValue();
                                            np["sub_TMNO"] = Ext.getCmp("sub_TMNO").getValue();
                                            //console.log('np:', np);
                                            Ext.getCmp('sub_Grid').store.getProxy().url = '../api/V120402API/getsubData';
                                            Ext.getCmp('sub_Grid').store.getProxy().extraParams = np; //分頁OK,篩選條件OK
                                            Ext.getCmp('sub_Grid').store.clearOnPageLoad = false;
                                            Ext.getCmp('sub_Grid').reloadGridData();                                            
                                        }
                                    },  // end of 顯示資料
                                    {
                                        xtype: 'button',
                                        id: 'sub_btn_Add',
                                        flex: 2,
                                        border: 1,
                                        text: '加入資料',  //sub_btn_Add
                                        iconCls: 'icon-search',
                                        hidden: true,  //隱藏不顯示  [加入資料]鈕
                                        handler: function () {
                                            //--> 需改為將 TMNO 的[AMM_TMDWG]資料加入 store 
                                            console.log("insider handler of sub_btn_Add");
                                            var np = {};
                                            np["sub_BRP"] = Ext.getCmp("sub_BRP").getValue();
                                            np["sub_TMNO"] = Ext.getCmp("sub_TMNO").getValue();
                                            var is_Ok = true;
                                            //console.log('np:', np);
                                            //Ext.getCmp('sub_Grid').store.getProxy().url = '../api/V120402API/getsubData';
                                            //Ext.getCmp('sub_Grid').store.getProxy().extraParams = np; //分頁OK,篩選條件OK
                                            //Ext.getCmp('sub_Grid').reloadGridData();
                                            Ext.Ajax.request({
                                                method: "POST",
                                                url: '../../api/V120402API/get_sub_data1',
                                                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 = "借閱人(" + np["sub_BRP"] + ")條碼編號(" + np["sub_TMNO"] + ")的資料取得(AMM_TMDWG)成功<br>";
                                                        //mysuccessalert(Tmp_Rtn_Msg);
                                                        console.log("1 Tmp_Obj[Rtn_Msg]:", Tmp_Obj["Rtn_Msg"]);
                                                        isOk = true;                                                        
                                                        var Tmp_recs = Ext.decode(Tmp_Obj["Rtn_Msg"]);
                                                        console.log("Tmp_recs:", Tmp_recs);
                                                        console.log("Tmp_recs.length:", Tmp_recs.length);
                                                        var Tmp_rec;
                                                        for (i = 0; i < Tmp_recs.length; i++) {
                                                            console.log("1 Tmp_rec:", Tmp_rec);
                                                            Tmp_rec = Tmp_recs[i];                                                            
                                                            console.log("Tmp_rec:", Tmp_rec);
                                                            if (Ext.getCmp("sub_Grid").store.find("TMNO", Tmp_rec["TMNO"]) == -1)
                                                                Ext.getCmp("sub_Grid").store.add(Tmp_rec); 
                                                            //2022/08/24 若已加入,則不顯示訊息
                                                            //else 
                                                                //mywarnalert("條碼編號(" + Tmp_rec["TMNO"].toString() + ")已加入,不可重複加入<br>");
                                                            
                                                        } // for (i=0;i<)
                                                    }
                                                    if (Tmp_Obj["success"] == false) {
                                                        console.log(" false , Tmp_Obj[Rtn_Msg]", Tmp_Obj["Rtn_Msg"]);
                                                        var Tmp_Rtn_Msg = "借閱人(" + np["sub_BRP"] + ")條碼編號(" + np["sub_TMNO"] + ")的資料錯誤訉息如下:<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 = "借閱人(" + np["sub_BRP"] + ")條碼編號(" + np["sub_TMNO"] + ")的資料錯誤訊息如下:<br>"                                                        
                                                        + Tmp_Obj["Rtn_Msg"];
                                                    mywarnalert(Tmp_Rtn_Msg);
                                                    isOk = false;
                                                }
                                            })  //end of Ext.Ajax.Request
                                            return isOk;
                                        } // end of handler of sub_btn_Add
                                    },// end of  button  sub_btn_Add  , 加入資料
                                    
                                    {
                                        xtype: 'label',
                                        id: 'sub_btn_label',
                                        flex: 2,
                                    },
                                ]
                            }  //end of sub_panel12
                        ]
                    },  //end of panel1                    
                    {
                        xtype: 'panel',
                        id: 'sub_panel2',
                        //title: 'sub_panel2',
                        region: 'center',
                        layout: 'fit',
                        //flex: 60,
                        //border: 20,
                        items: [sub_Grid]
                    },
                ] // end of   layout: "vbox", padding: "5", items: [
            }  //end of  my_Sub2 , items[{
        ]      //end of  my_Sub2 , items[


        Ext.getCmp('sub_Grid').store.on("load", function (me, records, successful, eOpts) {
            if (successful) {
                console.log("Ext.getCmp('sub_Grid').store", Ext.getCmp('sub_Grid').store);
                console.log("Ext.getCmp('sub_Grid').store.data", Ext.getCmp('sub_Grid').store.data);
            }
        }
        );       

        console.log("sub_Grid:", sub_Grid);
        
        var win = getMyWindow("借閱登記", sub_LendFlds, sub_LendFlds_Btns);                          
        win.setWidth(600);
        win.setHeight(400);
        win.show();
        Ext.getCmp('sub_Grid_ptb').hide();
        console.log("step6");
    } // end of   function LendBtn_click() {