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月28日 星期日

V120402 - Radiobox 處理 - 取得 radioGroup 欄位值

 目的:  在畫面上顯示 Radiobox

處理說明: 1> {xtype: 'radiogroup', fieldLabel: '現況', labelWidth: 40, layout: 'vbox', 
                                id: 's_STAT',

                                items: [
                                    {
                                        boxLabel: '全部(不含已刪除)',
                                        name: 's_STAT',

                                        inputValue: 'ALL',                                        
                                        width: 200,
                                        checked: true,                                        
                                    }, {
                                        boxLabel: ' 可借閱',
                                        name: 's_STAT',

                                        inputValue: 'A',    
                                        //width: 200,
                                    }, {  :



1>*.js
 {
    xtype: 'radiogroup', fieldLabel: '現況', labelWidth: 40, layout: 'vbox', 
    id: 's_STAT',
    items: [
                                    {
                                        boxLabel: '全部(不含已刪除)',
                                        name: 's_STAT',
                                        inputValue: 'ALL',                                        
                                        width: 200,
                                        checked: true,                                        
                                    }, {
                                        boxLabel: ' 可借閱',
                                        name: 's_STAT',

                                        inputValue: 'A',    
                                    }, {
                                        boxLabel: '已借出',
                                        name: 's_STAT',
                                        inputValue: 'B',    
                                    },
                                    {
                                        boxLabel: '已刪除',
                                        name: 's_STAT',
                                        inputValue: 'Z',                                            
                                    }



//顯示資料
  {
                //xtype: 'toolbar',
                xtype: 'panel',
                id: 'panel2',
                layout: { type: 'vbox', align: 'right' },
                flex: 1,
                border: 0,
                items: [
                    {
                        xtype: 'button',
                        id: 'btn_Show',
                        flex: 2,
                        border: 1,
                        text: '資料顯示',
                        iconCls: 'icon-search',
                        handler: function () {
                           var np = s_JSON('s_form'); //TMFunction.js, 組合form上的查詢條件為json參數傳遞
                            np["s_STAT"] = Ext.getCmp('s_STAT').getValue();

                            gridstore.getProxy().url = '../api/V120402API/getGridData_M';
                            gridstore.getProxy().extraParams = np; //分頁OK,篩選條件OK

                            Ext.getCmp('grid_M').reloadGridData();                            
                        }
                    },  // end of 顯示資料
                    {
                        xtype: 'button',
                        id: 'btn_clear',
                        flex: 2,
                        border: 1,
                        text: '清除條件',
                        iconCls: 'icon-clear',
                        handler: function () {
                            var f = Query.getForm();
                            f.reset();
                        }
                    },  // end of 清除條件                    
                    { xtype: 'label', id: 'label151', flex: 2, border: 0, text: '', },  // end of label
                    { xtype: 'label', id: 'label152', flex: 2, border: 0, text: '', },  // end of label                    
                ]  // end of items of [顯示資料][清除條件]
            }   // end of panel2
        ]  // end of  items of Query


2>V20107.js  - 下載匯入格式  - 出現子視窗 - 勾選下載類別
//[下載匯入格式]鈕 - 子視窗    
    function downloadBtn_click() {
        console.log("step1");
        //按鈕 : [確認] [取消]  - [借閱登記]鈕
        var sub_downloadFlds_Btns = [
            {
                xtype: 'button', text: '確定', id: 'sub_downloadFlds_OkBtn',
                listeners: {
                    click: function () {
                        //mysuccessalert("mysub2_確定 ");
                        sub_downloadFlds_OkBtn();
                    }
                }
            },            
            {
                xtype: 'button', text: '取消', id: 'sub_downloadFlds_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_downloadFlds = [
            {
                type: 'panel', bodyStyle: "background-color:transparent;", border: 0, padding: "5",                
                layout: { type: 'vbox', align: 'stretch' }, 
                //layout: 'border',
                items: [                    
                            {
                                xtype: 'radiogroup', fieldLabel: '選擇匯入格式', labelWidth: 100, layout: 'vbox',
                                id: 'sub_MAIN_SUB',
                                items: [
                                    {
                                        boxLabel: 'V20107_主檔匯入格式 ',
                                        name: 'sub_MAIN_SUB',
                                        inputValue: 'MAIN',
                                        width: 200,
                                        flex: 50,
                                        checked: true,
                                    }, {
                                        boxLabel: ' V20107_子步序匯入格式 ',
                                        name: 'sub_MAIN_SUB',
                                        inputValue: 'SUB',
                                        flex: 50,
                                        //width: 200,
                                    }, 
                                ]
                            }, //end of sub2_panel11 , flex:20                               
                ] // end of   layout: "vbox", padding: "5", items: [
            }  //end of   sub_downloadFlds , [{}
        ]      //end of  sub_downloadFlds , [        

        var win = getMyWindow("選擇要下載的匯入格式", sub_downloadFlds, sub_downloadFlds_Btns);
        win.setWidth(350);
        win.setHeight(200);
        win.show();                
    } // end of   function downloadBtn_click() {

    //下載匯入格式
    function sub_downloadFlds_OkBtn() {
        var Tmp_MAIN_SUB; 
        //radioGroup取得欄位值為 Object  需 Object.["sub_MAIN_SUB"] 才是字串
        Tmp_MAIN_SUB = Ext.getCmp('sub_MAIN_SUB').getValue();   
        console.log("Tmp_MAIN_SUB:", Tmp_MAIN_SUB);
        var Tmp_FName=""
        if (Tmp_MAIN_SUB["sub_MAIN_SUB"] == "MAIN")
        //if (Tmp_MAIN_SUB == "MAIN")
            Tmp_FName = "V20107_主檔匯入格式.xlsx"
        else 
            Tmp_FName = "V20107_子步序匯入格式.xlsx"
        console.log("Tmp_FName:", Tmp_FName);
        document.location = "../api/VUTLAPI/dnloadSS_File?FNAME="+Tmp_FName;           
    };

V120403 - TreeView 挑選員工 - getEmpTree 新方法

1>目的以 TreeView 方式挑選員工  - getEmpTree 新方法

    處理說明: 1>呼叫  getEmpTree
                           Ext.Loader.loadScript({ url: '../GUITemplate/EmployeeTree.js' });
                      2>{xtype: "button", id: "btn_MTEMPLYID", name: "btn_MTEMPLYID", text: "...",
handler: function () {
var win_tree = GetEmpTree('維修人員挑選', 'MTEMPLYID', 'MTEMPLYID_');
win_tree.show();
                                }
                              }






2>目的: 以 TreeView 方式挑選員工  - 原始方法 TreePanel

    處理說明: 1>//載入  [員工編號]  TreeView 挑選 source 

  Ext.Loader.setConfig({enabled: true,paths: { 'EmployeeTree': '../GUITemplate/EmployeeTree.js' } });

                   2>Create TreeView 物件,   Ext.create('EmployeeTree',
                        --> 不可加 id, 因為同一畫面可能多個人員挑選, 有多個同一id, 會 Error




1>*.js
//載入  [員工編號]  TreeView 挑選 source
Ext.Loader.setConfig({ enabled: true, paths: { 'EmployeeTree': '../GUITemplate/EmployeeTree.js' } });


//path : The mapping from namespaces to file paths { 'Ext': '.', // This is set by default,      Ext.layout.container.Containe...
:
{
xtype: "button", id: "s_btn_EMPLYID", name: "s_btn_EMPLYID", text: "...",
handler: function () {
                 var treepanel = Ext.create('EmployeeTree', {   
   listeners: {
itemclick: function (view, record, item, index, e) {
if (record.raw.leaf) {
var info = record.raw.text;
var newStr = info.split(":");
Ext.getCmp('CUSTODIAN').setValue(newStr[0]);
Ext.getCmp('CUSTODIAN_').setValue(newStr[1]);
win_tree.close();
}
}
}// end of listeners ); //end of treepanel
                                                        var win_tree = getWindow('保管人員挑選', treepanel);
win_tree.height = 400;
win_tree.show();
                                                     } // end of handler } // end of button ] // end of items[] },

-->
win_tree=getWindow() 的 Window.closeAction: 'hide' , 不會自動 destroy() , 需自行 destroy
Window.[關閉]鈕 , 會執行 win_tree.destroy()

2022年8月26日 星期五

V20306 - EditPick - 挑選欄位值 - 依目前畫面[交修單號]欄位值 ,來過濾挑選資料 -? - QueryString - 需即時,每次均重抓

目的:  挑選欄位值 - 依目前畫面[交修單號]欄位值 ,來過濾挑選資料 -url= xxx ?RPNOAF=xxxx

處理說明: 1>由 url  - xxxx?RPNOAF=xxxx 傳入目前的參數值
                  2>後端由 QueryString 取得傳入 url 的 ? 參數
                       string Tmp_RPNOAF = c.Request.QueryString["RPNOAF"];


1>*.js
{
xtype:"fieldcontainer",fieldLabel:"LRU件號",labelWidth:160,layout:"hbox",items:[
{id:"PN",name:"PN",xtype:"textfield",width:200,padding:"0 4 0 0",maxLength:32},
        {
id: "btn_PN", name: "btn_PN", xtype: "button", text: "...",
handler: function () {
                     var Tmp_RPNOAF = Ext.getCmp("RPNOAF").getValue();
var win = EditPickx('LRU件號', '../api/V20306API/get_F_PNPick?RPNOAF='+Tmp_RPNOAF, ['PN'], ['PN'], J_pickstore_F_PN, J_pickcolumns_F_PN);
win.show();
} }

2>*.cs  - c#
//過濾條件 [LRUPN]挑選
//url =  ?RPNOAF=xxxxx    --> 可由傳入的參數  or   Request.QueryString 取得
        [HttpPost]
        public dynamic get_F_PNPick(string RPNOAF="", string PN = "",int isComplete = 0)
        {
            var c = HttpContext.Current;
            NameValueCollection nvc = c.Request.Form;
            //string Tmp_RPNOAF = nvc["RPNOAF"];
            string Tmp_RPNOAF = c.Request.QueryString["RPNOAF"];
            Tmp_RPNOAF=RPNOAF;  //也可 


            string Tmp_Sql = " SELECT DISTINCT PN  "
                                       + "  FROM   AMM_FM  "
                                       + "  WHERE 1 = 1  "
                                       + "  AND PN IS NOT NULL  ";
            if (!myfunc.checkisnull(Tmp_RPNOAF))
                Tmp_Sql = Tmp_Sql + "    AND   RPNOAF = " + myfunc.AA(Tmp_RPNOAF);
            string n = funId + "F_PN";   //同一欄位的挑選, 但畫面挑選的n命名需和過濾條件不同
//即時抓SQL , 每次均重取, 不由現有的緩衝資料取行
//public DataSet setupPickDs(string pickKey, string sql, string[] tables, bool paging = true, bool realTime = false)
            DataSet ds = setupPickDs(n, Tmp_Sql, new string[] { "AMM_FM" },true,true);
            if (PN != null && !PN.Equals(""))
            {
                if (isComplete == 1)
                {
                    ds = getPickDsbyCondi(n, "PN='" + PN + "'");
                }
                else
                {
                    ds = getPickDsbyCondi(n, "PN  LIKE '%" + PN + "%'");
                }
            }
            return ds;
        }  // end of  get_F_PNPick

V20306 - EditPick - 挑選欄位 - 傳回多欄位值 - V80403維修人員

 目的: EditPick 挑選欄位值 - 傳回多欄位值

處理說明: 1> EditPick  , Fields 定義, Columns 定義
                  2>傳回多欄位值 , 以逗號分隔


1>*.js  Fields 定義, Columns 定義

{

id: "btn_LRWET", name: "btn_LRWET", xtype: "button", text: "...",
handler: function () {
//EditPick 傳回多欄位值 , 以逗號分隔
var win = EditPickx('系統件重量', '../api/V20306API/get_F_LRWETPick',
['LRWET','DESCPT'], ['LRWET','LRWET_'],
J_pickstore_F_LRWET, J_pickcolumns_F_LRWET);


win.show();
}
}

2>*.cs - 更改欄位名稱 as 前端欄位名稱 

//編輯畫面. [系統件重量]挑選
        [HttpPost]
        public dynamic get_F_LRWETPick(string LRWET = "", int isComplete = 0)
        {
            string Tmp_Sql = " SELECT  KEY_CODE as LRWET, DESCPT   "
                                       + "  FROM    KEYCODE "
                                       + "  WHERE   TBL_NAME=" + myfunc.AA("AMM_ASP")
                                       + "   AND         KEY_NAME=" + myfunc.AA("LRWET")
                                       + " ORDER  BY  KEY_CODE  ";
            string n = funId + "F_LRWET";
            DataSet ds = setupPickDs(n, Tmp_Sql, new string[] { "KEYCODE" });
            if (LRWET != null && !LRWET.Equals(""))
            {
                if (isComplete == 1)
                {
                    ds = getPickDsbyCondi(n, "LRWET='" + LRWET + "'");
                }
                else
                {
                    ds = getPickDsbyCondi(n, "LRWET  LIKE '%" + LRWET + "%'");
                }
            }
            return ds;
        }  // end of  get_F_LRWETPick


3>V80403 - 維修人員

3.1>>

//管制(生管)人員
    var cmp_CREMPLYID = get_cmp_txt1('管制(生管)人員', 's_CREMPLYID', 100, 60);
    var cmp_CREMPLYIDNM = get_cmp_txt0( 's_CREMPLYIDNM', 60);
    var cmp_pick_CREMPLYID = get_pick_btn0('挑選管制(生管)人員', 's_btn_CREMPLYID',
        '../api/V80403API/get_s_CREMPLYIDPick',
        ['CREMPLYID', 'EMPLYNM'], ['s_CREMPLYID', 's_CREMPLYIDNM'], J_pickstore_s_CREMPLYID, J_pickcolumns_s_CREMPLYID);
    cmp_CREMPLYID.items.push(cmp_CREMPLYIDNM,cmp_pick_CREMPLYID);
    //維修人員
    var cmp_MTEMPLYID = get_cmp_txt1('維修人員', 's_MTEMPLYID', 100, 60);
    var cmp_MTEMPLYIDNM = get_cmp_txt0('s_MTEMPLYIDNM', 60);
    var cmp_pick_MTEMPLYID = get_pick_btn0('挑選維修人員', 's_btn_MTEMPLYID',
        '../api/V80403API/get_s_MTEMPLYIDPick',
        ['MTEMPLYID', 'EMPLYNM'], ['s_MTEMPLYID','s_MTEMPLYIDNM'], J_pickstore_s_MTEMPLYID, J_pickcolumns_s_MTEMPLYID);
    cmp_MTEMPLYID.items.push(cmp_MTEMPLYIDNM,cmp_pick_MTEMPLYID);


2022年8月25日 星期四

V20306 - 套表列印 - 依勾選的資料匯出 - 將目前所選的資料,當成 np參數 , 傳至後端 - SS_FILES

 目的: 畫面的欄位值,直接匯出至套表, 不分頁

處理說明: 1>讀取套表檔案 SS_FILES

                  2>讀取 store 資料匯出至 XLS



1>*.js , 依所勾選的資料匯出轉成 JSONString 當參數, 傳至後端
//查詢  - 將目前所選的資料,匯出成報表
    function LookBtn_click() {
        var Tmp_Grid = Ext.getCmp('grid_Single');
        var cur_recs,cur_rec;
        var Tmp_SAPNO, Tmp_PN, Tmp_QTY, Tmp_EOCND, Tmp_RMK;
        var Tmp_data_JSON = "";  //將store資料轉成 JSON 的字串
        var Tmp_sub_np = {};
        let Tmp_DataAry1 = [];
        var Tmp_Str = "";
        cur_recs = Tmp_Grid.getView().selModel.getSelection();
        console.log("cur_recs:", cur_recs);
        if (cur_recs.length == 0) {
            mywarnalert("請先選擇要查詢的資料");
            return;
        }
        for (var i = 0; i < cur_recs.length; i++) {
            cur_rec = cur_recs[i];
            console.log(Tmp_Str + "cur_rec:", cur_rec);
            Tmp_DataAry1.push(cur_rec.data);
        }

        console.log("Tmp_DataAry1:", Tmp_DataAry1);
        // 將目前子畫面的資料(Table)轉成 JSON字串
        let Tmp_DataString1 = JSON.stringify(Tmp_DataAry1);
        console.log("Tmp_DataString1:", Tmp_DataString1);        
        var np = {};
        np = {
            DataString1: Tmp_DataString1,            
        };
        //Ext.Ajax.request   --> 傳送檔案至前端,不可使用 Ext.Ajax, 必需使用 Form.submit
        Ext.getCmp('s_form').submit({
            url: '../../api/V20306API/DoPRNLIST',
            method: 'POST',
            async: false,
            standardSubmit: true, //若要傳送檔案至前端, 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');
            console.log("r_cookies=", r);
            if (!checkisnull(r)) {
                mysuccessalert(r);
            }
        }, 5000);  //3000ms = 3sec
    }  // end of  function LookBtn_click() {





2>*.cs - 依傳入的資料參數, 匯出至 XLS

//加入JSON格式轉換參考 , JsonConvert 必需使用如下  library
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

//查詢 - 將所選的資料匯出至 xls - 套表
[HttpPost]

public void DoPRNLIST()
        {
            var c = HttpContext.Current;
            NameValueCollection nvc = c.Request.Form;
            // 1>將 SS_FILES.FBOLD 存成 Local檔案
            //取得目前子畫面的欄位值
string Tmp_DataString1 = nvc["DataString1"];  //取得目前子畫面的資料. JSON字串   
            //將 table 字串轉成 DataTable
            //DataTable DataTable1 = (DataTable)JsonConvert.DeserializeObject(Tmp_DataString1, (typeof(DataTable)));
            DataTable DataTable1 = myfunc.JSON2dt(Tmp_DataString1);
            
            OracleConnection conn = new OracleConnection(DBService.ConnectionString(DBLINK));//
            OracleCommand cmd = new OracleCommand();
            //OracleDataAdapter adp = new OracleDataAdapter();
            //DataSet ds = new DataSet();
            //var response = 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_Str1 = "";
            string Tmp_RtnMsg;
            string Tmp_FName = "V20306_列印報表.xlsx";      //套表的檔案名稱 , 
            string documentPath = HttpContext.Current.Server.MapPath("~") + "document\\";  // 取得實實的路徑            
            string pathFName = documentPath + Tmp_FName;
            //需要擷取大量資料時,DataReader 是很好的選擇,因為資料不會快取至記憶體。
            OracleDataReader reader;
            Workbook wk = null;
            MemoryStream mstream = new MemoryStream();
            string FileName = "V20306_列印報表_" + DateTime.Now.ToString("yyyyMMdd") + ".xlsx";
            string FileName1 = documentPath + FileName;
            try
            {
                wk = new Workbook();
                //1>將  SS_FILES. FBODY , 存至Local目錄.檔案                 
                if (File.Exists(pathFName))
                {
                    File.Delete(pathFName);
                }
                Tmp_Sql = " SELECT  FNAME,FBODY "
                                + " FROM     SS_FILES   "
                                + "   WHERE   1 = 1  "
                                + "  AND         FNAME = " + myfunc.AA(Tmp_FName);
                cmd.CommandText = Tmp_Sql;
                reader = cmd.ExecuteReader();
                byte[] file = null;
                //FileMode.OpenOrCreate: 開啟檔案若無檔案則新增
                //FileAccess.ReadWrite: 允許檔案讀取/寫入
                FileStream fs = File.Open(pathFName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                BinaryWriter bw = new BinaryWriter(fs);
                if (reader.HasRows)
                {
                    if (reader.Read())
                    {
                        file = (byte[])reader["FBODY"];
                        //fs.Write(file,0,50000);
                        bw.Write(file);
                        wk.LoadFromStream(fs);
                        bw.Close();
                        fs.Close();
                    }
                }
                //2 > 主機.Local檔案 XLS 讀入  FStream
                Worksheet ws = wk.Worksheets[0];//獲取第一個工作表
                //寫入[SAPNO][PN][QTY][EOCND][RMK]
                string Tmp_ASPNO, Tmp_RPNOAF, Tmp_LCNO, Tmp_LRWET_;
                string Tmp_MCNM, Tmp_ORDID_, Tmp_PCTP, Tmp_FICNMA, Tmp_STLCT;
                string Tmp_PCQTY,Tmp_ASLV,Tmp_ASPRMK,Tmp_NGONOAF,Tmp_PN;
                string Tmp_LCITM, Tmp_LCETDT, Tmp_LCCHID_, Tmp_LCORAO, Tmp_LRULT;
                string Tmp_LRUWT, Tmp_LRUHG,Tmp_WTLV,Tmp_ITPR;                
                //每筆資料列印後, 不分頁列印下一筆
                for (var i = 0; i < DataTable1.Rows.Count; i++)
                {
                    Tmp_ASPNO = DataTable1.Rows[i]["ASPNO"].ToString();
                    Tmp_RPNOAF = DataTable1.Rows[i]["RPNOAF"].ToString();
                    Tmp_LCNO = DataTable1.Rows[i]["LCNO"].ToString();
                    //直接取得畫面.CaluField欄位值        
                    Tmp_LRWET_ = DataTable1.Rows[i]["LRWET_"].ToString();//系統件重量說明

                    Tmp_ORDID_ = DataTable1.Rows[i]["ORDID_"].ToString();  //訂購者姓名
                    Tmp_MCNM = DataTable1.Rows[i]["MCNM"].ToString();
                    Tmp_PCTP = DataTable1.Rows[i]["PCTP"].ToString();
                    Tmp_FICNMA = DataTable1.Rows[i]["FICNMA"].ToString();
                    Tmp_STLCT = DataTable1.Rows[i]["STLCT"].ToString();
                    Tmp_PCQTY = DataTable1.Rows[i]["PCQTY"].ToString();
                    Tmp_ASLV = DataTable1.Rows[i]["ASLV"].ToString();
                    Tmp_ASPRMK = DataTable1.Rows[i]["ASPRMK"].ToString();
                    Tmp_NGONOAF = DataTable1.Rows[i]["NGONOAF"].ToString();
                    Tmp_PN = DataTable1.Rows[i]["PN"].ToString();
                    Tmp_LCITM = DataTable1.Rows[i]["LCITM"].ToString();
                    Tmp_LCETDT = DataTable1.Rows[i]["LCETDT"].ToString();
                    Tmp_LCCHID_ = DataTable1.Rows[i]["LCCHID_"].ToString();
                    Tmp_LCORAO = DataTable1.Rows[i]["LCORAO"].ToString();
                    Tmp_LRULT = DataTable1.Rows[i]["LRULT"].ToString();
                    Tmp_LRUWT = DataTable1.Rows[i]["LRUWT"].ToString();
                    Tmp_LRUHG = DataTable1.Rows[i]["LRUHG"].ToString();
                    Tmp_WTLV = DataTable1.Rows[i]["WTLV"].ToString();
                    Tmp_ITPR = DataTable1.Rows[i]["ITPR"].ToString();
                    //GetExcelPos(欄, 行) 以 0 開始, 
                    ws.Range[myfunc.GetExcelPos(0, i+1)].Text = Tmp_ASPNO;
                    ws.Range[myfunc.GetExcelPos(1, i+1)].Text = Tmp_RPNOAF;
                    ws.Range[myfunc.GetExcelPos(2, i + 1)].Text = Tmp_LCNO;
                    ws.Range[myfunc.GetExcelPos(3, i + 1)].Text = Tmp_LRWET_;                    
                    ws.Range[myfunc.GetExcelPos(4, i + 1)].Text = Tmp_MCNM;
                    ws.Range[myfunc.GetExcelPos(5, i + 1)].Text = Tmp_ORDID_;
                    ws.Range[myfunc.GetExcelPos(6, i + 1)].Text = Tmp_PCTP;
                    ws.Range[myfunc.GetExcelPos(7, i + 1)].Text = Tmp_FICNMA;
                    ws.Range[myfunc.GetExcelPos(8, i + 1)].Text = Tmp_STLCT;
                    ws.Range[myfunc.GetExcelPos(9, i + 1)].Text = Tmp_PCQTY;
                    ws.Range[myfunc.GetExcelPos(10, i + 1)].Text = Tmp_ASLV;
                    ws.Range[myfunc.GetExcelPos(11, i + 1)].Text = Tmp_ASPRMK;
                    ws.Range[myfunc.GetExcelPos(12, i + 1)].Text = Tmp_NGONOAF;
                    ws.Range[myfunc.GetExcelPos(13, i + 1)].Text = Tmp_PN;
                    ws.Range[myfunc.GetExcelPos(14, i + 1)].Text = Tmp_LCITM;
                    ws.Range[myfunc.GetExcelPos(15, i + 1)].Text = Tmp_LCETDT;
                    ws.Range[myfunc.GetExcelPos(16, i + 1)].Text = Tmp_LCCHID_;
                    ws.Range[myfunc.GetExcelPos(17, i + 1)].Text = Tmp_LCORAO;
                    ws.Range[myfunc.GetExcelPos(18, i + 1)].Text = Tmp_LRULT;
                    ws.Range[myfunc.GetExcelPos(19, i + 1)].Text = Tmp_LRUWT;
                    ws.Range[myfunc.GetExcelPos(20, i + 1)].Text = Tmp_LRUHG;
                    ws.Range[myfunc.GetExcelPos(21, i + 1)].Text = Tmp_WTLV;
                    ws.Range[myfunc.GetExcelPos(22, i + 1)].Text = Tmp_ITPR;
                }
                
                wk.SaveToStream(mstream, FileFormat.Version2007);
                wk.SaveToFile(FileName1, FileFormat.Version2007);
                //wk.SaveToStream(mstream, FileFormat.Version2013);
                //wk.SaveToFile(FileName1, FileFormat.Version2013);                
            }
            catch (Exception e)
            {
                var Tmp_ErrMsg = e.Message;
            }
            finally
            {                
                wk.Dispose();
                conn.Close();
            }
            HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=\"" + HttpUtility.UrlEncode((string)FileName, System.Text.Encoding.UTF8) + "\"");
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
            HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            HttpContext.Current.Response.BinaryWrite(mstream.ToArray());
            //包裝標籤檔產生完成
            Tmp_Str = "產生包裝匯出檔案成功<br>"
                            + "(" + FileName + ")<br>";
            HttpCookie MyCookie = new HttpCookie("EX_DFile", HttpUtility.UrlEncode(Tmp_Str));
            HttpContext.Current.Response.Cookies.Add(MyCookie);
            HttpContext.Current.Response.End();
        }  // end of public void DoPRNLIST()

2022年8月24日 星期三

FreeSPIRE.XLS 元件安裝 - XLS 開啟,使用

 目的:  安裝SPIRE.XLS元件 - XLS開啟使用

處理說明: 利用 SPIRE.XLS元件開啟使用 XLS檔案




2>安裝  FreeSpire.XLS 元件



3>安裝 FreeSpire.XLS 元件