顯示具有 getDataTable1 標籤的文章。 顯示所有文章
顯示具有 getDataTable1 標籤的文章。 顯示所有文章

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  , 資料顯示