コード例 #1
0
        object[] IDataController.GetListOfValues(string controller, string view, DistinctValueRequest request)
        {
            SelectView(controller, view);
            ViewPage page = new ViewPage(request);

            page.ApplyDataFilter(_config.CreateDataFilter(), controller, view, request.LookupContextController, request.LookupContextView, request.LookupContextFieldName);
            List <object> distinctValues = new List <object>();
            BusinessRules rules          = _config.CreateBusinessRules();

            _serverRules = rules;
            if (_serverRules == null)
            {
                _serverRules = CreateBusinessRules();
            }
            _serverRules.Page = page;
            if (rules != null)
            {
                rules.BeforeSelect(request);
            }
            else
            {
                _serverRules.ExecuteServerRules(request, ActionPhase.Before);
            }
            using (DbConnection connection = CreateConnection())
            {
                DbCommand command = CreateCommand(connection);
                ConfigureCommand(command, page, CommandConfigurationType.SelectDistinct, null);
                DbDataReader reader = command.ExecuteReader();
                while (reader.Read() && (distinctValues.Count < page.PageSize))
                {
                    object v = reader.GetValue(0);
                    if (!(DBNull.Value.Equals(v)))
                    {
                        v = ConvertObjectToValue(v);
                    }
                    distinctValues.Add(v);
                }
                reader.Close();
            }
            if (rules != null)
            {
                rules.AfterSelect(request);
            }
            else
            {
                _serverRules.ExecuteServerRules(request, ActionPhase.After);
            }
            return(distinctValues.ToArray());
        }
コード例 #2
0
ファイル: Controller.Core.cs プロジェクト: Ashrafnet/XIOT
        ViewPage IDataController.GetPage(string controller, string view, PageRequest request)
        {
            SelectView(controller, view);
            request.AssignContext(controller, this._viewId);
            ViewPage page = new ViewPage(request);

            if (_config.PlugIn != null)
            {
                _config.PlugIn.PreProcessPageRequest(request, page);
            }
            _config.AssignDynamicExpressions(page);
            page.ApplyDataFilter(_config.CreateDataFilter(), request.Controller, request.View, request.LookupContextController, request.LookupContextView, request.LookupContextFieldName);
            BusinessRules rules = _config.CreateBusinessRules();

            if (rules != null)
            {
                rules.Page = page;
                rules.BeforeSelect(request);
            }
            else
            {
                CreateBusinessRules().ExecuteServerRules(request, ActionPhase.Before);
            }
            using (DbConnection connection = CreateConnection())
            {
                if (page.RequiresRowCount && !((request.Inserting || request.DoesNotRequireData)))
                {
                    DbCommand countCommand = CreateCommand(connection);
                    ConfigureCommand(countCommand, page, CommandConfigurationType.SelectCount, null);
                    if (YieldsSingleRow(countCommand))
                    {
                        page.TotalRowCount = 1;
                    }
                    else
                    {
                        page.TotalRowCount = Convert.ToInt32(countCommand.ExecuteScalar());
                    }
                    if (page.RequiresAggregates)
                    {
                        DbCommand aggregateCommand = CreateCommand(connection);
                        ConfigureCommand(aggregateCommand, page, CommandConfigurationType.SelectAggregates, null);
                        DbDataReader reader = aggregateCommand.ExecuteReader();
                        if (reader.Read())
                        {
                            object[] aggregates = new object[page.Fields.Count];
                            for (int i = 0; (i < aggregates.Length); i++)
                            {
                                DataField field = page.Fields[i];
                                if (field.Aggregate != DataFieldAggregate.None)
                                {
                                    object v = reader[field.Name];
                                    if (!(DBNull.Value.Equals(v)))
                                    {
                                        aggregates[i] = v;
                                    }
                                }
                            }
                            page.Aggregates = aggregates;
                        }
                        reader.Close();
                    }
                }
                if (page.RequiresMetaData)
                {
                    PopulatePageCategories(page);
                }
                DbCommand selectCommand = CreateCommand(connection);
                ConfigureCommand(selectCommand, page, CommandConfigurationType.Select, null);
                if ((page.PageSize > 0) && !((request.Inserting || request.DoesNotRequireData)))
                {
                    DbDataReader reader = null;
                    if (selectCommand == null)
                    {
                        reader = ExecuteVirtualReader(request, page);
                    }
                    else
                    {
                        reader = TransactionManager.ExecuteReader(request, page, selectCommand);
                    }
                    while (page.SkipNext())
                    {
                        reader.Read();
                    }
                    while (page.ReadNext() && reader.Read())
                    {
                        object[] values = new object[page.Fields.Count];
                        for (int i = 0; (i < values.Length); i++)
                        {
                            DataField field = page.Fields[i];
                            object    v     = reader[field.Name];
                            if (!(DBNull.Value.Equals(v)))
                            {
                                if (field.IsMirror)
                                {
                                    v = String.Format(field.DataFormatString, v);
                                }
                                else
                                {
                                    v = ConvertObjectToValue(v);
                                }
                                values[i] = v;
                            }
                            if (!(String.IsNullOrEmpty(field.SourceFields)))
                            {
                                values[i] = CreateValueFromSourceFields(field, reader);
                            }
                        }
                        page.Rows.Add(values);
                    }
                    reader.Close();
                }
                if (request.RequiresFirstLetters && this._viewType != "Form")
                {
                    if (!(page.RequiresRowCount))
                    {
                        page.FirstLetters = String.Empty;
                    }
                    else
                    {
                        DbCommand firstLettersCommand = CreateCommand(connection);
                        string[]  oldFilter           = page.Filter;
                        ConfigureCommand(firstLettersCommand, page, CommandConfigurationType.SelectFirstLetters, null);
                        page.Filter = oldFilter;
                        if (!(String.IsNullOrEmpty(page.FirstLetters)))
                        {
                            DbDataReader  reader       = firstLettersCommand.ExecuteReader();
                            StringBuilder firstLetters = new StringBuilder(page.FirstLetters);
                            while (reader.Read())
                            {
                                firstLetters.Append(",");
                                string letter = Convert.ToString(reader[0]);
                                if (!(String.IsNullOrEmpty(letter)))
                                {
                                    firstLetters.Append(letter);
                                }
                            }
                            reader.Close();
                            page.FirstLetters = firstLetters.ToString();
                        }
                    }
                }
            }
            if (_config.PlugIn != null)
            {
                _config.PlugIn.ProcessPageRequest(request, page);
            }
            if (rules != null)
            {
                IRowHandler rowHandler = rules;
                if (request.Inserting)
                {
                    if (rowHandler.SupportsNewRow(request))
                    {
                        page.NewRow = new object[page.Fields.Count];
                        rowHandler.NewRow(request, page, page.NewRow);
                    }
                }
                else
                if (rowHandler.SupportsPrepareRow(request))
                {
                    foreach (object[] row in page.Rows)
                    {
                        rowHandler.PrepareRow(request, page, row);
                    }
                }
                if (rules != null)
                {
                    rules.ProcessPageRequest(request, page);
                }
            }
            page = page.ToResult(_config, _view);
            if (rules != null)
            {
                rules.AfterSelect(request);
                rules.Result.Merge(page);
            }
            else
            {
                CreateBusinessRules().ExecuteServerRules(request, ActionPhase.After);
            }
            return(page);
        }