public override void Apply(DataGridColumns dataGridColumns, ref DataGridRules rules) { DataGridColumn col = dataGridColumns[_filterDescriptor.PropertyName]; if (col != null) { DataGridRule customGridRule = new DataGridRule(); customGridRule.Table = col.Table; customGridRule.Name = col.Name; customGridRule.ExtendedFieldName = col.ExtendedFieldName; customGridRule.AliasField = col.AliasField; customGridRule.ExpressionDb = col.ExpressionDb; customGridRule.Criterio = DataGridRule.TranslateFromFilter(_filterDescriptor.Operator); customGridRule.CurrentFilterType = DataGridRule.FilterType.Text; if (_filterDescriptor.Operator == Telerik.WinControls.Data.FilterOperator.IsNull) { customGridRule.Value = ""; } else { customGridRule.Value = _filterDescriptor.Value; } base.UpdateRules(_filterDescriptor, customGridRule, ref rules); } }
public override void Apply(DataGridColumns dataGridColumns, ref DataGridRules rules) { DataGridRule dataGridRule = new DataGridRule(); DataGridColumn col = dataGridColumns[_filterDescriptor.PropertyName]; if ((col != null)) { dataGridRule.Table = col.Table; dataGridRule.Name = col.Name; dataGridRule.ExtendedFieldName = col.ExtendedFieldName; dataGridRule.AliasField = col.AliasField; dataGridRule.ExpressionDb = col.ExpressionDb; dataGridRule.Criterio = DataGridRule.TranslateFromFilter(_filterDescriptor.Operator); dataGridRule.CurrentFilterType = DataGridRule.FilterType.Data; if (_filterDescriptor.Operator == Telerik.WinControls.Data.FilterOperator.IsNull) { dataGridRule.Value = ""; } else { dataGridRule.Value = Convert.ToDateTime(_filterDescriptor.Value).ToString("yyyy-MM-dd"); } string filterValue = _filterDescriptor.Value as string; FilterOperator op = _filterDescriptor.Operator; UpdateRules(_filterDescriptor, dataGridRule, ref rules); } }
public DataGridViewCellViewModel this[string columnName, int rowIndex] { get { if (rowIndex < this.Rows.Count) { //Check rowIndex var selectedColumn = DataGridColumns.IndexOf(columnName); if (selectedColumn > -1) { return(this[selectedColumn, rowIndex]); } return(null); } return(null); } set { if (rowIndex < this.Rows.Count) { //Check rowIndex var selectedRow = this.Rows[rowIndex]; var selectedColumn = DataGridColumns.IndexOf(columnName); if (selectedColumn > -1) { selectedRow.ItemContent[selectedColumn] = value.Value.ToString(); } } } }
protected override void ProcessHeaders(DataGridColumns columns, DataGrid rawData) { if (rawData == null) throw new ArgumentNullException("rawData"); if (columns == null) throw new ArgumentNullException("columns"); if (!columns.Any()) throw new ArgumentException("No columns were specified.", "columns"); foreach (DataGridColumn dataGridColumn in columns.Expand()) { if (dataGridColumn.CellValue == null) { Log.Info(String.Format("Column '{0}' of Type '{1}' at column position '{2}, {3}'." , dataGridColumn , dataGridColumn.ColumnType.FriendlyName() , dataGridColumn.ColumnPosition , dataGridColumn.ColumnSize)); } else { Log.Info(String.Format("A cell column value was provided for Column '{0}' of Type '{1}'. Cells belonging to this column will inherit this value." , dataGridColumn , dataGridColumn.ColumnType.FriendlyName())); } if (!dataGridColumn.ColumnType.DerivesFromType(dataGridColumn.BindingType)) { Log.Warning(String.Format("Column '{0}': Type mismatch between Column Type '{1}' and Binding Type {2}. Data may be lost during Type Casting." , dataGridColumn , dataGridColumn.ColumnType.FriendlyName() , dataGridColumn.BindingType)); } } }
public DataGrid() { Columns = new DataGridColumns(); Columns.ItemsInserted += OnColumnsInserted; Rows = new DataGridRows(); Rows.ItemsInserted += OnRowsInserted; }
private void AddColumn(DataColumn role) { var binding = new Binding(role.ColumnName); var dataGridCheckBoxColumn = new DataGridTextColumn { Header = role.Caption, Binding = binding, CanUserSort = false, }; DataGridColumns.Add(dataGridCheckBoxColumn); }
protected override DataGrid ReadRawData(DataGridColumns columns) { if (columns == null) throw new ArgumentNullException("columns"); if (!columns.Any()) throw new ArgumentException("No columns were specified.", "columns"); Log.Info(String.Format("Reading data from Fixed-Length File '{0}'...", Settings.FilePath)); using (StreamReader reader = new StreamReader(Settings.FilePath)) { if (reader.EndOfStream) { throw new AbortException(String.Format("File '{0}' is Empty.", Settings.FilePath)); } DataGrid dataGrid = new DataGrid(); /* * Headers */ var allColumns = columns.Expand().Select(c => new DataGridColumn(c.ColumnName)); dataGrid.Columns.AddRange(allColumns); /* * Data */ while (!reader.EndOfStream) { DataGridRow dataGridRow = dataGrid.Rows.New(); string dataLine = reader.ReadLine(); foreach (DataGridColumn column in dataGrid.Columns) { try { string cellValue = dataLine.Substring(column.ColumnPosition - 1, column.ColumnSize); dataGridRow.Cells.Add(DataGridCell.StringCell(cellValue)); } catch (Exception exception) { throw new Exception(String.Format("An error occurred while reading cell at Row: '{0}', Position: '{1}, {2}'." , dataGridRow.Index() + 1 , column.ColumnPosition , column.ColumnSize) , exception); } } } return dataGrid; } }
private void InitializeRolesColumns() { int i = DataGridColumns.Count - 1; while (DataGridColumns.Count != 0) { DataGridColumns.RemoveAt(i); i--; } foreach (DataColumn role in Store.Tables[0].Columns) { this.AddColumn(role); } }
protected override DataGrid ReadRawData(DataGridColumns columns) { try { // Data using (DbContext context = new DbContext(Settings.ConnectionString)) { using (DbCommand dbCommand = context.Database.Connection.CreateCommand()) { context.Database.Connection.Open(); dbCommand.CommandText = Settings.SqlQuery; dbCommand.CommandTimeout = 300; DataGrid dataGrid = new DataGrid(); using (DbDataReader reader = dbCommand.ExecuteReader()) { for (int field = 0; field < reader.FieldCount; field++) { string columnName = reader.GetName(field); dataGrid.Columns.Add(new DataGridColumn(columnName) { ColumnType = reader.GetFieldType(field), OriginalSourceIndex = reader.GetOrdinal(columnName) }); } while (reader.Read()) { DataGridRow dataGridRow = dataGrid.Rows.New(); for (int field = 0; field < reader.FieldCount; field++) { DataGridCell cell = new DataGridCell(); cell.OriginalValue = !reader.IsDBNull(field) ? reader[field] : null; dataGridRow.Cells.Add(cell); } } return dataGrid; } } } } catch (Exception e) { throw new InvalidOperationException("An error occurred while executing the Sql Source Query.", e); } }
public override void Apply(DataGridColumns dataGridColumns, ref DataGridRules rules) { DataGridColumn dataGridColumn = dataGridColumns[_filterDescriptors.PropertyName]; DataGridRule dataGridRule; IDictionary <Type, DataGridRule.FilterType> kindOFilterTypes = new Dictionary <Type, DataGridRule.FilterType>(); kindOFilterTypes.Add(typeof(FilterDescriptor), DataGridRule.FilterType.Text); kindOFilterTypes.Add(typeof(DateFilterDescriptor), DataGridRule.FilterType.Data); DataGridRules dataGridRulesParts = new DataGridRules(); dataGridRule = new DataGridRule(); if (dataGridColumn != null) { int i = 0; foreach (var filterDescriptor in _filterDescriptors.FilterDescriptors) { dataGridRule.Table = dataGridColumn.Table; dataGridRule.Name = dataGridColumn.Name; dataGridRule.ExtendedFieldName = dataGridColumn.ExtendedFieldName; dataGridRule.AliasField = dataGridColumn.AliasField; dataGridRule.ExpressionDb = dataGridColumn.ExpressionDb; dataGridRule.Criterio = DataGridRule.TranslateFromFilter(_filterDescriptors.Operator); DataGridRule.FilterType type = kindOFilterTypes[filterDescriptor.GetType()]; bool isNull = (filterDescriptor.Operator == Telerik.WinControls.Data.FilterOperator.IsNull); switch (type) { case DataGridRule.FilterType.Text: { dataGridRule.Value = (isNull) ? "" : filterDescriptor.Value; break; } case DataGridRule.FilterType.Data: { dataGridRule.Value = (isNull) ? " " : Convert.ToDateTime(filterDescriptor.Value).ToString("yyyy-MM-dd"); break; } } bool validOperator = (filterDescriptor.Operator != FilterOperator.IsNull); string name = filterDescriptor.Value as string; if (!string.IsNullOrEmpty(name) || (!validOperator)) { dataGridRulesParts.Add(dataGridRule); i += 1; } } } DataGridRule tmpRule = dataGridRule; tmpRule.Table = dataGridColumn.Table; tmpRule.Name = dataGridColumn.Name; tmpRule.ExtendedFieldName = dataGridColumn.ExtendedFieldName; tmpRule.ExpressionDb = dataGridColumn.ExpressionDb; tmpRule.CurrentFilterType = DataGridRule.FilterType.Composed; tmpRule.Operador = (_filterDescriptors.LogicalOperator == FilterLogicalOperator.And) ? DataGridRule.OperatorRule.And : DataGridRule.OperatorRule.Or; tmpRule.Expresion = " " + (_filterDescriptors.NotOperator ? "NOT" : "") + "("; foreach (DataGridRule rlPart in tmpRule.Rules.Order()) { if (rlPart.Item > 0) { tmpRule.Expresion += tmpRule.OperadorVal; } tmpRule.Expresion += tmpRule.Rules.ComputeWhereClause(); } tmpRule.Expresion += ") "; if (tmpRule.Rules.Count() == 0) { rules.Remove(tmpRule.Name); } else if (rules.Exists(tmpRule.Name)) { tmpRule.Item = rules[tmpRule.Name].Item; rules.Modify(tmpRule); } else { rules.Add(tmpRule); } }
protected override DataGrid ReadRawData(DataGridColumns columns) { throw new NotImplementedException(); }
protected abstract DataGrid ReadRawData(DataGridColumns columns);
protected abstract void ProcessHeaders(DataGridColumns columns, DataGrid rawData);
public abstract void Apply(DataGridColumns dataGridColumns, ref DataGridRules rules);
public DataGrid(DataGridColumns columns) : this() { if (columns == null) throw new ArgumentNullException("columns"); Columns.AddRange(columns); }
protected override DataGrid ReadRawData(DataGridColumns columns) { if (columns == null) throw new ArgumentNullException("columns"); Framework.Excel.Interop.Excel excel = null; ExcelInterop.Worksheet worksheet = null; try { Log.Info(String.Format("Reading data from Excel File '{0}'...", Settings.FilePath)); excel = Framework.Excel.Interop.Excel.Open(Settings.FilePath, Settings.Password); worksheet = !Settings.Worksheet.IsNullOrBlank() ? excel.Worksheet(Settings.Worksheet) : excel.Worksheet(0); ExcelInterop.Range range = worksheet.UsedRange; object[,] cells = range.Value2; DataGrid dataGrid = new DataGrid(); /* * Headers */ var allColumns = columns.Expand(); int columnCount = range.Columns.Count; for (int colIndex = 1; colIndex <= columnCount; colIndex++) { string columnName = Convert.ToString(cells[1, colIndex]); if (columnName.IsNullOrBlank() || (columns.Any() && !allColumns.Any(c => c.ColumnName.Equals(columnName)))) { continue; } DataGridColumn column = new DataGridColumn(columnName) { OriginalSourceIndex = colIndex }; dataGrid.Columns.Add(column); } /* * Data */ int rowCount; if (Settings.RowCount > 0) { rowCount = (Settings.RowCount + 1 <= range.Rows.Count) ? Settings.RowCount + 1 : range.Rows.Count; } else if (Settings.RowCount < 0) { rowCount = range.Rows.Count + Settings.RowCount; } else { rowCount = range.Rows.Count; } for (int rowIndex = 2; rowIndex <= rowCount; rowIndex++) { DataGridRow dataGridRow = dataGrid.Rows.New(); foreach (DataGridColumn column in dataGrid.Columns) { try { DataGridCell cell = dataGridRow.Cells.New(); cell.OriginalValue = cells[rowIndex, column.OriginalSourceIndex]; } catch (Exception exception) { throw new Exception(String.Format("An error occurred while reading cell at Row '{0}', Column '{1}'." , rowIndex , column.OriginalSourceIndex) , exception); } } } return dataGrid; } catch (ExcelInteropException e) { throw e; } catch (Exception e) { throw new ExcelInteropException(String.Format("An error occurred while Reading data from Excel file '{0}'.", Settings.FilePath), e); } finally { // Worksheet if (worksheet != null) { Marshal.FinalReleaseComObject(worksheet); } // Excel if (excel != null) { excel.Dispose(); } } }
public override bool IsEmpty() { return(DataGridColumns == null || !DataGridColumns.Any()); }
protected override void ProcessHeaders(DataGridColumns columns, DataGrid rawData) { if (rawData == null) throw new ArgumentNullException("rawData"); if (columns == null) throw new ArgumentNullException("columns"); if (!columns.Any()) { Log.Warning("No column mappings were provided. Columns will be derived from source."); columns.AddRange(rawData.Columns); } foreach (DataGridColumn dataGridColumn in columns.Expand()) { if (dataGridColumn.CellValue != null) { Log.Info(String.Format("A cell column value was provided for Column '{0}' of Type '{1}'. Cells belonging to this column will inherit this value." , dataGridColumn , dataGridColumn.ColumnType.FriendlyName())); } else if (!dataGridColumn.ColumnMap.IsNullOrBlank()) { Log.Warning(String.Format("Column '{0}' of Type '{1}' is mapped to Column '{2}' from which its value will be derived." , dataGridColumn , dataGridColumn.ColumnType.FriendlyName() , dataGridColumn.ColumnMap)); } else { var allColumns = rawData.Columns.Find(dataGridColumn.ColumnName); DataGridColumn column = allColumns.FirstOrDefault(); if (allColumns.Count() > 1) { Log.Warning(String.Format("Multiple instances of Column '{0}' of Type '{1}'. Resolving to first instance found at position '{2}'." , dataGridColumn , dataGridColumn.ColumnType.FriendlyName() , column.OriginalSourceIndex)); } else if (allColumns.Count() == 1) { Log.Info(String.Format("Column '{0}' of Type '{1}' found at column position '{2}'." , dataGridColumn , dataGridColumn.ColumnType.FriendlyName() , column.OriginalSourceIndex)); } else { if (!dataGridColumn.AppendedColumns.Any()) { throw new AbortException(String.Format("Column '{0}' Not available and no Value was provided.", dataGridColumn)); } Log.Warning(String.Format("Composite Column '{0}' of Type '{1}' has not been mapped but a value may still be derived from its appended columns." , dataGridColumn , dataGridColumn.ColumnType.FriendlyName())); } } if (!dataGridColumn.ColumnType.DerivesFromType(dataGridColumn.BindingType)) { Log.Warning(String.Format("Column '{0}': Type mismatch between Column Type '{1}' and Binding Type '{2}'. Data may be lost during Type Casting." , dataGridColumn , dataGridColumn.ColumnType.FriendlyName() , dataGridColumn.BindingType.FriendlyName())); } } }