using Resources;
using SmartCoalApplication.Base;
using SmartCoalApplication.Base.CommTool;
using SmartCoalApplication.Base.MeasureModel;
using SmartCoalApplication.Core;
using SmartCoalApplication.PluginAssemblys;
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 SmartCoalApplication.MeasureProcedure
{
internal partial class MeasureProcedureImport : PdnBaseForm
{
#region [组件]
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 GroupBox groupBox6;
private TextBox textBox2;
private Label label2;
private Button button7;
private Button button1;
private Button button10;
private Button button9;
private Button button11;
#endregion
private AppWorkspace appWorkspace;
///
/// 测试规程树状图
///
private SmartCoalApplication.Core.CustomControl.TreeViewEnhanced treeView1;
///
/// 选择的步
///
private int chooseStep = 1;
private MeasureMaintenanceTypeList measureMaintenanceTypeList;
private MeasureMaintenanceTypeList importMeasureMaintenanceTypeList;
///
/// 压缩中间数据目录
///
private string temporaryFilePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\MidData\\Temp\\";
///
/// 解压中间数据目录
///
private string unZipTemporaryFilePath = Application.StartupPath + "\\Config\\MidData" + Program.instance.SettingPrefix + "\\UnZipTemp\\";
///
/// 测试规程文件路径
///
private string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\MeasureMaintenanceTypeList.xml";
///
/// 测试规程检验项目文件路径
///
private string rulerFilePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\MeasureMaintenanceType\\";
public MeasureProcedureImport(AppWorkspace appWorkspace)
{
InitializeComponent();
InitializeLanguageText();
this.appWorkspace = appWorkspace;
#region [获取测试规程]
if (!System.IO.File.Exists(filePath))
{
measureMaintenanceTypeList = new MeasureMaintenanceTypeList();
measureMaintenanceTypeList.measureMaintenanceTypeList = new List();
}
else
{
measureMaintenanceTypeList = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(filePath, FileMode.Open));
}
#endregion
#region [组织树状图]
this.treeView1.CheckBoxes = true;
this.treeView1.ItemHeight = 18;
this.createTreeView();
this.button1_Click(null, null);
#endregion
#region [生成中间文件夹]
this.createDefaultDirectory();
#endregion
}
#region [初始化]
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
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.groupBox5 = new System.Windows.Forms.GroupBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
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.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.groupBox4 = new System.Windows.Forms.GroupBox();
this.treeView1 = new SmartCoalApplication.Core.CustomControl.TreeViewEnhanced();
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.SuspendLayout();
this.groupBox5.SuspendLayout();
this.groupBox1.SuspendLayout();
this.groupBox6.SuspendLayout();
this.groupBox4.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// 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, 67);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(604, 409);
this.groupBox3.TabIndex = 19;
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;
//
// 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_CheckedChanged);
//
// groupBox5
//
this.groupBox5.Controls.Add(this.textBox1);
this.groupBox5.Controls.Add(this.label1);
this.groupBox5.Location = new System.Drawing.Point(133, 78);
this.groupBox5.Name = "groupBox5";
this.groupBox5.Size = new System.Drawing.Size(604, 398);
this.groupBox5.TabIndex = 21;
this.groupBox5.TabStop = false;
this.groupBox5.Text = "设置";
//
// 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 = "从......导入";
//
// 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, 2);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(115, 474);
this.groupBox1.TabIndex = 17;
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, 412);
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, 441);
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);
//
// 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, 78);
this.groupBox6.Name = "groupBox6";
this.groupBox6.Size = new System.Drawing.Size(604, 379);
this.groupBox6.TabIndex = 22;
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 = "选择配置文件存放位置";
//
// groupBox4
//
this.groupBox4.Controls.Add(this.treeView1);
this.groupBox4.Location = new System.Drawing.Point(133, 78);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(604, 379);
this.groupBox4.TabIndex = 20;
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.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.treeView1_NodeMouseClick);
//
// 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, 2);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(604, 58);
this.groupBox2.TabIndex = 18;
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 EventHandler(button8_Click);
//
// MeasureProcedureImport
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(742, 478);
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 = "MeasureProcedureImport";
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.groupBox3.ResumeLayout(false);
this.groupBox3.PerformLayout();
this.groupBox5.ResumeLayout(false);
this.groupBox5.PerformLayout();
this.groupBox1.ResumeLayout(false);
this.groupBox6.ResumeLayout(false);
this.groupBox6.PerformLayout();
this.groupBox4.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);
}
///
/// 语言包
///
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.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");
this.button7.Text = PdnResources.GetString("Menu.LabelAction.LabelSelect.Text");
}
///
/// 初始化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 createTreeView()
{
this.treeView1.Nodes.Clear();
foreach (var item in measureMaintenanceTypeList.measureMaintenanceTypeList)
{
TreeNode treeNode = new TreeNode();
treeNode.Text = item.measureMaintenanceName;
treeNode.Name = item.measureMaintenanceTypeId;
treeNode.Expand();
treeView1.Nodes.Add(treeNode);
}
}
#endregion
///
/// 点击文字选中
///
///
///
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
e.Node.Checked = true;
}
///
/// 点击第一步
///
///
///
private void button1_Click(object sender, EventArgs e)
{
this.chooseStep = 1;
InitializeUI();
}
///
/// 点击第二步
///
///
///
private void button2_Click(object sender, EventArgs e)
{
// 导出默认全部选中 导入则根据导入时拥有的情况来选择
if (radioButton1.Checked)
{
if (string.IsNullOrEmpty(textBox4.Text))
{
MessageBox.Show(PdnResources.GetString("SelectFileFirst") + "!");
return;
}
}
AllChecked();
this.chooseStep = 2;
InitializeUI();
}
///
/// 点击第三步
///
///
///
private void button3_Click(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
if (string.IsNullOrEmpty(textBox4.Text))
{
MessageBox.Show(PdnResources.GetString("SelectFileFirst") + "!");
return;
}
}
//假如不按套路出牌 直接跳到第三步 模拟第二步点击
if (this.chooseStep == 1)
{
button2_Click(sender, e);
}
this.chooseStep = 3;
InitializeUI();
}
///
/// 关闭
///
///
///
private void button8_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 全选
///
///
///
private void button9_Click(object sender, EventArgs e)
{
AllChecked();
}
///
/// 全不选
///
///
///
private void button10_Click(object sender, EventArgs e)
{
CancelAllChecked();
}
#region [节点选中相关方法]
///
/// 全选
///
private void AllChecked()
{
foreach (TreeNode e in this.treeView1.Nodes)
{
e.Checked = true;
}
}
///
/// 取消全选
///
private void CancelAllChecked()
{
foreach (TreeNode e in this.treeView1.Nodes)
{
e.Checked = false;
}
}
#endregion
///
/// 点击上一步
///
///
///
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 createDefaultDirectory()
{
//生成一个临时文件夹 用于存放各种xml
//先删除之前的
FileOperationHelper.DeleteFolder(unZipTemporaryFilePath);
FileOperationHelper.DeleteFolder(temporaryFilePath);
//生成新的
Directory.CreateDirectory(temporaryFilePath);
System.IO.Directory.CreateDirectory(temporaryFilePath + "\\ruleFile");
////复制测试规程总文件
//FileOperationHelper.CopyDirectory(this.filePath, temporaryFilePath, false);
//FileOperationHelper.CopyDirectory(this.rulerFilePath, temporaryFilePath + "\\ruleFile\\", false);
}
///
/// 选择文件
///
///
///
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;
}
#region [将文件解压到中间文件]
if (ZipHandleHelper.decompressionZip(file, unZipTemporaryFilePath))
{
this.importMeasureMaintenanceTypeList = XmlSerializeHelper.DESerializer(FileOperationHelper.ReadStringFromFile(unZipTemporaryFilePath + "\\ruleFile\\MeasureMaintenanceTypeList.xml", FileMode.Open));
this.treeView1.Nodes.Clear();
foreach (var item in this.importMeasureMaintenanceTypeList.measureMaintenanceTypeList)
{
TreeNode treeNode = new TreeNode();
treeNode.Text = item.measureMaintenanceName;
treeNode.Name = item.measureMaintenanceTypeId;
treeNode.Expand();
treeView1.Nodes.Add(treeNode);
}
}
else
{
MessageBox.Show(PdnResources.GetString("zipFail") + "!");
return;
}
#endregion
}
///
/// 导出选择路径
///
///
///
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 button11_Click(object sender, EventArgs e)
{
List checkList = new List();
foreach (TreeNode item in this.treeView1.Nodes)
{
if (!item.Checked)
{
continue;
}
checkList.Add(item.Name);
}
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 checkList)
{
var realMeasureMaintenanceTypeList = this.importMeasureMaintenanceTypeList.measureMaintenanceTypeList.Where(m => m.measureMaintenanceTypeId.Equals(item)).FirstOrDefault();
if (realMeasureMaintenanceTypeList == null)
{
continue;
}
var hadMeasureMaintenanceTypeList = this.measureMaintenanceTypeList.measureMaintenanceTypeList.Where(m => m.measureMaintenanceName.Equals(realMeasureMaintenanceTypeList.measureMaintenanceName)).FirstOrDefault();
if (hadMeasureMaintenanceTypeList != null)
{
string fileName = RecursionData(realMeasureMaintenanceTypeList.measureMaintenanceName);
FileOperationHelper.reNameFile(unZipTemporaryFilePath + "ruleFile\\" + realMeasureMaintenanceTypeList.measureMaintenanceName + ".xml", unZipTemporaryFilePath + "\\ruleFile\\" + fileName + ".xml");
FileOperationHelper.CopyDirectory(unZipTemporaryFilePath + "ruleFile\\" + fileName + ".xml", rulerFilePath, false);
realMeasureMaintenanceTypeList.measureMaintenanceName = fileName;
}
else {
FileOperationHelper.CopyDirectory(unZipTemporaryFilePath + "\\ruleFile\\" + realMeasureMaintenanceTypeList.measureMaintenanceName + ".xml", rulerFilePath, false);
}
this.measureMaintenanceTypeList.measureMaintenanceTypeList.Add(realMeasureMaintenanceTypeList);
}
string stageModelXml = XmlSerializeHelper.XmlSerialize(this.measureMaintenanceTypeList);
FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create);
}
catch (Exception ex)
{
}
finally
{
progressEvents.EndOperation(OperationResult.Finished);
}
};
procClass.StartProgressAction(this, itemCount, copyThreadProc, progressEvents, null);
FileOperationHelper.DeleteFolder(unZipTemporaryFilePath);
MessageBox.Show(PdnResources.GetString("importSuccess") + "!");
#endregion
}
else if (radioButton2.Checked)
{
#region [开始导出]
if (string.IsNullOrEmpty(textBox2.Text))
{
MessageBox.Show(PdnResources.GetString("selectfilepath") + "!");
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;
MeasureMaintenanceTypeList thisMeasureMaintenanceTypeList = new MeasureMaintenanceTypeList();
thisMeasureMaintenanceTypeList.measureMaintenanceTypeList = new List();
foreach (var item in checkList)
{
var realMeasureMaintenanceTypeList = this.measureMaintenanceTypeList.measureMaintenanceTypeList.Where(m => m.measureMaintenanceTypeId.Equals(item)).FirstOrDefault();
if (realMeasureMaintenanceTypeList == null)
{
continue;
}
thisMeasureMaintenanceTypeList.measureMaintenanceTypeList.Add(realMeasureMaintenanceTypeList);
FileOperationHelper.CopyDirectory($"{this.rulerFilePath}{realMeasureMaintenanceTypeList.measureMaintenanceName}.xml", temporaryFilePath + "\\ruleFile\\", false);
}
string filePath = temporaryFilePath + "\\ruleFile\\MeasureMaintenanceTypeList.xml";
string stageModelXml = XmlSerializeHelper.XmlSerialize(thisMeasureMaintenanceTypeList);
FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create);
ZipHandleHelper.createZip(temporaryFilePath, choosePath);
}
catch (Exception)
{
}
finally
{
progressEvents.EndOperation(OperationResult.Finished);
}
};
procClass.StartProgressAction(this, itemCount, copyThreadProc, progressEvents, null);
MessageBox.Show(PdnResources.GetString("exportSuccess") + "!");
#endregion
}
this.Close();
}
///
/// 递归赋名称
///
///
///
private string RecursionData(string name)
{
name += "-导入";
var hadMeasureMaintenanceTypeList = this.measureMaintenanceTypeList.measureMaintenanceTypeList.Where(m => m.measureMaintenanceName.Equals(name)).FirstOrDefault();
if (hadMeasureMaintenanceTypeList != null)
{
name = RecursionData(name);
}
return name;
}
///
/// 选中导入
///
///
///
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
createTreeView();
}
}
}