Esempio n. 1
0
        public async Task ExportTable(ExportProgressArgs ea)
        {
            try
            {
                DBETable table = ea.Table;
                if ((mode & ExportMode.Patch) != ExportMode.Patch)
                {
                    table.SourceTable.Clear();
                    table.TargetTable.Clear();
                }
                using (var transacton = new DBTransaction(table.SourceTable.Connection))
                {
                    ea.Current     = 0;
                    ea.Count       = table.SourceTable.GetRowCount(transacton, table.Query);
                    ea.Description = null;
                    OnExportProgress(ea);

                    using (transacton.Reader = transacton.ExecuteQuery(table.SourceTable.CreateQuery(table.Query, null), DBExecuteType.Reader) as IDataReader)
                    {
                        table.SourceTable.CheckColumns(transacton);
                        while (transacton.Reader.Read())
                        {
                            if (ea.Cancel)
                            {
                                transacton.Cancel();
                                return;
                            }
                            var row    = table.SourceTable.LoadItemFromReader(transacton);
                            var newRow = ExportRow(table, row);

                            await table.TargetTable.SaveItem(newRow, null);

                            ea.Current++;
                            ea.Row = newRow;

                            OnExportProgress(ea);

                            if ((mode & ExportMode.Patch) != ExportMode.Patch)
                            {
                                table.SourceTable.Clear();
                                table.TargetTable.Clear();
                            }
                        }
                        transacton.Reader.Close();
                    }
                    transacton.Commit();
                }
            }
            catch (Exception ex)
            {
                ea.Exception = ex;
                OnExportProgress(ea);
            }
        }
Esempio n. 2
0
        public DBItem ExportRow(DBETable table, DBItem row)
        {
            DBItem newRow = null;

            if (table.TargetTable.PrimaryKey != null && table.SourceTable.PrimaryKey != null)
            {
                newRow = table.TargetTable.LoadItemById(row.PrimaryId, DBLoadParam.None);
            }
            if (newRow == null)
            {
                newRow = table.TargetTable.NewItem(DBUpdateState.Insert, false);
            }

            foreach (var column in table.Columns)
            {
                if (!column.Check || column.UserDefined || column.TargetColumn == null || column.SourceColumn == null)
                {
                    continue;
                }
                if ((mode & ExportMode.ExcludeAccess) == ExportMode.ExcludeAccess && (mode & ExportMode.Patch) == ExportMode.Patch &&
                    (column.TargetColumn.Keys & DBColumnKeys.Access) == DBColumnKeys.Access && newRow.Attached)
                {
                    continue;
                }
                object val = row[column.SourceColumn];
                if ((mode & ExportMode.DateValidation) == ExportMode.DateValidation && val is DateTime && ((DateTime)val).Year < 1900)
                {
                    val = null;
                }
                if ((mode & ExportMode.StringTrimm) == ExportMode.StringTrimm && val is string)
                {
                    val = ((string)val).Trim();
                }

                newRow[column.TargetColumn] = val;
            }
            return(newRow);
        }
Esempio n. 3
0
        public DBTable GenerateTable(DBETable extable)
        {
            var newTable = extable.TargetTable;

            if (newTable == null)
            {
                newTable = new DBTable <DBItem>(extable.Target)
                {
                    Schema = Target
                }
            }
            ;

            foreach (var column in extable.Columns)
            {
                if (column.Check && !newTable.Columns.Contains(column.Target))
                {
                    newTable.Columns.Add(GenerateColumn(column));
                }
            }

            return(newTable);
        }
Esempio n. 4
0
 public DBEColumnList(DBETable table)
 {
     Table = table;
 }
Esempio n. 5
0
        public void Initialize(ExportProgressArgs ea, IEnumerable <DBTable> list = null)
        {
            try
            {
                if (Source == null)
                {
                    throw new Exception("Source Schema not specified!");
                }

                if (ea != null)
                {
                    ea.Type        = ExportProgressType.Initialize;
                    ea.Description = "Process start!";
                    ea.Count       = Source.Tables.Count;
                    ea.Current     = 0;
                    OnExportProgress(ea);
                }
                if (list == null)
                {
                    list = Source.Tables;
                }
                Tables.Clear();

                foreach (var table in list)
                {
                    if (ea.Cancel)
                    {
                        return;
                    }

                    var esetting = new DBETable(table.Name)
                    {
                        Target = prefix + table.Name.Trim().Replace("_", "")
                    };
                    Tables.Add(esetting);

                    foreach (var column in table.Columns)
                    {
                        esetting.Columns.Add(new DBEColumn(column.Name)
                        {
                            Target   = column.Name.Trim().Replace(" ", "_"),
                            DataType = column.DBDataType,
                            Order    = column.Order,
                            Size     = column.Size,
                            Scale    = column.Scale
                        });
                    }
                    if (ea != null)
                    {
                        ea.Current++;
                        ea.Table       = esetting;
                        ea.Description = $"Table:{esetting} ({esetting.Columns.Count} columns)";
                    }
                }
                PatchQuery();
            }
            catch (Exception ex)
            {
                ea.Description = ex.Message;
                ea.Exception   = ex;
                OnExportProgress(ea);
            }
        }
Esempio n. 6
0
        public int CompareTo(object obj)
        {
            DBETable ts = obj as DBETable;

            return(string.Compare(this.source, ts.Source));
        }