顯示具有 分頁 標籤的文章。 顯示所有文章
顯示具有 分頁 標籤的文章。 顯示所有文章

2023年8月22日 星期二

V120401A -myfunc.getDataTable1() -T1C - 自訂 SQL 取得 Grid資料 - 不含RNK , 自行處理分頁

 目的: V120401A -myfunc.getDataTable1() - 自訂 SQL 取得 Grid資料 - 不含RNK , 自行處理分頁 

處理說明: 1> 自訂 SQL 取得 Grid資料, 不含 RNK  , 不用 count_Sql                       
                        --> 呼叫  ds = myfunc.getDataTable1(par_Sql,par_page);
                  2> 順序依自訂 SQL 的  order  by xxxx; 排序 
                  3>新增 DataTable("T1C")  的 [TOTAL]欄位值=目前筆數
                      DataSet ds = new DataSet();
                      DataTable T1C = new DataTable();
                      T1C.TableName = "T1C";
                      DataRow row = T1C.NewRow();
                      T1C.Columns.Add(new DataColumn("TOTAL", typeof(Int32)));
                       row["TOTAL"] = dt.Rows.Count;
                      T1C.Rows.Add(row);
                      ds.Tables.Add(T1C);
                  4>取得 dt 的目前頁次資料 傳回 ds.T1
                      OracleDataAdapter da = new OracleDataAdapter();
                      da.SelectCommand = cmd;
                      //取 cmd 結果的 page資料,存入 ds.Tables["T1"]
                      da.Fill(ds, start, limit, "T1");   


1>myfunc.cs - get_DataTable1(string par_Sql, bool  par_page)
        //函式名稱: getDataTable1
           傳入參數  :  par_Sql  :  目前 SQL
                                par_page: true/false  : 分頁,不分頁 , 預設值: true 
          傳回值 : ds   - 已分頁的資料 , 依 page,start,limit 分頁
        */
        public static dynamic getDataTable1(string par_Sql, bool par_page=true)
        {            
            var c = HttpContext.Current;
            NameValueCollection nvc = c.Request.Form;
            DataSet ds = new DataSet();
            OracleConnection conn = new OracleConnection(DBService.ConnectionString("AMMEU"));
            try
            {            
            int page = 1;
            int start = 1;
            int limit = 30;

            if (nvc.Count > 0 && nvc["page"] != null)
            {
                page = int.Parse(nvc["page"]);
                start = int.Parse(nvc["start"]);
                limit = int.Parse(nvc["limit"]);                
            }

            //產生 par_SQL  的 DataTable , 全部資料全取
            OracleCommand cmd = new OracleCommand();
            cmd.Connection = conn;
            cmd.CommandText = par_Sql;                
            conn.Open();
            DataTable dt = new DataTable();
            dt.Load(cmd.ExecuteReader());

            //加入 T1C 
            DataTable T1C = new DataTable();
            T1C.TableName = "T1C";
            DataRow row = T1C.NewRow();
            T1C.Columns.Add(new DataColumn("TOTAL", typeof(Int32)));
            row["TOTAL"] = dt.Rows.Count;
            T1C.Rows.Add(row);
            ds.Tables.Add(T1C);

            //加入 T1  -將 par_Sql 的 分頁資料填入 ds.T1 
            OracleDataAdapter da = new OracleDataAdapter();
            da.SelectCommand = cmd;
            if (par_page)
               da.Fill(ds, start, limit, "T1");
            else
               da.Fill(ds, "T1");
             return ds;
            }  // end try 
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {                
            }         
            return ds;
        }

2>*.js
 {
                                    xtype: 'button',
                                    id: 'btn_sub_Show',
                                    flex: 2,
                                    border: 1,
                                    text: '資料顯示',  //sub_btn_Add
                                    iconCls: 'icon-search',                                    
                                    handler: function () {
                                        //清空 - 勾選註記
                                        CHK_PK_OBJ1.PK_LIST = [];
                                        CHK_PK_OBJ1.ALL_LIST = [];
                                        //--> 需改為將 TMNO 的[AMM_TMDWG]資料加入 store 
                                        var np = {};
                                        np["sub_DOC_NUM"] = Ext.getCmp("sub_DOC_NUM").getValue();                                        
                                        np["sub_STAT"] = Ext.getCmp("sub_STAT").getValue();
                                        var is_Ok = true;
                                                                                
                                        var Tmp_store = Ext.getCmp('sub_Grid').store;
                                        console.log("0 Tmp_store: ", Tmp_store);
                                        Tmp_store.getProxy().url = '../../api/V120401AAPI/get_sub_Data1';
                                        Tmp_store.getProxy().extraParams = np; //分頁OK,篩選條件OK                  
                                        Tmp_store.pageSize = 30;
                                        Tmp_store.load();
                                        console.log("1 Tmp_store: ", Tmp_store);
                                    } // end of handler of sub_btn_Add
                                },// end of  button  sub_btn_Show  , 資料顯示

2023年5月31日 星期三

V120202 -getUrlStr() - url傳回字串 - checkRtnOk() – [全部選取] [全部取消] – 允許分頁選取保留 - checkbox - url傳回值

 目的: V120202 – [全部選取] [全部取消] – 允許分頁選取保留 -checkbox

處理說明:  1>[全部選取]鈕
                                           1>將目前 store.CHECK   欄位均設為    true                                          
                                           2>cbxAry  :   將所有的  PK(APNO)     存入  cbxAry                                           


1>*. js
//全部選取 , 將所有資料 PK 加入 cbxArr 
    function SelAllBtn_click() {
        var Tmp_PKStr = "";  //所有資料 PK 字串, 以 , 分隔
        var Tmp_url = "../../api/V120202API/getALLPKStr";
        var np = grid.store.getProxy().extraParams;
        var rtn = getUrlStr(Tmp_url, np, "全部選取鈕");
        if (checkRtnOK(rtn)) {
              set_PgAll();
             var Tmp_PKStr = rtn;
            setCbxArr(Tmp_PKStr);            
    }  // end of SelAllBtn_click


//全部取消 , 將所有資料 PK 加入 cbxArr 
    function unSelAllBtn_click() {
        var Tmp_PKStr = "";  //所有資料 PK 字串, 以 , 分隔
        var Tmp_url = "../../api/V120202API/getALLPKStr";
        var np = grid.store.getProxy().extraParams;
        var rtn = getUrlStr(Tmp_url, np, "全部取消鈕");
        if (checkRtnOK(rtn)) {
            //set_AllUn();            
            set_PgUn();
            resetCbxArr();
        } // end of chkRtnOk(rtn)
    }  // end of unSelAllBtn_click

2>*.cs
//取所有資料.PKStr , 並以 , 分隔
        [HttpPost]
        public dynamic getALLPKStr()
        {            
            var c = HttpContext.Current;
            NameValueCollection nvc = c.Request.Form;
            //DataSet ds = getGridDataPage();
            //return ds;
            string Tmp_LCAA = nvc["s_LCAA"];
            string Tmp_ASN = nvc["s_ASN"];
            string Tmp_MATNR = nvc["s_MATNR"];
            string Tmp_APNO = nvc["s_APNO"];
            string Tmp_APER = nvc["s_APER"];

            string Tmp_APDT1 = "";   //申請日期  - 起迄
            string Tmp_APDT2 = "";   //申請日期  - 起迄
            if (!myfunc.checkisnull(nvc["s_APDT1"]))
            {
                Tmp_APDT1 = string.Format("{0:yyyy/MM/dd}", DateTime.Parse(nvc["s_APDT1"]));
            };
            if (!myfunc.checkisnull(nvc["s_APDT2"]))
            {
                Tmp_APDT2 = string.Format("{0:yyyy/MM/dd}", DateTime.Parse(nvc["s_APDT2"]));
            };

            //單況(A/B/C/D/Z)
            string Tmp_STAT = nvc["s_STAT"];


            OracleCommand cmd = new OracleCommand();
            string Tmp_Sql = " SELECT  RNK,     "
                                       + "   APNO,LCAA,ASN,SAPNO,PN,MATNR,RPN,QTY,UNIT,"
                                       + "    APER,APDT,STAT,MPKUPP,MPKUPDT,COMPER,COMPDT,DELTP,DELTDT  "
                                       + "  FROM  ( "
                                      + "   select  dense_rank()  over(order by  APNO) as RNK,"
                                                  + "   APNO,LCAA,ASN,SAPNO,PN,MATNR,RPN,QTY,UNIT,  "
                                                  + "   APER,APDT,STAT,MPKUPP,MPKUPDT,COMPER,COMPDT,DELTP,DELTDT  "
                                      + "  FROM  AMM_COMQ "
                                      + "  Where  1=1  ";

            //機位
            if (!myfunc.checkisnull(Tmp_LCAA))
            {
                Tmp_Sql = Tmp_Sql + " AND   LCAA  = " + myfunc.AA(Tmp_LCAA);
            };
            //機號
            if (!myfunc.checkisnull(Tmp_ASN))
            {
                Tmp_Sql = Tmp_Sql + " AND   ASN= " + myfunc.AA(Tmp_ASN);
            };
            //物料編號
            if (!myfunc.checkisnull(Tmp_MATNR))
            {
                Tmp_Sql = Tmp_Sql + " AND   (       (MATNR  LIKE " + myfunc.AA("%" + Tmp_MATNR + "%") + ")"
                                                                 + "  OR  (MATNR IN (  SELECT  SPN  "
                                                                                                   + " FROM    AMM_SPN "
                                                                                                   + " WHERE  PN LIKE " + myfunc.AA("%" + Tmp_MATNR + "%")
                                                                                                   + "  AND       STATUS='A'   ) )"
                                                                + ")";
            };
            //申請單號
            if (!myfunc.checkisnull(Tmp_APNO))
            {
                Tmp_Sql = Tmp_Sql + " AND   APNO  = " + myfunc.AA(Tmp_APNO);
            };
            //申請人
            if (!myfunc.checkisnull(Tmp_APER))
            {
                Tmp_Sql = Tmp_Sql + " AND   APER= " + myfunc.AA(Tmp_APER);
            };

            string Tmp_Sql1 = "";
            //申請日期 - 起  - 迄
            if ((!myfunc.checkisnull(Tmp_APDT1)) || (!myfunc.checkisnull(Tmp_APDT2)))
            {
                if (!myfunc.checkisnull(Tmp_APDT1))
                {
                    Tmp_Sql1 = Tmp_Sql1 + "  AND        APDT>=" + myfunc.AA(Tmp_APDT1);
                };
                if (!myfunc.checkisnull(Tmp_APDT2))
                {
                    Tmp_Sql1 = Tmp_Sql1 + "  AND        APDT<=" + myfunc.AA(Tmp_APDT2);
                }
                Tmp_Sql = Tmp_Sql + Tmp_Sql1;
            };


            //單況 : 待撥料/撿料中/撿料完成/已領用/已撤銷(A/B/C/D/Z)  全部: ALL - radioboxgroup
            if (!myfunc.checkisnull(Tmp_STAT))
            {
                switch (Tmp_STAT)
                {
                    case "ALL":  //全部
                        Tmp_Sql = Tmp_Sql;
                        break;
                    default:
                        Tmp_Sql = Tmp_Sql + " AND   STAT=" + myfunc.AA(Tmp_STAT);
                        break;
                }
            };

            Tmp_Sql = Tmp_Sql + "   )   ";

            cmd.CommandText = Tmp_Sql;
            string countSql = " SELECT COUNT(*) as total FROM (" + Tmp_Sql + ")";
            //匯出時 ,取全部資料, par_paging =false , 取全部資料
            DataSet ds = getDataTable(cmd, countSql, false);

            int Tmp_Cnt = ds.Tables["T1"].Rows.Count;
            var Tmp_PKStr = "";
            for (var i=0; i<Tmp_Cnt;i++)
            {
                DataRow dr = ds.Tables["T1"].Rows[i];
                Tmp_APNO = dr["APNO"].ToString();
                Tmp_PKStr = Tmp_PKStr + Tmp_APNO + ",";
            }
            if (Tmp_PKStr != "")
            {
                Tmp_PKStr = Tmp_PKStr.TrimEnd(',');
            }
            return Tmp_PKStr;
        }

V120202 – 勾選 checkbox , 分頁時可以保留勾選

 目的: V120202 – 勾選 checkbox , 分頁時可以保留勾選 

處理說明: 1>*_json.js  利用 cbxAry 記錄目前勾選資料的 PK(APNO)
                       var cbxArr = []; //記錄目前 PK Array ,(PK:APNO)
                       var cbxIdx = -1; //記錄目前 cbxAry 的 index
                        var curPage = 0; //記錄目前 Page (store)
                  2>*_json.js , columns 新增  CHECK欄位, onClick 會觸發 renderer event ,
                       若原本未勾選, 則變勾選, 若原本勾選,則變未勾選
                       var J_columns = [{
               header: "勾選", dataIndex: "CHECK", width: 40, xtype: 'checkcolumn',
        renderer: function (value, metadata, record, rowIndex, colIndex, store) {
                                :
                                 var i = cbxArr.indexOf(record.get('APNO'));
if ((value === 'Y') || (value === true)) {
if (i < 0) {
chkd = 'checked';
cbxIdx++;
cbxArr[cbxIdx] = record.get('APNO');
}
else {
chkd = '';
cbxArr[i] = '';
}
}
               3>*.js  , 若 store.onload 則記錄目前的 頁次(store.currentPage),且顯示 CHECK是否勾選
                         curPage=gridstore.currentPage;   
                         var idx = cbxArr.indexOf(rec.data['APNO']);
                          if (idx >= 0) {  rec.data['CHECK'] = true; }
                          else {  rec.data['CHECK'] = false; }






2023年4月13日 星期四

V80204 - [發工人員]挑選 - 列出所有的資料,且不顯示[分頁]Toolbar - 傳回多欄位 -搜尋

目的: V80204 - [發工人員]挑選 - 列出所有的資料,且不顯示[分頁]Toolbar - 傳回多欄位 - 搜尋

處理說明: 1> *.js  EditPickx 函式的paging 設為 false
                               var win = EditPickx('發工人員', '../api/V80204API/get_s_SAPMANPick', ['SAPMAN_', 'SAPMAN'], 
                                              ['s_SAPMAN_', 's_SAPMAN'], J_pickstore_s_SAPMAN, J_pickcolumns_s_SAPMAN, false);
                  2>*.cs get_s_SAPMANPick 的寫法相同, 不需修改
                      [HttpPost]
                      public dynamic get_s_SAPMANPick(string SAPMAN_ = "", int isComplete = 0)

 

1>*.js 
{
      xtype: "fieldcontainer", fieldLabel: "發工人員", labelWidth: 70, layout: "hbox", flex: 2,
      items: [
             { xtype: "textfield", id: "s_SAPMAN_", name: "s_SAPMAN_", width: 50, padding: "0 4 0 0" },
             { xtype: "textfield", id: "s_SAPMAN", name: "s_SAPMAN", width: 50, padding: "0 4 0 0" },
             { xtype: "button", id: "s_btn_SAPMAN", name: "s_btn_SAPMAN", text: "...",width:20,
                handler: function () {
                        var win = EditPickx('發工人員', '../api/V80204API/get_s_SAPMANPick', 
                       ['SAPMAN_', 'SAPMAN'], ['s_SAPMAN_', 's_SAPMAN'], J_pickstore_s_SAPMAN,                             J_pickcolumns_s_SAPMAN, false);
                       win.show();
                                        }
                                    }
                                ]
                            },  // end of s_發工人員                      



2>*.cs
       //過濾條件 [發工人員]挑選
        [HttpPost]
        public dynamic get_s_SAPMANPick(string SAPMAN_ = "", int isComplete = 0)
        {
    string Tmp_Sql = " SELECT  DISTINCT B.EMPLYNM as SAPMAN_,B.EMPLYID  as SAPMAN "
                              +"  FROM    AMM_SRO A, HR_EMPLYM B "
                              +"  WHERE  A.SAPMAN = B.EMPLYID  "
                              +"  ORDER  BY  B.EMPLYNM,B.EMPLYID ";
            string n = funId + "s_SAPMAN";
            // public DataSet setupPickDs(string pickKey, string sql, string[] tables, bool paging = true, bool realTime = false)
            DataSet ds = setupPickDs(n, Tmp_Sql, new string[] { "AMM_SRO" });
            if (SAPMAN_ != null && !SAPMAN_.Equals(""))
            {
                if (isComplete == 1)
                {
                    ds = getPickDsbyCondi(n, "SAPMAN_='" + SAPMAN_ + "'");
                }
                else
                {
                    ds = getPickDsbyCondi(n, "SAPMAN_  LIKE '%" + SAPMAN_ + "%'");
                }
            }
            return ds;
        }  // end of  get_s_SAPMANPick

2022年9月12日 星期一

V80C03 - 顯示資料 - 分頁不正確

 目的: 顯示資料的分頁處理(RNK), RNK 必需為唯一, 即 order by 必需為 PK

處理說明:  1>*.cs 顯示資料的 SQL  , RNK 必需為唯一 , 即 order by 必需為 PK 



1>*.cs
[HttpPost]
        public dynamic getGridData_M(bool par_paging= true)
        {
        
Sql = " SELECT  RNK,     "
                          + " ACNO,SAPNO,AMMNO,ITM,PN,MOSM, PLANNINGCARD,AREA, TEAM,CRITCL,BSDT,BEDT,STAFF,HRS,STDHRS,DURAION,STARTDAY,ENDDAY,INSDT, CLS,  "
                            + "  GRP,FOREMAN1,TEAM,LDMAN1,EMPLYID,DT,CLSRM,PATCHMAN,ASHR,REMARK,PTY,CREWBOARDSDT "
                            + "  FROM  ( "
+"select  dense_rank()  over(order by  nvl(d.STARTVAL,d.ACNO),d.SAPNO,a.AMMNO,a.ITM,b.EMPLYID,b.DT) as RNK,"
//+ "select  dense_rank()  over(order by  nvl(d.STARTVAL,d.ACNO),d.SAPNO) as RNK,"   //非唯一,分頁會有問題
                                                   + "   nvl(d.STARTVAL,d.ACNO) as ACNO, d.SAPNO,d.PTY,d.CREWBOARDSDT, "
                                                   + "  a.AMMNO,a.ITM,a.PN,a.MOSM,a.PLANNINGCARD,a.AREA, a.TEAM,a.CRITCL,a.BSDT,a.BEDT,a.STAFF,a.HRS,a.STDHRS,a.DURAION,a.STARTDAY,a.ENDDAY,a.INSDT, a.CLS, "
                                                   + "  b.GRP,b.FOREMAN1,b.TEAM as bTEAM,b.LDMAN1,b.EMPLYID,b.DT,b.CLSRM,b.PATCHMAN,b.ASHR,b.REMARK "
                                       + "  from AMM_CREW a, AMM_SRO d,  "
                                                   + " (select    a.AMMNO,a.ITM,a.GRP,b.FOREMAN1,a.TEAM,c.LDMAN1,a.EMPLYID,a.DT,a.CLSRM,a.PATCHMAN,a.ASHR,a.REMARK  "
                                                   + "  from      AMM_CREWD a, AMM_CREWGRP b,AMM_CREWTEAM c "
                                                   + "   where   a.GRP = b.GRP and a.TEAM = c.TEAM) b  "
                                      + "   where  a.AMMNO = b.AMMNO(+)  "
                                      + "   and       a.ITM = b.ITM(+)   "
                                      + "   and      a.AMMNO=d.AMMNO  ";                                    
            //AMM單號
            if (!myfunc.checkisnull(Tmp_AMMNO))
            {
                Tmp_Sql = Tmp_Sql + " AND   A.AMMNO=" + myfunc.AA(Tmp_AMMNO);
            };
            //分工單計畫開始日   起~迄
            if ((!myfunc.checkisnull(Tmp_BEDT1)) || (!myfunc.checkisnull(Tmp_BEDT2)))
            {
                if (!myfunc.checkisnull(Tmp_BEDT1))
                {
                    Tmp_Sql = Tmp_Sql + " AND   A.BEDT  >=" + myfunc.AA(Tmp_BEDT1);
                }
                if (!myfunc.checkisnull(Tmp_BEDT2))
                {
                    Tmp_Sql = Tmp_Sql + " AND   A.BEDT  <=" + myfunc.AA(Tmp_BEDT2);
                }
            };
            //施工日期   起~迄
            if ((!myfunc.checkisnull(Tmp_DT1)) || (!myfunc.checkisnull(Tmp_DT2)))
            {
                if (!myfunc.checkisnull(Tmp_DT1))
                {
                    Tmp_Sql = Tmp_Sql + " AND   B.DT  >=" + myfunc.AA(Tmp_DT1);
                }
                if (!myfunc.checkisnull(Tmp_DT2))
                {
                    Tmp_Sql = Tmp_Sql + " AND   B.DT  <=" + myfunc.AA(Tmp_DT2);
                }
            };
            //區域
            if (!myfunc.checkisnull(Tmp_AREA))
            {
                Tmp_Sql = Tmp_Sql + " AND   A.AREA=" + myfunc.AA(Tmp_AREA);
            };
            //發工件號
            if (!myfunc.checkisnull(Tmp_PN))
            {
                Tmp_Sql = Tmp_Sql + " AND   A.PN=" + myfunc.AA(Tmp_PN);
            };
            //CREWBOARD起始天   起~迄
            if ((!myfunc.checkisnull(Tmp_PLANDAY1)) || (!myfunc.checkisnull(Tmp_PLANDAY2)))
            {
                Tmp_Sql = Tmp_Sql + " AND   A.PN  IN  (SELECT  DISTINCT PLANNINGCARD FROM   AMM_PLANCARD  WHERE  1=1 ";
                if (!myfunc.checkisnull(Tmp_PLANDAY1))
                {
                    Tmp_Sql = Tmp_Sql + " AND   PLANDAY  >=" + myfunc.AA(Tmp_PLANDAY1);
                }
                if (!myfunc.checkisnull(Tmp_PLANDAY2))
                {
                    Tmp_Sql = Tmp_Sql + " AND   PLANDAY  <=" + myfunc.AA(Tmp_PLANDAY2);
                }
                Tmp_Sql = Tmp_Sql + " ) ";
            };
            //TEAM
            if (!myfunc.checkisnull(Tmp_TEAM))
            {
                Tmp_Sql = Tmp_Sql + " AND   A.TEAM=" + myfunc.AA(Tmp_TEAM);
            };
            //領班 FOREMAN1 of   AMM_CREWGRP.GRP
            if (!myfunc.checkisnull(Tmp_FOREMAN1))
            {
                Tmp_Sql = Tmp_Sql + " AND   B.GRP  IN (SELECT GRP FROM  AMM_CREWGRP  WHERE  FOREMAN1=" + myfunc.AA(Tmp_FOREMAN1) + ")";
            };
            //小組長 LDMAN1 of  AMM_CREWTEAM.TEAM
            if (!myfunc.checkisnull(Tmp_LDMAN1))
            {
                Tmp_Sql = Tmp_Sql + " AND   B.TEAM  IN (SELECT TEAM FROM  AMM_CREWTEAM  WHERE  LDMAN1=" + myfunc.AA(Tmp_LDMAN1) + ")";
            };
            // AMM_SRO的過濾條件
            //機號 & 工號
            if ((!myfunc.checkisnull(Tmp_ACNO)) || (!myfunc.checkisnull(Tmp_SAPNO)) ||
                  (!myfunc.checkisnull(Tmp_PTY1)) || (!myfunc.checkisnull(Tmp_PTY2)) ||
                  (!myfunc.checkisnull(Tmp_CREWBOARDSDT1)) || (!myfunc.checkisnull(Tmp_CREWBOARDSDT2)))
            {
                Tmp_Sql = Tmp_Sql + " AND   A.AMMNO  IN (SELECT AMMNO FROM  AMM_SRO WHERE  1=1 ";
                if (!myfunc.checkisnull(Tmp_ACNO))
                {
                    Tmp_Sql = Tmp_Sql + " AND   nvl(STARTVAL,ACNO)=" + myfunc.AA(Tmp_ACNO);
                };
                if (!myfunc.checkisnull(Tmp_SAPNO))
                {
                    Tmp_Sql = Tmp_Sql + " AND   SAPNO=" + myfunc.AA(Tmp_SAPNO);
                };
                if (!myfunc.checkisnull(Tmp_PTY1))
                {
                    Tmp_Sql = Tmp_Sql + " AND   PTY>=" + Tmp_PTY1;
                };
                if (!myfunc.checkisnull(Tmp_PTY2))
                {
                    Tmp_Sql = Tmp_Sql + " AND   PTY<=" + Tmp_PTY2;
                };
                if (!myfunc.checkisnull(Tmp_CREWBOARDSDT1))
                {
                    Tmp_CREWBOARDSDT1 = string.Format("{0:yyyy/MM/dd}", DateTime.Parse(Tmp_CREWBOARDSDT1));
                    Tmp_Sql = Tmp_Sql + " AND   CREWBOARDSDT>=" + myfunc.AA(Tmp_CREWBOARDSDT1);
                };
                if (!myfunc.checkisnull(Tmp_CREWBOARDSDT2))
                {
                    Tmp_CREWBOARDSDT2 = string.Format("{0:yyyy/MM/dd}", DateTime.Parse(Tmp_CREWBOARDSDT2));
                    Tmp_Sql = Tmp_Sql + " AND   CREWBOARDSDT<=" + myfunc.AA(Tmp_CREWBOARDSDT2);
                };
                Tmp_Sql = Tmp_Sql + " )";
            }

            Tmp_Sql = Tmp_Sql + "   )   ";                                                     
            cmd.CommandText = Tmp_Sql;
            string countSql = " SELECT COUNT(*) as total FROM (" + Tmp_Sql + ")";
            //匯出時 ,取全部資料, par_paging =true
            DataSet ds = getDataTable(cmd, countSql, par_paging);


2022年8月18日 星期四

V120402D - xls套表列印 - 請稍候訊息 - Cookie - xls欄位格式設定 - 欄位合併, 插入圖片 - JSON2dt - 開啟檔案

 目的: xls套表列印, 分頁處理- Cookie - xls欄位格式設定 - 欄位合併, 插入圖片

處理說明: 1>由 SS_FILES 讀取套表檔案 , 存至 Server檔案目錄
                  2>xls分頁處理
                  3> xls欄位合併, 插入圖片                  




1>*.js  - V120402D.js

//[列印]鈕  - 列印套表  - Txxxx 技令借用登記表    - Dxxx 文件借用登記簿
    function sub_LookFlds_OkBtn() {
         //1>將子畫面 store 的資料轉成 JSON 字串,當參數傳至後端 Ext.Ajax
        var Tmp_sub_store = Ext.getCmp("sub_Grid").store;
        var Tmp_JSONString = store2JSON(Tmp_sub_store);
        var np = {};
        np["JSONString"] = Tmp_JSONString;
        //子畫面 submit
        Ext.getCmp('mySubForm').submit({
            //Ext.Ajax.request({
            url: '../../api/V120402DAPI/DoPRNLIST',
            method: 'POST',
            async: false,
       standardSubmit: true,// 非 Ajax 的方式  //若要傳送檔案至前端, standardSubmit必需設為 true 
            params: np,  //把目前 store資料轉成JSON, 當成處理參數 np
        });

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

        mask.show();//使用 mask 需手動呼叫show() 方法下
        var timer = setInterval(function () {
            clearInterval(timer);
            mask.hide();
            timer = null;
            //讀取 cookie的訊息 
            var r = r_cookies('EX_DFile');
            console.log("r_cookies=", r);
            if (!checkisnull(r)) {
                mysuccessalert(r);
            }
        }, 5000);  //3000ms = 3sec
    };  // end of function mySub1_OkBtn_click()


2>*.cs  - SS_FILES 轉成 xls 處理, xls欄位格式設定, 加入圖片

//套表列印 - 借閱記錄 - 列印文件借閱登記簿
        [HttpPost]
        public void DoPRNLIST()
        {
            var c = HttpContext.Current;
            NameValueCollection nvc = c.Request.Form;
            // 1>將 SS_FILES.FBOLD 存成 Local檔案
            //取得目前子畫面的欄位值            
  string Tmp_JSONString = nvc["JSONString"];//Tmp_DataJSON:  將目前子畫面的資料. JSON字串  
            DataTable Tmp_dt = myfunc.JSON2dt(Tmp_JSONString);
            //DataTable DataTable1 = (DataTable)JsonConvert.DeserializeObject(Tmp_DataString1, (typeof(DataTable)));
            
            OracleConnection conn = new OracleConnection(DBService.ConnectionString(DBLINK));//
            OracleCommand cmd = new OracleCommand();

            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 = "V120402_文件借閱登記簿.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 = "V120402_文件借閱登記簿" + 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
                //FileStream fs = File.Open(pathFName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)                
                Worksheet ws = wk.Worksheets[0];//獲取第一個工作表
                                                //寫入[SAPNO][PN][QTY][EOCND][RMK]

                //int RowCnt = 0;  //每頁 行                    
                int PageRowIndex = 0;  //本頁啟始 rowindex
                int PageSize = 29;            //每頁29行 , 含 頁首 行數                        
                int DataSize = 21;           //資料行數 , 資料row 行數
                int PageTitleRows = 6;  //頁首行數 (含資料標題行)
                string Tmp_DOCNO, Tmp_STLCT, Tmp_BRP_, Tmp_TELNO;
                string Tmp_BRDT, Tmp_RTDT, Tmp_REMARK;
                string Tmp_PicName = "V120402_Pic.jpg";
                string Tmp_pathPicName = documentPath + Tmp_PicName;
                int Pages = 0;
                int PageRow = -1;


                //每筆資料列印後, 分頁印下一筆
                for (var i = 0; i < Tmp_dt.Rows.Count; i++)
                {
                    //每筆資料均分頁 & 複製樣板 rows      
                    //每21筆資料,則分頁
                    if ((i % DataSize) ==0)
                    {
                        Pages = Pages + 1;
                        PageRow = -1;                        
                        if (Pages == 2)
                            Console.WriteLine("Pages", Pages);
                        PageRowIndex = PageRowIndex + PageSize;
                        //分頁
                        ws.HPageBreaks.Add(ws.Range[myfunc.GetExcelPos(0, PageRowIndex)]);
                        string Tmp_Range = "A" + string.Format("{0:D}", PageRowIndex + 1) + ":H" + string.Format("{0:D}", PageRowIndex + 1 + (PageSize - 1));
                        ws.Copy(ws.Range["A1:H29"], ws.Range[Tmp_Range], true);
                        Tmp_Range = "D" + string.Format("{0:D}", PageRowIndex + 2) + ":F" + string.Format("{0:D}", PageRowIndex + 2);
                        //文件借閱登記簿 merge - 欄位合併
                        //ws.Range[D2: F2].Merge();
                        ws.Range[Tmp_Range].Merge();
                        //設定列高度
                        ws.SetRowHeight(PageRowIndex + 2, 30);
                        //(Document On-loan Records)  merge
                        Tmp_Range = "D" + string.Format("{0:D}", PageRowIndex + 3) + ":F" + string.Format("{0:D}", PageRowIndex + 3);
                        //ws.Range[D3: F3].Merge();
                        ws.Range[Tmp_Range].Merge();
                        ws.SetRowHeight(PageRowIndex + 3, 25);
                        //加入圖片
                        int Tmp_row = PageRowIndex + 1;


                        //string Tmp_pathPicName = "C:\\Users\\611292\\Desktop\\demo.jpg";
                       //將 SS_FILES 存成檔案(Tmp_PathFName)
                        Tmp_pathPicName = myfunc.SS_FILES2PathFName(Tmp_PicName, DBLINK);  
                        ws.Pictures.Add(Tmp_row, 1, Tmp_pathPicName);
                    }
                    PageRow = PageRow + 1;
                    Tmp_DOCNO = Tmp_dt.Rows[i]["DOCNO"].ToString();
                    Tmp_STLCT = Tmp_dt.Rows[i]["STLCT"].ToString();
                    Tmp_BRP_ = Tmp_dt.Rows[i]["BRP_"].ToString();
                    Tmp_TELNO = Tmp_dt.Rows[i]["TELNO"].ToString();
                    if (Tmp_dt.Rows[i]["BRDT"].ToString().Length > 0)
        Tmp_BRDT = DateTime.Parse(Tmp_dt.Rows[i]["BRDT"].ToString()).ToString("yyyy/MM/dd");
                    else
                        Tmp_BRDT = "";
                    if (Tmp_dt.Rows[i]["RTDT"].ToString().Length > 0)
        Tmp_RTDT = DateTime.Parse(Tmp_dt.Rows[i]["RTDT"].ToString()).ToString("yyyy/MM/dd");
                    else
                        Tmp_RTDT = "";
                    Tmp_REMARK = Tmp_dt.Rows[i]["REMARK"].ToString();                    
ws.Range[myfunc.GetExcelPos(1, PageRowIndex + PageTitleRows + PageRow)].Text =Tmp_DOCNO;
ws.Range[myfunc.GetExcelPos(2, PageRowIndex + PageTitleRows + PageRow)].Text = Tmp_STLCT;
ws.Range[myfunc.GetExcelPos(3, PageRowIndex + PageTitleRows + PageRow)].Text = Tmp_BRP_;
ws.Range[myfunc.GetExcelPos(4, PageRowIndex + PageTitleRows + PageRow)].Text = Tmp_TELNO;
ws.Range[myfunc.GetExcelPos(5, PageRowIndex + PageTitleRows + PageRow)].Text = Tmp_BRDT;
ws.Range[myfunc.GetExcelPos(6, PageRowIndex + PageTitleRows + PageRow)].Text = Tmp_RTDT;
ws.Range[myfunc.GetExcelPos(7, PageRowIndex + PageTitleRows + PageRow)].Text = Tmp_REMARK;                    
                }
                //刪除樣板  rows                            
                ws.DeleteRow(1, PageSize);
                ws.Activate();
                wk.SaveToStream(mstream, FileFormat.Version2007);
                wk.SaveToFile(FileName1, FileFormat.Version2007);
                
                //開啟 xls file
                System.Diagnostics.Process.Start(FileName1);
                //wk.SaveToFile(FileName, ExcelVersion.Version2007);       
                /* 開啟 Local xls 檔案
                 * using System.Diagnostics;
                    Process process = new Process();
                   process.StartInfo.FileName = "WINWORD.EXE";
                   process.StartInfo.Arguments = @"C:\Users\Shani\Desktop\process.docx";
                   process.Start();
                 */
            }
            catch (Exception e)
            {
                var Tmp_ErrMsg = e.Message;                
                Tmp_Str = "開啟XLS檔案 , 錯誤訊息如下<br>"
                                + "(" + FileName + ")報表<br>"
                                + Tmp_ErrMsg;
                HttpCookie MyCookie1 = new HttpCookie("EX_DFile", HttpUtility.UrlEncode(Tmp_Str));
                HttpContext.Current.Response.Cookies.Add(MyCookie1);
                //HttpContext.Current.Response.End();
                //throw;                
            }
            finally
            {
                //reader.Close();
                //bw.Close();
                //fs.Close();
                wk.Dispose();
                conn.Close();
                //wk.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.BinaryWrite(file);
            //HttpContext.Current.Response.ContentType = "application/ms-excel";
            HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            HttpContext.Current.Response.BinaryWrite(mstream.ToArray());
            //包裝標籤檔產生完成
            Tmp_Str = "請開啟如下XLS檔案<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月15日 星期一

V120402C - 隱藏子視窗的分頁Bar , PagingToolbar - 資料全取 -_ptb - Toolbar

 目的: 隱藏子視窗的分頁Bar , PagingToolbar

處理說明: 1>Pagingtoolbar 的id = sub_Grid+"_ptb"
                   2>Ext.getCmp('sub_Grid_ptb').hide();
                        //Ext.getCmp("sub_Grid").bbar.hidden = true;   --> 無效


1>*.js   -     Ext.getCmp('sub_Grid_ptb').hide();

//[續借登記]鈕 - 子視窗
function ContiBtn_click() {
       :
    var win = getMyWindow("續借登記", sub_ContiFlds, sub_ContiFlds_Btns);
    //var win = getMyWindow("續借登記", sub_ContiFlds);
    win.width = 600;
    win.heigh = 400;
    win.show();
    //隱藏[分頁控制] Bar  -->單檔主畫面.PagingToolbar='grid_ptb';
    Ext.getCmp('sub_Grid_ptb').hide();
    //Ext.getCmp("sub_Grid").bbar.hidden = true;  //--> 無效
    console.log("step6");
} // end of   function LendBtn_click() {