public override void Run()
 {
     IDataObject dataObject = ClipboardWrapper.GetDataObject();
     if (dataObject.GetDataPresent(typeof(DTProject)))
     {
         DTProject data = (DTProject) dataObject.GetData(typeof(DTProject));
         if (data != null)
         {
             DTProject dtProject = new DTProject(data.Name, data.Description, data.MapXMLElementName);
             dtProject.Save();
             foreach (DTDatabase database in data.DTDatabases)
             {
                 DTDatabase dtDatabase = new DTDatabase(dtProject, database.Name, database.Description, database.DSType, database.ConnectionString, database.BeforeProcedure, database.AfterProcedure);
                 dtDatabase.Save();
                 foreach (DTTable table in database.DTTables)
                 {
                     DTTable dtTable = new DTTable(table.NamespacePrefix, table.NamespaceUri, dtDatabase, table.Name, table.Description, table.MapXMLElementName, table.Hiberarchy, table.SourceType);
                     dtTable.Save();
                     foreach (DTColumn column in table.DTColumns)
                     {
                         new DTColumn(column.NamespacePrefix, column.NamespaceUri, dtTable, column.Name, column.Description, column.DisplayOrder, column.DefaultValue, column.MapXMLElementName, column.Type).Save();
                     }
                 }
             }
             ((TaskTreeNode) this.Owner).AddSingleNode<DTProject, DTProjectNode>(dtProject);
         }
     }
 }
 public override void Run()
 {
     UnitOfWork work = new UnitOfWork(typeof(DTColumn));
     DTProject project = new DTProject();
     project.Name = "新XML数据交换项目";
     work.RegisterNew(project);
     work.Commit();
     ((TaskTreeNode) this.Owner).AddSingleNode<DTProject, DTProjectNode>(project);
 }
 private static DataSet DB2XML(string dsName, string where, DTProject dtProject)
 {
     DataSet set = new DataSet(string.IsNullOrEmpty(dsName) ? (string.IsNullOrEmpty(dtProject.MapXMLElementName) ? dtProject.Name : dtProject.MapXMLElementName) : dsName);
     StringBuilder builder = new StringBuilder();
     foreach (DTDatabase database in dtProject.DTDatabases)
     {
         if (database.IsActive && database.IfExport)
         {
             if (LoggingService.IsInfoEnabled)
             {
                 LoggingService.InfoFormatted("开始导出'{0}'", new object[] { database.Name });
             }
             DbConnection connection = DbProviderFactories.GetFactory(database.DSType).CreateConnection();
             connection.ConnectionString = database.DecryptConnectionString;
             if (LoggingService.IsDebugEnabled)
             {
                 LoggingService.DebugFormatted("数据库连接字符串是:{0}", new object[] { connection.ConnectionString });
             }
             connection.Open();
             try
             {
                 foreach (DTTable table in database.DTTables)
                 {
                     if ((!table.IsActive || !table.IfExport) || ((dsName != null) && (table.DataSetName != dsName)))
                     {
                         continue;
                     }
                     builder.Append("select ");
                     foreach (DTColumn column in table.DTColumns)
                     {
                         if (column.IsActive && column.IfExport)
                         {
                             builder.Append(column.Name);
                             if (!string.IsNullOrEmpty(column.MapXMLElementName))
                             {
                                 builder.Append(" as ").Append(column.MapXMLElementName.Replace("{0}:", string.Empty));
                             }
                             builder.Append(",");
                         }
                     }
                     if (builder.ToString().EndsWith(","))
                     {
                         builder.Remove(builder.Length - 1, 1);
                     }
                     else
                     {
                         builder.Append("*");
                     }
                     builder.Append(" from ").Append(table.Name);
                     if (!string.IsNullOrEmpty(where))
                     {
                         builder.Append(" where ").Append(where);
                     }
                     DataTable table2 = new DataTable(string.IsNullOrEmpty(table.MapXMLElementName) ? table.Name : table.MapXMLElementName.Replace("{0}:", string.Empty));
                     DbCommand command = connection.CreateCommand();
                     command.CommandText = builder.ToString();
                     builder.Remove(0, builder.Length);
                     if (LoggingService.IsDebugEnabled)
                     {
                         LoggingService.DebugFormatted("将执行SQL:{0}", new object[] { command.CommandText });
                     }
                     IDataReader reader = command.ExecuteReader();
                     try
                     {
                         table2.Load(reader);
                     }
                     finally
                     {
                         reader.Close();
                     }
                     set.Tables.Add(table2);
                 }
                 continue;
             }
             finally
             {
                 connection.Close();
             }
         }
     }
     if (LoggingService.IsInfoEnabled)
     {
         LoggingService.Info("导出完成.");
     }
     return set;
 }
 public static void XML2DB(DTProject dtProject, string namespacePrefix, string namespaceUri, XPathDocument genericXMLDate, XPathDocument formData, XPathDocument resultData, string prodef_id, string project_id, DateTime? applyingDate, DateTime? finishedDate)
 {
     if (LoggingService.IsInfoEnabled)
     {
         LoggingService.Info("准备处理交换文件");
     }
     List<DbTransaction> list = new List<DbTransaction>(dtProject.DTDatabases.Count);
     List<DbConnection> list2 = new List<DbConnection>(dtProject.DTDatabases.Count);
     try
     {
         foreach (DTDatabase database in dtProject.DTDatabases)
         {
             if (database.IsActive && database.IfImport)
             {
                 if (LoggingService.IsInfoEnabled)
                 {
                     LoggingService.InfoFormatted("开始交换到'{0}'", new object[] { database.Name });
                 }
                 DbProviderFactory dataFactory = DbProviderFactories.GetFactory(database.DSType);
                 DbConnection item = dataFactory.CreateConnection();
                 item.ConnectionString = database.DecryptConnectionString;
                 if (LoggingService.IsDebugEnabled)
                 {
                     LoggingService.DebugFormatted("数据库连接字符串是:{0}", new object[] { item.ConnectionString });
                 }
                 item.Open();
                 DbTransaction transaction = item.BeginTransaction();
                 list.Add(transaction);
                 list2.Add(item);
                 XML2DB(dataFactory, item, transaction, database, namespacePrefix, namespaceUri, genericXMLDate, formData, resultData, prodef_id, project_id, applyingDate, finishedDate);
                 if (LoggingService.IsInfoEnabled)
                 {
                     LoggingService.Info("交换完成.");
                 }
             }
         }
         foreach (DbTransaction transaction2 in list)
         {
             transaction2.Commit();
             if (LoggingService.IsInfoEnabled)
             {
                 LoggingService.Info("提交数据库事务");
             }
         }
     }
     catch (Exception exception)
     {
         foreach (DbTransaction transaction3 in list)
         {
             transaction3.Rollback();
             if (LoggingService.IsInfoEnabled)
             {
                 LoggingService.Info("遇到了错误,事务将回滚!");
             }
         }
         LoggingService.Error(exception);
         throw exception;
     }
     finally
     {
         foreach (DbConnection connection2 in list2)
         {
             connection2.Close();
         }
     }
     if (LoggingService.IsInfoEnabled)
     {
         LoggingService.Info("处理完成!");
     }
 }