Ext.grid.Panel表格分页存储过程

 /*首先需要引入两个Extjs插件类  Ext.ux.data.PagingMemoryProxy和Ext.ux.ProgressBarPager这两个类*/

/*下面是控制弹出窗体放大缩小时窗体居中的方法*/

1 var HotalOrderResizeCenterWindow; 2 Ext.EventManager.onWindowResize(function() { 3 if (HotalOrderResizeCenterWindow) { 4 HotalOrderResizeCenterWindow.setHeight(480); 5 HotalOrderResizeCenterWindow.setWidth(1225); 6 HotalOrderResizeCenterWindow.center() 7 } 8 }); 9  /*下面这个方法是根据加载STORE值时,控制某字段样式的*/ 11 function changeIsOrNoReturnRoom(val) { 12 if (val == '未退房') { 13 return '<span style="color:black;">' + val + '</span>' 14 } else if (val == "已退房") { 15 return '<span style="color:red;">' + val + '</span>' 16 } 17 return val 18 } 19 20
  /*store的实体类*/ 21 Ext.define('RoomOrder', { 22 extend: 'Ext.data.Model', 23 idProperty: 'roomorder', 24 fields: [{ 25 name: 'orderId' 26 }, { 27 name: 'orderForAdmin' 28 }, { 29 name: 'orderCustomerName' 30 }, { 31 name: 'orderCustomerIDcard' 32 }, { 33 name: 'orderCustomerPhone' 34 }, { 35 name: 'orderRoomNumber' 36 }, { 37 name: 'orderRoomPrice', 38 type: 'float' 39 }, { 40 name: 'orderCashPledge', 41 type: 'float' 42 }, { 43 name: 'orderOpenRoomTime' 44 }, { 45 name: 'orderRuleReturnRoomTime' 46 }, { 47 name: 'orderCheckInDayCount' 48 }, { 49 name: 'orderIsOrNoReturnRoom' 50 }, { 51 name: 'orderReturnRoomTime' 52 }] 53 }); 54 55
  /*gride的store*/ 56 var store = Ext.create('Ext.data.Store', { 57 model: 'RoomOrder', 58 pageSize: 3,/*这个参数就是每页加载数据的条数,这个参数都会在你POST或GET时,自动加为参数*/ 59 autoLoad: true, 60 proxy: { 61 type: 'ajax', 62 url: 'shareMediumPage.ashx', 63 reader: { 64 root: 'data',
/*totalProperty这个字段很重要是符合查询条件的所有数据的总条数,虽然
查询时只需要查询出需要的部分,但是返回的数据中必须加上这个总数量字段,这个字段原本在你数据库的表中肯定是没有,需要你反回数据时自加上,后面数据库部分有说明*/
65 totalProperty: 'allCount' 66 }, 67 extraParams: { 68 sign: '12', 69 loadSign: '0' 70 } 71 }, 72 remoteSort: true, 73 listeners: { 74 beforeload: function() {} 75 } 76 });
  /*gride的tabbar*/
77 var orderContronllerBar = Ext.create("Ext.Toolbar", { 78 items: ['', "-", 79 { 80 xtype: "splitbutton", 81 text: '未退房', 82 menu: true, 83 handler: function() { 84 alert("liaohang") 85 }, 86 }, '', "-", 87 { 88 xtype: "splitbutton", 89 text: '已退房', 90 handler: function() { 91 alert("liaohang") 92 } 93 }, "关键字:", 94 { 95 xtype: 'textfield', 96 id: 'searchBar' 97 }, { 98 xtype: 'button', 99 text: "搜索", 100 handler: function() { 101 alert("al;ksdfjaljdsfljfas") store.load({ 102 params: { 103 keyword: Ext.getCmp("searchBar").getValue() 104 } 105 }) 106 } 107 }] 108 }); 109 110
  /*grid类*/ 111 Ext.define('HotalOrderWindowContentPanelClass', { 112 extend: 'Ext.grid.Panel', 113 xtype: 'OrderPanelXtype', 114 id: "orderListGridPanel", 115 title: '订单', 116 store: store, 117 columns: [new Ext.grid.RowNumberer({ 118 text: "序号", 119 width: 40, 120 dataIndex: function(value, metadata, record, rowIndex) { 121 return 1 + rowIndex 122 } 123 }), 124 { 125 id: 'orderCustomerName', 126 text: '姓名', 127 sortable: true, 128 dataIndex: 'orderCustomerName', 129 width: 75 130 }, { 131 text: '身份证号', 132 sortable: true, 133 dataIndex: 'orderCustomerIDcard', 134 width: 175 135 }, { 136 text: '电话', 137 sortable: true, 138 dataIndex: 'orderCustomerPhone', 139 width: 120 140 }, { 141 text: '房号', 142 sortable: true, 143 dataIndex: 'orderRoomNumber', 144 width: 100 145 }, { 146 text: '价格', 147 sortable: true, 148 renderer: Ext.util.Format.usMoney, 149 dataIndex: 'orderRoomPrice', 150 width: 100 151 }, { 152 text: '押金', 153 sortable: true, 154 renderer: Ext.util.Format.usMoney, 155 dataIndex: 'orderCashPledge', 156 width: 100 157 }, { 158 text: '入住时间', 159 sortable: true, 160 dataIndex: 'orderOpenRoomTime', 161 width: 125 162 }, { 163 text: '必须退房时间', 164 sortable: true, 165 dataIndex: 'orderRuleReturnRoomTime', 166 width: 125 167 }, { 168 text: '入住天数', 169 sortable: true, 170 dataIndex: 'orderCheckInDayCount', 171 width: 75 172 }, { 173 text: '是否退房', 174 sortable: true, 175 renderer: changeIsOrNoReturnRoom, 176 dataIndex: 'orderIsOrNoReturnRoom', 177 width: 75 178 }, { 179 text: '退房时间', 180 sortable: true, 181 dataIndex: 'orderReturnRoomTime', 182 width: 134 183 }], 184 stripeRows: true, 185 tbar: orderContronllerBar, 186 height: 450, 187 width: 1210, 188 frame: true, 189 bbar: Ext.create('Ext.PagingToolbar', { 190 store: store, 191 displayInfo: true, 192 plugins: Ext.create('Ext.ux.ProgressBarPager', {}) 193 }) 194 }) 195 196 197
  /*主窗体*/ 198 Ext.define("HotalOrderWindowClass", { 199 extend: "Ext.window.Window", 200 requests: [], 201 id: 'HotalOrderManagerWindow', 202 xtype: 'HotalOrderManagerXtype', 203 title: "订单管理", 204 height: 480, 205 width: 1225, 206 autoRender: true, 207 region: 'center', 208 autoScroll: false, 209 closable: true, 210 border: 0, 211 plain: true, 212 layout: 'border', 213 closeAction: 'hide', 214 draggable: true, 215 floating: true, 216 items: [{ 217 xtype: 'OrderPanelXtype', 218 title: '', 219 frame: true, 220 }], 221 listeners: { 222 'show': function(e) {}, 223 'beforeshow': function(o) { 224 HotalOrderResizeCenterWindow = o 225 }, 226 'destroy': function(o) { 227 HotalOrderResizeCenterWindow = null 228 } 229 } 230 })

 

 

  /*Post页面代码  shareMediumPage.ashx*/

 1  public void ProcessRequest(HttpContext context)
 2      {
 3          HttpResponse res = context.Response;
 4          shareMediumPage master = new shareMediumPage();
 5          HttpRequest req = context.Request;
 6          JavaScriptSerializer jss = new JavaScriptSerializer();
 7          int sgin =Convert.ToInt32( req["sign"]);
 8          string adminName = "adsfasaf";
 9          int sPage = Convert.ToInt32(req["page"]);//extjs自加的参数
10          int sStart = Convert.ToInt32(req["start"]);//extjs自加的参数
11          int sLimit = Convert.ToInt32(req["limit"]);//extjs自加的参数
12           //由于我们是在存储过程中处理的,所以三个参数中我们只需要两个 sPage, sLimit
13 
14          string currentDatetime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
15          currentDatetime = Convert.ToDateTime(currentDatetime).Ticks.ToString();
16          res.Write(OptionLoadOrder(req["loadSign"].ToString(), adminName, currentDatetime, sPage, sLimit));
17          res.ContentType = "text/plain";
18          res.End();
19 
20      }

 1  public String OptionLoadOrder(string loadSign, string adminName, string currentDatetime, int pageIndex, int pageSize)  
 2       {  
 3 
 4           shareParameter = new SqlParameter[] { new SqlParameter("@loadSign", loadSign), new SqlParameter("@adminName", adminName), new SqlParameter("@currentDatetime", currentDatetime)
 5             , new SqlParameter("@PageIndex", pageIndex), new SqlParameter("@PageSize", pageSize)};
 6           SqlDataReader reader = SqlHelper.SqlHelper.ExecuteReader(SqlHelper.SqlHelper.connecString, "proc_AccodingPassTypeLoadOrder", shareParameter);
 7 
 8           ORDERLIST list = new ORDERLIST();
 9           List<orderClass> data = new List<orderClass>();
10        
11           while (reader.Read())
12           {
13               list.allCount=Convert.ToInt32(reader["allCount"]);
14               orderClass order = new orderClass();
15               order.orderId = reader["orderId"].ToString();
16               order.orderForAdmin = reader["orderForAdmin"].ToString();
17               
18               order.orderCustomerName = reader["orderCustomerName"].ToString();
19               order.orderCustomerIDcard = reader["orderCustomerIDcard"].ToString();
20               order.orderCustomerPhone = reader["orderCustomerPhone"].ToString();
21               order.orderRoomNumber = reader["orderRoomNumber"].ToString();
22               order.orderRoomPrice = reader["orderRoomPrice"].ToString();
23               order.orderCashPledge = reader["orderCashPledge"].ToString();
24               order.orderOpenRoomTime = reader["orderOpenRoomTime"].ToString();
25               order.orderRuleReturnRoomTime = reader["orderRuleReturnRoomTime"].ToString();
26               order.orderCheckInDayCount = reader["orderCheckInDayCount"].ToString();
27               order.orderIsOrNoReturnRoom = reader["orderIsOrNoReturnRoom"].ToString();
28               order.orderReturnRoomTime = reader["orderReturnRoomTime"].ToString();
29               data.Add(order);
30           }
31 
32           list.data = data;
33           return jss.Serialize(list);
34       }

 

 /*数据库存储过程*/

 

 1 create proc [dbo].[proc_AccodingPassTypeLoadOrder]
 2  
 3  @loadSign varchar(50), 
 4  @adminName  varchar(50),
 5  @currentDatetime varchar(50),
 6  @PageIndex int, /*第几页*/
 7   @PageSize int  /*每页的行数*/
 8 as
 9 declare @BeginRow int 
10 declare @EndRow int
11                
12 set @BeginRow=@PageSize*(@PageIndex-1)+1; /*获得分页第一行所在位置*/
13 set @EndRow=@PageSize*@PageIndex;/*获得分页最后一行所在位置*/
14 declare @allCount int/*这个参数就是存放符合条件的所有数据总数量,然后加入返回数据中作为一个字段*/
15 if(@loadSign=0) --加载所有
16 begin
17 select @allCount=COUNT(*) from hotalOrderSheet where orderForAdmin=@adminName
18  select * from (select ROW_NUMBER() over(order by(orderId)) as RowIndex,@allCount as allCount, * from hotalOrderSheet where orderForAdmin=@adminName) as a
19 where RowIndex between @BeginRow and @EndRow 
20 --select * from hotalOrderSheet
21   
22 end 
23 else if(@loadSign=1)--未退房
24 begin
25 select @allCount=COUNT(*) from hotalOrderSheet where orderForAdmin=@adminName and orderIsOrNoReturnRoom is null  and orderReturnRoomTime is null
26 select * from (select ROW_NUMBER() over(order by(orderId)) as RowIndex,@allCount as allCount,* from hotalOrderSheet  where orderForAdmin=@adminName and    orderIsOrNoReturnRoom is null  and orderReturnRoomTime is null) as a
27 where RowIndex between @BeginRow and @EndRow
28  
29  
30 end
31 else if(@loadSign=2)--已退房
32 begin
33 
34 select @allCount=COUNT(*) from hotalOrderSheet where orderForAdmin=@adminName and orderIsOrNoReturnRoom is not null    and orderReturnRoomTime is not null
35 select * from (select ROW_NUMBER() over(order by(orderId)) as RowIndex,@allCount as allCount,* from hotalOrderSheet  where orderForAdmin=@adminName and    orderIsOrNoReturnRoom is not null  and orderReturnRoomTime is not null) as a
36 where RowIndex between @BeginRow and @EndRow
37  
38 end
39 else if(@loadSign=3)--超时退房用户
40 begin
41 
42 
43 select @allCount=COUNT(*) from dbo.getOverTimeReturnCustomerList(@adminName,@currentDatetime)
44 select * from  (select ROW_NUMBER() over(order by(orderId)) as RowIndex, @allCount as allCount, * from  dbo.getOverTimeReturnCustomerList(@adminName,@currentDatetime)) as a
45 where RowIndex between @BeginRow and @EndRow
46 end

 

 

 

 

 下面是效果图

Ext.grid.Panel表格分页存储过程_第1张图片

 

你可能感兴趣的:(Ext.grid.Panel表格分页存储过程)