2023年5月12日 星期五

V20302A - 取得 TreePanel 所選的 nodes資料 , node.raw

 目的:V20302A - 取得 TreePanel 所選的 nodes資料

處理說明: 1>treepanel的 node 屬性  {id:611292 , leaf: true, text :"611292:蔡聰進"}
                  2>treepanel的 選擇 nodes , 
                      var nodes=treepanel.getSelectionModel().getSelection();
                      var node=nodes[0];
                      node.raw.id
                      node.raw.text
                      node.raw.leaf



1>*.js
   1>>[右移]鈕
         var nodes = treepanel.getSelectionModel().getSelection();
         var node = nodes[0];
         if (checkisnull(node))
              return;
         console.log("node:", node);
         console.log("node.raw:", node.raw);
         var Tmp_Emplyid, Tmp_EmplyNM, Tmp_Notes_EMAIL;
          if (node.raw.leaf) {
               Tmp_Emplyid = node.raw.id;
               Tmp_EmplyNM = StrExtract(node.raw.text, 2, ":");
               console.log("姓名:", Tmp_EmplyNM);
                var Tmp_Email = getEmp_Email(Tmp_Emplyid);
                console.log("Email:", Tmp_Email);
                var Tmp_rec = { EMPLYNM: Tmp_EmplyNM, NOTES_MAIL: Tmp_Email };
                Ext.getCmp("sub_Grid1").store.add(Tmp_rec);
         }

2>>[左移]鈕:
      var nodes = Ext.getCmp("sub_Grid1").getSelectionModel().getSelection();                                               
                                                if (nodes.length == 0) {                                                    
                                                        mywarnalert("請先選擇要左移的資料");                                                        
                                                    return;
                                                }
                                                var node = nodes[0];                                                
                                                Ext.getCmp("sub_Grid1").store.remove(node);

2023年5月11日 星期四

V20302A - 畫面版面設計 , layout , vbox, hbox

 目的: V20302A - 畫面版面設計 , layout , vbox, hbox

處理說明: 1>layout: { type: "vbox", align: 'stretch' }
                       flex: 設定垂直的比例, 若沒設align: stretch,則items必需設width
                  2>layout: { type: "hbox", align: 'stretch' }
                      flex: 設定水平的比例,若沒設align: stretch,則items必需設height




1>*.js
 //[顯示Email]  - 子畫面欄位
    var sub_ShowEmail_Flds = [
        {
            xtype:'panel',bodyStyle: "background-color:transparent;", border: false, 
            layout: {  type: "vbox",  align: 'stretch' }, padding: "5",
            id: 'sub_myForm', items: [
                {
                    xtype: "fieldcontainer", fieldLabel: "主旨", labelWidth: 60, layout: "fit", flex: 1, items: [
                        {
                            xtype: "textfield", id: "sub_Subjext", name: "sub_Subject",  padding: "0 4 0 0",
                            //value: "AJT",
                        },
                    ]
                },  //end of 主旨
                {
                    xtype: "fieldcontainer", fieldLabel: "內容", labelWidth: 60, layout: "fit", flex: 4, items: [
                        {
                            id: "sub_content", name: "sub_content", xtype: "textfield",  padding: "0 4 0 0",
                            //value: "AJT",
                        },
                    ]
                }, // end of 內容
                {  //下方 TreeView, 左右移,正本/副本
                    xtype: "panel", flex: 5,
                    layout: {type: 'hbox', align: 'stretch' },
                    items: [
                        { // TreeView
                            xtype: "panel", flex: 4, layout: 'fit',                            
                            autoScroll: true, items: [treepanel]
                        },  //TreeView
                        {  //正本&副本.[左移/右移]按鈕
                            xtype: "panel", flex: 2, layout: { type: 'vbox', align: 'stretch' }, border: false,
                            //bodyStyle: 'background:blue; ',
                            items: [
                                {  //  正本.左右移的 Button
                                    xtype: 'panel', id: 'panel_btns1', layout: { type: 'vbox', align: 'stretch' }, flex: 1, border: false,
                                    //bodyStyle: 'background:yellow; ',                                    
                                    items: [                                        
                                        {//space panel
                                            xtype: 'panel',    flex: 1,                                            
                                        },// end of 
                                        {//正本.往右移
                                            xtype: 'button',
                                            id: 'btn_move11',
                                            text: '1往右',
                                            iconCls: 'icon-right',
                                            flex: 1,
                                            handler: function () {
                                            }
                                        },// end of 往右移                                        
                                        {//正本.往左移
                                            xtype: 'button',
                                            id: 'btn_move12',
                                            text: '1往左',
                                            iconCls: 'icon-left',
                                            flex: 1,
                                            handler: function () {
                                            }
                                        },//往左移
                                        {//space panel
                                            xtype: 'panel',flex: 1,
                                        },// end of 
                                    ]
                                }, //panel_btn1
                                {  //  副本.左右移的 Button
                                    xtype: 'panel', id: 'panel_btns2', layout: { type: 'vbox', align: 'stretch' }, flex: 1, border: false,                                    
                                    //bodyStyle: 'background:red; ',
                                    items: [
                                    {//space panel                                    
                                    xtype: 'panel', flex: 1,                                },// end of 
                                        {//副本.往右移
                                            xtype: 'button',
                                            id: 'btn_move21',
                                            text: '2往右',
                                            iconCls: 'icon-right',
                                            flex: 1,
                                            handler: function () {
                                            }
                                        },// end of 往右移
                                        //{ xtype: 'panel', flex: 1, },// end of  虛 space
                                        {//副本.往左移
                                            xtype: 'button',
                                            id: 'btn_move22',
                                            text: '2往左',
                                            iconCls: 'icon-left',
                                            flex: 1,
                                            handler: function () {
                                            }
                                        },//往左移
                                        {//space panel
                                            xtype: 'panel', flex: 1,
                                        },// end of 
                                    ]
                                }, //panel_btn2                                                        
                            ]
                        },  //按鈕
                        {  //正本,副本人員
                            xtype: "panel", flex: 4,                            
                            layout: { type: 'vbox', align: 'stretch' },                            
                            items: [
                                {
                                    xtype: "panel", flex: 1, title: '正本人員', layout: 'fit',                                  
                                     bodyStyle: 'background:yellow; ', 
                                },
                                {
                                    xtype: "panel", flex: 1, title: '副本人員', layout: 'fit',                                                                       
                                    bodyStyle: 'background:blue; ',
                                },
                            ],                            
                        },  //正本副本
                    ]
                }, // end of TreeView                
            ]  //end of sub_myForm
        }]  //end of sub_ShowPN_Flds
        
    console.log(" ShowEmail  step4");   

    var win = getMyWindow("挑選 Email 人員", sub_ShowEmail_Flds, sub_ShowEmail_Btns);


2023年5月9日 星期二

V20302A - TextField 充滿範圍 (多行) -

 目的: V20302A - TextField 充滿範圍 (多行) -

處理說明: 1>{
                    xtype: "fieldcontainer", fieldLabel: "主旨", labelWidth: 80, layout: "fit", flex: 1, items: [
                        {
                            id: "sub_Subjext", name: "sub_Subject", xtype: "textfield",  padding: "0 4 0 0",
                        },
                    ]
                },  //end of 主旨



1>*.js
   {
     bodyStyle: "background-color:transparent;", border: false, layout: { type: "vbox", align: 'stretch' }, padding: "5",
            id: 'sub_myForm', items: [
                {
                    xtype: "fieldcontainer", fieldLabel: "主旨", labelWidth: 80, layout: "fit", flex: 1, items: [
                        {
                            id: "sub_Subjext", name: "sub_Subject", xtype: "textfield",  padding: "0 4 0 0",
                            //value: "AJT",
                        },
                    ]
                },  //end of 主旨
                {
                    xtype: "fieldcontainer", fieldLabel: "內容", labelWidth: 80, layout: "fit", flex: 4, items: [
                        {
                            id: "sub_content", name: "sub_content", xtype: "textfield",  padding: "0 4 0 0",
                            //value: "AJT",
                        },
                    ]
                }, // end of 內容


V20302A - TreeView挑選Email人員, Scrollbar 無法動作

目的: V20302A - TreeView挑選Email人員, Scrollbar 無法動作 

處理說明: 1>上層Panel必須設定 ScrollBar: true
           2>  width: 400, height: 300 必需設定數值,才會有ScrollBar
                3> TreePanel.layout 不可設為 fit, 設為 vbox
                    { // TreeView
                            xtype: "panel", flex: 4, layout: { type: 'vbox', align: 'stretch' },                            
                            autoScroll: true, items: [treepanel1]
                        },  //TreeView



JSFiddle : javascript 的線上測試平台 - 如何 include ext

 目的: JSFiddle : javascript 的線上測試平台 - 如何 include ext



2023年5月4日 星期四

V20302 - 下載文字檔案至前端

 目的:  V20302 - 下載文字檔案至前端

處理說明: 1>    必需用 form.submit , 不可用 Ext.Ajax
                  2>    standardSubmit: true, 必用設為 true



1>1>*.js 

//  //[確認除帳]鈕 -
    function DoRemoveBtn_click() {
        var cur_recs = Ext.getCmp('grid_Single').getSelectionModel().getSelection();
        if (cur_recs.length == 0) {
            mywarnalert("請先選擇要編輯的資料");
            return false;
        }
        var cur_rec;
        let Tmp_DataAry1 = [];
        var Tmp_RPNOAF;
        var Tmp_Str="";
        console.log("cur_recs.length:", cur_recs.length);        
        //判斷約別, 不可空白, 若有空白,則顯示訊息,不再往下
        for (let i = 0; i <= cur_recs.length - 1; i++) {
            console.log("i:", i);
            cur_rec = cur_recs[i];
            if (checkisnull(cur_rec.data["TYPEAF"])) {
                Tmp_Str = Tmp_Str + "系統件單號(" + cur_rec.data["FMNO"] + ")的約別不可空白<br>";
            }
        }  // for i=0 to 
        if (Tmp_Str.length > 0) {
            Tmp_Str = Tmp_Str 
                           + "請檢核  !!<br>";
            mywarnalert(Tmp_Str);
            return;
        }

        //判斷約別是否一致  &  執行結果是否有錯誤, 若有,則存成 *_log.txt 傳至前端
        //若有成功除帳的資料,則發  Email 通知使用者
        for (let i = 0; i <= cur_recs.length - 1; i++) {
            console.log("i:", i);
            cur_rec = cur_recs[i];
            Tmp_DataAry1.push(cur_rec.data);
        }  // for i=0 to 
        let Tmp_DataString1 = JSON.stringify(Tmp_DataAry1);
            var np = {};
        np["DataString1"] = Tmp_DataString1;            
            var isOk = true; 
         ///若下載檔案至前端, 則不可用 Ext.Ajax
        //Ext.Ajax.request({
            Ext.getCmp('s_form').submit({
                method: "POST",
                url: '../../api/V20302API/DoRemove',
                standardSubmit: true,      
                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_RtnMsg = "系統件除帳,錯誤訊息如下: <br>"
                            + Tmp_Obj["Rtn_Msg"];
                        mywarnalert(Tmp_RtnMsg);
                        isOk = false;
                    }
                    else {
                        Tmp_Str = "系統件除帳 OK <br>";                            
                        mywarnalert(Tmp_Str);
                    };

                    
                    
                },  //end of success                
                failure: function (response, opts) {
                    var Tmp_Obj = Ext.decode(response.responseText);
                    var Tmp_Rtn_Msg = "系統件除帳,錯誤訊息如下: <br>"
                        + Tmp_Obj["Rtn_Msg"];                        
                    mywarnalert(Tmp_Rtn_Msg);
                    isOk = false;
                }            
            })  //end of Ext.Ajax.Request
         };  // end of    function ConfirmRemoveBtn_click() {
2>
2>2>*.cs
pupublic void DoRemove()
        {
            var c = HttpContext.Current;
            NameValueCollection nvc = c.Request.Form;
            OracleConnection conn = new OracleConnection(DBService.ConnectionString(DBLINK));//
            OracleCommand cmd = new OracleCommand();
            OracleDataReader reader;
            var response = Request.CreateResponse();

            conn.Open();
            string Tmp_RtnMsg;
            try
            { 
            conn.ClientInfo = User.Identity.Name;
            conn.ModuleName = BaseSYS + "_" + BaseMODID;
            conn.ActionName = ActionName;
            cmd.Connection = conn;
            string Tmp_Sql = "";
            
            string Tmp_out_FName = "V20306_系統件除帳_log.txt";      //處理_log.txt
          string documentPath=HttpContext.Current.Server.MapPath("~") +"document\\"; //取得實實的路徑            
            string Tmp_out_pFName = documentPath + Tmp_out_FName;    //含 path 的Filename
            if (File.Exists(Tmp_out_pFName))
            {
                File.Delete(Tmp_out_pFName);
            }

            //將 table 字串轉成 DataTable
            //DataTable DataTable1 = (DataTable)JsonConvert.DeserializeObject(Tmp_DataString1, (typeof(DataTable)));
            string Tmp_DataString1 = nvc["DataString1"];    //Tmp_DataString:  將目前子畫面的資料. JSON字串                           
            DataTable dt1 = myfunc.JSON2dt(Tmp_DataString1);
                //每筆資料列印後, 不分頁列印下一筆            
                string Tmp_FMNO;
            string Tmp_Str, Tmp_RPNOAF, Tmp_CSM_TYPEAF, Tmp_FM_TYPEAF;
            //using (StreamWriter sw = new StreamWriter(Tmp_out_pFName))   //小寫TXT  
            //不用 sw, 改用File.AppendText(Tmp_out_pFName,Tmp_Str)  
            {
                for (var i = 0; i < dt1.Rows.Count; i++)
                {
                    Tmp_FMNO = dt1.Rows[i]["FMNO"].ToString();
            Tmp_Sql = " SELECT   A.RPNOAF,A.TYPEAF as CSM_TYPEAF,B.TYPEAF as FM_TYPEAF  "
                                    + "  FROM     CSM_AF@TLS_245 A, AMM_FM B   "
                                    + "   WHERE  A.RPNOAF = nvl(B.MRPNOAF, B.RPNOAF)  "
                                    + "   AND        B.FMNO = " + myfunc.AA(Tmp_FMNO);
                    Tmp_Str = myfunc.SqlValue(Tmp_Sql);
                    Tmp_RPNOAF = myfunc.StrExtract(Tmp_Str, 1);
                    Tmp_CSM_TYPEAF = myfunc.StrExtract(Tmp_Str, 2);
                    Tmp_FM_TYPEAF = myfunc.StrExtract(Tmp_Str, 3);
                    if (Tmp_CSM_TYPEAF != Tmp_FM_TYPEAF)
                    {
                        Tmp_Str = "交修單號(" + Tmp_RPNOAF + ")"
                                       + " AMM約別(" + Tmp_FM_TYPEAF + ") "
                                       + "和 TLS的約別(" + Tmp_CSM_TYPEAF + ") 不同 ,"
                                       + "敬請檢核!!<br>";
//                      //sw.WriteLine(Tmp_Str);
                        File.AppendAllText(Tmp_out_pFName, Tmp_Str);  //不用 sw , 改用 File.AppendAllText
                    }
                }//   for (var i = 0; i < dt1.Rows.Count; i++)
                // sw.Close才會實際寫入檔案(Tmp_out_pFName)
//              //sw.Close();
                    
                    //讀取檔案的文字內容 , 若內容>0 ,郥 success : false , 傳回檔案內容
                    //string Tmp_FStr = File.ReadAllText(Tmp_out_pFName);
                    //if  (Tmp_FStr.Length>0)
                    //{
                    //    Tmp_RtnMsg = "[確認除帳]失敗 !!  <br>"
                    //                     + Tmp_FStr;
                    //    response.Content = new StringContent("{success: false,Rtn_Msg:" + Tmp_RtnMsg+ "}");    // 回應內容
                    //}
                    //else
                    //    response.Content = new StringContent("{success: true,Rtn_Msg:約別正確}");    // 回應內容
                    //return response;
                    

                    ////FileInfo fileInfo = new FileInfo(Tmp_out_pFName);                    
                    HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=\"" + HttpUtility.UrlEncode((string)Tmp_out_FName, System.Text.Encoding.UTF8) + "\"");
                    HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
                    HttpContext.Current.Response.ContentType = "text/plain";                  
                    ////HttpContext.Current.Response.BinaryWrite(ms.ToArray());
                    HttpContext.Current.Response.WriteFile(Tmp_out_pFName);
                    //////包裝標籤檔產生完成
                    ////Tmp_Str = "產生包裝匯出檔案成功<br>"
                    ////                + "(" + FileName + ")<br>";
                    ////MyCookie = new HttpCookie("EX_DFile", HttpUtility.UrlEncode(Tmp_Str));
                    ////HttpContext.Current.Response.Cookies.Add(MyCookie);
                    HttpContext.Current.Response.End();                
            };// using 
        }  // end of try
            catch (Exception e)
            {
                string Tmp_msg;
                Tmp_msg = myfunc.Get1ORA(e.Message);
                Tmp_RtnMsg = "[確認除帳]失敗 !!  <br>"
                                         + Tmp_msg;
                //response.Content = new StringContent("{'success': false,'Rtn_Msg':'" + Tmp_RtnMsg + "'}");    // 回應內容
                //return response;
            }
            finally
            {
              conn.Close();
            }
        } // end of DoRemove


1


2023年5月3日 星期三

V20302 檔案處理 , 開啟檔案,寫入文字,讀取文字 - 存成 *_log.TXT , 並傳送至前端

 目的: V20302 將文字存入 *_log.TXT , 並傳送至前端

處理說明: 0>傳送檔案至前端 
                      1>>必需用 form.submit , 不可用 Ext.Ajax
                      2>>standardSubmit=true
                      3>>必需用主畫面 Ext.getCmp("s_form").submit
                             不可用子畫面 me.up("form").submit() 
                             也不可用子畫面 Ext.getCmp("mySubForm").submit()
                              --> 因為執行 submit 時,本子畫面已被 destroy() 
                                       this.up("window").close();
                                       this.up("window").destroy();
                  1>判斷檔案是否存在,若已存在,則刪除檔案
                       if (File.Exists(Tmp_out_pFName))
                       {   File.Delete(Tmp_out_pFName);  }

                  2>如何將文字存入 //換行
                       string  Tmp_Str = "Hello text" + "\r\n";
                       File.WriteAllText("myfilename.txt", Tmp_Str);
                       File.AppendAllText("myfilename.txt", Tmp_Str);

                  3>讀取檔案的文字
                      string  Tmp_Str = File.ReadAllText("myfilename.txt");

                   4>複製檔案
                       File.Copy("myname.txt", "myname2.txt");





1>*.js
  var cur_recs = Ext.getCmp('grid_Single').getSelectionModel().getSelection();
 for (let i = 0; i <= cur_recs.length - 1; i++) {
            console.log("i:", i);
            cur_rec = cur_recs[i];
            Tmp_DataAry1.push(cur_rec.data);
 }  // for i=0 to 
        let Tmp_DataString1 = JSON.stringify(Tmp_DataAry1);
            var np = {};
        np["DataString1"] = Tmp_DataString1;      
   //me.up("form").submit({      
   Ext.getCmp('s_form').submit({
                method: "POST",
                url: '../../api/V20302API/DoRemove',
                standardSubmit: true,      
                params: np,
                async: false,
            })  //end of form.submit


2>*.cs
//開啟檔案
string Tmp_out_FName = "V20306_系統件除帳_log.txt";      //處理_log.txt
string documentPath = HttpContext.Current.Server.MapPath("~") + "document\\";  // 取得實實的路徑  string Tmp_out_pFName = documentPath + Tmp_out_FName;    //含 path 的Filename
            if (File.Exists(Tmp_out_pFName))
            {
                File.Delete(Tmp_out_pFName);
            }

//using (StreamWriter sw = new StreamWriter(Tmp_out_pFName))   //小寫TXT     
//{            
  for (var i = 0; i < dt1.Rows.Count; i++)
 {
     Tmp_FMNO = dt1.Rows[i]["FMNO"].ToString();
      Tmp_Sql = " SELECT   A.RPNOAF,A.TYPEAF as CSM_TYPEAF,B.TYPEAF as FM_TYPEAF  "
                      + "  FROM     CSM_AF@TLS_245 A, AMM_FM B   "
                      + "   WHERE  A.RPNOAF = nvl(B.MRPNOAF, B.RPNOAF)  "
                      + "   AND        B.FMNO = " + myfunc.AA(Tmp_FMNO);
                    Tmp_Str = myfunc.SqlValue(Tmp_Sql);
                    Tmp_RPNOAF = myfunc.StrExtract(Tmp_Str, 1);
                    Tmp_CSM_TYPEAF = myfunc.StrExtract(Tmp_Str, 2);
                    Tmp_FM_TYPEAF = myfunc.StrExtract(Tmp_Str, 3);
                    if (Tmp_CSM_TYPEAF != Tmp_FM_TYPEAF)
                    {
                        Tmp_Str = "交修單號(" + Tmp_RPNOAF + ")"
                                       + " AMM約別(" + Tmp_FM_TYPEAF + ") "
                                       + "和 TLS的約別(" + Tmp_CSM_TYPEAF + ") 不同 ,"
                                       + "敬請檢核!!<br>"+"\r\n";
                        //File.WriteAllText(Tmp_out_pFName, Tmp_Str);
                        File.AppendAllText(Tmp_out_pFName, Tmp_Str);
                        Tmp_Str =File.ReadAllText(Tmp_out_pFName);
                            //sw.WriteLine(Tmp_Str);
                        }
                }//   for (var i = 0; i < dt1.Rows.Count; i++)
   //sw.Close();


PS: c# using 的使用方法如下:
1>引入命名空間
    using System.Text;
2>使用資源後,自動釋放 
using (var file = File.Open("filePath", FileMode.OpenOrCreate))
{
   //do something
}

-->
FileStream file = File.Open("filePath", FileMode.OpenOrCreate);
try
{
//do something
}
finally
{
if (file!= null)
{
((IDisposable)file).Dispose();
}
}