2024年5月28日 星期二

目的:V20304F – [批次工時匯入]鈕 – Transaction

目的:V20304F – [批次工時匯入]鈕 – Transaction

處理說明: 1> SQLStringList_A.Add(Tmp_Sql);
                  2> excuteSQLTran(SQLStringList_A);
                       --> 執行 SQLStringList_A 內的 SQL
                             若不成功,則自動 Rollback
                  3>若呼叫executeSqlTran()API函式名稱太長,
                       則會出現錯誤訊息    


1>*.cs

// Transaction SQL List - 存放  Transaction 的 SQL 
   List<string> SQLStringList_A = new List<string>();           

  Tmp_Sql = " DELETE   AMM_AR  "
                  + "  WHERE  FMNO=" + myfunc.AA(Tmp_FMNO);
  SQLStringList_A.Add(Tmp_Sql);

Tmp_Sql = "  UPDATE   AMM_AR  "
                +"   SET   RQHR=" + myfunc.AA(Tmp_PR04AR) 
                + "  WHERE FMNO = " + myfunc.AA(Tmp_FMNO) 
                + "  AND    AMINO=" + myfunc.AA("0400");
SQLStringList_A.Add(Tmp_Sql);

excuteSQLTran(SQLStringList_A);




2>BaseAPIController.cs
public int excuteSQLTran(List<string> SQLStringList, bool sysException = true)
        {
            setActionName();
            int rows = 0;
            OracleConnection conn = new OracleConnection(DBService.ConnectionString(DBLINK));
            conn.Open();
            conn.ClientInfo = User.Identity.Name;
            conn.ModuleName = BaseSYS + "_" + BaseMODID;
            conn.ActionName = ActionName;  //ActionName=API函式名稱 ,不可太長,否則會Error
            OracleTransaction trn = conn.BeginTransaction();
            OracleCommand cmd = new OracleCommand();
            cmd.Connection = conn;
            cmd.Transaction = trn;
            try
            {
                excMsg = "";
                for (int n = 0; n < SQLStringList.Count; n++)
                {
                    string strsql = SQLStringList[n].ToString();
                    cmd.CommandText = strsql;                    
                    //rows += cmd.ExecuteNonQuery();
                    cmd.ExecuteNonQuery();
                    rows = 1;
                }
                trn.Commit();
            }
            catch (Exception ex)
            {
                trn.Rollback();
                rows = -1;
                //Console.WriteLine("error : " + ex.Message);
                excMsg = ex.Message;
                if (sysException)
                {
                    throw ex; //如果沒有另外寫例外訊息的話,以此為主
                }
            }
            finally
            {
                cmd.Cancel();
                conn.Close();
            }
            return rows;
        }

PS: API函式名稱不可太長,否則會出現錯誤訊息



2024年5月27日 星期一

V30204F – [批次匯入]鈕 – 若匯入資料有錯誤,則寫入*.xlsx, 傳至前端 - XLS2XLS

 目的:V30204F – [批次匯入] 若匯入資料有錯誤,則寫入*.xlsx, 傳至前端

處理說明:  1>出現[選擇檔案]子畫面, 若未選擇檔案,則顯示訊息
                        var Tmp_FileObj = Ext.getCmp('FName');
                        var Tmp_FName = Ext.getDom(Tmp_FileObj.inputId).value;
                        if (checkisnull(Tmp_FName)) {
 
                          Tmp_Str = "檔案名稱不可空白,敬請檢核!!"
                             myalert(Tmp_Str);
                            return;
                         }
                         par_OkProcess(this,e,eOpts);
                  2> 將檔案傳送至後端處理 
                       1>>*.js
                           var np = {}
                           np["FName"] = Ext.getDom(Tmp_FileObj.inputId).value;    
                           console.log("FName: ", np.FName);
                           //submit會將fileUploadForm裡面input name送到後端
                           me.up("form").submit({                       
                                url: '../api/V20304FAPI/uploadFileToDB',
                                method: 'POST',
                               headers: { 'Content-type': 'multipart/form-data' },
                               params: np,
                          });
                     2>*.cs  : 取得前端檔案
                         Stream file_Strm = Request.Files[cur_FName].InputStream;
                         file_Name = Path.GetFileName(Request.Files[cur_FName].FileName); 

            3>將 xls 檔案傳至前端
                wk.SaveToStream(mstream, FileFormat.Version2007);
                wk.SaveToFile(FileName1, FileFormat.Version2007);
                HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=\"" + HttpUtility.UrlEncode((string)FileName1, 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());




1>*.js
//[單筆工時匯入]鈕 - - 匯入單筆工時資料,無子畫面
function Call_V20304F() {
      //挑選檔案後, 送給 Ok_prrocess 函式處理
     SelectFile(Ok_process);

}
function Ok_process(me, e, eOpts) {
    //取得 [檔案上傳].檔名
    var Tmp_FileObj = Ext.getCmp('FName');
    console.log("FName Obj:", Tmp_FileObj);
    var Tmp_Str = "";
    var np = {}
    np["FName"] = Ext.getDom(Tmp_FileObj.inputId).value;    
    console.log("FName: ", np.FName);
    //submit會將fileUploadForm裡面input name送到後端
    //Ext.getCmp('btn_FileIn').getForm().submit({
    me.up("form").submit({
        //standardSubmit: false,    //default:false
        url: '../api/V20304FAPI/uploadFileToDB',
        method: 'POST',
        headers: { 'Content-type': 'multipart/form-data' },
        params: np,        
    });

    //顯示結果訊息..
    var mask = new Ext.LoadMask(Ext.getBody(), {
        msg: '處理中,請稍待...'
    });

    mask.show();//使用 mask 需手動呼叫show() 方法下
    //若要傳送檔案到前端, 必需用 Cookie 判斷後端是否已完成
    //每1秒檢核一次,是否已完成, 若已完成,則不再檢核
    var timer = setInterval(function () {

        var r = r_cookies('EX_DFile');
        //console.log("r_cookies=", r);
        if (!checkisnull(r)) {
            mysuccessalert(r);
            clearInterval(timer);
            mask.hide();
            timer = null;
            //將視窗關閉
            Ext.getCmp("SelectForm_cancelbtn").fireHandler();
        }
    }, 1000);  //1000ms = 1sec
};  // end of Ok_process() {  //批次新增

2>*.cs
         //[批次工時匯入] 鈕 , 匯入 XLS 檔案
        //因為傳送[錯誤訊息]檔案至前端, 所以不可以使用  HttpResponseMessage  response
        [HttpPost]
        public void uploadFileToDB()
        {

            HttpContext c = HttpContext.Current;
            NameValueCollection nvc = c.Request.Form;
            string FName = nvc["FName"];

            MemoryStream mstream = new MemoryStream();
         // 取得實實的路徑            
            string documentPath = HttpContext.Current.Server.MapPath("~") + "document\\";  
            string FileName = "V20304_工時批次匯入_錯誤說明" + ".xlsx";
            string FileName1 = documentPath + FileName;
            HttpCookie MyCookie;  //將訊息傳至前端
        
            Stream file_Strm = Request.Files[cur_FName].InputStream;
            wk = new Workbook();
            wk.LoadFromStream(file_Strm);
            Worksheet sheet1 = wk.Worksheets[0];//獲取第一個工作表

            Tmp_OGONOAF = sheet1.Range[myfunc.GetExcelPos(0,i+1)].Value;
            sheet1.Range[myfunc.GetExcelPos(27, i + 1)].Value = Tmp_RtnMsg1;

          if (Tmp_isOk==false)
                    {
                        wk.SaveToStream(mstream, FileFormat.Version2007);
                        wk.SaveToFile(FileName1, FileFormat.Version2007);
                        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=\"" + HttpUtility.UrlEncode((string)FileName1, 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>"
                                        + "(" + FName + ")<br>";
                        MyCookie = new HttpCookie("EX_DFile", HttpUtility.UrlEncode(Tmp_Str));
                        HttpContext.Current.Response.Cookies.Add(MyCookie);
                        HttpContext.Current.Response.End();
                        return;                   
                    }                                    

 目的: V20304F – [批次匯入] 如何將如下錯誤訊息存成*.XLS , 下載至前端

處理說明:







V20304F – [批次匯入]鈕 – 如何將如下錯誤訊息存成*.XLS , 下載至前端

 目的: V20304F – [批次匯入] 如何將如下錯誤訊息存成*.XLS , 下載至前端

處理說明: 1>




2024年5月23日 星期四

Array 新增值 *.js *.cs - - c# 判斷字串是否在長字串內

 目的: Array 新增值 - 判斷值是否在Array

處理說明:  1> *.js  , js  Array 才有 push method
                        var   PK_LIST: [], //儲存 PK欄位.欄位值
                        PK_LIST.push(Tmp_PK);

                        if  (PK_LIST.indexOf(Tmp_PK)== -1){}

                   2>*.cs , cs Arrary 無 puch method , 必需先增加Array長度, 再 Assign 欄位值
                         再 Assign  Tmp_Ary[i] = Tmp_Str
                          string[] Tmp_RPNOAF_Ary = new string[] {};      
                          Array.Resize(ref Tmp_RPNOAF_Ary, Tmp_RPNOAF_Ary.Length + 1);
                         Tmp_RPNOAF_Ary[Tmp_RPNOAF_Ary.Length - 1] = Tmp_RPNOAF;

                         if (Array.IndexOf(Tmp_RPNOAF_Ary,Tmp_RPNOAF) ==-1)  {}
                         if ("1;2;3;4;5;6;7;8;".IndexOf(Tmp_IRESAK) == -1)  {}
                     
                  3>c# 字串判斷是否存在 , 若 Tmp_IRESAK 為"", 則傳回 0 , 非 -1
                        if ("1;2;3;4;5;6;7;8;".IndexOf(Tmp_IRESAK) == -1)
                            {
                                Tmp_RtnMsg1 = Tmp_RtnMsg1 + "[檢測結果代碼]欄位值不符!!"
                                                          +"(" +Tmp_IRESAK + ")<br>";
                            }
                        --> 所以必需先判斷 Tmp_IRESAK 是否為空字串
                               if (myfunc.checkisnull(Tmp_IRESAK.Trim()))
                                {
                                  Tmp_RtnMsg1 = Tmp_RtnMsg1 + "[檢測結果代碼]欄位值不可空白!!<br>";
                                  }  


1>*.cs  string.IndexOf   &  Array.IndexOf(Tmp_Ary,Tmp_Str) 
if (Array.IndexOf(Tmp_RPNOAF_Ary,Tmp_RPNOAF) ==-1)  {}
if ("1;2;3;4;5;6;7;8;".IndexOf(Tmp_IRESAK) ==-1)  {}


 if (myfunc.checkisnull(Tmp_IRESAK.Trim()))
{
     Tmp_RtnMsg1 = Tmp_RtnMsg1 + "[檢測結果代碼]欄位值不可空白!!<br>";
}
else
{
  if ("1;2;3;4;5;6;7;8;".IndexOf(Tmp_IRESAK) == -1)
  {
  Tmp_RtnMsg1 = Tmp_RtnMsg1 + "[檢測結果代碼]欄位值不符!!(" + Tmp_IRESAK + ")<br>";
   }
}                        

2024年5月22日 星期三

V20304B SPIRE.xls 設定 Excel 背景顏色 & 本文顏色 & 欄高/欄寬 - CELL

 目的:V20304B SPIRE.xls  設定 Excel 背景顏色 &  本文顏色

處理說明: 1> 設定背景顏色 Range ["A1:E1"] and ["A2:A10"]                
                       worksheet.Range["A1:E1"].Style.Color = Color.MediumSeaGreen;         
                       worksheet.Range["A2:A10"].Style.Color = Color.LightYellow; 

                  2>設定背景顏色  cell E6 
                      using System.Drawing;
                       worksheet.Range["E6"].Style.Color = Color.Red;

                  3>設定字體顏色          
                     worksheet.Range["A2:G3"].Style.Font.Color = Color.Red;         
                   
                   sheet.Range["A1"].Text = "我是A1单元格";
                   sheet.Range[1, 2].Text = "我是第1行的第2个单元格";
                   sheet.Range[“G11”].RowHeight = 30;          //欄高
                   sheet.Range[“G11”].ColumnWidth = 40;      //欄寬
                   sheet.Range["A5:B6"].Merge();                    /欄位合併
                   worksheet.Range["A2:G3"].Style.Font.Color = Color.Red;    //字體顏色









2024年5月16日 星期四

V20302B – 調整版面 panel 的高度大小 - splitter - 版面 - 挑選人員

 目的: V20302B – 系統件除帳 工號(25284247) – 調整版面 panel 的高度大小

處理說明:  1> {  xtype: 'splitter',  width: 2,    },



1>*.js

//[顯示Email]  - 子畫面欄位
    var sub1_ShowEmail_Flds = [
        {
            xtype:'panel',bodyStyle: "background-color:transparent;", border: false, layout: {  type: "vbox",  align: 'stretch' }, padding: "5",
            id: 'sub1_myForm', items: [
                {
                    xtype: "fieldcontainer", fieldLabel: "主旨", labelWidth: 60, layout: "fit", flex: 1, items: [
                        {
                            xtype: "textfield", id: "sub1_Subject", name: "sub1_Subject",  padding: "0 4 0 0",
                            //value: "AJT",
                        },
                    ]
                },  //end of 主旨
                {
                    xtype: "fieldcontainer", fieldLabel: "內容", labelWidth: 60, layout: "fit", flex: 3, items: [
                        {
                            id: "sub1_content", name: "sub1_content", xtype: "textareafield",  padding: "0 4 0 0", 
                            //value: "AJT",
                        },
                    ]
                }, // end of 內容
                {
                    xtype: 'splitter',
                    width: 2,
                },

                {  //下方 TreeView, 左右移,正本/副本
                    xtype: "panel", flex: 5,
                    layout: {
                        type: 'hbox',
                        align: 'stretch'
                    },
                    //autoScroll: true,
                    items: [
                        { // TreeView
                            xtype: "panel", flex: 4, layout: { type: 'vbox', align: 'stretch' },                            
                            autoScroll: true, items: [treepanel1]
                        },  //TreeView
                        {  //正本&副本.[左移/右移]按鈕
                            xtype: "panel", flex: 2, layout: { type: 'vbox', align: 'stretch' }, border: false,
                            //bodyStyle: 'background:blue; ',
                            items: [
                                {  //  正本.左右移的 Button
                                    xtype: 'panel', id: 'panel1_btns1', layout: { type: 'vbox', align: 'stretch' }, flex: 1, border: false,
                                    //bodyStyle: 'background:yellow; ',                                    
                                    items: [                                        
                                        {//space panel
                                            xtype: 'panel',    flex: 1,                                            
                                        },// end of 
                                        {//正本.1往右移
                                            xtype: 'button',
                                            id: 'btn1_move11',
                                            text: '往右',
                                            iconCls: 'icon-right',
                                            flex: 1,
                                            handler: function () {
                                                //console.log("Ext.getCmp('sub1_treepanel'):", Ext.getCmp('sub1_treepanel'));
                                                //var node = treepanel1.getSelectionModel().getSelectedNode();
                                                var nodes = treepanel1.getSelectionModel().getSelection();
                                                var node = nodes[0];
                                                if (checkisnull(node)) {
                                                    var Tmp_Str = "請先選擇要Email的人員!!";
                                                    mywarnalert(Tmp_Str);
                                                    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 };
                                                    var find = Ext.getCmp("sub1_Grid1").store.find('EMPLYNM', Tmp_EmplyNM);
                                                    if (find != -1) {
                                                        // 已存在,則不再加入
                                                        Tmp_Str = "人員(" + Tmp_EmplyNM + ")已存在,不可再加入";
                                                        mywarnalert(Tmp_Str);
                                                        return;
                                                    } else {
                                                        Ext.getCmp("sub1_Grid1").store.add(Tmp_rec);
                                                    };
                                                }
                                                else {
                                                    var Tmp_Str = "請先選擇要Email的人員!!";
                                                    mywarnalert(Tmp_Str);
                                                }
                                            }
                                        },// end of 往右移                                        
                                        {//正本.1往左
                                            xtype: 'button',
                                            id: 'btn1_move12',
                                            text: '往左',
                                            iconCls: 'icon-left',
                                            flex: 1,
                                            handler: function () {
                                                var nodes = Ext.getCmp("sub1_Grid1").getSelectionModel().getSelection();                                               
                                                if (nodes.length == 0) {                                                    
                                                        mywarnalert("請先選擇要左移的資料");                                                        
                                                    return;
                                                }
                                                var node = nodes[0];                                                
                                                Ext.getCmp("sub1_Grid1").store.remove(node);
                                            }
                                        },//往左移
                                        {//space panel
                                            xtype: 'panel',flex: 1,
                                        },// end of 
                                    ]
                                }, //panel_btn1
                                {  //  副本.左右移的 Button
                                    xtype: 'panel', id: 'panel1_btns2', layout: { type: 'vbox', align: 'stretch' }, flex: 1, border: false,                                    
                                    //bodyStyle: 'background:red; ',
                                    items: [
                                    {//space panel                                    
                                    xtype: 'panel', flex: 1,                                },// end of 
                                        {//副本.2往右
                                            xtype: 'button',
                                            id: 'btn1_move21',
                                            text: '往右',
                                            iconCls: 'icon-right',
                                            flex: 1,
                                            handler: function () {
                                                //console.log("Ext.getCmp('sub1_treepanel'):", Ext.getCmp('sub1_treepanel'));
                                                //var node = treepanel1.getSelectionModel().getSelectedNode();
                                                var nodes = treepanel1.getSelectionModel().getSelection();
                                                var node = nodes[0];
                                                var Tmp_Str;
                                                if (checkisnull(node)) {
                                                    Tmp_Str = "請先選擇要Email的人員!!";
                                                    mywarnalert(Tmp_Str);
                                                    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 };
                                                    var find = Ext.getCmp("sub1_Grid2").store.find('EMPLYNM', Tmp_EmplyNM);
                                                    if (find != -1) {
                                                        // 已存在,則不再加入
                                                        Tmp_Str = "人員(" + Tmp_EmplyNM + ")已存在,不可再加入";
                                                        mywarnalert(Tmp_Str);
                                                        return;
                                                    } else {
                                                        Ext.getCmp("sub1_Grid2").store.add(Tmp_rec);
                                                    };
                                                    
                                                }
                                                else {
                                                    var Tmp_Str = "請先選擇要Email的人員!!";
                                                    mywarnalert(Tmp_Str);
                                                }
                                            }
                                        },// end of 往右移
                                        //{ xtype: 'panel', flex: 1, },// end of  虛 space
                                        {//副本.2往左
                                            xtype: 'button',
                                            id: 'btn1_move22',
                                            text: '往左',
                                            iconCls: 'icon-left',
                                            flex: 1,
                                            handler: function () {
                                                var nodes = Ext.getCmp("sub1_Grid2").getSelectionModel().getSelection();
                                                if (nodes.length == 0) {
                                                    mywarnalert("請先選擇要左移的資料");
                                                    return;
                                                }
                                                var node = nodes[0];
                                                Ext.getCmp("sub1_Grid2").store.remove(node);                                            
                                            }
                                        },//往左移
                                        {//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; ', items: [sub1_Grid1],
                                },
                                {
                                    xtype: "panel", flex: 1, title: '副本人員', layout: 'fit',                                                                       
                                    bodyStyle: 'background:blue; ', items: [sub1_Grid2],
                                },
                            ],                            
                        },  //正本副本
                    ]
                }, // end of TreeView                
            ]  //end of sub_myForm
        }]  //end of sub_ShowPN_Flds