DataInto

来源:互联网 发布:中国十大良心公知 编辑:程序博客网 时间:2024/05/01 06:50

using System;
using System.IO;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using DevExpress.Xpo;
using ArtArchives.Business;
using System.Reflection;

namespace datainto

 public class Form1 : System.Windows.Forms.Form
 {
  private System.Windows.Forms.Label label1;
  private System.Windows.Forms.Label label2;
  private System.Windows.Forms.Label label3;  
  private System.Windows.Forms.TextBox txbOPwd;
  private System.Windows.Forms.Label label4;
  private System.Windows.Forms.Label label5;
  private System.Windows.Forms.Label label6;
  private System.Windows.Forms.Label label7;
  private System.Windows.Forms.Label label8;
  private System.Windows.Forms.Label label9;
  private System.Windows.Forms.TextBox txbNUid;
  private System.Windows.Forms.TextBox txbNPwd;
  private System.Windows.Forms.Button butInto;
  private System.Windows.Forms.Label lbl;
  private System.Windows.Forms.Button butOCheck;
  private System.Windows.Forms.Button butNCheck;
  private System.Windows.Forms.ComboBox cboxOServer;
  private System.Windows.Forms.ComboBox cboxNServer;
  private System.Windows.Forms.ComboBox cboxOData;
  private System.Windows.Forms.TextBox txbOUid;
  private System.Windows.Forms.ComboBox cboxNData;
 // ----------------------------------------------------变量
  protected DataSet ds;             //原数据集合
  private string oldDirectory;
  private SQLDMO.Application sqlApp = new SQLDMO.ApplicationClass();
  private string connstring="Server={0};DataBase={1};Uid={2};Pwd={3}";
  public string rootPath=@"UploadFiles/ArchiveAccessories";   //上传附近根目录
  private string busnamespace="ArtArchives.Business.";
  private string topelist="剧目人物综合资料";           //顶级 菜单名称
  private string[] dtype={"图片","视音频","其他"};     //附件中 最后 一 级
  
  private Guid[] guids = new Guid[]{new Guid("8C5B274F-AC17-43C3-B6F1-3DA9BA2EE0AC"),// 剧目
           new Guid("760B1D3E-019D-4944-9C14-FF8FF30384EA"),// 人物
           new Guid("4D80CACC-1AA1-4F8B-A24E-9240FCEB4E29"),// 资料
           new Guid("B96544FC-C7D5-4C97-B8C6-7D45695194DE") // 综合
          };
  //-----------------------为加入三级菜单Beging-------------
  private string[] type1={"剧目","人物","综合","资料"};
  private string[] className1={"Drama","Person","",""};
  private string[] type2={ "剧本,宣传评论,乐谱,导表演,照片,获奖情况,舞台美术,音像,演出活动",
         "个人基本情况,获奖情况,照片,生活照,音像,业务成就,其他",
         "文艺刊物,业务计划,照片,对外文化交流,获奖情况,宣传评论,文化艺术活动,综合性活动,大事记、历史沿革,演出统计,艺术挖掘抢救",
         "图片,视频,文字"};
  private string[] className2={"PlayBook,Publicize,MusicBook,DirectorAndActor,DramaPhoto,Award,Decor,Vidio,Performance",
        "PersonBasicInfo,PersonalAward,PersonalPhoto,LivingFigure,Personalaudiovidio,Achievement,PersonalOthers",
        "Journal,BusinessPlan,IntegrationPhoto,Exchange,IntegrationAward,IntegrationPublicize,ArtActivity,IntegrativeActivity,Memorabilia,PerformanceCalCulation,Salvage",
        "DatumPhoto,DatumVidio,Doc"};
  string[]type3={"移植本,译稿本,改编本,导演本,演出本,文学本;报刊评论,海报,广告,说明书,观众来信;曲谱,旋律谱,总谱,分谱,歌曲谱,舞谱,合唱谱,钢琴谱;场记,提纲,导演计划,角色;空景照,剧照,造型照,活动照;;服装,气氛,布景,音响,化妆,灯光,道具;光盘,录音带,像带,唱片;审查,日志,演出计划,座谈会",
        ";;;;录音,录像;;社会活动,宣传评论", 
        ";;;来访,出访;;报刊评论,海报,广告,观众来信,说明书,;学术会议,专场文演,艺术节;;;场次统计,剧节目统计;剧节目抢救,文化史志,文艺集成",
        ";;"}; 
  //-----------------------为加入三级菜单 End-------------

  //-----------------------为加入权限和栏目 Begin------------- 
  private string[] fmenu={"首页","档案浏览","档案管理","附件管理","档案统计","权限管理","系统配置","个人信息","帮助"};
  private string[] smenu={"","基本浏览,高级查询,精确查询","立卷归档,收集录入","图片附件,视音频附件,其它附件","访问统计,高级统计,特制统计","角色管理,用户管理","栏目管理,单位信息,日志浏览,媒体介质编辑,剧种选择","修改密码","使用手册,关于我们"};
  //-----------------------为加入权限和栏目 EnD-------------
  private System.Windows.Forms.Button butDefine; //根据ArtArchives.Business.ArchiveClassStructural 里面 初始化的 编号
  private System.ComponentModel.Container components = null;

  public Form1()
  {
   //
   // Windows 窗体设计器支持所必需的
   //
   InitializeComponent();
   
   //
   // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
   //
  }

  /// <summary>
  /// 清理所有正在使用的资源。
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows 窗体设计器生成的代码
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {
   this.label1 = new System.Windows.Forms.Label();
   this.label2 = new System.Windows.Forms.Label();
   this.label3 = new System.Windows.Forms.Label();
   this.txbOPwd = new System.Windows.Forms.TextBox();
   this.butInto = new System.Windows.Forms.Button();
   this.lbl = new System.Windows.Forms.Label();
   this.label4 = new System.Windows.Forms.Label();
   this.label5 = new System.Windows.Forms.Label();
   this.label6 = new System.Windows.Forms.Label();
   this.label7 = new System.Windows.Forms.Label();
   this.txbNUid = new System.Windows.Forms.TextBox();
   this.label8 = new System.Windows.Forms.Label();
   this.txbNPwd = new System.Windows.Forms.TextBox();
   this.label9 = new System.Windows.Forms.Label();
   this.butDefine = new System.Windows.Forms.Button();
   this.butOCheck = new System.Windows.Forms.Button();
   this.butNCheck = new System.Windows.Forms.Button();
   this.cboxOServer = new System.Windows.Forms.ComboBox();
   this.cboxNServer = new System.Windows.Forms.ComboBox();
   this.cboxOData = new System.Windows.Forms.ComboBox();
   this.txbOUid = new System.Windows.Forms.TextBox();
   this.cboxNData = new System.Windows.Forms.ComboBox();
   this.SuspendLayout();
   //
   // label1
   //
   this.label1.AutoSize = true;
   this.label1.Location = new System.Drawing.Point(40, 48);
   this.label1.Name = "label1";
   this.label1.Size = new System.Drawing.Size(48, 17);
   this.label1.TabIndex = 2;
   this.label1.Text = "机器名:";
   this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
   //
   // label2
   //
   this.label2.AutoSize = true;
   this.label2.Location = new System.Drawing.Point(16, 80);
   this.label2.Name = "label2";
   this.label2.Size = new System.Drawing.Size(72, 17);
   this.label2.TabIndex = 3;
   this.label2.Text = "Sql用户名 :";
   this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
   //
   // label3
   //
   this.label3.Location = new System.Drawing.Point(32, 112);
   this.label3.Name = "label3";
   this.label3.Size = new System.Drawing.Size(56, 24);
   this.label3.TabIndex = 4;
   this.label3.Text = "Sql密码:";
   this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
   //
   // txbOPwd
   //
   this.txbOPwd.Location = new System.Drawing.Point(96, 112);
   this.txbOPwd.Name = "txbOPwd";
   this.txbOPwd.TabIndex = 5;
   this.txbOPwd.Text = "lzhm";
   //
   // butInto
   //
   this.butInto.Location = new System.Drawing.Point(208, 224);
   this.butInto.Name = "butInto";
   this.butInto.TabIndex = 6;
   this.butInto.Text = "数据导入";
   this.butInto.Click += new System.EventHandler(this.butInto_Click);
   //
   // lbl
   //
   this.lbl.AutoSize = true;
   this.lbl.Location = new System.Drawing.Point(16, 168);
   this.lbl.Name = "lbl";
   this.lbl.Size = new System.Drawing.Size(72, 17);
   this.lbl.TabIndex = 7;
   this.lbl.Text = "数据库名称:";
   this.lbl.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
   //
   // label4
   //
   this.label4.AutoSize = true;
   this.label4.Location = new System.Drawing.Point(16, 16);
   this.label4.Name = "label4";
   this.label4.Size = new System.Drawing.Size(54, 17);
   this.label4.TabIndex = 9;
   this.label4.Text = "原数据库";
   //
   // label5
   //
   this.label5.AutoSize = true;
   this.label5.Location = new System.Drawing.Point(288, 16);
   this.label5.Name = "label5";
   this.label5.Size = new System.Drawing.Size(72, 17);
   this.label5.TabIndex = 10;
   this.label5.Text = "目标数据库:";
   this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
   //
   // label6
   //
   this.label6.AutoSize = true;
   this.label6.Location = new System.Drawing.Point(304, 48);
   this.label6.Name = "label6";
   this.label6.Size = new System.Drawing.Size(48, 17);
   this.label6.TabIndex = 11;
   this.label6.Text = "机器名:";
   //
   // label7
   //
   this.label7.AutoSize = true;
   this.label7.Location = new System.Drawing.Point(280, 80);
   this.label7.Name = "label7";
   this.label7.Size = new System.Drawing.Size(72, 17);
   this.label7.TabIndex = 13;
   this.label7.Text = "Sql用户名 :";
   //
   // txbNUid
   //
   this.txbNUid.Location = new System.Drawing.Point(368, 80);
   this.txbNUid.Name = "txbNUid";
   this.txbNUid.TabIndex = 14;
   this.txbNUid.Text = "sa";
   //
   // label8
   //
   this.label8.AutoSize = true;
   this.label8.Location = new System.Drawing.Point(304, 112);
   this.label8.Name = "label8";
   this.label8.Size = new System.Drawing.Size(48, 17);
   this.label8.TabIndex = 15;
   this.label8.Text = "Sql密码";
   //
   // txbNPwd
   //
   this.txbNPwd.Location = new System.Drawing.Point(368, 104);
   this.txbNPwd.Name = "txbNPwd";
   this.txbNPwd.TabIndex = 16;
   this.txbNPwd.Text = "lzhm";
   //
   // label9
   //
   this.label9.AutoSize = true;
   this.label9.Location = new System.Drawing.Point(280, 168);
   this.label9.Name = "label9";
   this.label9.Size = new System.Drawing.Size(72, 17);
   this.label9.TabIndex = 17;
   this.label9.Text = "数据库名称:";
   //
   // butDefine
   //
   this.butDefine.Location = new System.Drawing.Point(368, 8);
   this.butDefine.Name = "butDefine";
   this.butDefine.TabIndex = 19;
   this.butDefine.Text = "初始化";
   this.butDefine.Click += new System.EventHandler(this.butDefine_Click);
   //
   // butOCheck
   //
   this.butOCheck.Location = new System.Drawing.Point(72, 136);
   this.butOCheck.Name = "butOCheck";
   this.butOCheck.Size = new System.Drawing.Size(88, 23);
   this.butOCheck.TabIndex = 20;
   this.butOCheck.Text = "原数据库测试";
   this.butOCheck.Click += new System.EventHandler(this.butOCheck_Click);
   //
   // butNCheck
   //
   this.butNCheck.Location = new System.Drawing.Point(336, 136);
   this.butNCheck.Name = "butNCheck";
   this.butNCheck.Size = new System.Drawing.Size(104, 23);
   this.butNCheck.TabIndex = 22;
   this.butNCheck.Text = "目标数据库测试";
   this.butNCheck.Click += new System.EventHandler(this.butNCheck_Click);
   //
   // cboxOServer
   //
   this.cboxOServer.Location = new System.Drawing.Point(96, 40);
   this.cboxOServer.Name = "cboxOServer";
   this.cboxOServer.Size = new System.Drawing.Size(121, 20);
   this.cboxOServer.TabIndex = 24;
   this.cboxOServer.SelectedIndexChanged += new System.EventHandler(this.cboxOServer_SelectedIndexChanged);
   //
   // cboxNServer
   //
   this.cboxNServer.Location = new System.Drawing.Point(368, 48);
   this.cboxNServer.Name = "cboxNServer";
   this.cboxNServer.Size = new System.Drawing.Size(121, 20);
   this.cboxNServer.TabIndex = 25;
   this.cboxNServer.SelectedIndexChanged += new System.EventHandler(this.cboxNServer_SelectedIndexChanged);
   //
   // cboxOData
   //
   this.cboxOData.Enabled = false;
   this.cboxOData.Location = new System.Drawing.Point(96, 168);
   this.cboxOData.Name = "cboxOData";
   this.cboxOData.Size = new System.Drawing.Size(121, 20);
   this.cboxOData.TabIndex = 26;
   //
   // txbOUid
   //
   this.txbOUid.Location = new System.Drawing.Point(96, 80);
   this.txbOUid.Name = "txbOUid";
   this.txbOUid.TabIndex = 27;
   this.txbOUid.Text = "sa";
   //
   // cboxNData
   //
   this.cboxNData.Enabled = false;
   this.cboxNData.Location = new System.Drawing.Point(368, 168);
   this.cboxNData.Name = "cboxNData";
   this.cboxNData.Size = new System.Drawing.Size(121, 20);
   this.cboxNData.TabIndex = 28;
   //
   // Form1
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(512, 293);
   this.Controls.Add(this.cboxNData);
   this.Controls.Add(this.txbOUid);
   this.Controls.Add(this.cboxOData);
   this.Controls.Add(this.cboxNServer);
   this.Controls.Add(this.cboxOServer);
   this.Controls.Add(this.butNCheck);
   this.Controls.Add(this.butOCheck);
   this.Controls.Add(this.butDefine);
   this.Controls.Add(this.label9);
   this.Controls.Add(this.txbNPwd);
   this.Controls.Add(this.label8);
   this.Controls.Add(this.txbNUid);
   this.Controls.Add(this.label7);
   this.Controls.Add(this.label6);
   this.Controls.Add(this.label5);
   this.Controls.Add(this.lbl);
   this.Controls.Add(this.txbOPwd);
   this.Controls.Add(this.label2);
   this.Controls.Add(this.label1);
   this.Controls.Add(this.label4);
   this.Controls.Add(this.butInto);
   this.Controls.Add(this.label3);
   this.Name = "Form1";
   this.Load += new System.EventHandler(this.Form1_Load);
   this.Closed += new System.EventHandler(this.Form1_Closed);
   this.ResumeLayout(false);

  }
  #endregion

  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [STAThread]
  static void Main()
  {
   Application.Run(new Form1());
  }
  private void Form1_Load(object sender, System.EventArgs e)
  {
//   butInto.Visible=false;   
   string appPath=Path.GetDirectoryName(Application.ExecutablePath);
   oldDirectory=appPath+"//附件";
   sqlApp = new SQLDMO.ApplicationClass();
   SQLDMO.NameList sqlServers=sqlApp.ListAvailableSQLServers();
   for(int i=0;i<sqlServers.Count;i++)
   {
    object srv = sqlServers.Item( i + 1);
    if(srv != null)
    {
     this.cboxOServer.Items.Add(srv); 
     this.cboxNServer.Items.Add(srv);
    }
     
   }
   if( this.cboxOServer.Items.Count > 0)
    this.cboxOServer.SelectedIndex = 0;
   else
    this.cboxOServer.Text = "<没有检测到服务器>";
   if( this.cboxNServer.Items.Count > 0)
    this.cboxNServer.SelectedIndex = 0;
   else
    this.cboxNServer.Text = "<没有检测到服务器>";   
  }
  private void SetConnect()     //对xpo 的 数据库连接的 设置
  {
   string nserver=cboxOServer.SelectedItem.ToString();  
   string nuid=txbNUid.Text.Trim();
   string npwd=txbNPwd.Text.Trim();
   string ndata=this.cboxNData.SelectedItem.ToString();    
   string newstring =string.Format("Data Source={0};Initial Catalog= {1};User ID={2};Password= {3}",nserver,ndata,nuid ,npwd);
   if(DBConnect.ArtSession.IsConnected)  //若连接 ,则关闭
    DBConnect.ArtSession.Disconnect();
   DBConnect.ArtSession.ConnectionString=newstring;
  }

  private void butInto_Click(object sender, System.EventArgs e)
  {   
   string oserver=cboxOServer.SelectedItem.ToString();
   string ouid=txbOUid.Text.Trim();
   string opwd=txbOPwd.Text.Trim();
   string odata=this.cboxOData.SelectedItem.ToString();   
   string oldString=String.Format(connstring,oserver,odata,ouid,opwd);  //原数据库的字符串连接
  
   string[] tableName={"gerenjibenziliao","juzhong","jumu","anjuan","juannei","huojiangqingkuang","shuxing","jumumodule","jumubanben"};    //原数据库 的表名
   foreach(string name in tableName) 
    GetList(oldString,name);
   CreateRelations(); 
   CreateComputer(); 
   
   #region   对相关 表的初始化(案卷 和件的初始化,剧目的初始化 ,个人信息和三大类的获奖情况)
   //单位信息的导入
   string className="ArchivesOrg";
   string[] oldFieldName=new string []{"name","description"};
   string[] newFieldName=new string []{"Name","Description"};
   Save(tableName[1],className,oldFieldName,newFieldName,null);
   //案卷 和件的 导入
   string[] sorts={"剧目","人物","综合","资料"};  
   for(int i=0;i<sorts.Length;i++)
   {
    Guid guid=guids[i];
    SetType(sorts[i].Trim(),tableName[3],guid);
   }
    // 剧目的导入
   className="Drama";           
   oldFieldName=new string []{"name","jumuhao"};
   newFieldName=new string []{"Name","DramaNo"};
   Save(tableName[2],className,oldFieldName,newFieldName,null); 
   //个人基本资料的导入
   className="Person";
   oldFieldName=new string []{"name","birthday","sex","nativeplace","nation"};
   newFieldName=new string []{"Name","BornDate","Sex","NativePlace","Nation"}; 
   Save(tableName[0],className,oldFieldName,newFieldName,null); 
   //剧目中 获奖情况的导入
   className="Award";   
   oldFieldName=new string []{"instance","man","eventtime","issue"};
   newFieldName=new string []{"AwardName","Author","Time","OrgName"};
   string whereString=string.Format("shuxing_id in ({0})",GetChildsList("剧目"));  
   Save(tableName[5],className,oldFieldName,newFieldName,whereString); 
   //人物中  获奖情况的导入
   className="PersonalAward";   
   oldFieldName=new string []{"instance","man","eventtime","issue"};
   newFieldName=new string []{"AwardName","Author","Time","AwradORG"};
   whereString=string.Format("shuxing_id in ({0})",GetChildsList("人物"));
   Save(tableName[5],className,oldFieldName,newFieldName,whereString); 
   ////其他中  获奖情况的导入
   className="IntegrationAward";   
   oldFieldName=new string []{"instance","man","eventtime","issue","rank"};
   newFieldName=new string []{"AwardName","Author","Time","AwardORG","AwardGrade"};
   whereString=string.Format("shuxing_id in ({0})",GetChildsList("综合"));
   Save(tableName[5],className,oldFieldName,newFieldName,whereString);
   #endregion  
   DataTable dt=ds.Tables["jumumodule"];   
   className="MediumTypeDefine";
   oldFieldName=new string []{"filemedium"};
   newFieldName=new string []{"Name"};
   Save("medium",className,oldFieldName,newFieldName,null);   //添加数据到媒体介质表中
   Assembly bus=Assembly.Load("Business"); 
   
   foreach(DataRow row in dt.Rows)
   {
    object obj=new object();
    string topeType="";                          //四大类别(剧目 人物,其他 综合)
    string thisType=row.GetParentRow("jumumodule_shuxing")["shuxing"].ToString().Trim();
    string module=row.GetParentRow("jumumodule_shuxing").GetParentRow("shuxing_shuxing")["shuxing"].ToString().Trim();  
    if(topelist.IndexOf(module)>=0)   //若到达 一级目录,说明已经是二级目录了
     module=row.GetParentRow("jumumodule_shuxing")["shuxing"].ToString().Trim();
    topeType=GetTopeType("jumumodule_shuxing",row,topelist);   
    object banbenId=row["jumubanben_id"];    
    if(banbenId!=null)
    {
     Drama drama=null;
     if(row.GetParentRow("jumumodule_jumubanben")!=null)
      if(row.GetParentRow("jumumodule_jumubanben").GetParentRow("jumu_jumubanben")!=null)        {   //jumubanben 这个是 剧目版本 ,则现在系统中 没有这个数据,但是要和剧目连接起来
       string jumuName=row.GetParentRow("jumumodule_jumubanben").GetParentRow("jumu_jumubanben")["name"].ToString().Trim(); 
       drama=DBConnect.ArtSession.FindObject(typeof(Drama),new BinaryOperator("Name",jumuName)) as Drama; 
      }
     switch(module)
     {
      case "剧本":
       className="PlayBook";  
       oldFieldName=new string []{"name","author","eventtime"};
       newFieldName=new string []{"Name","Author","Time"};     
       obj=bus.CreateInstance(busnamespace+className);
       SetValue(row,obj,oldFieldName,newFieldName);       
       PlayBook play=(PlayBook)obj;
       if(drama!=null)
        play.drama=drama;        
       break;
      case "导表演":
       className="DirectorAndActor";  
       oldFieldName=new string []{"name","author","eventtime"};
       newFieldName=new string []{"Name","Author","Time"};     
       obj=bus.CreateInstance(busnamespace+className);
       SetValue(row,obj,oldFieldName,newFieldName);
       DirectorAndActor diract=(DirectorAndActor)obj;
       if(drama!=null)
        diract.drama=drama;    
       break;
      case "舞台美术":
       className="Decor";  
       oldFieldName=new string []{"name","author","player","rolename","sounder","propname","area","program","eventtime"};
       newFieldName=new string []{"Name","Author","Cast","Role","Dub","PropName","Theater","PerformancName","Time"};     
       obj=bus.CreateInstance(busnamespace+className);
       SetValue(row,obj,oldFieldName,newFieldName);
       Decor dec=(Decor)obj;
       if(drama!=null)
        dec.drama=drama;    
       break;
      case "乐谱":
       className="MusicBook";  
       oldFieldName=new string []{"author","mixname","roundname"};
       newFieldName=new string []{"Name","Tools","RoomName"};         
       obj=bus.CreateInstance(busnamespace+className);
       SetValue(row,obj,oldFieldName,newFieldName);
       MusicBook music=(MusicBook)obj;
       if(drama!=null)
        music.drama=drama;    
       break;
      case "演出活动":
       className="Performance";  
       oldFieldName=new string []{"name","author","eventtime"};
       newFieldName=new string []{"Name","Author","Time"};     
       obj=bus.CreateInstance(busnamespace+className);
       SetValue(row,obj,oldFieldName,newFieldName);
       Performance per=(Performance)obj;
       if(drama!=null)
        per.drama=drama;    
       break;
      case "宣传评论":
       className="Publicize";  
       oldFieldName=new string []{"name","author","eventtime"};//
       newFieldName=new string []{"Name","Author","Time"};//    
       obj=bus.CreateInstance(busnamespace+className);
       SetValue(row,obj,oldFieldName,newFieldName);
       Publicize pbliz=(Publicize)obj;
       if(drama!=null)
        pbliz.drama=drama;
       break;
      case "照片":
       className="DramaPhoto";  
       oldFieldName=new string []{"name","author","col_backup3","eventtime"};
       newFieldName=new string []{"Name","Author","PhotoContext","Time"};    
       obj=bus.CreateInstance(busnamespace+className);
       SetValue(row,obj,oldFieldName,newFieldName);
       DramaPhoto photo=(DramaPhoto)obj;
       if(drama!=null)
        photo.drama=drama;
       break;
      case "音像":
       className="Vidio";  
       oldFieldName=new string []{"name","soundstuffid","soundtype","producecompany","eventtime"};
       newFieldName=new string []{"Name","SortNo","Spec","Author","Time"};     
       obj=bus.CreateInstance(busnamespace+className);
       SetValue(row,obj,oldFieldName,newFieldName);
       Vidio vidio=(Vidio)obj;
       if(drama!=null)
        vidio.drama=drama;
       break;      
     }
    }
    else    //非剧目类别
    {     
     switch(module)
     {
      case "音像":
       className="Personalaudiovidio";  
       oldFieldName=new string []{"name","soundstuffid","soundtype","soundstuffid","producecompany","eventtime"};
       newFieldName=new string []{"Name","SortNo","Spec","soundstuffid","Author","Time"};         
       obj=bus.CreateInstance(busnamespace+className);
       SetValue(row,obj,oldFieldName,newFieldName);
       break;      
      case "照片":
       string shuxing=row.GetParentRow("jumumodule_shuxing").GetParentRow("shuxing_shuxing")["shuxing"].ToString().Trim();
       if(shuxing== "人物")
        className="PersonalPhoto";  
       else
        className="IntegrationPhoto";
       oldFieldName=new string []{"name","author","col_backup3","eventtime"};
       newFieldName=new string []{"Name","Author","PhotoContext","Time"};        
       obj=bus.CreateInstance(busnamespace+className);
       SetValue(row,obj,oldFieldName,newFieldName);
       break;      
      case "生活照":
       className="LivingFigure";  
       oldFieldName=new string []{"name","author","eventtime"};
       newFieldName=new string []{"Name","Author","Time"};     
       obj=bus.CreateInstance(busnamespace+className);
       SetValue(row,obj,oldFieldName,newFieldName);
       break;      
      case "业务成就":
       className="Achievement";  
       oldFieldName=new string []{"col_backup3","col_backup2","eventtime"};
       newFieldName=new string []{"Author","DramaName","Time"};     
       obj=bus.CreateInstance(busnamespace+className);
       SetValue(row,obj,oldFieldName,newFieldName);
       break;    
      case "其他":
       className="PersonalOthers";  
       oldFieldName=new string []{"name","author","eventtime"};
       newFieldName=new string []{"Name","Author","Time"};     
       obj=bus.CreateInstance(busnamespace+className);
       SetValue(row,obj,oldFieldName,newFieldName);
       break;  
      case "文艺刊物":
       className="Journal";  
       oldFieldName=new string []{"name","author","eventtime"};
       newFieldName=new string []{"Name","Author","Time"};     
       obj=bus.CreateInstance(busnamespace+className);
       SetValue(row,obj,oldFieldName,newFieldName);
       break;    
      case "业务计划、总结":
       className="BusinessPlan";  
       oldFieldName=new string []{"name","author","eventtime"};
       newFieldName=new string []{"Name","Author","Time"};     
       obj=bus.CreateInstance(busnamespace+className);
       SetValue(row,obj,oldFieldName,newFieldName);
       break;    
      case "对外交流":
       className="Exchange";  
       oldFieldName=new string []{"name","author","eventtime"};
       newFieldName=new string []{"Name","Author","Time"};     
       obj=bus.CreateInstance(busnamespace+className);
       SetValue(row,obj,oldFieldName,newFieldName);
       break;    
      case "宣传评论":
       className="IntegrationPublicize";  
       oldFieldName=new string []{"name","author","eventtime"};
       newFieldName=new string []{"Name","Author","Time"};     
       obj=bus.CreateInstance(busnamespace+className);
       SetValue(row,obj,oldFieldName,newFieldName);
       break;    
      case "重大文化艺术活动":
       className="ArtActivity";  
       oldFieldName=new string []{"name","author","eventtime"};
       newFieldName=new string []{"Name","Author","Time"};     
       obj=bus.CreateInstance(busnamespace+className);
       SetValue(row,obj,oldFieldName,newFieldName);
       break;    
      case "综合性活动":
       className="IntegrativeActivity";  
       oldFieldName=new string []{"name","author","eventtime"};
       newFieldName=new string []{"Name","Author","Time"};     
       obj=bus.CreateInstance(busnamespace+className);
       SetValue(row,obj,oldFieldName,newFieldName);
       break;    
      case "大事记、历史沿革":
       className="Memorabilia";  
       oldFieldName=new string []{"name","author","eventtime"};
       newFieldName=new string []{"Name","Author","Time"};     
       obj=bus.CreateInstance(busnamespace+className);
       SetValue(row,obj,oldFieldName,newFieldName);
       break;  
      case "演出统计":
       className="PerformanceCalCulation";  
       oldFieldName=new string []{"name","author","eventtime"};
       newFieldName=new string []{"Name","Author","Time"};     
       obj=bus.CreateInstance(busnamespace+className);
       SetValue(row,obj,oldFieldName,newFieldName);
       break;    
      case "艺术挖掘抢救":
       className="Salvage";  
       oldFieldName=new string []{"name","author","eventtime"};
       newFieldName=new string []{"Name","Author","Time"};     
       obj=bus.CreateInstance(busnamespace+className);
       SetValue(row,obj,oldFieldName,newFieldName);
       break;   
      case "文字":
       className="Doc";  
       oldFieldName=new string []{"name","author","eventtime"};
       newFieldName=new string []{"Name","Author","Time"};     
       obj=bus.CreateInstance(busnamespace+className);
       SetValue(row,obj,oldFieldName,newFieldName);
       break;   
      case "图片":
       className="DatumPhoto";  
       oldFieldName=new string []{"name","author","col_backup3","eventtime"};
       newFieldName=new string []{"Name","Author","Memo","Time"};     
       obj=bus.CreateInstance(busnamespace+className);
       SetValue(row,obj,oldFieldName,newFieldName);
       break;   
      case "视频":
       className="DatumVidio";  
       oldFieldName=new string []{"name","soundstuffid","soundtype","producecompany","eventtime"};
       newFieldName=new string []{"Name","SortNo","Spec","Author","Time"};     
       obj=bus.CreateInstance(busnamespace+className);
       SetValue(row,obj,oldFieldName,newFieldName);       
       break;  
     }
    }
    if(obj.GetType()==typeof(object))   //若 "对象"没有复制
     continue;
    ArchiveObject aobj=(ArchiveObject)obj;
    CustomType ctype=DBConnect.ArtSession.FindObject(typeof(CustomType),new BinaryOperator("Name",thisType)) as CustomType;
    //-------设置三级菜单的 索引号
    if(thisType!=module)
    {
//     GroupOperator gop =new GroupOperator();
//     gop.OperatorType = GroupOperatorType.And;    
//     BinaryOperator op1= new BinaryOperator("ClassType",className);
//     BinaryOperator op2 = new BinaryOperator("Name",module,BinaryOperatorType.NotEqual); 
//     gop.Operands.Add(op1);  
//     gop.Operands.Add(op2);      
//     XPCollection xp=new XPCollection(typeof(ArchivesType),gop);
//     int index=xp.IndexOf(DBConnect.ArtSession.FindObject(typeof(ArchivesType),new BinaryOperator("Name",thisType)))+1;
//     int index=0;
//     for(int i=0;i<xp.Count;i++)
//     {
//      ArchivesType a=xp[i] as ArchivesType;
//      if(a.Name==thisType)
//      {
//       index=i+1;
//       break; 
//      }
//     }
     aobj.Classification= GetTypeIndex(thisType); ;   //三级菜单的 索引号 GetTypeIndex(thisType);
    }
   
    
    //if(ctype!=null)
     aobj.Type=DBConnect.ArtSession.GetObjectByKey(typeof(ArchivesType),ctype.guid) as ArchivesType;    //类别

    if(row.GetParentRow("jumumodule_juannei")!=null) //若件也没有
    {
     if(row.GetParentRow("jumumodule_juannei").GetParentRow("anjuan_juannei")!=null)  //若只有件没卷的话
     {          
      string groupName=row.GetParentRow("jumumodule_juannei")["name"].ToString().Trim();
      string bagNum=row.GetParentRow("jumumodule_juannei").GetParentRow("anjuan_juannei")["number"].ToString().Trim();
      string bagName=row.GetParentRow("jumumodule_juannei").GetParentRow("anjuan_juannei")["name"].ToString().Trim();
      string groupNum=row.GetParentRow("jumumodule_juannei").GetParentRow("anjuan_juannei")["number"].ToString().Trim();

      ArchivesBag aBag = null;
      if(bagName!="")
      {
       GroupOperator Gop =new GroupOperator();
       Gop.OperatorType = GroupOperatorType.And;    
       BinaryOperator opName = new BinaryOperator("Name",bagNum+"|"+bagName);
       BinaryOperator opNumber = new BinaryOperator("Number",bagNum); 
       Gop.Operands.Add(opName);  
       Gop.Operands.Add(opNumber);        
       aBag = DBConnect.ArtSession.FindObject(typeof(ArchivesBag),Gop) as ArchivesBag;
       aobj.Bag=aBag;       
      } 
      
      ArchivesGroup group=new ArchivesGroup();
      if(groupName!=""&& bagName!=null)
      {            
       XPCollection childs = aBag.Childs;
       foreach(ArchivesGroup aGoup in childs)
       {
        if(aGoup.Name == groupName)
        {
         aobj.Group=aGoup;
         break;
        }
       }
      }
   
     }
    }    
    string orgName=row.GetParentRow("jumumodule_juzhong")["name"].ToString().Trim();  
    string mediumName=row["filemedium"].ToString().Trim(); 
    string[] files=row["filepath"].ToString().Split(new char[]{';'});
    string oldDirPath=GetPath(oldDirectory,row["juzhong_id"].ToString(),row["shuxing_id"].ToString());
    string newrootPath=getrootPath(rootPath);
    string path;
    if(topeType== "剧目"||topeType== "人物")
     path=string.Format(@"{0}/{1}/{2}",orgName,topeType,CheckDirName(row["name"].ToString()));
    else
     path=string.Format(@"{0}/{1}",orgName,topeType);
    foreach(string file in files)
    {
     string filename=row["filename"].ToString().Trim();
     CopyUpFile(aobj,file.Trim(),filename,path,oldDirPath);           //附件添加 
    }
    if(orgName!="")      
     aobj.Org=ArchivesOrg.GetOrgByName(orgName);//单位设置 
    if(mediumName!="")
     aobj.Medium= (Enum)Enum.Parse(ArchiveObject.MediumEnumType,MediumTypeDefine.getIndex(mediumName).ToString());                                                     //媒体介质设置
    else
     aobj.Medium=null;
    aobj.Save(); 
   }
   MessageBox.Show("导入成功!");
   
   ds.Relations.Clear();              //移初 所有表关系
   ds.Tables.Clear();                 //移初 所有表
  }
  public void GetList(string oldString,string tableName)
  {      // 原来 所有表 导入到 DataSet 对象中 ,oldString: 数据库联接,tableName: 原表名
   SqlConnection conn=new SqlConnection(oldString);
   if(ds!=null)
   {
    foreach(DataTable dt in ds.Tables)
     if(dt.TableName==tableName)             //若有 就不需要创建
      return;
   }
   else
    ds=new DataSet();
   string sql=string.Format("Select * from {0}",tableName);
   SqlDataAdapter adapter=new SqlDataAdapter(sql,conn);   
   adapter.Fill(ds,tableName); 
   if(tableName=="jumumodule")   //若为jumumodule表,则要添加一个 媒体介质表
   {
    sql=string.Format("SELECT DISTINCT filemedium FROM jumumodule");
    adapter.SelectCommand.CommandText=sql;
    adapter.Fill(ds,"medium");
   }
  }
  public int GetTypeIndex(string typeName)   //取三级菜单 的索引号 根据type1,type2,type3 数组 
  {
   int k=0;
   int i=0;
   int j=0;   //三级菜单 的索引号    
   for(k=0;k<4;k++)
   {
    int b=type3[k].IndexOf("aa");
    //string aa = type3[k].Substring(1,type3[k].Length-1);    
    int a=type3[k].IndexOf(typeName);
    if(type3[k].IndexOf(typeName)>=0)
    {
     string[] tlist=type3[k].Split(new char[]{';'});
     for(i=0;i<tlist.Length;i++)
     {
      if(tlist[i].Trim().IndexOf(typeName)>=0)
      {
       string[] mlist=tlist[i].Split(new char[]{','});
       for(j=0;j<mlist.Length;j++)
       {
        if(mlist[j].Trim()==typeName)//type3 中的 顺序和系统显示的三级类别的索引一样
        {
         j++;
         break;
        }
       }
       break;
      }
     }
     if(i==tlist.Length)    //查不到 则为0
      j=0;
     break;
    }   
   }
   return j;//Lzid改了
  }
  public string GetTopeType(string relname,DataRow row,string topelist)
  {   
   string topeType=row.GetParentRow(relname).GetParentRow("shuxing_shuxing")["shuxing"].ToString().Trim();                             //总目录名称
   if(topelist.IndexOf(topeType)<0)   //若到达 一级目录,说明已经是二级目录了
    topeType=row.GetParentRow(relname).GetParentRow("shuxing_shuxing").GetParentRow("shuxing_shuxing")["shuxing"].ToString().Trim();   
   return topeType;
  }
  public void CopyUpFile(ArchiveObject aobj,string file,string filename,string path,string oldDirPath)          //拷贝 附件 到 目标 目录下 ,aobj,
  {
   if(file=="")
    return;
   try
   {
    string oldFilePath=Path.Combine(oldDirPath,file);
    if(!File.Exists(oldFilePath))     //不存在原文件 则 不要添加数据进入
     return;
    Guid guid=Guid.NewGuid();
    string type=ArchiveAccessory.GetFileExtSort(Path.GetExtension(file));
    string newfile=guid.ToString()+Path.GetExtension(file);     
    string dpath=string.Format(@"{0}/{1}",getrootPath(rootPath),path);
    string newDirPath=string.Format(@"{0}/{1}/{2}",getrootPath(rootPath),path,type);
    string virPath=Path.Combine(string.Format(@"/{0}/{1}/{2}",rootPath,path,type),newfile);
    string storePath=string.Format(@"{0}/{1}/{2}",path,type,newfile);
    string newFilePath=Path.Combine(newDirPath,newfile);
    
    foreach(string t in dtype)
    {
     string p=Path.Combine(dpath,t);
     CheckDirectory(p);
    }
    if(!File.Exists(newFilePath)) //原文件存在,目标文件不在  
     File.Copy(oldFilePath,newFilePath,true);
    ArchiveAccessory acc=new ArchiveAccessory();
    acc.Guid=guid;
    if(filename!="")
     acc.Name=filename; 
    acc.ClientFilePath=oldFilePath;
    acc.VirtualFilePath=virPath.Replace(@"/","/");
    acc.StoreFilePath=storePath;
    acc.Archive=aobj;
    acc.Save();
   }
   catch
   {
//    MessageBox.Show(n.ToString());
   }
  }
  public void CreateRelations()   //创建原来表主外键 关系在ds容器中
  {   
   ds.Relations.Add("jumu_juzhong",ds.Tables["juzhong"].Columns["id"],ds.Tables["jumu"].Columns["juzhong_id"],false);  //剧目和单位
   ds.Relations.Add("anjuan_juzhong",ds.Tables["juzhong"].Columns["id"],ds.Tables["anjuan"].Columns["juzhong_id"],false);  //案卷 和单位
   ds.Relations.Add("gerenjibenziliao_juzhong",ds.Tables["juzhong"].Columns["id"],ds.Tables["gerenjibenziliao"].Columns["juzhong_id"],false);  //个人基本资料和单位
   ds.Relations.Add("gerenjibenziliao_juannei",ds.Tables["juannei"].Columns["id"],ds.Tables["gerenjibenziliao"].Columns["juannei_id"],false);     //个人基本资料和件
   ds.Relations.Add("gerenjibenziliao_shuxing",ds.Tables["shuxing"].Columns["shuxing_id"],ds.Tables["gerenjibenziliao"].Columns["shuxing_id"],false);    //个人基本资料和栏目
   ds.Relations.Add("hqqk_juzhong",ds.Tables["juzhong"].Columns["id"],ds.Tables["huojiangqingkuang"].Columns["juzhong_id"],false);                  //获奖情况和单位
   ds.Relations.Add("hqqk_juannei",ds.Tables["juannei"].Columns["id"],ds.Tables["huojiangqingkuang"].Columns["juannei_id"],false);                          //获奖情况和件
   ds.Relations.Add("hqqk_shuxing",ds.Tables["shuxing"].Columns["shuxing_id"],ds.Tables["huojiangqingkuang"].Columns["shuxing_id"],false);                     //获奖情况和栏目
   ds.Relations.Add("shuxing_shuxing",ds.Tables["shuxing"].Columns["shuxing_id"],ds.Tables["shuxing"].Columns["Parent_ID"],false);          //栏目和栏目
   ds.Relations.Add("jumu_jumubanben",ds.Tables["jumu"].Columns["id"],ds.Tables["jumubanben"].Columns["jumu_id"],false);                                    //剧目和剧目版本
   ds.Relations.Add("jumumodule_jumubanben",ds.Tables["jumubanben"].Columns["id"],ds.Tables["jumumodule"].Columns["jumubanben_id"],false);                      //各大类资料 和剧目版本
   ds.Relations.Add("jumumodule_shuxing",ds.Tables["shuxing"].Columns["shuxing_id"],ds.Tables["jumumodule"].Columns["shuxing_id"],false);                //各大类资料 和 栏目 
   ds.Relations.Add("jumumodule_juannei",ds.Tables["juannei"].Columns["id"],ds.Tables["jumumodule"].Columns["juannei_id"],false);      //各大类资料 和  件
   ds.Relations.Add("jumumodule_juzhong",ds.Tables["juzhong"].Columns["id"],ds.Tables["jumumodule"].Columns["juzhong_id"],false);      //各大类资料 和 单位
   ds.Relations.Add("anjuan_juannei",ds.Tables["anjuan"].Columns["id"],ds.Tables["juannei"].Columns["anjuan_id"],false);                            //案卷和件
  }

  public void Save(string tableName,string className,string[] oldFieldName,string[] newFieldName,string whereString)
  {   
   DataTable dt=ds.Tables[tableName];
   IntoData(dt,className,oldFieldName,newFieldName,whereString);  
  }
  public string GetChildsList(string name)  //获取所有下一子级菜单的 编号
  {
   DataTable dt=ds.Tables["shuxing"];
   string where=string.Format("shuxing='{0}'",name);
   string id="";
   foreach(DataRow row in dt.Select(where))
   {
    foreach(DataRow child in row.GetChildRows("shuxing_shuxing"))
     id=id+","+child["shuxing_id"];
   } 
   return id.Trim(new char[]{','});
  }

  public void SetType(string sortName,string tableName,Guid guid)  //卷和件的数据导入
  {
   DataTable dt=ds.Tables[tableName];
   string wherestring=string.Format("sort='{0}'",sortName);
   foreach(DataRow row in dt.Select(wherestring))   //卷的 处理
   {
    string bagName=row["name"].ToString().Trim();
    string bagNum=row["number"].ToString();
    ArchivesBag bag=new ArchivesBag(); 
    bag.Number = bagNum;
    bag.Name= bagNum + "|" + bagName; 
    bag.WriteBagYear = Convert.ToDateTime(row["eventtime"]).Year.ToString();
    bag.Type=GetTypeByField("guid",guid.ToString());
    bag.Save();   
    
    string where1="anjuan_id="+row["id"].ToString();
    foreach(DataRow crow in ds.Tables["juannei"].Select(where1))  //卷下的件的处理
    {  
     ArchivesGroup group=new ArchivesGroup();
     group.Name=crow["name"].ToString().Trim();
     group.Number=Convert.ToInt32(crow["number"]);
     group.Parent=bag;
     group.Save();
    }    
   } 
  }

  public ArchivesType GetTypeByField(string field,string val)   //同过字段field和值val 取的ArchivesType 对象
  {
   ArchivesType type=DBConnect.ArtSession.FindObject(typeof(ArchivesType),new BinaryOperator(field,val)) as ArchivesType;
   return type;
  }
  /// <summary>
  /// 通过反射把字段赋值
  /// </summary>
  /// <param name="row"></param>
  /// <param name="obj"></param>
  /// <param name="oldFieldName"></param>
  /// <param name="newFieldName"></param>
  public void SetValue(DataRow row,object obj,string[] oldFieldName,string[] newFieldName)  //通过反射把字段赋值
  {                       
   if(obj==null)
    return ;
   Type otype=obj.GetType();
   for(int i=0;i<oldFieldName.Length;i++)
   {      
    string nFieldName=newFieldName[i];                  //新数据源字段名
    string oFieldName=oldFieldName[i];
    object oValue=row[oFieldName];
    FieldInfo[] fields=otype.GetFields();
    bool isPorperty=true;
    
    if(fields.Length>0)   //类是否定义了 公共字段
    {
     foreach(FieldInfo fieldInfo in fields)
     {
      if(fieldInfo.Name==nFieldName)
      {
       if(Convert.ToString(oValue)=="")
        oValue=null;
       else if(fieldInfo.FieldType==typeof(Date)||fieldInfo.Name=="Time")
       {
        string date=row[oFieldName].ToString().Trim();       
        oValue=Date.Parse(SetData(date)); 
       }
       else if(fieldInfo.FieldType==typeof(DateTime))//出现 日期格式不完整
        oValue=Convert.ToDateTime(SetData(row[oFieldName].ToString()));                      
       else
        oValue=Convert.ToString(row[oFieldName]).Trim();
       otype.InvokeMember(nFieldName,BindingFlags.SetField|BindingFlags.Instance|BindingFlags.Public|BindingFlags.IgnoreCase,null,obj,new object[]{oValue});
       isPorperty=false;
       break;
      }
     }
    }
    if(isPorperty)        // 是否属性
    {
     PropertyInfo[] porertys=otype.GetProperties();
     foreach(PropertyInfo porertyInfo in porertys)
     {
      if(porertyInfo.Name==nFieldName)
      {
       if(Convert.ToString(oValue)=="")
        oValue=null;
       else if(porertyInfo.PropertyType==typeof(Date)||nFieldName=="Time")
       {
        string date=row[oFieldName].ToString().Trim();       
        oValue=Date.Parse(SetData(date)); 
       }
       else if(porertyInfo.PropertyType==typeof(DateTime))//出现 日期格式不完整
        oValue=Convert.ToDateTime(SetData(row[oFieldName].ToString().Trim()));                       else
        oValue=Convert.ToString(row[oFieldName]).Trim();
       otype.InvokeMember(nFieldName,BindingFlags.SetProperty|BindingFlags.Instance|BindingFlags.Public|BindingFlags.IgnoreCase,null,obj,new object[]{oValue});   
       break;
      }
     }
    
    }
   } 
  }
  public void IntoParentData(DataRow row,object obj,string[] oldFieldName,string[] newFieldName)
  {    
   SetValue(row,obj,oldFieldName,newFieldName);
   ((XPBaseObject)obj).Save(); 
  }
  /// <summary>
  /// 相关表数据
  /// </summary>
  /// <param name="dt">原表</param>
  /// <param name="className">新类名、新表</param>
  /// <param name="oldFieldName">原字段列</param>
  /// <param name="newFieldName">新字段列</param>
  /// <param name="whereString">//</param>
  public void IntoData(DataTable dt,string className,string[] oldFieldName,string[] newFieldName,string whereString)             
  {// 倒入 相关表数据,dt 原标DataTable对象 ,className 目标类名,oldFieldName 原字段列,newFieldName 目标字段列
   //   try
   //   { 
   
   foreach(DataRow row in dt.Select(whereString))
   { 
    Assembly bus=Assembly.Load("Business");  
    object obj=bus.CreateInstance(busnamespace+className);
    bool hasName=false;
    if(dt.TableName=="medium")
    {
     string name=row["filemedium"].ToString().Trim();
     if(name=="")
     {
      hasName=true;
      break;
     }
     XPCollection list=MediumTypeDefine.List;
     for(int i=0;i<list.Count;i++)
     {
      if(name==list[0].ToString().Trim())   //若有相
      {
       hasName=true;
       break;
      }
     }
    }
    if(!hasName)
     SetValue(row,obj,oldFieldName,newFieldName);
    string orgName=""; 
    string bagName="";
    string bagNum="";
    string groupName="";
    string groupNum="";
    string dtName=dt.TableName;
    string topeType="";
    string thisType="";
    if(dtName=="gerenjibenziliao")
    {
     Person person=(Person)obj;       
     PersonBasicInfo perbasic=new PersonBasicInfo();
     person.BaseInfo=perbasic; 
     perbasic.personVita=person; 
     string[] oldPFieldName={"Duty","title","actor","SocialDuty"};
     string[] newPFieldName={"Duty","TecPost","Role","CommunityDuty"};
     IntoParentData(row,perbasic,oldPFieldName,newPFieldName); 
     orgName=row.GetParentRow("gerenjibenziliao_juzhong")["name"].ToString().Trim(); 
     if(row.GetParentRow("gerenjibenziliao_juannei")!=null) //若件也没有
     {
      if(row.GetParentRow("gerenjibenziliao_juannei").GetParentRow("anjuan_juannei")!=null)  //若只有件没卷的话
      {
       groupName=row.GetParentRow("gerenjibenziliao_juannei")["name"].ToString().Trim();
       bagNum=row.GetParentRow("gerenjibenziliao_juannei").GetParentRow("anjuan_juannei")["number"].ToString().Trim();
       bagName=row.GetParentRow("gerenjibenziliao_juannei").GetParentRow("anjuan_juannei")["name"].ToString().Trim();
       groupNum=row.GetParentRow("gerenjibenziliao_juannei")["number"].ToString().Trim();
      }
     }
     topeType=GetTopeType("gerenjibenziliao_shuxing",row,topelist);
     if(orgName!="")
     {
      ArchiveObject aobj=(ArchiveObject)obj;  
      aobj.Org=ArchivesOrg.GetOrgByName(orgName); 
      aobj.Save();
     }
     obj=perbasic;
    }       
     
    if(dtName=="jumu")  
    {
     orgName=row.GetParentRow("jumu_juzhong")["name"].ToString().Trim();
     ArchiveObject aobj=(ArchiveObject)obj; 
     if(orgName!="")      
      aobj.Org=ArchivesOrg.GetOrgByName(orgName);//单位设置 
     aobj.Save();
    }
     
  
    if(dtName=="huojiangqingkuang" )
    {      
     orgName=row.GetParentRow("hqqk_juzhong")["name"].ToString().Trim();     
     if(row.GetParentRow("hqqk_juannei")!=null) //若件也没有
     {
      if(row.GetParentRow("hqqk_juannei").GetParentRow("anjuan_juannei")!=null)  //若只有件没卷的话
      {
       bagName=row.GetParentRow("hqqk_juannei").GetParentRow("anjuan_juannei")["name"].ToString().Trim();    
       groupName=row.GetParentRow("hqqk_juannei")["name"].ToString().Trim(); 
       bagNum=row.GetParentRow("hqqk_juannei").GetParentRow("anjuan_juannei")["number"].ToString().Trim();
       groupNum=row.GetParentRow("hqqk_juannei")["number"].ToString().Trim();
      }
     }
     topeType=GetTopeType("hqqk_shuxing",row,topelist);
    }
    if(dtName=="gerenjibenziliao"||dtName=="huojiangqingkuang")
    {
     ArchiveObject aobj=(ArchiveObject)obj;  
     
     aobj.Type=DBConnect.ArtSession.FindObject(typeof(ArchivesType),new BinaryOperator("ClassType",className)) as ArchivesType;//类别
    
     
     ArchivesBag aBag = null;
     if(bagName!="")
     {
      GroupOperator Gop =new GroupOperator();
      Gop.OperatorType = GroupOperatorType.And;    
      BinaryOperator opName = new BinaryOperator("Name",bagNum+"|"+bagName);
      BinaryOperator opNumber = new BinaryOperator("Number",bagNum); 
      Gop.Operands.Add(opName);  
      Gop.Operands.Add(opNumber);        
      aBag = DBConnect.ArtSession.FindObject(typeof(ArchivesBag),Gop) as ArchivesBag;
      aobj.Bag=aBag;       
     } 
      
     ArchivesGroup group=new ArchivesGroup();
     if(groupName!=""&& bagName!=null)
     {            
      XPCollection childs = aBag.Childs;
      foreach(ArchivesGroup aGoup in childs)
      {
       if(aGoup.Name == groupName)
       {
        aobj.Group=aGoup;
        break;
       }
      }
     }
     if(orgName!="")      
      aobj.Org=ArchivesOrg.GetOrgByName(orgName);//单位设置 
     string oldDirPath=GetPath(oldDirectory,row["juzhong_id"].ToString().Trim(),row["shuxing_id"].ToString().Trim());
     string newrootPath=getrootPath(rootPath); 
     string path="";
     if(dtName=="gerenjibenziliao")
      path=string.Format(@"{0}/{1}/{2}",orgName,topeType,CheckDirName(row["name"].ToString().Trim()));
     else if(topeType!= "综合")   //获奖情况的 人物或者 剧目
      path=string.Format(@"{0}/{1}/{2}",orgName,topeType,CheckDirName(row["man"].ToString().Trim()));
     else
      path=string.Format(@"{0}/{1}",orgName,topeType);     
     string[] files=row["col_backup3"].ToString().Split(new char[]{';'}); //存放图片的是col_backup3
     foreach(string file in files)     
      CopyUpFile(aobj,file.Trim(),"",path,oldDirPath);
    }
    ((XPBaseObject)obj).Save();    
   }
   //   }
   //   catch(Exception ex)
   //   {
   //    Response.Write(Help.AlertScript("数据导入出错了"));
   //   }  
  }
  public string GetPath(string root,string juzhongId,string shuxingId)  //原附件路径 规则
  {
   return Path.Combine(Path.Combine(root,juzhongId),shuxingId);
  }
  public void CheckDirectory(string path)              //检测 是否有 文件
  {   
   if(!Directory.Exists(path))
    Directory.CreateDirectory(path);
  }
  public void CreateComputer()       //创建 附件 所有公司文件夹
  {
   DataTable dt=ds.Tables["juzhong"];   
   foreach(DataRow row in dt.Rows)
   {
    string newpath=Path.Combine(getrootPath(rootPath),row["name"].ToString().Trim());
    CheckDirectory(newpath);
   }
  }
  public string getrootPath(string root)    //工程文件 所在实际路径
  {
   string appPath=Path.GetDirectoryName(Application.ExecutablePath);
   string path=appPath+@"/../web/"+rootPath;
   return path;
  }
 
  private void butDefine_Click(object sender, System.EventArgs e)
  {   //初始化按钮 触发的 方法
   SetConnect();   
   //栏目类别初始化
   //1级加入
   for(int i=0;i<type1.Length;i++)
   {
    Guid guid1=guids[i];
    ArchivesType ftype=new ArchivesType();
    ftype.guid=guid1;
    ftype.Name=type1[i].Trim();
    ftype.Parent=null;
    ftype.ClassType=className1[i].Trim();
    ftype.Save();    
    string[] ftypelist=type2[i].Split(new char[]{','});//中文名
    string[] classlist=className2[i].Split(new char[]{','});//对应的类名
    string[] mtypelist=type3[i].Split(new char[]{';'});// 3级的中文名
    
    //2级加入
    for(int j=0;j<ftypelist.Length;j++)
    {
     if(ftypelist[j].Trim()=="")
      continue;
     ArchivesType stype=new ArchivesType();
     string className=classlist[j].Trim();             
     stype.Name=ftypelist[j].Trim();
     stype.ClassType=className;
     stype.Parent=DBConnect.ArtSession.GetObjectByKey(typeof(CustomType),guid1) as CustomType;
     stype.Save();
     Guid guid2=stype.guid;
     //3级加入
     string[] btypelist=mtypelist[j].Split(new char[]{','});
     //int tempIndex=0; //用于当第一个
     foreach(string btype in btypelist)
     {
      if(btype.Trim()=="")
       continue;
      ArchivesType ttype=new ArchivesType(); 
      ttype.Name=btype.Trim();
      ttype.ClassType=className;
      ttype.Parent=(CustomType)DBConnect.ArtSession.GetObjectByKey(typeof(CustomType),guid2);
      ttype.SortID=GetTypeIndex(btype.Trim());
      ttype.Save();
      
     }
    }
   }
   //----------------模块信息 初始化
   
   RoleInfo role=new RoleInfo();       //创建一个 管理员角色
   role.Name="管理员";  
   role.OpenFile=true;
   for(int i=0;i<fmenu.Length;i++)
   {
    ModuleInfo module=new ModuleInfo();
    module.Name=fmenu[i].Trim();
    string[] smenulist=smenu[i].Split(new char[]{','});
    module.Save();
    Guid guid=module.guid;
    role.Modules.Add(module);
    foreach(string sm in smenulist)
    {
     if(sm!="")
     {
      ModuleInfo smodule=new ModuleInfo();
      smodule.Name=sm.Trim();
      smodule.Parent=ModuleInfo.GetModuleById(guid.ToString());
      smodule.Save();
      role.Modules.Add(smodule);
     }
    }
   }
   //--------------用户创建,角色是 “管理员”
   UserInfo user=new UserInfo();
   user.LoginId="a";
   user.PassWord="a";   
   user.Name="张三";
   user.Stated=true;  
   user.Role=role;
   user.Save();
   MessageBox.Show("初始化成功!");
  } 

  private void Form1_Closed(object sender, System.EventArgs e)
  {
   DBConnect.ArtSession.Disconnect();
  }

  private void butOCheck_Click(object sender, System.EventArgs e)
  {   //点击按钮 “原数据库连接测试” 触发内容
   string oserver=cboxOServer.SelectedItem.ToString();
   string ouid=txbOUid.Text.Trim();
   string opwd=txbOPwd.Text.Trim();   
   //   string oldString=String.Format(connstring,oserver,odata,ouid,opwd); 
   try
   {    
    SQLDMO.SQLServer srv = new SQLDMO.SQLServerClass();    
    srv.Connect(oserver,ouid,opwd);
    MessageBox.Show("连接成功!");
    cboxOData.Enabled=true;
    try
    {
     this.Cursor = Cursors.WaitCursor;
     this.cboxOData.Items.Clear();     
     foreach(SQLDMO.Database db in srv.Databases)
     {
      if(db.Name!=null)
       this.cboxOData.Items.Add(db.Name);
     }
     this.cboxOData.Sorted = true;
     if(this.cboxOData.Items.Count >0)
      this.cboxOData.SelectedIndex=0;  
     else
      this.cboxOData.Text = "<No databases found>";
   
     this.Cursor = Cursors.Default;
    }
    catch(Exception err)
    {
     this.Cursor = Cursors.Default;
     MessageBox.Show(err.Message,"出错!");
    }
   }
   catch(Exception err)
   {
    cboxNData.Enabled=false;
    MessageBox.Show(err.Message,"出错!");
   }
  }

  private void butNCheck_Click(object sender, System.EventArgs e)
  {////点击按钮 “目标数据库连接测试” 触发内容
   string nserver=cboxNServer.SelectedItem.ToString();
   string nuid=txbNUid.Text.Trim();
   string npwd=txbNPwd.Text.Trim();
   
   try
   {
    SQLDMO.SQLServer srv = new SQLDMO.SQLServerClass();    
    srv.Connect(nserver,nuid,npwd);  
    MessageBox.Show("连接成功!");
    cboxNData.Enabled=true;
    try
    {
     this.Cursor = Cursors.WaitCursor;
     this.cboxNData.Items.Clear();     
     foreach(SQLDMO.Database db in srv.Databases)
     {
      if(db.Name!=null)
       this.cboxNData.Items.Add(db.Name);
     }
     this.cboxNData.Sorted = true;
     if(this.cboxNData.Items.Count >0)
     {      
      this.cboxNData.SelectedIndex=0;
     }
     else
      this.cboxOData.Text = "<No databases found>";
     this.Cursor = Cursors.Default;
    }
    catch(Exception err)
    {
     this.Cursor = Cursors.Default;
     MessageBox.Show(err.Message,"Error");
    }
   }
   catch(Exception err)
   {
    cboxNData.Enabled=false;
    MessageBox.Show(err.Message,"Error");
   }
  }
  private string SetData(string date)     //日期的设置 判断是 用什么 分割符号 如(- , . 等)如果格式没包括年月日,则自动补全,如 "1992" -> "1992-1-1"
  {
   char[] chlist={'-' ,'.' ,'/'};
   int i;
   for(i=0;i<chlist.Length;i++)
   {
    char c=chlist[i];
    if(date.IndexOf(c)>=0)
    {
     string[] d=date.Split(new char[]{c});     
     if(d.Length==2)
      date+="-1";
     string t=c.ToString();
     date=date.Replace(t,"-");
     break;
    }
   }
   chlist=new char[]{'年','月','日'};
   string[] list=date.Split(chlist);
   int l=list.Length;
   if(l>1)
   {
    if(l==2)
    {
     date+="1-1";
    }
    else if(l==3)
     date+="1";
    foreach(char ch in chlist)
    {
     string s=ch.ToString();
     date=date.Replace(s,"-");
    }
    date=date.Trim(new char[]{'-'});
   }
   if(i==chlist.Length&&l==1)
   {
    date+="-1-1";
   }
   return date;
  } 
  public string CheckDirName(string name)   //附件目录文件名称中,如有 非法字符 则去掉
  {
   string noNumber=@"/,/,:,*,/,<,>,|";
   string[] list=noNumber.Split(new char[]{','});
   foreach(string str in list)
    name=name.Replace(str,""); 
   return name;

  }
  private void cboxOServer_SelectedIndexChanged(object sender, System.EventArgs e)
  {
   cboxOData.Items.Clear();
   cboxOData.Enabled=false;
  }

  private void cboxNServer_SelectedIndexChanged(object sender, System.EventArgs e)
  {
   cboxNData.Items.Clear();
   cboxNData.Enabled=false;
  } 
 }
}

原创粉丝点击