public DataSetListModel(DataSet dataSet) : base(dataSet) { PageStyle = dataSet.GetFieldValue <string>("Info", "Style"); HasListButtons = CalcHasListButtons(dataSet); DecoderSelfUrl = dataSet.GetFieldValue <string>("URL", "DSelfURL"); DataRow countRow = dataSet.GetRow("Count"); if (countRow != null) { PageInfo = new CountInfo(1, 1, 1); PageInfo.ReadFromDataRow(countRow); } DataRow sortRow = dataSet.GetRow("Sort"); if (sortRow != null) { SortInfo = new ListSortInfo(null); SortInfo.ReadFromDataRow(sortRow); } DataTable table = dataSet.Tables["ListOperator"]; ListOperators = Operator.ReadFromDataTable(table); table = dataSet.Tables["RowOperator"]; RowOperators = Operator.ReadFromDataTable(table); fEmptyProvider = new DataRowFieldValueProvider(null, dataSet); }
protected void FillListDataSet(IInputData input, int pageNumber, int pageSize, int start) { ParamBuilderContainer condition = CreateListCondition(input); IOperateRight operateRight = null; if (TabSheets != null && TabSheets.Count > 0) { var selectedTab = GetSelectTabSheet(input); selectedTab.Selected = true; condition.Add(selectedTab.ParamBuilder); DataSet.Tables.Add(TabSheets.CreateTable("TabSheet")); } if (input.QueryString["GetData"] != "Page" && !input.IsPost) { MainResolver.FillCodeTable(input.Style); CreateListOperators(input, ref operateRight); } ListSortInfo listInfo = new ListSortInfo(input); string orderby = null; if (input.IsPost) { orderby = SetPostListInfo(input, condition, listInfo); } else { orderby = SetGetListInfo(input, condition, listInfo); } CountInfo pageInfo = CreatePageInfo(input, pageNumber, pageSize, condition); DataSet.Tables.Add(EnumUtil.Convert(pageInfo).CreateTable("Count")); DataSet.Tables.Add(EnumUtil.Convert(listInfo).CreateTable("Sort")); if (pageInfo.TotalCount <= 0) { OnFilledListTables(new FilledListEventArgs(input.IsPost, pageNumber, pageSize, pageInfo.TotalCount, orderby, MainResolver, input.PostObject, condition)); return; } int recCount = pageSize * pageNumber + start; string whereSql = condition.IsEmpty ? string.Empty : "WHERE " + condition.Sql; var listContext = FillListTable(MainResolver.ListFields, GetTableName(Context), MainResolver.GetKeyFieldArray(), whereSql, orderby, recCount, pageSize); SqlSelector selector = new SqlSelector(Context, DataSet); using (selector) { ISimpleAdapter adapter = selector; adapter.SetSql(listContext.ListSql, condition); Context.ContextConfig.SetListData(listContext, adapter, DataSet, recCount, pageSize, FillTableName); MainResolver.AddVirtualFields(); if (Operators != null) { if (operateRight == null) { operateRight = Operators.Right.CreateObject(); } var allOperators = Operators.Operators; if (allOperators != null) { CreateRowOperators(input, operateRight, allOperators); } } MainResolver.Decode(input.Style); OnFilledListTables(new FilledListEventArgs(input.IsPost, pageNumber, pageSize, pageInfo.TotalCount, orderby, MainResolver, input.PostObject, condition)); } }
private string SetPostListInfo(IInputData input, ParamBuilderContainer condition, ListSortInfo listInfo) { MetaDataTableResolver metaResolver = MainResolver as MetaDataTableResolver; if (metaResolver != null) { QueryConditionObject conditionData = input.PostObject.Convert <QueryConditionObject>(); IParamBuilder builder = metaResolver.GetQueryCondition(conditionData); if (builder != null) { QueryCondition queryCondition = new QueryCondition(conditionData.Condition, builder); condition.Add(builder); listInfo.SqlCon = queryCondition.ToEncodeString(); } } if (SortQuery) { //string orderby; //int sort; //string order; var jsonOrder = ParseSortParams2(input); //ParseSortParams(input, out orderby, out sort, out order); //listInfo.SortField = sort; //listInfo.Order = order != "DESC" ? "ASC" : "DESC"; listInfo.JsonOrder = jsonOrder.ToJson(); return(jsonOrder.ToSqlOrder(MainResolver)); } return(string.Empty); }
//private void ParseSortParams(IInputData input, out string orderby, out int sort, out string order) //{ // sort = input.QueryString["Sort"].Value<int>(-1); // order = null; // if (sort == -1 || fListFields == null) // { // orderby = OrderBy; // if (!string.IsNullOrEmpty(orderby) && fListFields != null) // { // int comma = orderby.IndexOf(','); // string subOrder = comma >= 0 ? orderby.Substring(0, comma - 1) : orderby; // sort = fListFields.FindIndex(field => // subOrder.IndexOf(field.FieldName, StringComparison.Ordinal) != -1); // if (sort != -1 && subOrder.IndexOf("DESC", StringComparison.OrdinalIgnoreCase) != -1) // order = "DESC"; // } // } // else // { // if (sort < 0 || sort >= fListFields.Count) // sort = 0; // order = input.QueryString["Order"].Value<string>(string.Empty); // orderby = string.Format(ObjectUtil.SysCulture, "ORDER BY {0} {1}", // fListFields[sort].FieldName, order); // } //} private string SetGetListInfo(IInputData input, ParamBuilderContainer condition, ListSortInfo listInfo) { //string orderby; //int sort; //string order; var jsonOrder = ParseSortParams2(input); //ParseSortParams(input, out orderby, out sort, out order); string queryCon = input.QueryString[CONDITION_HEADER_NAME]; if (!string.IsNullOrEmpty(queryCon)) { queryCon = Uri.UnescapeDataString(queryCon); QueryCondition queryCondition = QueryCondition.FromEncodeString(queryCon); condition.Add(queryCondition.Builder); DataTable queryTable = queryCondition.QueryData.CreateTable("_QueryData"); DataSet.Tables.Add(queryTable); MetaDataTableResolver metaResolver = MainResolver as MetaDataTableResolver; if (metaResolver != null) { metaResolver.DecodeQueryTable(queryTable); } } PrepareConditionData(DataSet.Tables[QUERY_TABLE_NAME], input); //listInfo.SortField = sort; //listInfo.Order = order != "DESC" ? "ASC" : "DESC"; listInfo.SqlCon = queryCon; string result = jsonOrder.ToSqlOrder(MainResolver); // 对于自定义排序,由于无法改变ASC和DESC,将在ToSqlOrder中重置,所以,这行代码要放在后面 listInfo.JsonOrder = jsonOrder.ToJson(); return(result); }