public System.Data.DataTable ChangePageTo(string currPage = "0", string perPageRowCount = "0", Dictionary <string, string> dssPostData = null, string dataTableName = "DataTableName", string dataTableNamespace = "DataTableNameSpace", Dictionary <string, string> columnKeyIDPair = null, System.Web.UI.WebControls.Table t = null) { #region when dataTable Exist columnKeyIDPair = (null == columnKeyIDPair) ? new Dictionary <string, string>() : columnKeyIDPair; this.DataTable = new System.Data.DataTable(dataTableName, dataTableNamespace); columnKeyIDPair.Select(x => this.DataTable.Columns.Add(x.Key)).ToArray(); #endregion try { string date = string.Empty; Dictionary <string, string> dss = dssPostData ?? RequestBus.GetPostData(Request: Request); AjaxResponse ar = new AjaxResponse(); #region set status ar.status = "success"; // ar.location = new Location(); // ar.location.search = "?view=1&date=" + date; #endregion Dictionary <string, AjaxResponse> dsar = new Dictionary <string, AjaxResponse>(); Dictionary <string, List <Dictionary <string, string> > > resultData = new Dictionary <string, List <Dictionary <string, string> > >(); List <Dictionary <string, string> > ldss = new List <Dictionary <string, string> >(); Boolean carryOnAfterEvent = false; #region TableInfo try { currPage = RequestBus.GetPageNum(currPage, dss: dss, currPageNumKeyName: this.Name + this.CurrPageNumKey, pageTotalCountKeyName: this.Name + this.PageTotalCountKey); perPageRowCount = "0" == perPageRowCount ? (dss.TryGetValue(this.Name + this.PerPageRowCountKey, out perPageRowCount) ? perPageRowCount : "5") : perPageRowCount; this.ResultMsgFromService = RequestPageData(dss, currPageNum: currPage, perPageRowCount: perPageRowCount); #region when dataTable Exist try { // fill table with empty data int _perPageRowCount = int.TryParse(perPageRowCount, out _perPageRowCount) ? _perPageRowCount : 5; System.Data.DataRow dr = this.DataTable.NewRow(); Object[] oAry = new Object[columnKeyIDPair.Count]; while (_perPageRowCount-- > 0) { dr = this.DataTable.NewRow(); dr.ItemArray = oAry.Clone() as Object[]; this.DataTable.Rows.InsertAt(dr, 0); } } catch (Exception exd) { } #endregion #region trigger Before PageChange event EventArgsForBeforePageChange eventArgsForBeforePageChange = new EventArgsForBeforePageChange(dss, currPageNum: currPage, perPageRowCount: perPageRowCount); if (false == OnBeforePageChange(eventArgsForBeforePageChange)) { return(this.DataTable); } else { } #endregion #region when dataTable Exist #endregion RFDataTable.ServiceResultMsg resultMsg = this.ResultMsgFromService; if (null == resultMsg) { } else if (resultMsg.DefaultSuccessRetCode != resultMsg.RetCode) { } else { #region trigger WhenPageChange event EventArgsForWhenPageChange eventArgsForWhenPageChange = new EventArgsForWhenPageChange(this.ResultMsgFromService); carryOnAfterEvent = OnPageChange(eventArgsForWhenPageChange); #endregion if (false != carryOnAfterEvent) { #region fill data to result resultData = fillResultDataToResultDict(resultMsg, currPage: currPage, perPageRowCount: perPageRowCount); /* * //ldss = RequestBus.ConvertResultMsgObjj(resultMsg.Obj); * // [{"dptid":"合计 ","zs":"1212","ROWSTAT":null},{"dptid":"6156 ","zs":"11","ROWSTAT":null},{"dptid":"1672 ","zs":"8","ROWSTAT":null}] * ldss = RequestBus.ConvertResultMsgObjj(resultMsg.Obj); * resultData[Name] = ldss; * ldss = RequestBus.ConvertResultMsgObj(resultMsg.Obj); * // [{"recordcount":"744","pagecount":"248","currentpage":"1"}] * string recordCount = "", pageCount = "", currentPage = ""; * ldss.ForEach(delegate(Dictionary<string, string> _dss) * { * _dss.TryGetValue(ServiceResultMsg.RecordCountName, out recordCount); * _dss.TryGetValue(ServiceResultMsg.PageCountName, out pageCount); * _dss.TryGetValue(ServiceResultMsg.CurrentPageName, out currentPage); * }); * currentPage = currentPage ?? currPage; * int currentPageIndex = 0; * int.TryParse(currentPage.Trim(), out currentPageIndex); * currentPageIndex = --currentPageIndex; * int rowTotalCount = 0; * int pageTotalCount = 0; * int.TryParse(recordCount.Trim(), out rowTotalCount); * pageCount = pageCount == "0" ? "1" : pageCount; * int.TryParse(pageCount.Trim(), out pageTotalCount); * resultData[InfoName] = (new List<Dictionary<string, string>> { new Dictionary<string, string> { * { RowTotalCountKey, recordCount}, * { PerPageRowCountKey, Math.Max(int.Parse(perPageRowCount),(0== pageTotalCount? 0: ((rowTotalCount)/(pageTotalCount)+(0==(rowTotalCount)%(pageTotalCount)?0:1)))).ToString() }, * { PageTotalCountKey,pageCount}, * { CurrPageIndexKey, currentPageIndex.ToString() }, * { CurrPageNumKey, currentPage}, * { RowCheckedStatusKey, "false"} * } }); * */ #endregion } else { } } } catch (Exception ex) { } #endregion ar.data = resultData; dsar["d"] = ar; ResultDataToAjaxResponse = ar; try { int _perPageRowCount = 0; List <Dictionary <string, string> > _ldss = new List <Dictionary <string, string> >(); string perPageRowCountStr = String.Empty; #region when dataTable Exist try { // get table info if (this.ResultDataToAjaxResponse.data.TryGetValue(this.InfoName, out _ldss) && null != t) { System.Web.UI.ITextControl itcCurrPageNum = null; itcCurrPageNum = (t.FindControl(t.ID + "_" + this.CurrPageNumKey) as System.Web.UI.ITextControl); string tableCurrPageNum = itcCurrPageNum.Text = (_ldss.FirstOrDefault().TryGetValue(this.CurrPageNumKey, out tableCurrPageNum) ? tableCurrPageNum : itcCurrPageNum.Text); int.TryParse((_ldss.FirstOrDefault().TryGetValue(this.PerPageRowCountKey, out perPageRowCountStr) ? perPageRowCountStr : "1"), out _perPageRowCount); string tablePageTotalCount = (t.FindControl(t.ID + "_" + this.PageTotalCountKey) as System.Web.UI.ITextControl).Text = (_ldss.FirstOrDefault().TryGetValue(this.PageTotalCountKey, out tablePageTotalCount) ? tablePageTotalCount : itcCurrPageNum.Text); string tablePerageRowCount = (t.FindControl(t.ID + "_" + this.PerPageRowCountKey) as System.Web.UI.ITextControl).Text = (_ldss.FirstOrDefault().TryGetValue(this.PerPageRowCountKey, out tablePerageRowCount) ? tablePerageRowCount : "5"); string tableRowTotalCount = (t.FindControl(t.ID + "_" + this.RowTotalCountKey) as System.Web.UI.ITextControl).Text = (_ldss.FirstOrDefault().TryGetValue(this.RowTotalCountKey, out tableRowTotalCount) ? tableRowTotalCount : "x"); #region set paging button status try { System.Web.UI.WebControls.WebControl itcPageLast = (t.FindControl(t.ID + "_" + this.PageLastKey) as System.Web.UI.WebControls.WebControl); System.Web.UI.WebControls.WebControl itcPageNext = (t.FindControl(t.ID + "_" + this.PageNextKey) as System.Web.UI.WebControls.WebControl); System.Web.UI.WebControls.WebControl itcPageFirst = (t.FindControl(t.ID + "_" + this.PageFirstKey) as System.Web.UI.WebControls.WebControl); System.Web.UI.WebControls.WebControl itcPagePrev = (t.FindControl(t.ID + "_" + this.PagePrevKey) as System.Web.UI.WebControls.WebControl); try { if (int.Parse(tablePageTotalCount) > int.Parse(itcCurrPageNum.Text ?? "0")) { itcPageLast.Enabled = true; itcPageLast.CssClass = itcPageLast.CssClass.Replace("disabled", ""); itcPageNext.Enabled = true; itcPageNext.CssClass = itcPageNext.CssClass.Replace("disabled", ""); } else { } } catch (Exception exe) { } try { if (int.Parse(itcCurrPageNum.Text ?? "0") > 1) { itcPageFirst.Enabled = true; itcPageFirst.CssClass = itcPageFirst.CssClass.Replace("disabled", ""); itcPagePrev.Enabled = true; itcPagePrev.CssClass = itcPagePrev.CssClass.Replace("disabled", ""); } else { } } catch (Exception exe) { } } catch (Exception ex) { } #endregion } else { } } catch (Exception exe) { } #endregion #region trigger After PageChange event EventArgsForAfterPageChange eventArgsForAfterPageChange = new EventArgsForAfterPageChange(this.ResultDataToAjaxResponse); carryOnAfterEvent = OnAfterPageChange(eventArgsForAfterPageChange); #endregion try { // fill the data if (this.ResultDataToAjaxResponse.data.TryGetValue(this.Name, out _ldss)) { this.DataTable.Rows.Clear(); System.Data.DataRow dr = this.DataTable.NewRow(); _ldss.ForEach(delegate(Dictionary <String, String> _dss) { dr = this.DataTable.NewRow(); dr.ItemArray = columnKeyIDPair.Select((KeyValuePair <string, string> x, int i) => { string _tmpStr = _dss.ContainsKey(x.Value) ? _dss[x.Value] : String.Empty; return(_tmpStr); }).ToArray(); this.DataTable.Rows.InsertAt(dr, 0); }); Object[] oAry = new Object[columnKeyIDPair.Count]; if (_perPageRowCount > this.DataTable.Rows.Count) { int tmpCount = _perPageRowCount - this.DataTable.Rows.Count; while (tmpCount-- > 0) { dr = this.DataTable.NewRow(); dr.ItemArray = oAry.Clone() as Object[]; this.DataTable.Rows.InsertAt(dr, 0); } } else { } } else { } } catch (Exception exf) { } } catch (Exception exd) { } if (false != carryOnAfterEvent) { Response.ClearContent(); List <Dictionary <string, string> > _ldss = new List <Dictionary <string, string> >(); if (this.ResultDataToAjaxResponse.data.TryGetValue(this.Name, out _ldss)) { columnKeyIDPair.Select((KeyValuePair <string, string> x, int i) => { RequestBus.ChangeKeyNameOfLDSS(x.Value, x.Key, _ldss); return(x.Value); }).ToArray(); } else { } Response.Write(RF.GlobalClass.Utils.Convert.ObjectToJSON(dsar)); // Response.End(); HttpContext.Current.Response.Flush(); // Sends all currently buffered output to the client. HttpContext.Current.Response.SuppressContent = true; // Gets or sets a value indicating whether to send HTTP content to the client. HttpContext.Current.ApplicationInstance.CompleteRequest(); // Causes ASP.NET to bypass all events and filtering in the HTTP pipeline chain of execution and directly execute the EndRequest event. } else { } } catch (Exception ex) { Response.ClearContent(); AjaxResponse ar = new AjaxResponse(); Dictionary <string, AjaxResponse> dsar = new Dictionary <string, AjaxResponse>(); ar.status = "failure"; ar.message = "系统异常,请稍后再试。"; // ex.Message; dsar["d"] = ar; Response.Write(RF.GlobalClass.Utils.Convert.ObjectToJSON(dsar)); Response.End(); } return(this.DataTable); }
/// <summary> /// Get data for table list /// </summary> /// <param name="tableName"></param> /// <param name="tableNameSpace"></param> /// <param name="tableCurrPageNum"></param> /// <param name="tablePerPageRowCount"></param> /// <param name="beforePageChange"></param> /// <param name="whenPageChange"></param> /// <param name="afterPageChange"></param> /// <param name="request"></param> /// <param name="response"></param> /// <param name="table"></param> /// <param name="columnKeyIDPair"></param> /// <param name="perPageRowCountControl"></param> /// <param name="currPageNumControl"></param> /// <param name="pageTatolCountControl"></param> /// <param name="rowTotalCountControl"></param> /// <param name="perPageRowCountName"></param> /// <param name="currPageNumName"></param> /// <param name="pageTotalCountName"></param> /// <param name="rowTotalCountName"></param> /// <param name="jumpingDataName"></param> /// <param name="perPageRowCountParamName"></param> /// <param name="dataSet"></param> /// <example> /// <code language="CSharp" description=""> /// WebAppOffice.GB.WebReference.getDataForListTable(tableName: "", tableNameSpace: "", tableCurrPageNum: "1", tablePerPageRowCount: "10", /// beforePageChange: (new WebAppOffice.RFDataTable.BeforePageChangeHandler(rfdtarql_BeforePageChange)), /// whenPageChange: (new WebAppOffice.RFDataTable.WhenPageChangeHandler(rfdtarql_WhenPageChange)), /// afterPageChange: (new WebAppOffice.RFDataTable.AfterPageChangeHandler(rfdtarql_AfterPageChange)), /// request: Request, response: Response, /// table: v2_TableInformationQueryItemList, /// columnKeyIDPair: new Dictionary<string, string> { /// { "Code", "dptid" }, { "Name", "dptdes" }, /// { "Address", "adr1" }, { "PhoneNumber", "tel" }, /// {"Section","prtdptid"},{"EffectsRadius","jl"}, /// {"MasterName","xm"},{"MasterPhoneNumber","sj"}, /// {"SectionDirectorName","prtdz"},{"SectionDirectorPhoneNumber","prtdztel"} }, /// perPageRowCountControl: v2_TableInformationQueryItemList_PerPageRowCount, /// currPageNumControl: v2_TableInformationQueryItemList_CurrPageNum, /// pageTatolCountControl: v2_TableInformationQueryItemList_PageTotalCount, /// rowTotalCountControl: v2_TableInformationQueryItemList_RowTotalCount, /// perPageRowCountName: "PerPageRowCount", /// currPageNumName: "CurrPageNum", /// pageTotalCountName: "pageTotalCount", /// rowTotalCountName: "RowTotalCount", /// jumpingDataName: "jumpdata", /// perPageRowCountParamName: "PerPageRowCount", dataSet:dataSet); /// </code> /// </example> public static void getDataForListTable(string tableName, string tableNameSpace, string tableCurrPageNum, string tablePerPageRowCount, RFDataTable.BeforePageChangeHandler beforePageChange, RFDataTable.WhenPageChangeHandler whenPageChange, RFDataTable.AfterPageChangeHandler afterPageChange, HttpRequest request, HttpResponse response, System.Web.UI.WebControls.Table table, Dictionary <string, string> columnKeyIDPair, System.Web.UI.WebControls.DropDownList perPageRowCountControl, System.Web.UI.WebControls.TextBox currPageNumControl, System.Web.UI.WebControls.Label pageTatolCountControl, System.Web.UI.WebControls.Label rowTotalCountControl, string perPageRowCountName, string currPageNumName, string pageTotalCountName, string rowTotalCountName, string jumpingDataName, string perPageRowCountParamName, System.Data.DataSet dataSet, RFDataTable rfDataTable) { Dictionary <string, string> dssPost = new Dictionary <string, string>(); Dictionary <string, string> dssPut = RequestBus.GetPutData(request); Dictionary <String, List <Dictionary <string, string> > > dsldssPost = RequestBus.GetPostData <Dictionary <String, List <Dictionary <string, string> > > >(request); AjaxResponse ar = new AjaxResponse(); ar.data = dsldssPost; string jumpdata = RequestBus.Param(jumpingDataName); List <Dictionary <string, string> > ldss = new List <Dictionary <string, string> >(); rfDataTable = rfDataTable ?? new RFDataTable(tableName, request: request, response: response); rfDataTable.Name = tableName ?? rfDataTable.Name; tableName = rfDataTable.Name; if (null != dsldssPost && ((dsldssPost.TryGetValue(jumpdata, out ldss)) || dsldssPost.ContainsKey(tableName + perPageRowCountParamName))) { #region set data to the view // ldss[0].TryGetValue("", out jumpdata); dssPost = (ldss.Count > 0 ? (ldss[0] ?? dssPost) : dssPost); dssPut.ToList().ForEach(x => dssPost[x.Key] = dssPost.ContainsKey(x.Key) ? dssPost[x.Key] : x.Value); //string beginDate = v0_BeginDate.Text = dssPost.TryGetValue("BeginDate", out beginDate) ? beginDate : String.Empty; //string endDate = v0_EndDate.Text = dssPost.TryGetValue("EndDate", out endDate) ? endDate : String.Empty; perPageRowCountControl.Text = tablePerPageRowCount ?? perPageRowCountControl.Text; tablePerPageRowCount = perPageRowCountControl.Text = dssPost.TryGetValue(tableName + perPageRowCountName, out tablePerPageRowCount) ? tablePerPageRowCount : perPageRowCountControl.Text; tableCurrPageNum = currPageNumControl.Text = dssPost.TryGetValue(tableName + currPageNumName, out tableCurrPageNum) ? tableCurrPageNum : tableCurrPageNum; string TablePageTotalCount = pageTatolCountControl.Text = dssPost.TryGetValue(tableName + pageTotalCountName, out TablePageTotalCount) ? TablePageTotalCount : tableCurrPageNum; string TableRowTotalCount = rowTotalCountControl.Text = dssPost.TryGetValue(tableName + rowTotalCountName, out TableRowTotalCount) ? TableRowTotalCount : "X"; #endregion } else { } int perPageRowCount = int.TryParse(tablePerPageRowCount, out perPageRowCount) ? perPageRowCount : 5; rfDataTable.BeforePageChange += new RFDataTable.BeforePageChangeHandler(beforePageChange); rfDataTable.WhenPageChange += new RFDataTable.WhenPageChangeHandler(whenPageChange); rfDataTable.AfterPageChange += new RFDataTable.AfterPageChangeHandler(afterPageChange); dataSet.Tables.Add(rfDataTable.ChangePageTo( currPage: tableCurrPageNum, perPageRowCount: perPageRowCount.ToString(), dssPostData: dssPost, dataTableName: tableName, dataTableNamespace: tableNameSpace, columnKeyIDPair: columnKeyIDPair, t: table)); }
public void _ChangePageTo(string currPage = "0", string perPageRowCount = "0", Dictionary <string, string> dssPostData = null) { try { string date = string.Empty; Dictionary <string, string> dss = RequestBus.GetPostData(Request: Request) ?? dssPostData; AjaxResponse ar = new AjaxResponse(); #region set status ar.status = "success"; // ar.location = new Location(); // ar.location.search = "?view=1&date=" + date; #endregion Dictionary <string, AjaxResponse> dsar = new Dictionary <string, AjaxResponse>(); Dictionary <string, List <Dictionary <string, string> > > resultData = new Dictionary <string, List <Dictionary <string, string> > >(); List <Dictionary <string, string> > ldss = new List <Dictionary <string, string> >(); Boolean carryOnAfterEvent = false; #region TableInfo try { currPage = RequestBus.GetPageNum(currPage, dss: dss, currPageNumKeyName: this.Name + this.CurrPageNumKey, pageTotalCountKeyName: this.Name + this.PageTotalCountKey); perPageRowCount = "0" == perPageRowCount ? (dss.TryGetValue(this.Name + this.PerPageRowCountKey, out perPageRowCount) ? perPageRowCount : "5") : perPageRowCount; this.ResultMsgFromService = RequestPageData(dss, currPageNum: currPage, perPageRowCount: perPageRowCount); #region trigger Before PageChange event EventArgsForBeforePageChange eventArgsForBeforePageChange = new EventArgsForBeforePageChange(dss, currPageNum: currPage, perPageRowCount: perPageRowCount); if (false == OnBeforePageChange(eventArgsForBeforePageChange)) { return; } else { } #endregion RFDataTable.ServiceResultMsg resultMsg = this.ResultMsgFromService; if (null == resultMsg) { } else if ("00" != resultMsg.RetCode) { } else { #region trigger WhenPageChange event EventArgsForWhenPageChange eventArgsForWhenPageChange = new EventArgsForWhenPageChange(this.ResultMsgFromService); carryOnAfterEvent = OnPageChange(eventArgsForWhenPageChange); #endregion if (false != carryOnAfterEvent) { #region fill data to result //ldss = RequestBus.ConvertResultMsgObjj(resultMsg.Obj); // [{"dptid":"合计 ","zs":"1212","ROWSTAT":null},{"dptid":"6156 ","zs":"11","ROWSTAT":null},{"dptid":"1672 ","zs":"8","ROWSTAT":null}] ldss = RequestBus.ConvertResultMsgObjj(resultMsg.Obj); resultData[Name] = ldss; ldss = RequestBus.ConvertResultMsgObj(resultMsg.Obj); // [{"recordcount":"744","pagecount":"248","currentpage":"1"}] string recordCount = "", pageCount = "", currentPage = ""; ldss.ForEach(delegate(Dictionary <string, string> _dss) { _dss.TryGetValue(ServiceResultMsg.RecordCountName, out recordCount); _dss.TryGetValue(ServiceResultMsg.PageCountName, out pageCount); _dss.TryGetValue(ServiceResultMsg.CurrentPageName, out currentPage); }); currentPage = currentPage ?? currPage; int currentPageIndex = 0; int.TryParse(currentPage.Trim(), out currentPageIndex); currentPageIndex = --currentPageIndex; int rowTotalCount = 0; int pageTotalCount = 0; int.TryParse(recordCount.Trim(), out rowTotalCount); pageCount = pageCount == "0" ? "1" : pageCount; int.TryParse(pageCount.Trim(), out pageTotalCount); resultData[InfoName] = (new List <Dictionary <string, string> > { new Dictionary <string, string> { { RowTotalCountKey, recordCount }, { PerPageRowCountKey, Math.Max(int.Parse(perPageRowCount), (0 == pageTotalCount? 0: ((rowTotalCount) / (pageTotalCount) + (0 == (rowTotalCount) % (pageTotalCount)?0:1)))).ToString() }, { PageTotalCountKey, pageCount }, { CurrPageIndexKey, currentPageIndex.ToString() }, { CurrPageNumKey, currentPage }, { RowCheckedStatusKey, "false" } } }); #endregion } else { } } } catch (Exception ex) { } #endregion ar.data = resultData; dsar["d"] = ar; ResultDataToAjaxResponse = ar; #region trigger After PageChange event EventArgsForAfterPageChange eventArgsForAfterPageChange = new EventArgsForAfterPageChange(this.ResultDataToAjaxResponse); carryOnAfterEvent = OnAfterPageChange(eventArgsForAfterPageChange); #endregion if (false != carryOnAfterEvent) { Response.ClearContent(); Response.Write(RF.GlobalClass.Utils.Convert.ObjectToJSON(dsar)); // Response.End(); HttpContext.Current.Response.Flush(); // Sends all currently buffered output to the client. HttpContext.Current.Response.SuppressContent = true; // Gets or sets a value indicating whether to send HTTP content to the client. HttpContext.Current.ApplicationInstance.CompleteRequest(); // Causes ASP.NET to bypass all events and filtering in the HTTP pipeline chain of execution and directly execute the EndRequest event. } else { } } catch (Exception ex) { Response.ClearContent(); AjaxResponse ar = new AjaxResponse(); Dictionary <string, AjaxResponse> dsar = new Dictionary <string, AjaxResponse>(); ar.status = "failure"; ar.message = "系统异常,请稍后再试。"; // ex.Message; dsar["d"] = ar; Response.Write(RF.GlobalClass.Utils.Convert.ObjectToJSON(dsar)); Response.End(); } }