Exemplo n.º 1
0
        internal static void ReadDataTable(DataTable dataTable, Table table)
        {
            if (dataTable == null)
            {
                return;
            }
            SortColumn[] mylist = table.OrderBySortList.ColumnsSorted();

            string sort = table.GroupByExpression;

            foreach (SortColumn sortcolumn in mylist)
            {
                if (string.IsNullOrEmpty(sortcolumn.m_ColumnName))
                {
                    continue;
                }
                if (string.IsNullOrEmpty(sort) == false)
                {
                    sort += ", ";
                }
                sort += sortcolumn.m_ColumnName.Replace(".", string.Empty);
                sort += sortcolumn.m_Desc ? " DESC" : " ASC";
            }
            DataSourceControlType type = table.DataSourceType;

            table.DataSourceType = DataSourceControlType.EnumerableDataSource;
            string datasource = table.DataSourceId;

            table.DataSourceId   = null;
            string where         = Interface.BuildFilter(table, true);
            table.DataSourceType = type;
            table.DataSourceId   = datasource;
            if (where.EndsWith("???", StringComparison.OrdinalIgnoreCase))
            {
                table.m_Grid.SystemMessage.Add("Your datasource is missing primary key(s) or identity key.", true);
                return;
            }
            if (where.StartsWith(" WHERE ", StringComparison.OrdinalIgnoreCase))
            {
                where = where.Substring(7);
            }
            DataRow[] datarows;
            try
            {
                if (string.IsNullOrEmpty(where) && string.IsNullOrEmpty(sort))
                {
                    List <DataRow> dtrows = new List <DataRow>();
                    foreach (DataRow row in dataTable.Rows)
                    {
                        dtrows.Add(row);
                    }
                    datarows = dtrows.ToArray();
                }
                else
                {
                    datarows = dataTable.Select(where, sort);
                }
            }
            catch (Exception ee)
            {
                throw new GridDataSourceException(string.Format("Failed to select from DataTable. (filterExpression: {0} sort:{1})", where, sort), ee);
            }
            if (!table.IsCustomPaging)
            {
                table.RecordCount = datarows.Length;
            }
            if (table == table.m_Grid.MasterTable && table.DataSource is OleDbDataAdapter == false)
            {
                datarows = FilterDataRows(datarows, table.m_Grid);
            }

            foreach (DataRow datarow in datarows)
            {
                if (datarow == null)
                {
                    continue;
                }
                Row newrow = new Row(table)
                {
                    m_DataRow = datarow
                };
                foreach (DataColumn col in dataTable.Columns)
                {
                    if (table == table.m_Grid.MasterTable && table.DataSource is XmlDataDocument)
                    {
                        if (table.m_XmlDataSet.Tables[datarow.Table.TableName].Columns[col.ColumnName] == null)
                        {
                            newrow.Columns[col.ColumnName].AllowEdit = false;
                        }
                    }

                    newrow[col.ColumnName].Row             = newrow;
                    newrow[col.ColumnName].Value           = table.Columns[col.ColumnName].OnLoadFromDatabase(datarow[col]);
                    newrow[col.ColumnName].DataSourceValue = datarow[col];
                }

                foreach (Column column in table.Columns)
                {
                    if (column.ColumnType != ColumnType.ColumnTemplate)
                    {
                        continue;
                    }
                    newrow[column.ColumnId].Value = ((ColumnTemplate)column).CreateCellControls;
                }
                table.Rows.Add(newrow);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Finds data source web control.
        /// </summary>
        /// <param name="dataSourceId"></param>
        /// <returns></returns>
        public DataSourceControlType FindDataSourceType(string dataSourceId)
        {
            if (m_Grid.Page == null || Grid.FindControl<Control>(m_Grid.Parent, dataSourceId) == null)
            {
                m_DataSourceType = DataSourceControlType.InternalDataSource;

                return m_DataSourceType;
            }

            Control control = Grid.FindControl<Control>(m_Grid.Page, dataSourceId);
            if (control == null)
                return DataSourceControlType.Undefined;
            if (control is AccessDataSource)
                m_DataSourceType = DataSourceControlType.AccessDataSource;
            else if (control is SqlDataSource)
                m_DataSourceType = DataSourceControlType.SqlDataSource;
            else if (control is XmlDataSource)
                m_DataSourceType = DataSourceControlType.XmlDataSource;
            else if (control is ObjectDataSource)
                m_DataSourceType = DataSourceControlType.ObjectDataSource;
             #if NET35  
            else if (control is LinqDataSource)
                m_DataSourceType = DataSourceControlType.LinqDataSource;
            else if (control is EntityDataSource)
                m_DataSourceType = DataSourceControlType.EntityDataSource;
            #endif
            else
                m_DataSourceType = DataSourceControlType.InternalDataSource;

            //Create a reference to the data control we are using.
            if (m_DataSourceType != DataSourceControlType.InternalDataSource)
                m_controlDataSource = control;

            return m_DataSourceType;
        }