public RowEditorWindow(ImportStagingService service, int rowId, List <ImportFieldMapping> mappings, DataRowView row) { InitializeComponent(); this.Service = service; this.RowID = rowId; this.Row = row; this.Mappings = mappings; int rowIndex = 0; foreach (ImportFieldMapping mapping in mappings) { gridFields.RowDefinitions.Add(CreateRowDefinition()); var lbl = new Label(); lbl.SetValue(Grid.RowProperty, rowIndex); lbl.Content = mapping.SourceColumn; gridFields.Children.Add(lbl); var txt = new Extensibility.TextBox(); txt.SetValue(Grid.ColumnProperty, 1); txt.SetValue(Grid.RowProperty, rowIndex); txt.Height = 23; var objValue = row[mapping.SourceColumn]; var strValue = (objValue == null ? "" : objValue.ToString()); var value = new FieldValue(mapping.TargetColumn, strValue); var binding = new Binding("Value"); binding.Source = value; binding.ValidatesOnDataErrors = true; txt.SetBinding(TextBox.TextProperty, binding); // txt.Text = strValue; var fieldMapping = mapping; // need to keep a copy of this mapping so its captured in the closure txt.TextChanged += new TextChangedEventHandler((source, e) => { var textbox = source as TextBox; if (textbox.Text != strValue) { _changeMap[fieldMapping.SourceColumn] = textbox.Text; } else { if (_changeMap.ContainsKey(fieldMapping.SourceColumn)) { _changeMap.Remove(fieldMapping.SourceColumn); } } }); gridFields.Children.Add(txt); rowIndex++; } }
public override List <string> GetColumnNames() { var service = new ImportStagingService(_options.Filename); var mappings = service.GetMappings(); service.Dispose(); _columnNames = new List <string>(mappings.Select((mapping) => { return(mapping.SourceColumn); })); return(_columnNames); }
public override ImportRowSource CreateRowSource(IProgressObserver progress) { if (_options == null) { throw new Exception("Null or incorrect options type received!"); } ImportRowSource rowsource = null; var service = new ImportStagingService(); int rowCount = 0; var values = new List <string>(); if (progress != null) { progress.ProgressMessage(String.Format("Importing data - Stage 1 Connecting to input source...", rowCount)); } WithExcelWorksheetRows(_options.Filename, _options.Worksheet, 0, row => { if (rowCount == 0) { var columnNames = new List <String>(); foreach (DataColumn column in row.Table.Columns) { columnNames.Add(column.ColumnName); } service.CreateImportTable(columnNames); service.BeginTransaction(); } values.Clear(); foreach (DataColumn col in row.Table.Columns) { var value = row[col]; values.Add((value == null ? "" : value.ToString())); } service.InsertImportRow(values); if (++rowCount % 1000 == 0) { if (progress != null) { progress.ProgressMessage(String.Format("Importing data - Stage 1 {0} rows copied to staging database...", rowCount)); } } ; }); service.CommitTransaction(); rowsource = new ImportRowSource(service, rowCount); return(rowsource); }
public override ImportRowSource CreateRowSource(IProgressObserver progress) { if (_options == null) { throw new Exception("Null or incorrect options type received!"); } ImportRowSource rowsource = null; var columnNames = GetColumnNames(); var service = new ImportStagingService(); service.CreateImportTable(columnNames); if (WithWorksheetDataTable(_options.Filename, string.Format("SELECT * FROM [{0}]", _options.Worksheet), (dt) => { service.BeginTransaction(); var values = new List <string>(); int rowcount = 0; foreach (DataRow row in dt.Rows) { values.Clear(); foreach (DataColumn col in dt.Columns) { var value = row[col]; values.Add((value == null ? "" : value.ToString())); } service.InsertImportRow(values); rowcount++; } service.CommitTransaction(); rowsource = new ImportRowSource(service, rowcount); })) { return(rowsource); } return(null); }
public ErrorDatabaseImportOptionsWindow(ErrorDatabaseImporterOptions options, ImportWizardContext context) { InitializeComponent(); _service = new ImportStagingService(options.Filename); Options = options; Context = context; _mappings = _service.GetMappings(); dataGrid.AutoGenerateColumns = false; foreach (ImportFieldMapping mapping in _mappings) { dataGrid.Columns.Add(CreateColumn(mapping)); } var ds = _service.GetErrorsDataSet(); dataGrid.ItemsSource = ds.Tables[0].DefaultView; dataGrid.IsReadOnly = true; dataGrid.MouseDoubleClick += new MouseButtonEventHandler(dataGrid_MouseDoubleClick); }
public override ImportRowSource CreateRowSource(IProgressObserver progress) { var errorSource = new ImportStagingService(_options.Filename); var service = new ImportStagingService(); service.CreateImportTable(_columnNames); int rowcount = 0; var reader = errorSource.GetErrorReader(); while (reader.Read()) { var values = new List <String>(); for (int i = 0; i < reader.FieldCount - 1; ++i) { var val = reader[i]; values.Add(val == null ? null : val.ToString()); } service.InsertImportRow(values); rowcount++; } return(new ImportRowSource(service, rowcount)); }
public ImportRowSource(ImportStagingService service, int?rowcount) { this.Reader = service.GetImportReader(); this.RowCount = rowcount; this.Service = service; }