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);
         }
     }
 }
        private static void XML2DB(DbProviderFactory dataFactory, DbConnection dbcn, DbTransaction tran, DTDatabase dtDatabase, string namespacePrefix, string namespaceUri, XPathDocument genericXMLDate, XPathDocument formData, XPathDocument resultData, string prodef_id, string project_id, DateTime? applyingDate, DateTime? finishedDate)
        {
            if (!string.IsNullOrEmpty(dtDatabase.BeforeProcedure))
            {
                if (LoggingService.IsInfoEnabled)
                {
                    LoggingService.InfoFormatted("执行交换前存储过程:{0}", new object[] { dtDatabase.BeforeProcedure });
                }
                DbCommand command = dbcn.CreateCommand();
                command.CommandText = dtDatabase.BeforeProcedure;
                command.CommandType = CommandType.StoredProcedure;
                command.Transaction = tran;
                command.ExecuteNonQuery();
            }
            XPathDocument[] documents = new XPathDocument[] { formData, resultData, genericXMLDate };
            foreach (DTTable table in dtDatabase.DTTables)
            {
                XPathDocument document;
                if (!table.IsActive || !table.IfImport)
                {
                    continue;
                }
                if (LoggingService.IsInfoEnabled)
                {
                    LoggingService.InfoFormatted("准备交换数据至表:'{0}<{1}>'", new object[] { table.Name, table.Description });
                }
                if (LoggingService.IsDebugEnabled)
                {
                    LoggingService.DebugFormatted("基础数据来自:{0}", new object[] { table.SourceType });
                }
                switch (table.SourceType)
                {
                    case SourceType.FormData:
                        document = formData;
                        break;

                    case SourceType.ResultData:
                        document = resultData;
                        break;

                    case SourceType.GenericXMLData:
                        document = genericXMLDate;
                        break;

                    default:
                        throw new NotSupportedException(string.Format("尚不支持的类型:{0}!", table.SourceType));
                }
                if (document != null)
                {
                    DbDataAdapter adapter = dataFactory.CreateDataAdapter();
                    DbCommand command2 = dbcn.CreateCommand();
                    command2.Transaction = tran;
                    command2.CommandText = string.Format("select * from {0} where 1<>1", string.IsNullOrEmpty(table.ImportToTable) ? table.Name : table.ImportToTable);
                    adapter.SelectCommand = command2;
                    DbCommandBuilder builder = dataFactory.CreateCommandBuilder();
                    builder.DataAdapter = adapter;
                    adapter.InsertCommand = builder.GetInsertCommand();
                    adapter.InsertCommand.Transaction = tran;
                    XPathNavigator navigator = document.CreateNavigator();
                    XPathNodeIterator iterator = null;
                    if (!string.IsNullOrEmpty(namespacePrefix) && !string.IsNullOrEmpty(namespaceUri))
                    {
                        table.NamespacePrefix = string.Format(table.NamespacePrefix, namespacePrefix);
                        table.NamespaceUri = string.Format(table.NamespaceUri, namespaceUri);
                        table.MapXMLElementName = string.Format(table.MapXMLElementName, namespacePrefix);
                    }
                    if (!string.IsNullOrEmpty(table.NamespacePrefix))
                    {
                        if (LoggingService.IsDebugEnabled)
                        {
                            LoggingService.DebugFormatted("搜索:'{0}',前缀:'{1}',命名空间:'{2}'", new object[] { table.MapXMLElementName, table.NamespacePrefix, table.NamespaceUri });
                        }
                        XmlNamespaceManager resolver = new XmlNamespaceManager(navigator.NameTable);
                        resolver.AddNamespace(table.NamespacePrefix, table.NamespaceUri);
                        iterator = navigator.Select(table.MapXMLElementName, resolver);
                        if ((iterator.Count == 0) && !string.IsNullOrEmpty(table.DataSetName))
                        {
                            if (LoggingService.IsDebugEnabled)
                            {
                                LoggingService.DebugFormatted("搜索:'/{0}:{1}/{2}'", new object[] { namespacePrefix, table.DataSetName, table.MapXMLElementName });
                            }
                            iterator = navigator.Select(string.Format("/{0}:{1}/{2}", namespacePrefix, table.DataSetName, table.MapXMLElementName), resolver);
                        }
                    }
                    else
                    {
                        iterator = navigator.Select(table.MapXMLElementName);
                    }
                    if (iterator.Count > 0)
                    {
                        DataTable dataTable = new DataTable();
                        adapter.Fill(dataTable);
                        foreach (XPathNavigator navigator2 in iterator)
                        {
                            DataRow row = dataTable.NewRow();
                            foreach (DTColumn column in table.DTColumns)
                            {
                                if (!column.IsActive || !column.IfImport)
                                {
                                    continue;
                                }
                                if (!dataTable.Columns.Contains(column.Name))
                                {
                                    goto Label_0615;
                                }
                                if (!string.IsNullOrEmpty(column.MapXMLElementName))
                                {
                                    switch (column.MapXMLElementName.ToUpper())
                                    {
                                        case "[GUID]":
                                            try
                                            {
                                                row[column.Name] = StringHelper.GetNewGuid();
                                            }
                                            catch (Exception exception)
                                            {
                                                LoggingService.Error(exception);
                                            }
                                            goto Label_0580;

                                        case "[PROJECT_ID]":
                                            try
                                            {
                                                row[column.Name] = project_id;
                                            }
                                            catch (Exception exception2)
                                            {
                                                LoggingService.Error(exception2);
                                            }
                                            goto Label_0580;

                                        case "[PRODEF_ID]":
                                            try
                                            {
                                                row[column.Name] = prodef_id;
                                            }
                                            catch (Exception exception3)
                                            {
                                                LoggingService.Error(exception3);
                                            }
                                            goto Label_0580;

                                        case "[NUM]":
                                            try
                                            {
                                                row[column.Name] = dataTable.Rows.Count + 1;
                                            }
                                            catch (Exception exception4)
                                            {
                                                LoggingService.Error(exception4);
                                            }
                                            goto Label_0580;

                                        case "[APPLYING_DATE]":
                                            try
                                            {
                                                row[column.Name] = applyingDate;
                                            }
                                            catch (Exception exception5)
                                            {
                                                LoggingService.Error(exception5);
                                            }
                                            goto Label_0580;

                                        case "[FINISHED_DATE]":
                                            try
                                            {
                                                row[column.Name] = finishedDate;
                                            }
                                            catch (Exception exception6)
                                            {
                                                LoggingService.Error(exception6);
                                            }
                                            goto Label_0580;
                                    }
                                    try
                                    {
                                        SetColumnValue(documents, namespacePrefix, namespaceUri, navigator2, row, column);
                                    }
                                    catch (Exception exception7)
                                    {
                                        LoggingService.Error(string.Format("设置'{0}<{1}>'时出错", column.Name, column.Description), exception7);
                                    }
                                }
                            Label_0580:
                                if (!string.IsNullOrEmpty(column.DefaultValue) && Convert.IsDBNull(row[column.Name]))
                                {
                                    row[column.Name] = column.DefaultValue;
                                }
                                if (LoggingService.IsDebugEnabled && !Convert.IsDBNull(row[column.Name]))
                                {
                                    LoggingService.DebugFormatted("获取的列'{0}<{1}>'的值为:'{2}'", new object[] { column.Name, column.Description, row[column.Name] });
                                }
                                continue;
                            Label_0615:;
                                LoggingService.WarnFormatted("表‘{0}<{1}>’已经不包含列‘{2}<{3}>’", new object[] { table.Name, table.Description, column.Name, column.Description });
                            }
                            dataTable.Rows.Add(row);
                        }
                        if (dataTable.Rows.Count > 0)
                        {
                            if (LoggingService.IsDebugEnabled)
                            {
                                LoggingService.Debug("添加了新数据,更新表");
                            }
                            adapter.Update(dataTable);
                        }
                        continue;
                    }
                    LoggingService.WarnFormatted("没有找到与表'{0}'对应的'{1}'节点!", new object[] { table.Name, table.MapXMLElementName });
                }
            }
            if (!string.IsNullOrEmpty(dtDatabase.AfterProcedure))
            {
                DbCommand command3 = dbcn.CreateCommand();
                command3.CommandText = dtDatabase.AfterProcedure;
                command3.CommandType = CommandType.StoredProcedure;
                command3.Transaction = tran;
                command3.ExecuteNonQuery();
                if (LoggingService.IsDebugEnabled)
                {
                    LoggingService.DebugFormatted("执行导入后存储过程:'{0}'!", new object[] { dtDatabase.AfterProcedure });
                }
            }
        }