private IParamBuilder GetDetailParamBuilder(TableResolver detailResolver, DataRow row, string filterSql) { ParamBuilderContainer container = new ParamBuilderContainer(); container.Add(GetManyToManyParamBuilder(detailResolver, row[fMasterFields[0]])); container.Add(filterSql); return(container); }
private ParamBuilderContainer CreateListCondition(IInputData input) { ParamBuilderContainer condition = new ParamBuilderContainer(); condition.Add(MainResolver.CreateFixCondition()); condition.Add(CreateCustomCondition(input)); condition.Add(GetDataRight(input)); if (FilterSql != null) { string sql = Expression.Execute(FilterSql, this); condition.Add(sql); } return(condition); }
protected virtual TabConditionCount DoTabCountAction(IInputData input) { TabConditionCount result = new TabConditionCount(); if (TabSheets != null && TabSheets.Count > 0) { ParamBuilderContainer condition = CreateListCondition(input); string sql = string.Format(ObjectUtil.SysCulture, "SELECT COUNT(*) FROM {0}", GetTableName(Context)); string queryCon = input.QueryString[CONDITION_HEADER_NAME]; if (!string.IsNullOrEmpty(queryCon)) { queryCon = Uri.UnescapeDataString(queryCon); QueryCondition queryCondition = QueryCondition.FromEncodeString(queryCon); condition.Add(queryCondition.Builder); } foreach (var tabItem in TabSheets) { IParamBuilder builder = condition.IsEmpty ? tabItem.ParamBuilder : ParamBuilder.CreateParamBuilder(condition, tabItem.ParamBuilder); int count = DbUtil.ExecuteScalar(sql, Context, builder).Value <int>(); result.Add(tabItem.Id, count); } } return(result); }
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); }
public IParamBuilder GetCondition(QueryConditionObject condition) { TkDebug.AssertArgumentNull(condition, "condition", this); ParamBuilderContainer container = new ParamBuilderContainer(); foreach (var item in condition.Condition) { if (string.IsNullOrEmpty(item.Value)) { continue; } if (fIgnoreFields.Contains(item.Key)) { continue; } FieldItem field = new FieldItem(item.Key); BaseListSearch search = ObjectUtil.TryGetValue(fSearchMethod, item.Key); if (search == null) { search = fDefaultSearch; } search.Context = Context; search.ConditionData = condition.Condition; search.IsEqual = false; search.FieldName = field; var builder = search.GetCondition(field, item.Value); container.Add(builder); } return(container); }
protected virtual void FillData(IInputData input) { ParamBuilderContainer container = new ParamBuilderContainer(); container.Add(GetDataRight(input)); if (FilterSql != null) { string sql = Expression.Execute(FilterSql, this); container.Add(sql); } if (container.IsEmpty) { MainResolver.Select(); } else { MainResolver.Select(container); } }
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)); } }