示例#1
0
 public override IEnumerable <string> GetFieldNames(string tableName)
 {
     using (var excel = ExcelOpenXmlDocument.Load(ConnectionDetails.Database))
     {
         return(excel.ReadSheet(tableName).Columns.Cast <DataColumn>().Select(x => x.ColumnName));
     }
 }
示例#2
0
 public override bool CreateTable(string tableName)
 {
     using (var excel = ExcelOpenXmlDocument.Load(ConnectionDetails.Database))
     {
         excel.AddSheet(tableName);
     }
     return(true);
 }
示例#3
0
        //protected override void CreateTable(string tableName, string pkColumnName, string pkDataType, bool pkIsIdentity)
        //{
        //    throw new NotSupportedException();
        //}

        #endregion

        #region Field Methods

        public override bool CreateField(string tableName, Field field)
        {
            using (var excel = ExcelOpenXmlDocument.Load(ConnectionDetails.Database))
            {
                int columnCount = excel.GetColumnCount(tableName);
                excel.InsertText(tableName, field.Name, 1, columnCount + 1);
            }
            return(true);
        }
示例#4
0
        public override int GetRecordCount(string tableName)
        {
            bool hasHeaderRow = ConnectionDetails.ExtendedProperties["HasHeaderRow"].GetValue <bool>();

            using (var excel = ExcelOpenXmlDocument.Load(ConnectionDetails.Database))
            {
                int rowCount = excel.GetRowCount(tableName);
                return(hasHeaderRow ? rowCount - 1 : rowCount);
            }
        }
示例#5
0
        public override void InsertRecords(string tableName, IEnumerable <Record> records)
        {
            var collection = new RecordCollection();

            collection.AddRange(records);

            using (var excel = ExcelOpenXmlDocument.Load(ConnectionDetails.Database))
            {
                var data = collection.ToDataTable();
                excel.Import(data, tableName, true, (uint)(excel.GetRowCount(tableName) + 1));
            }
        }
示例#6
0
 public override bool CreateTable(string tableName, IEnumerable <Field> fields)
 {
     using (var excel = ExcelOpenXmlDocument.Load(ConnectionDetails.Database))
     {
         excel.AddSheet(tableName);
         int columnIndex = 0;
         foreach (var field in fields)
         {
             excel.InsertText(tableName, field.Name, 1, ++columnIndex);
         }
         excel.Save();
     }
     return(true);
 }
示例#7
0
 public bool ValidateConnection()
 {
     try
     {
         //using (OleDbConnection connection = new OleDbConnection(ConnectionString))
         //{
         //    return connection.Validate();
         //}
         using (var excel = ExcelOpenXmlDocument.Load(ConnectionString))
         {
             return(true);
         }
     }
     catch { return(false); }
 }
示例#8
0
        public override IEnumerator <Record> GetRecordsEnumerator(string tableName, IEnumerable <Field> fields)
        {
            bool hasHeaderRow = ConnectionDetails.ExtendedProperties["HasHeaderRow"].GetValue <bool>();

            using (var excel = ExcelOpenXmlDocument.Load(ConnectionDetails.Database))
            {
                foreach (DataRow row in excel.ReadSheet(tableName, hasHeaderRow).Rows)
                {
                    var record = new Record();
                    record.Fields.AddRange(fields);
                    fields.ForEach(f =>
                    {
                        record[f.Name].Value = row[f.Name];
                    });
                    yield return(record);
                }
            }
        }
示例#9
0
 public override FieldCollection GetFields(string tableName)
 {
     using (var excel = ExcelOpenXmlDocument.Load(ConnectionDetails.Database))
     {
         var fields = new FieldCollection();
         foreach (DataColumn column in excel.ReadSheet(tableName, true).Columns)
         {
             var field = new Field
             {
                 DisplayName = column.ColumnName,
                 IsRequired  = !column.AllowDBNull,
                 MaxLength   = column.MaxLength,
                 Name        = column.ColumnName,
                 Ordinal     = column.Ordinal,
                 Type        = AppContext.SystemTypeConverter.GetDataMigratorFieldType(column.DataType)
             };
             fields.Add(field);
         }
         return(fields);
     }
 }