using PaintDotNet; using PaintDotNet.Base.CommTool; using PaintDotNet.Base.SettingModel; using PaintDotNet.DbOpreate.DbBll; using PaintDotNet.DbOpreate.DbModel; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Metis.Setting { internal partial class ImportExportSettingDialog : PdnBaseForm { private GroupBox groupBox1; private Button button6; private Button button5; private Button button3; private Button button2; private GroupBox groupBox2; private Button button8; private GroupBox groupBox3; private RadioButton radioButton2; private RadioButton radioButton1; private TextBox textBox4; private Button button4; private GroupBox groupBox4; private GroupBox groupBox5; private Label label1; private TextBox textBox1; private CheckBox checkBox1; private GroupBox groupBox6; private TextBox textBox2; private Label label2; private Button button7; private Button button1; private Button button10; private Button button9; private Button button11; /// /// 选择的步 /// private int chooseStep = 1; private ImportExportModel importExportModel; /// /// 工具栏组成的结构数据 /// private List toolbarModelList = new List(); /// /// 工作流程组成的结构数据 /// private List workFlowModelList = new List(); private PaintDotNet.CustomControl.TreeViewEnhanced treeView1; /// /// 脚本组成的结构数据 /// private List stepModelList = new List(); /// /// 压缩中间数据目录 /// private string temporaryFilePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Temp\\"; /// /// 解压中间数据目录 /// private string unZipTemporaryFilePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\UnZipTemp\\"; private Dictionary originalPathDict = new Dictionary(); private Dictionary newPathDict = new Dictionary(); private Dictionary importPathDict = new Dictionary(); /// /// (导出)选择的树状信息 /// private List checkDataList = new List(); /// /// (导出)二级结构选择 /// private Dictionary> checkSecondData = new Dictionary>(); /// /// (导入)选择的树状信息 /// private List importCheckDataList = new List(); /// /// (导入)二级结构选择 /// private Dictionary> importCheckSecondData = new Dictionary>(); public ImportExportSettingDialog() { InitializeComponent(); InitializeLanguageText(); #region [默认展示第一步] button1_Click(null, null); #endregion #region [获取二级结构数据] this.getSonData(); #endregion #region [读取树状图结构] this.getTreeData(); #endregion #region [组织树状图] this.treeView1.CheckBoxes = true; this.treeView1.ItemHeight = 18; this.createTreeView(); #endregion #region [生成中间文件夹] this.createDefaultDirectory(); #endregion } private void InitializeLanguageText() { this.radioButton2.Text = PdnResources.GetString("export"); this.radioButton1.Text = PdnResources.GetString("Import"); this.groupBox3.Text = PdnResources.GetString("Menu.Setting.Text"); this.groupBox5.Text = PdnResources.GetString("Menu.Setting.Text"); this.label1.Text = PdnResources.GetString("Import"); this.checkBox1.Text = PdnResources.GetString("OverrideCurrentData"); this.button1.Text = PdnResources.GetString("Menu.firststep.text"); this.button2.Text = PdnResources.GetString("Menu.Secondstep.text"); this.button3.Text = PdnResources.GetString("Menu.thirdstep.text"); this.button6.Text = PdnResources.GetString("Menu.Previous.text"); this.button5.Text = PdnResources.GetString("Menu.Nextstep.text"); this.groupBox2.Text = PdnResources.GetString("Menu.operation.text"); this.groupBox4.Text = PdnResources.GetString("Menu.Setting.Text"); this.button8.Text = PdnResources.GetString("Menu.File.Close.Text"); this.button9.Text = PdnResources.GetString("Menu.LabelAction.SelectAllLabel.Text"); this.button10.Text = PdnResources.GetString("Menu.Binaryoperation.Objecthandling.unselectall.text"); this.button11.Text = PdnResources.GetString("Menu.finish.text"); this.button4.Text = PdnResources.GetString("Menu.LabelAction.LabelSelect.Text"); this.Text = PdnResources.GetString("ImportAndExportSet"); } private void InitializeComponent() { this.groupBox1 = new System.Windows.Forms.GroupBox(); this.button6 = new System.Windows.Forms.Button(); this.button5 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.button11 = new System.Windows.Forms.Button(); this.button10 = new System.Windows.Forms.Button(); this.button9 = new System.Windows.Forms.Button(); this.button8 = new System.Windows.Forms.Button(); this.groupBox3 = new System.Windows.Forms.GroupBox(); this.button4 = new System.Windows.Forms.Button(); this.textBox4 = new System.Windows.Forms.TextBox(); this.radioButton2 = new System.Windows.Forms.RadioButton(); this.radioButton1 = new System.Windows.Forms.RadioButton(); this.groupBox4 = new System.Windows.Forms.GroupBox(); this.treeView1 = new PaintDotNet.CustomControl.TreeViewEnhanced(); this.groupBox5 = new System.Windows.Forms.GroupBox(); this.checkBox1 = new System.Windows.Forms.CheckBox(); this.textBox1 = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.groupBox6 = new System.Windows.Forms.GroupBox(); this.button7 = new System.Windows.Forms.Button(); this.textBox2 = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox3.SuspendLayout(); this.groupBox4.SuspendLayout(); this.groupBox5.SuspendLayout(); this.groupBox6.SuspendLayout(); this.SuspendLayout(); // // groupBox1 // this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left))); this.groupBox1.Controls.Add(this.button6); this.groupBox1.Controls.Add(this.button5); this.groupBox1.Controls.Add(this.button3); this.groupBox1.Controls.Add(this.button2); this.groupBox1.Controls.Add(this.button1); this.groupBox1.Location = new System.Drawing.Point(12, 10); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(115, 445); this.groupBox1.TabIndex = 2; this.groupBox1.TabStop = false; // // button6 // this.button6.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.button6.Location = new System.Drawing.Point(20, 383); this.button6.Name = "button6"; this.button6.Size = new System.Drawing.Size(75, 23); this.button6.TabIndex = 4; this.button6.Text = "上一步"; this.button6.UseVisualStyleBackColor = true; this.button6.Click += new System.EventHandler(this.button6_Click); // // button5 // this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.button5.Location = new System.Drawing.Point(20, 412); this.button5.Name = "button5"; this.button5.Size = new System.Drawing.Size(75, 23); this.button5.TabIndex = 3; this.button5.Text = "下一步"; this.button5.UseVisualStyleBackColor = true; this.button5.Click += new System.EventHandler(this.button5_Click); // // button3 // this.button3.Location = new System.Drawing.Point(20, 89); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(75, 23); this.button3.TabIndex = 2; this.button3.Text = "第三步"; this.button3.UseVisualStyleBackColor = true; this.button3.Click += new System.EventHandler(this.button3_Click); // // button2 // this.button2.Location = new System.Drawing.Point(20, 59); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(75, 23); this.button2.TabIndex = 1; this.button2.Text = "第二步"; this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(this.button2_Click); // // button1 // this.button1.Location = new System.Drawing.Point(20, 29); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 0; this.button1.Text = "第一步"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // groupBox2 // this.groupBox2.Controls.Add(this.button11); this.groupBox2.Controls.Add(this.button10); this.groupBox2.Controls.Add(this.button9); this.groupBox2.Controls.Add(this.button8); this.groupBox2.Location = new System.Drawing.Point(133, 12); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(604, 58); this.groupBox2.TabIndex = 3; this.groupBox2.TabStop = false; this.groupBox2.Text = "操作"; // // button11 // this.button11.Location = new System.Drawing.Point(512, 20); this.button11.Name = "button11"; this.button11.Size = new System.Drawing.Size(75, 23); this.button11.TabIndex = 4; this.button11.Text = "完成"; this.button11.UseVisualStyleBackColor = true; this.button11.Click += new System.EventHandler(this.button11_Click); // // button10 // this.button10.Location = new System.Drawing.Point(431, 20); this.button10.Name = "button10"; this.button10.Size = new System.Drawing.Size(75, 23); this.button10.TabIndex = 3; this.button10.Text = "全不选"; this.button10.UseVisualStyleBackColor = true; this.button10.Click += new System.EventHandler(this.button10_Click); // // button9 // this.button9.Location = new System.Drawing.Point(350, 20); this.button9.Name = "button9"; this.button9.Size = new System.Drawing.Size(75, 23); this.button9.TabIndex = 2; this.button9.Text = "全选"; this.button9.UseVisualStyleBackColor = true; this.button9.Click += new System.EventHandler(this.button9_Click); // // button8 // this.button8.Location = new System.Drawing.Point(512, 20); this.button8.Name = "button8"; this.button8.Size = new System.Drawing.Size(75, 23); this.button8.TabIndex = 1; this.button8.Text = "关闭"; this.button8.UseVisualStyleBackColor = true; this.button8.Click += new System.EventHandler(this.button8_Click); // // groupBox3 // this.groupBox3.Controls.Add(this.button4); this.groupBox3.Controls.Add(this.textBox4); this.groupBox3.Controls.Add(this.radioButton2); this.groupBox3.Controls.Add(this.radioButton1); this.groupBox3.Location = new System.Drawing.Point(133, 76); this.groupBox3.Name = "groupBox3"; this.groupBox3.Size = new System.Drawing.Size(604, 379); this.groupBox3.TabIndex = 4; this.groupBox3.TabStop = false; this.groupBox3.Text = "设置"; // // button4 // this.button4.Location = new System.Drawing.Point(512, 64); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(75, 21); this.button4.TabIndex = 13; this.button4.Text = "选择"; this.button4.UseVisualStyleBackColor = true; this.button4.Click += new System.EventHandler(this.button4_Click); // // textBox4 // this.textBox4.Location = new System.Drawing.Point(24, 65); this.textBox4.Name = "textBox4"; this.textBox4.ReadOnly = true; this.textBox4.Size = new System.Drawing.Size(482, 21); this.textBox4.TabIndex = 12; // // radioButton2 // this.radioButton2.AutoSize = true; this.radioButton2.Location = new System.Drawing.Point(24, 109); this.radioButton2.Name = "radioButton2"; this.radioButton2.Size = new System.Drawing.Size(47, 16); this.radioButton2.TabIndex = 1; this.radioButton2.TabStop = true; this.radioButton2.Text = "导出"; this.radioButton2.UseVisualStyleBackColor = true; this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton2_Check); // // radioButton1 // this.radioButton1.AutoSize = true; this.radioButton1.Checked = true; this.radioButton1.Location = new System.Drawing.Point(24, 30); this.radioButton1.Name = "radioButton1"; this.radioButton1.Size = new System.Drawing.Size(47, 16); this.radioButton1.TabIndex = 0; this.radioButton1.TabStop = true; this.radioButton1.Text = "导入"; this.radioButton1.UseVisualStyleBackColor = true; this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_Check); // // groupBox4 // this.groupBox4.Controls.Add(this.treeView1); this.groupBox4.Location = new System.Drawing.Point(133, 76); this.groupBox4.Name = "groupBox4"; this.groupBox4.Size = new System.Drawing.Size(604, 379); this.groupBox4.TabIndex = 14; this.groupBox4.TabStop = false; this.groupBox4.Text = "设置"; // // treeView1 // this.treeView1.Location = new System.Drawing.Point(189, 13); this.treeView1.Name = "treeView1"; this.treeView1.Size = new System.Drawing.Size(227, 360); this.treeView1.TabIndex = 16; this.treeView1.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.treeViewChecked); // // groupBox5 // this.groupBox5.Controls.Add(this.checkBox1); this.groupBox5.Controls.Add(this.textBox1); this.groupBox5.Controls.Add(this.label1); this.groupBox5.Location = new System.Drawing.Point(133, 76); this.groupBox5.Name = "groupBox5"; this.groupBox5.Size = new System.Drawing.Size(604, 379); this.groupBox5.TabIndex = 15; this.groupBox5.TabStop = false; this.groupBox5.Text = "设置"; // // checkBox1 // this.checkBox1.AutoSize = true; this.checkBox1.Location = new System.Drawing.Point(24, 110); this.checkBox1.Name = "checkBox1"; this.checkBox1.Size = new System.Drawing.Size(96, 16); this.checkBox1.TabIndex = 2; this.checkBox1.Text = "覆盖当前数据"; this.checkBox1.UseVisualStyleBackColor = true; // // textBox1 // this.textBox1.Location = new System.Drawing.Point(24, 65); this.textBox1.Name = "textBox1"; this.textBox1.ReadOnly = true; this.textBox1.Size = new System.Drawing.Size(462, 21); this.textBox1.TabIndex = 1; // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(22, 34); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(77, 12); this.label1.TabIndex = 0; this.label1.Text = "从......导入"; // // groupBox6 // this.groupBox6.Controls.Add(this.button7); this.groupBox6.Controls.Add(this.textBox2); this.groupBox6.Controls.Add(this.label2); this.groupBox6.Location = new System.Drawing.Point(133, 76); this.groupBox6.Name = "groupBox6"; this.groupBox6.Size = new System.Drawing.Size(604, 379); this.groupBox6.TabIndex = 16; this.groupBox6.TabStop = false; this.groupBox6.Text = "设置"; // // button7 // this.button7.Location = new System.Drawing.Point(512, 62); this.button7.Name = "button7"; this.button7.Size = new System.Drawing.Size(75, 23); this.button7.TabIndex = 2; this.button7.Text = "选择"; this.button7.UseVisualStyleBackColor = true; this.button7.Click += new System.EventHandler(this.button7_Click); // // textBox2 // this.textBox2.Location = new System.Drawing.Point(24, 65); this.textBox2.Name = "textBox2"; this.textBox2.ReadOnly = true; this.textBox2.Size = new System.Drawing.Size(471, 21); this.textBox2.TabIndex = 1; // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(22, 34); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(125, 12); this.label2.TabIndex = 0; this.label2.Text = "选择配置文件存放位置"; // // ImportExportSettingDialog // this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.ClientSize = new System.Drawing.Size(749, 467); this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox5); this.Controls.Add(this.groupBox1); this.Controls.Add(this.groupBox6); this.Controls.Add(this.groupBox4); this.Controls.Add(this.groupBox2); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "ImportExportSettingDialog"; this.Text = "导入导出向导"; this.Controls.SetChildIndex(this.groupBox2, 0); this.Controls.SetChildIndex(this.groupBox4, 0); this.Controls.SetChildIndex(this.groupBox6, 0); this.Controls.SetChildIndex(this.groupBox1, 0); this.Controls.SetChildIndex(this.groupBox5, 0); this.Controls.SetChildIndex(this.groupBox3, 0); this.groupBox1.ResumeLayout(false); this.groupBox2.ResumeLayout(false); this.groupBox3.ResumeLayout(false); this.groupBox3.PerformLayout(); this.groupBox4.ResumeLayout(false); this.groupBox5.ResumeLayout(false); this.groupBox5.PerformLayout(); this.groupBox6.ResumeLayout(false); this.groupBox6.PerformLayout(); this.ResumeLayout(false); } /// /// 初始化UI /// private void InitializeUI() { switch (this.chooseStep) { case 1: this.groupBox3.Visible = true; this.groupBox4.Visible = false; this.groupBox5.Visible = false; this.groupBox6.Visible = false; this.button1.BackColor = Color.Black; this.button1.ForeColor = Color.White; this.button2.BackColor = Color.White; this.button2.ForeColor = Color.Black; this.button3.BackColor = Color.White; this.button3.ForeColor = Color.Black; this.button6.Enabled = false; this.button5.Enabled = true; this.button8.Visible = true; this.button9.Visible = false; this.button10.Visible = false; this.button11.Visible = false; break; case 2: this.groupBox3.Visible = false; this.groupBox4.Visible = true; this.groupBox5.Visible = false; this.groupBox6.Visible = false; this.button1.BackColor = Color.White; this.button1.ForeColor = Color.Black; this.button2.BackColor = Color.Black; this.button2.ForeColor = Color.White; this.button3.BackColor = Color.White; this.button3.ForeColor = Color.Black; this.button6.Enabled = true; this.button5.Enabled = true; this.button8.Visible = true; this.button9.Visible = true; this.button10.Visible = true; this.button11.Visible = false; break; case 3: this.groupBox3.Visible = false; this.groupBox4.Visible = false; if (this.radioButton1.Checked) { this.groupBox5.Visible = true; this.groupBox6.Visible = false; } else if (this.radioButton2.Checked) { this.groupBox5.Visible = false; this.groupBox6.Visible = true; } this.button1.BackColor = Color.White; this.button1.ForeColor = Color.Black; this.button2.BackColor = Color.White; this.button2.ForeColor = Color.Black; this.button3.BackColor = Color.Black; this.button3.ForeColor = Color.White; this.button5.Enabled = false; this.button6.Enabled = true; this.button8.Visible = false; this.button9.Visible = false; this.button10.Visible = false; this.button11.Visible = true; break; } } /// /// 关闭 /// /// /// private void button8_Click(object sender, EventArgs e) { this.Close(); } /// /// 导入按钮选择 /// /// /// private void radioButton2_Check(object sender, EventArgs e) { clearData(); } /// /// 导入按钮选择 /// /// /// private void radioButton1_Check(object sender, EventArgs e) { clearData(); } /// /// 清理之前的数据 /// private void clearData() { checkDataList.Clear(); checkSecondData.Clear(); importCheckDataList.Clear(); importCheckSecondData.Clear(); } /// /// 导入选择 /// /// /// private void button4_Click(object sender, EventArgs e) { if (!radioButton1.Checked) { MessageBox.Show(PdnResources.GetString("PleaseFelectFile") + "!"); return; } OpenFileDialog dialog = new OpenFileDialog(); dialog.Multiselect = false; //该值确定是否可以选择多个文件 dialog.Filter = "压缩包(*.zip)|*.zip"; if (dialog.ShowDialog() != DialogResult.OK) { return; } string file = dialog.FileName; this.textBox4.Text = file; this.textBox1.Text = file; if (!file.EndsWith(".zip")) { MessageBox.Show(PdnResources.GetString("PleaseSelectZip") + "!"); return; } clearData(); #region [将文件解压到中间文件] if (ZipHandleHelper.decompressionZip(file, unZipTemporaryFilePath)) { List allFileList = FileOperationHelper.GetAllDirectoryList(unZipTemporaryFilePath); #region [校验应勾选的树状信息] if (allFileList.Contains("CameraParam")) { this.importCheckDataList.Add("camera"); } if (allFileList.Contains("Config")) { this.importCheckDataList.Add("generalSetting"); } if (allFileList.Contains("Hotkey")) { this.importCheckDataList.Add("hotkey"); } if (allFileList.Contains("Label")) { this.importCheckDataList.Add("label"); } if (allFileList.Contains("Measure")) { this.importCheckDataList.Add("measure"); } if (allFileList.Contains("ModuleManage")) { this.importCheckDataList.Add("reportModel"); } if (allFileList.Contains("ParameterSaving")) { this.importCheckDataList.Add("parameter"); } if (allFileList.Contains("Ruler")) { this.importCheckDataList.Add("ruler"); } if (allFileList.Contains("Shortcutbar")) { this.importCheckDataList.Add("shortcutbar"); } if (allFileList.Contains("Toolbar")) { this.importCheckDataList.Add("toolbar"); string filePath = unZipTemporaryFilePath + "Toolbar\\Toolbar.xml"; var importToolBar = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(filePath, FileMode.Open)); List secondDataList = new List(); foreach (var item in importToolBar.Flows) { secondDataList.Add(item.Name); } importCheckSecondData.Add("toolbar", secondDataList); addTreeView(4,secondDataList); } if (allFileList.Contains("WorkFlow")) { this.importCheckDataList.Add("workFlow"); string filePath = unZipTemporaryFilePath + "WorkFlow\\WorkFlow.xml"; var importWorkFlow = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(filePath, FileMode.Open)); List secondDataList = new List(); foreach (var item in importWorkFlow.Flows) { secondDataList.Add(item.Name); } addTreeView(12, secondDataList); importCheckSecondData.Add("workFlow", secondDataList); } //脚本 if (allFileList.Contains("ScriptStep")) { this.importCheckDataList.Add("scriptStep"); string filePath = unZipTemporaryFilePath + "ScriptStep\\ScriptStep.xml"; List importMicScriptList = XmlSerializeHelper.DESerializer>(FileOperationHelper.ReadStringFromFile(filePath, FileMode.Open)); List secondDataList = new List(); foreach (var item in importMicScriptList) { secondDataList.Add(item.name); } addTreeView(10, secondDataList); importCheckSecondData.Add("scriptStep", secondDataList); } #endregion } else { MessageBox.Show("解压文件失败,请稍后再试!"); return; } #endregion } /// /// /// /// /// private void addTreeView(int type,List secondDataList) { this.treeView1.Nodes[type - 1].Nodes.Clear(); foreach (var item in secondDataList) { TreeNode node = new TreeNode(); node.Text = item; node.Name = item; this.treeView1.Nodes[type - 1].Nodes.Add(node); } } /// /// 导出选择 /// /// /// private void button7_Click(object sender, EventArgs e) { SaveFileDialog exe = new SaveFileDialog(); exe.Filter = "Compressed Package(*.zip)|*.zip"; exe.FilterIndex = 0; exe.RestoreDirectory = true; //exe.CreatePrompt = true; exe.Title = "Export Compressed Package"; exe.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); exe.FileName = DateTime.Now.ToString("yyyyMMddhhmmss") + "参数导出"; DialogResult dr = exe.ShowDialog(); if (dr != DialogResult.OK) { return; } this.textBox2.Text = exe.FileName; } /// /// 点击第一步 /// /// /// private void button1_Click(object sender, EventArgs e) { this.chooseStep = 1; InitializeUI(); } /// /// 点击第二步 /// /// /// private void button2_Click(object sender, EventArgs e) { // 导出默认全部选中 导入则根据导入时拥有的情况来选择 if (radioButton2.Checked) { AllChecked(); } else if (radioButton1.Checked) { CancelAllChecked(); if (string.IsNullOrEmpty(textBox4.Text)) { MessageBox.Show(PdnResources.GetString("PleaseSelectZipFirst") + "!"); return; } this.treeView1.AfterCheck -= new System.Windows.Forms.TreeViewEventHandler(this.treeViewChecked); foreach (TreeNode node in treeView1.Nodes) { switch (node.Name) { case "1": if (importCheckDataList.Contains("camera")) { node.Checked = true; } break; case "2": if (importCheckDataList.Contains("measure")) { node.Checked = true; } break; case "3": if (importCheckDataList.Contains("label")) { node.Checked = true; } break; case "4": if (importCheckDataList.Contains("toolbar")) { node.Checked = true; RecursiveNodeCheck(node, 4); } break; case "5": if (importCheckDataList.Contains("shortcutbar")) { node.Checked = true; } break; case "6": if (importCheckDataList.Contains("hotkey")) { node.Checked = true; } break; case "7": if (importCheckDataList.Contains("reportModel")) { node.Checked = true; } break; case "8": if (importCheckDataList.Contains("ruler")) { node.Checked = true; } break; case "9": if (importCheckDataList.Contains("parameter")) { node.Checked = true; } break; case "10": if (importCheckDataList.Contains("scriptStep")) { node.Checked = true; RecursiveNodeCheck(node, 10); } break; case "11": if (importCheckDataList.Contains("generalSetting")) { node.Checked = true; } break; case "12": if (importCheckDataList.Contains("workFlow")) { node.Checked = true; RecursiveNodeCheck(node, 12); } break; } } this.treeView1.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.treeViewChecked); } this.chooseStep = 2; InitializeUI(); } /// /// 点击第三步 /// /// /// private void button3_Click(object sender, EventArgs e) { //假如不按套路出牌 直接跳到第三步 模拟第二步点击 if (this.chooseStep == 1) { button2_Click(sender, e); } foreach (TreeNode item in this.treeView1.Nodes) { if (!item.Checked) { continue; } switch (item.Name) { case "1": this.checkDataList.Add("camera"); break; case "2": this.checkDataList.Add("measure"); break; case "3": this.checkDataList.Add("label"); break; case "4": this.checkDataList.Add("toolbar"); break; case "5": this.checkDataList.Add("shortcutbar"); break; case "6": this.checkDataList.Add("hotkey"); break; case "7": this.checkDataList.Add("reportModel"); break; case "8": this.checkDataList.Add("ruler"); break; case "9": this.checkDataList.Add("parameter"); break; case "10": this.checkDataList.Add("scriptStep"); break; case "11": this.checkDataList.Add("generalSetting"); break; case "12": this.checkDataList.Add("workFlow"); break; } if (item.Nodes.Count > 0) { RecursiveDataCheck(item); } } this.chooseStep = 3; InitializeUI(); } /// /// 递归将所需子集选中 /// /// private void RecursiveNodeCheck(TreeNode node,int type) { switch (type) { case 4: foreach (TreeNode treeNode in node.Nodes) { if (importCheckSecondData["toolbar"].Contains(treeNode.Text)) { treeNode.Checked = true; } } break; case 10: foreach (TreeNode treeNode in node.Nodes) { if (importCheckSecondData["scriptStep"].Contains(treeNode.Text)) { treeNode.Checked = true; } } break; case 12: foreach (TreeNode treeNode in node.Nodes) { if (importCheckSecondData["workFlow"].Contains(treeNode.Text)) { treeNode.Checked = true; } } break; } } /// /// 递归查询子集点击 /// /// private void RecursiveDataCheck(TreeNode node) { List list = new List(); foreach (TreeNode item in node.Nodes) { if (!item.Checked) { continue; } list.Add(item.Text); } if (list.Count > 0) { if (checkSecondData.ContainsKey(node.Name)) { checkSecondData[node.Name] = list; } else { checkSecondData.Add(node.Name, list); } } } /// /// 点击上一步 /// /// /// private void button6_Click(object sender, EventArgs e) { switch (this.chooseStep) { case 1: break; case 2: button1.Focus(); button1_Click(sender, e); break; case 3: button2.Focus(); button2_Click(sender, e); break; } } /// /// 点击下一步 /// /// /// private void button5_Click(object sender, EventArgs e) { switch (this.chooseStep) { case 1: button2.Focus(); button2_Click(sender, e); break; case 2: button3.Focus(); button3_Click(sender, e); break; case 3: break; } } /// /// 获取二级数据 /// private void getSonData() { #region [工具栏] ToolbarModel toolbarModel = Startup.instance.toolbarModel; foreach (var item in toolbarModel.Flows) { ProjectData sonData = new ProjectData(); sonData.ProjectID = Guid.NewGuid().ToString(); sonData.ProjectName = item.Name; sonData.ProjectParentID = "4"; sonData.isCheck = true; this.toolbarModelList.Add(sonData); } #endregion #region [工作流程] WorkFlowModel workFlowModel = Startup.instance.workFlowModel; foreach (var item in workFlowModel.Flows) { ProjectData sonData = new ProjectData(); sonData.ProjectID = Guid.NewGuid().ToString(); sonData.ProjectName = item.Name; sonData.ProjectParentID = "12"; sonData.isCheck = true; this.workFlowModelList.Add(sonData); } #endregion #region [脚本] List list = mic_script_BLL.FindAll(); foreach (var item in list) { ProjectData sonData = new ProjectData(); sonData.ProjectID = Guid.NewGuid().ToString(); sonData.ProjectName = item.name; sonData.ProjectParentID = "10"; sonData.isCheck = true; this.stepModelList.Add(sonData); } #endregion } /// /// 读取树状图结构 /// private void getTreeData() { string filePath = Application.StartupPath + "\\Config\\"+ Startup.instance.SettingPrefix + "\\ImportExportModel.xml"; //文件不在 生成默认文件 if (!File.Exists(filePath)) { importExportModel = new ImportExportModel(); #region [生成实体类结构] for (int i = 1; i <= 12; i++) { ProjectData data = new ProjectData(); data.ProjectID = i.ToString(); #region [分别处理] switch (i) { case 1: data.ProjectName = "预览属性"; break; case 2: data.ProjectName = "测量属性"; break; case 3: data.ProjectName = "标注属性"; break; case 4: data.ProjectName = "工具栏"; data.sonDataList = this.toolbarModelList; break; case 5: data.ProjectName = "快捷栏"; break; case 6: data.ProjectName = "快捷键"; break; case 7: data.ProjectName = "报告模板"; break; case 8: data.ProjectName = "比例尺"; break; case 9: data.ProjectName = "功能参数"; break; case 10: data.ProjectName = "脚本信息"; data.sonDataList = this.stepModelList; break; case 11: data.ProjectName = "常规设置"; break; case 12: data.ProjectName = "工作流程"; data.sonDataList = this.workFlowModelList; break; } #endregion importExportModel.AllProjectList.Add(data); } #endregion string importExportXml = XmlSerializeHelper.XmlSerialize(importExportModel); FileOperationHelper.WriteStringToFile(importExportXml, filePath, FileMode.Create); } else { importExportModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(filePath, FileMode.Open)); //替换最新的工具栏 工作流程 脚本 foreach (var item in importExportModel.AllProjectList) { switch (item.ProjectID) { case "4": item.sonDataList = toolbarModelList; break; case "10": item.sonDataList = stepModelList; break; case "12": item.sonDataList = workFlowModelList; break; } } } } /// /// 组织树状图 /// private void createTreeView() { foreach (var item in importExportModel.AllProjectList) { TreeNode treeNode = new TreeNode(); treeNode.Text = item.ProjectName; treeNode.Name = item.ProjectID; #region [如果含有子集 开始递归搞起] if (item.sonDataList != null && item.sonDataList.Count > 0) { RecursiveDataView(treeNode, item); } #endregion treeNode.Expand(); treeView1.Nodes.Add(treeNode); } } private void RecursiveDataView(TreeNode node, ProjectData data) { foreach (var item in data.sonDataList) { TreeNode treeNode = new TreeNode(); treeNode.Text = item.ProjectName; treeNode.Name = item.ProjectID; if (item.sonDataList != null && item.sonDataList.Count > 0) { RecursiveDataView(treeNode, item); } node.Nodes.Add(treeNode); } } /// /// 全选 /// /// /// private void button9_Click(object sender, EventArgs e) { this.treeView1.AfterCheck -= new System.Windows.Forms.TreeViewEventHandler(this.treeViewChecked); AllChecked(); this.treeView1.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.treeViewChecked); } /// /// 全不选 /// /// /// private void button10_Click(object sender, EventArgs e) { this.treeView1.AfterCheck -= new System.Windows.Forms.TreeViewEventHandler(this.treeViewChecked); CancelAllChecked(); this.treeView1.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.treeViewChecked); } /// /// 节点选中 /// /// /// private void treeViewChecked(object sender, TreeViewEventArgs e) { this.treeView1.AfterCheck -= new System.Windows.Forms.TreeViewEventHandler(this.treeViewChecked); CheckParentNode(e.Node); if (e.Node.Nodes.Count > 0) { CheckAllChildNodes(e.Node, e.Node.Checked); } this.treeView1.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.treeViewChecked); } #region [节点选中相关方法] /// /// 全选 /// private void AllChecked() { foreach (TreeNode e in this.treeView1.Nodes) { e.Checked = true; if (e.Nodes.Count > 0) { CheckAllChildNodes(e, true); } } } /// /// 取消全选 /// private void CancelAllChecked() { foreach (TreeNode e in this.treeView1.Nodes) { e.Checked = false; if (e.Nodes.Count > 0) { CheckAllChildNodes(e, false); } } } /// /// 改变所有子节点的状态 /// /// /// private void CheckAllChildNodes(TreeNode pn, bool IsChecked) { foreach (TreeNode tn in pn.Nodes) { tn.Checked = IsChecked; if (tn.Nodes.Count > 0) { CheckAllChildNodes(tn, IsChecked); } } } /// /// 改变父节点的选中状态,此处为所有子节点不选中时才取消父节点选中,可以根据需要修改 /// /// private void CheckParentNode(TreeNode curNode) { bool bChecked = false; if (curNode.Parent != null) { foreach (TreeNode node in curNode.Parent.Nodes) { if (node.Checked) { bChecked = true; break; } } if (bChecked) { curNode.Parent.Checked = true; CheckParentNode(curNode.Parent); } else { curNode.Parent.Checked = false; CheckParentNode(curNode.Parent); } } } #endregion /// /// 完成 /// /// /// private void button11_Click(object sender, EventArgs e) { if (radioButton1.Checked) { #region [开始导入] ProgressThreadProcClass procClass = new ProgressThreadProcClass(); int itemCount = 100; ProgressThreadProcClass.IFileTransferProgressEvents progressEvents = new ProgressThreadProcClass.IFileTransferProgressEvents(); System.Threading.ThreadStart copyThreadProc = delegate () { try { foreach (var item in originalPathDict) { if (!checkDataList.Contains(item.Key) || item.Key.Equals("toolbar") || item.Key.Equals("shortcutbar") || item.Key.Equals("ruler") || item.Key.Equals("scriptStep") || item.Key.Equals("workFlow")) { continue; } FileOperationHelper.CopyDirectory(importPathDict[item.Key], item.Value, true); } #region [快捷键特殊处理下] if (checkDataList.Contains("hotkey")) { string toolBarPath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\"; string importBarPath = importPathDict["hotkey"] + "Hotkey.xml"; FileOperationHelper.CopyDirectory(importBarPath, toolBarPath, true); } #endregion #region [常规设置特殊处理下] if (checkDataList.Contains("generalSetting")) { string toolBarPath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\"; string importBarPath = importPathDict["generalSetting"] + "Config.xml"; FileOperationHelper.CopyDirectory(importBarPath, toolBarPath, true); } #endregion #region [测量特殊处理下] if (checkDataList.Contains("measure")) { string toolBarPath = originalPathDict["generalSetting"]; string importSettingPath = importPathDict["measure"] + "Config.xml"; var importNowSetting = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(importSettingPath, FileMode.Open)); Startup.instance.configModel.MarkpointWidth = importNowSetting.MarkpointWidth; string toolXml = XmlSerializeHelper.XmlSerialize(Startup.instance.configModel); FileOperationHelper.WriteStringToFile(toolXml, toolBarPath, FileMode.Create); FileOperationHelper.DeleteFolder(originalPathDict["measure"] + "Config.xml"); } #endregion #region [脚本信息特殊处理下] if (checkDataList.Contains("scriptStep")) { string filePath = unZipTemporaryFilePath + "ScriptStep\\ScriptStep.xml"; List importMicScriptList = XmlSerializeHelper.DESerializer>(FileOperationHelper.ReadStringFromFile(filePath, FileMode.Open)); List needImportDataList = new List(); if (checkSecondData.ContainsKey("10")) { needImportDataList = checkSecondData["10"]; } #region [如果覆盖 则清除数据] if (checkBox1.Checked) { List mainList = mic_script_BLL.FindAll(); List secondList = mic_script_step_BLL.FindAll(); List thirdList = mic_script_step_param_BLL.FindAll(); foreach (var item in mainList) { mic_script_BLL.Del(item.id); } foreach (var item in secondList) { mic_script_step_BLL.Del(item.id); } foreach (var item in thirdList) { mic_script_step_param_BLL.Del(item.id); } } #endregion foreach (var item in importMicScriptList) { if (!needImportDataList.Contains(item.name)) { continue; } mic_script script = new mic_script(); script.name = item.name; mic_script_BLL.Add(script); foreach (var s in item.sonList) { mic_script_step mic_Script_Step = new mic_script_step(); mic_Script_Step.automatic = s.automatic; mic_Script_Step.menu_id = s.menu_id; mic_Script_Step.script_id = script.id; mic_Script_Step.step_name = s.step_name; mic_Script_Step.step_sort = s.step_sort; mic_script_step_BLL.Add(mic_Script_Step); foreach (var m in s.sonList) { mic_script_step_param param = new mic_script_step_param(); param.param_key = m.param_key; param.param_type = m.param_type; param.param_value = m.param_value; param.script_id = script.id; param.step_id = mic_Script_Step.script_id; param.value = m.value; mic_script_step_param_BLL.Add(param); } } } } #endregion #region [快捷栏特殊处理下] if (checkDataList.Contains("shortcutbar")) { string toolBarPath = originalPathDict["shortcutbar"]; var nowToolBar = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(toolBarPath, FileMode.Open)); string importBarPath = importPathDict["shortcutbar"] + "Shortcutbar.xml"; var importToolBar = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(importBarPath, FileMode.Open)); if (checkBox1.Checked) { nowToolBar = importToolBar; } else { foreach (var item in importToolBar.Menus) { nowToolBar.Menus.Add(item); } } Startup.instance.shortcutbarModel = nowToolBar; string toolXml = XmlSerializeHelper.XmlSerialize(nowToolBar); FileOperationHelper.WriteStringToFile(toolXml, toolBarPath, FileMode.Create); } #endregion #region [标尺特殊处理下] if (checkDataList.Contains("ruler")) { string filePath = unZipTemporaryFilePath + "Ruler\\Ruler.xml"; List importRulerList = XmlSerializeHelper.DESerializer>(FileOperationHelper.ReadStringFromFile(filePath, FileMode.Open)); List allRulerList = mic_rulers_BLL.FindAll(); if (checkBox1.Checked) { foreach (var item in allRulerList) { mic_rulers_BLL.Del(item.id); } } foreach (var item in importRulerList) { mic_rulers rulers = new mic_rulers(); rulers.gain_multiple = item.gain_multiple; rulers.microscope = item.objective_lens; rulers.physical_length = item.physical_length; rulers.objective_lens = item.objective_lens; rulers.pixel_length = item.pixel_length; rulers.ruler_camera = item.ruler_camera; rulers.ruler_connector = item.ruler_connector; rulers.ruler_eyepiece = item.ruler_eyepiece; rulers.ruler_height = item.ruler_height; rulers.ruler_name = item.ruler_name; rulers.ruler_type = item.ruler_type; rulers.ruler_units = item.ruler_units; rulers.ruler_width = item.ruler_width; rulers.ruler_zoom = item.ruler_zoom; mic_rulers_BLL.Add(rulers); } } #endregion #region [工具栏特殊处理下] if (checkDataList.Contains("toolbar")) { string toolBarPath = originalPathDict["toolbar"]; var nowToolBar = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(toolBarPath, FileMode.Open)); string importBarPath = importPathDict["toolbar"] + "Toolbar.xml"; var importToolBar = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(importBarPath, FileMode.Open)); #region [如果覆盖 则清除数据] List list = new List(); foreach (var item in importToolBar.Flows) { if (checkSecondData["4"].Contains(item.Name)) { continue; } list.Add(item); } foreach (var item in list) { importToolBar.Flows.Remove(item); } if (checkBox1.Checked) { nowToolBar = importToolBar; } else { foreach (var item in importToolBar.Flows) { nowToolBar.Flows.Add(item); } } #endregion Startup.instance.toolbarModel = nowToolBar; string toolXml = XmlSerializeHelper.XmlSerialize(nowToolBar); FileOperationHelper.WriteStringToFile(toolXml, toolBarPath, FileMode.Create); } #endregion #region [工作流程特殊处理下] if (checkDataList.Contains("workFlow")) { string filePath = originalPathDict["workFlow"]; var workFlowModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(filePath, FileMode.Open)); string importWorkFlowPath = importPathDict["workFlow"] + "WorkFlow.xml"; var importWorkFlow = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(importWorkFlowPath, FileMode.Open)); #region [[如果覆盖 则清除数据] List list = new List(); foreach (var item in importWorkFlow.Flows) { if (checkSecondData["12"].Contains(item.Name)) { continue; } list.Add(item); } foreach (var item in list) { importWorkFlow.Flows.Remove(item); } if (checkBox1.Checked) { workFlowModel = importWorkFlow; } else { foreach (var item in importWorkFlow.Flows) { workFlowModel.Flows.Add(item); } } #endregion string workFlowModelXml = XmlSerializeHelper.XmlSerialize(workFlowModel); FileOperationHelper.WriteStringToFile(workFlowModelXml, filePath, FileMode.Create); } #endregion if (checkDataList.Contains("parameter")) { //晶粒度单独处理下 string GrainSizePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\"; FileOperationHelper.CopyDirectory(importPathDict["parameter"] + "\\GrainSizeAnalysisModel.xml", GrainSizePath, true); } if (checkDataList.Contains("generalSetting")) { //常规设置需要单独处理下 string userInfoFilePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\"; FileOperationHelper.CopyDirectory(importPathDict["generalSetting"] + "\\UserInfo.xml", userInfoFilePath, true); string setUpFilePath = Application.StartupPath + @"\Config\" + Startup.instance.SettingPrefix + @"\SetUp\"; FileOperationHelper.CopyDirectory(importPathDict["generalSetting"] + "\\GuideStyle.xml", setUpFilePath, true); } } catch (Exception ex) { } finally { progressEvents.EndOperation(OperationResult.Finished); } }; procClass.StartProgressAction(this, itemCount, copyThreadProc, progressEvents, null); MessageBox.Show(PdnResources.GetString("ImportSuccessful") + "!"); #endregion } else if (radioButton2.Checked) { #region [开始导出] if (string.IsNullOrEmpty(textBox2.Text)) { MessageBox.Show("请先选择要导出文件的路径!"); return; } ProgressThreadProcClass procClass = new ProgressThreadProcClass(); int itemCount = 100; ProgressThreadProcClass.IFileTransferProgressEvents progressEvents = new ProgressThreadProcClass.IFileTransferProgressEvents(); System.Threading.ThreadStart copyThreadProc = delegate () { try { string choosePath = this.textBox2.Text; foreach (var item in originalPathDict) { if (!checkDataList.Contains(item.Key)) { continue; } FileOperationHelper.CopyDirectory(item.Value, newPathDict[item.Key], false); } #region [脚本信息特殊处理] if (checkDataList.Contains("scriptStep")) { List mainList = mic_script_BLL.FindAll(); List secondList = mic_script_step_BLL.FindAll(); List thirdList = mic_script_step_param_BLL.FindAll(); if (checkSecondData.ContainsKey("10")) { List hasDataList = checkSecondData["10"]; List shouldExportDataList = new List(); foreach (var item in mainList) { if (!hasDataList.Contains(item.name)) { continue; } var mic = item; mic.sonList = secondList.Where(m => m.script_id == mic.id).ToList(); foreach (var s in mic.sonList) { s.sonList = thirdList.Where(m => m.script_id == mic.id && m.step_id == s.id).ToList(); } shouldExportDataList.Add(mic); } string scriptExportXml = XmlSerializeHelper.XmlSerialize(shouldExportDataList); FileOperationHelper.WriteStringToFile(scriptExportXml, newPathDict["scriptStep"] + "ScriptStep.xml", FileMode.Create); } } #endregion #region [标尺信息特殊处理] if (checkDataList.Contains("ruler")) { List mainList = mic_rulers_BLL.FindAll(); string scriptExportXml = XmlSerializeHelper.XmlSerialize(mainList); FileOperationHelper.WriteStringToFile(scriptExportXml, newPathDict["ruler"] + "Ruler.xml", FileMode.Create); } #endregion #region [获取二级数据] if (checkSecondData.ContainsKey("4")) { var toolbarModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(newPathDict["toolbar"] + "\\Toolbar.xml", FileMode.Open)); List list = new List(); foreach (var item in toolbarModel.Flows) { if (checkSecondData["4"].Contains(item.Name)) { continue; } list.Add(item); } foreach (var item in list) { toolbarModel.Flows.Remove(item); } string toolbarModelXml = XmlSerializeHelper.XmlSerialize(toolbarModel); FileOperationHelper.WriteStringToFile(toolbarModelXml, newPathDict["toolbar"] + "\\Toolbar.xml", FileMode.Create); } if (checkSecondData.ContainsKey("12")) { var workFlowModel = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(newPathDict["workFlow"] + "\\WorkFlow.xml", FileMode.Open)); List list = new List(); foreach (var item in workFlowModel.Flows) { if (checkSecondData["12"].Contains(item.Name)) { continue; } list.Add(item); } foreach (var item in list) { workFlowModel.Flows.Remove(item); } string workFlowModelXml = XmlSerializeHelper.XmlSerialize(workFlowModel); FileOperationHelper.WriteStringToFile(workFlowModelXml, newPathDict["workFlow"] + "\\WorkFlow.xml", FileMode.Create); } #endregion if (checkDataList.Contains("measure")) { //测量标记点单独处理下 string pointPath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml"; FileOperationHelper.CopyDirectory(pointPath, newPathDict["measure"], false); } if (checkDataList.Contains("parameter")) { //晶粒度单独处理下 string GrainSizePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\GrainSizeAnalyze\\GrainSizeAnalysisModel.xml"; FileOperationHelper.CopyDirectory(GrainSizePath, newPathDict["parameter"], true); } if (checkDataList.Contains("generalSetting")) { //常规设置需要单独处理下 string userInfoFilePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\UserInfo.xml"; FileOperationHelper.CopyDirectory(userInfoFilePath, newPathDict["generalSetting"], true); string setUpFilePath = Application.StartupPath + @"\Config\" + Startup.instance.SettingPrefix + @"\SetUp\GuideStyle.xml"; FileOperationHelper.CopyDirectory(setUpFilePath, newPathDict["generalSetting"], true); } ZipHandleHelper.createZip(temporaryFilePath, choosePath); } catch (Exception) { } finally { progressEvents.EndOperation(OperationResult.Finished); } }; procClass.StartProgressAction(this, itemCount, copyThreadProc, progressEvents, null); MessageBox.Show("导出成功!"); #endregion } this.Close(); } /// /// 生成默认的中间数据文件夹 /// private void createDefaultDirectory() { //生成一个临时文件夹 用于存放各种xml //先删除之前的 FileOperationHelper.DeleteFolder(unZipTemporaryFilePath); FileOperationHelper.DeleteFolder(temporaryFilePath); //生成新的 Directory.CreateDirectory(temporaryFilePath); #region [相机设置] string cameraFilePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\CameraParam\\"; string temporaryCameraFilePath = $"{temporaryFilePath}\\CameraParam\\"; Directory.CreateDirectory(temporaryCameraFilePath); originalPathDict.Add("camera", cameraFilePath); newPathDict.Add("camera", temporaryCameraFilePath); string importTemporaryCameraFilePath = $"{unZipTemporaryFilePath}\\CameraParam\\"; importPathDict.Add("camera", importTemporaryCameraFilePath); #endregion #region [测量参数] string measure = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Measure\\"; string temporaryMeasureFilePath = $"{temporaryFilePath}\\Measure\\"; Directory.CreateDirectory(temporaryMeasureFilePath); originalPathDict.Add("measure", measure); newPathDict.Add("measure", temporaryMeasureFilePath); string importTemporaryMeasureFilePath = $"{unZipTemporaryFilePath}\\Measure\\"; importPathDict.Add("measure", importTemporaryMeasureFilePath); #endregion #region [标注参数] string label = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Label\\"; string temporaryLabelFilePath = $"{temporaryFilePath}\\Label\\"; Directory.CreateDirectory(temporaryLabelFilePath); originalPathDict.Add("label", label); newPathDict.Add("label", temporaryLabelFilePath); string importTemporaryLabelFilePath = $"{unZipTemporaryFilePath}\\Label\\"; importPathDict.Add("label", importTemporaryLabelFilePath); #endregion #region [工具栏] string toolbar = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Toolbar.xml"; string temporaryToolbarFilePath = $"{temporaryFilePath}\\Toolbar\\"; Directory.CreateDirectory(temporaryToolbarFilePath); originalPathDict.Add("toolbar", toolbar); newPathDict.Add("toolbar", temporaryToolbarFilePath); string importTemporaryToolbarFilePath = $"{unZipTemporaryFilePath}\\Toolbar\\"; importPathDict.Add("toolbar", importTemporaryToolbarFilePath); #endregion #region [快捷栏] string shortcutbar = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Shortcutbar.xml"; string temporaryShortcutbarFilePath = $"{temporaryFilePath}\\Shortcutbar\\"; Directory.CreateDirectory(temporaryShortcutbarFilePath); originalPathDict.Add("shortcutbar", shortcutbar); newPathDict.Add("shortcutbar", temporaryShortcutbarFilePath); string importTemporaryShortcutbarFilePath = $"{unZipTemporaryFilePath}\\Shortcutbar\\"; importPathDict.Add("shortcutbar", importTemporaryShortcutbarFilePath); #endregion #region [快捷键] string hotkey = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Hotkey.xml"; string temporaryHotkeyFilePath = $"{temporaryFilePath}\\Hotkey\\"; Directory.CreateDirectory(temporaryHotkeyFilePath); originalPathDict.Add("hotkey", hotkey); newPathDict.Add("hotkey", temporaryHotkeyFilePath); string importTemporaryHotkeyFilePath = $"{unZipTemporaryFilePath}\\Hotkey\\"; importPathDict.Add("hotkey", importTemporaryHotkeyFilePath); #endregion #region [报告模板] string reportModel = Application.StartupPath + "\\ModuleManage\\"; string temporaryReportModelPath = $"{temporaryFilePath}\\ModuleManage\\"; Directory.CreateDirectory(temporaryReportModelPath); originalPathDict.Add("reportModel", reportModel); newPathDict.Add("reportModel", temporaryReportModelPath); string importTemporaryReportModelPath = $"{unZipTemporaryFilePath}\\ModuleManage\\"; importPathDict.Add("reportModel", importTemporaryReportModelPath); #endregion #region [比例尺] string temporaryRulerFilePath = $"{temporaryFilePath}\\Ruler\\"; Directory.CreateDirectory(temporaryRulerFilePath); newPathDict.Add("ruler", temporaryRulerFilePath); string importTemporaryRulerFilePath = $"{unZipTemporaryFilePath}\\Ruler\\"; importPathDict.Add("ruler", importTemporaryRulerFilePath); #endregion #region [功能参数] string parameter = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\ParameterSaving\\"; string temporaryParameterFilePath = $"{temporaryFilePath}\\ParameterSaving\\"; Directory.CreateDirectory(temporaryParameterFilePath); originalPathDict.Add("parameter", parameter); newPathDict.Add("parameter", temporaryParameterFilePath); string importTemporaryParameterFilePath = $"{unZipTemporaryFilePath}\\ParameterSaving\\"; importPathDict.Add("parameter", importTemporaryParameterFilePath); #endregion #region [脚本信息] string temporaryScriptStepPath = $"{temporaryFilePath}\\ScriptStep\\"; Directory.CreateDirectory(temporaryScriptStepPath); newPathDict.Add("scriptStep", temporaryScriptStepPath); string importTemporaryScriptStepPath = $"{temporaryScriptStepPath}\\ScriptStep\\"; importPathDict.Add("scriptStep", importTemporaryScriptStepPath); #endregion #region [常规设置] string generalSetting = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Config.xml"; string temporaryGeneralSettingPath = $"{temporaryFilePath}\\Config\\"; Directory.CreateDirectory(temporaryGeneralSettingPath); originalPathDict.Add("generalSetting", generalSetting); newPathDict.Add("generalSetting", temporaryGeneralSettingPath); string importTemporaryGeneralSettingPath = $"{unZipTemporaryFilePath}\\Config\\"; importPathDict.Add("generalSetting", importTemporaryGeneralSettingPath); #endregion #region [工作流程] string workFlow = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\WorkFlow.xml"; string temporaryWorkFlowPath = $"{temporaryFilePath}\\WorkFlow\\"; Directory.CreateDirectory(temporaryWorkFlowPath); originalPathDict.Add("workFlow", workFlow); newPathDict.Add("workFlow", temporaryWorkFlowPath); string importTemporaryWorkFlowPath = $"{unZipTemporaryFilePath}\\WorkFlow\\"; importPathDict.Add("workFlow", importTemporaryWorkFlowPath); #endregion } } }