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);
        }
예제 #2
0
        public void CopyToErrorTable(ImportRowSource source, string message)
        {
            var parmSpec = new StringBuilder();

            for (int i = 0; i < source.ColumnCount + 1; ++i)
            {
                parmSpec.Append("@param" + i).Append(",");
            }

            parmSpec.Remove(parmSpec.Length - 1, 1);

            Command((cmd) => {
                cmd.CommandText = String.Format(@"INSERT INTO [Errors] VALUES ({0})", parmSpec.ToString());
                for (int i = 0; i < source.ColumnCount; ++i)
                {
                    cmd.Parameters.Add(new SQLiteParameter("@param" + i, source[i]));
                }
                cmd.Parameters.Add(new SQLiteParameter("@param" + source.ColumnCount, message));
                cmd.ExecuteNonQuery();
            });
        }
예제 #3
0
        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);
        }
예제 #4
0
        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;
        }
예제 #5
0
        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;
        }