Form1.Designer.cs
namespace
WriteCard
{
partial class Form1
{
/**//// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/**//// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
Windows Form Designer generated code#region Windows Form Designer generated code
/**//// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.button1 = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.richTextBox2 = new System.Windows.Forms.RichTextBox();
this.button2 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.label4 = new System.Windows.Forms.Label();
this.groupBox3.SuspendLayout();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// timer1
//
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// groupBox3
//
this.groupBox3.Controls.Add(this.button1);
this.groupBox3.Controls.Add(this.label3);
this.groupBox3.Controls.Add(this.groupBox1);
this.groupBox3.Controls.Add(this.groupBox2);
this.groupBox3.Controls.Add(this.button2);
this.groupBox3.Location = new System.Drawing.Point(13, 98);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(490, 305);
this.groupBox3.TabIndex = 18;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "WriteCard";
//
// button1
//
this.button1.Location = new System.Drawing.Point(397, 20);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(87, 28);
this.button1.TabIndex = 2;
this.button1.Text = "start";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label3
//
this.label3.AutoSize = true;
this.label3.ForeColor = System.Drawing.Color.Red;
this.label3.Location = new System.Drawing.Point(7, 279);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(0, 12);
this.label3.TabIndex = 15;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.richTextBox1);
this.groupBox1.ForeColor = System.Drawing.SystemColors.ActiveCaption;
this.groupBox1.Location = new System.Drawing.Point(26, 22);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(166, 249);
this.groupBox1.TabIndex = 16;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "移动设备";
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(17, 20);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(132, 217);
this.richTextBox1.TabIndex = 13;
this.richTextBox1.Text = "";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.richTextBox2);
this.groupBox2.ForeColor = System.Drawing.SystemColors.ActiveCaption;
this.groupBox2.Location = new System.Drawing.Point(207, 20);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(184, 251);
this.groupBox2.TabIndex = 17;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "线程状态";
//
// richTextBox2
//
this.richTextBox2.ForeColor = System.Drawing.Color.Red;
this.richTextBox2.Location = new System.Drawing.Point(25, 22);
this.richTextBox2.Name = "richTextBox2";
this.richTextBox2.Size = new System.Drawing.Size(132, 217);
this.richTextBox2.TabIndex = 14;
this.richTextBox2.Text = "";
//
// button2
//
this.button2.Location = new System.Drawing.Point(397, 68);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(87, 26);
this.button2.TabIndex = 7;
this.button2.Text = " stop";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(105, 21);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(254, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "E:\\test";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(173, 53);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(186, 21);
this.textBox2.TabIndex = 1;
this.textBox2.Text = "G:\\";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(83, 12);
this.label1.TabIndex = 3;
this.label1.Text = "选择源文件夹:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(11, 58);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(161, 12);
this.label2.TabIndex = 4;
this.label2.Text = "请选择你机器的最后一个盘: ";
//
// button3
//
this.button3.Location = new System.Drawing.Point(402, 19);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(100, 23);
this.button3.TabIndex = 10;
this.button3.Text = "浏览";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.Location = new System.Drawing.Point(403, 53);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(100, 23);
this.button4.TabIndex = 11;
this.button4.Text = " 浏览";
this.button4.UseVisualStyleBackColor = true;
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// label4
//
this.label4.AutoSize = true;
this.label4.ForeColor = System.Drawing.Color.Blue;
this.label4.Location = new System.Drawing.Point(204, 411);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(95, 12);
this.label4.TabIndex = 19;
this.label4.Text = "@小子好黑 2007";
this.label4.Click += new System.EventHandler(this.label4_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(521, 429);
this.Controls.Add(this.label4);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Form1";
this.Text = "Write Cart ";
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox3.ResumeLayout(false);
this.groupBox3.PerformLayout();
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.RichTextBox richTextBox2;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Label label4;
}
}
{
partial class Form1
{
/**//// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/**//// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
Windows Form Designer generated code#region Windows Form Designer generated code
/**//// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.button1 = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.richTextBox2 = new System.Windows.Forms.RichTextBox();
this.button2 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.label4 = new System.Windows.Forms.Label();
this.groupBox3.SuspendLayout();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// timer1
//
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// groupBox3
//
this.groupBox3.Controls.Add(this.button1);
this.groupBox3.Controls.Add(this.label3);
this.groupBox3.Controls.Add(this.groupBox1);
this.groupBox3.Controls.Add(this.groupBox2);
this.groupBox3.Controls.Add(this.button2);
this.groupBox3.Location = new System.Drawing.Point(13, 98);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(490, 305);
this.groupBox3.TabIndex = 18;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "WriteCard";
//
// button1
//
this.button1.Location = new System.Drawing.Point(397, 20);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(87, 28);
this.button1.TabIndex = 2;
this.button1.Text = "start";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label3
//
this.label3.AutoSize = true;
this.label3.ForeColor = System.Drawing.Color.Red;
this.label3.Location = new System.Drawing.Point(7, 279);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(0, 12);
this.label3.TabIndex = 15;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.richTextBox1);
this.groupBox1.ForeColor = System.Drawing.SystemColors.ActiveCaption;
this.groupBox1.Location = new System.Drawing.Point(26, 22);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(166, 249);
this.groupBox1.TabIndex = 16;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "移动设备";
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(17, 20);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(132, 217);
this.richTextBox1.TabIndex = 13;
this.richTextBox1.Text = "";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.richTextBox2);
this.groupBox2.ForeColor = System.Drawing.SystemColors.ActiveCaption;
this.groupBox2.Location = new System.Drawing.Point(207, 20);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(184, 251);
this.groupBox2.TabIndex = 17;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "线程状态";
//
// richTextBox2
//
this.richTextBox2.ForeColor = System.Drawing.Color.Red;
this.richTextBox2.Location = new System.Drawing.Point(25, 22);
this.richTextBox2.Name = "richTextBox2";
this.richTextBox2.Size = new System.Drawing.Size(132, 217);
this.richTextBox2.TabIndex = 14;
this.richTextBox2.Text = "";
//
// button2
//
this.button2.Location = new System.Drawing.Point(397, 68);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(87, 26);
this.button2.TabIndex = 7;
this.button2.Text = " stop";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(105, 21);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(254, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "E:\\test";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(173, 53);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(186, 21);
this.textBox2.TabIndex = 1;
this.textBox2.Text = "G:\\";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(83, 12);
this.label1.TabIndex = 3;
this.label1.Text = "选择源文件夹:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(11, 58);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(161, 12);
this.label2.TabIndex = 4;
this.label2.Text = "请选择你机器的最后一个盘: ";
//
// button3
//
this.button3.Location = new System.Drawing.Point(402, 19);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(100, 23);
this.button3.TabIndex = 10;
this.button3.Text = "浏览";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.Location = new System.Drawing.Point(403, 53);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(100, 23);
this.button4.TabIndex = 11;
this.button4.Text = " 浏览";
this.button4.UseVisualStyleBackColor = true;
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// label4
//
this.label4.AutoSize = true;
this.label4.ForeColor = System.Drawing.Color.Blue;
this.label4.Location = new System.Drawing.Point(204, 411);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(95, 12);
this.label4.TabIndex = 19;
this.label4.Text = "@小子好黑 2007";
this.label4.Click += new System.EventHandler(this.label4_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(521, 429);
this.Controls.Add(this.label4);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Form1";
this.Text = "Write Cart ";
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox3.ResumeLayout(false);
this.groupBox3.PerformLayout();
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.RichTextBox richTextBox2;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Label label4;
}
}
Form1.cs
using
System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading; //
/**/ /*Author:zhouhai*/
/**/ /*2007.11.4*/
namespace WriteCard
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string oldFolder = string.Empty;
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Init and Validate#region Init and Validate
this.button1.Enabled = false;
this.button2.Enabled = true;
this.button3.Enabled = false;
this.button4.Enabled = false;
if (!Directory.Exists(this.textBox1.Text))
{
MessageBox.Show("源文件目录不存在");
return;
}
#endregion
oldFolder = this.textBox1.Text;
timer1.Start();
}
public string ExistPathResult = string.Empty;
public void ThreadGetPath()
{
char Char = textBox2.Text.Substring(0, 1).ToCharArray()[0];
int Int = (int)Char;
for (int i = 0; i < 5; i++)
{
char thePath = (char)(Int + i);
string path = thePath.ToString() + @":\";
if (Directory.Exists(path))
{
//存在盘
ExistPathResult += path + "准备好了\n";
if (copy.copyStatus.Count > 0)
{
if (copy.copyStatus.ContainsKey(path.Substring(0,1)))
{
bool flag=copy.copyStatus[path.Substring(0,1)];
if (flag)
copyThreadHelper.hasFinished += path + "拷贝完了\n";
else
{
copyThreadHelper.hasFinished += path + "正在拷贝中……\n";
}
}
else
{
开始拷贝文件#region 开始拷贝文件
//开始拷贝文件
copyThreadHelper argu = new copyThreadHelper();
argu.Src = oldFolder;
argu.Dst = path;
Thread copyThread1 = new Thread(new ParameterizedThreadStart(copy.copyDirectory));
copyThread1.Start(argu);
#endregion
}
}
else
{
拷贝文件#region 拷贝文件
//开始拷贝文件
copyThreadHelper argu = new copyThreadHelper();
argu.Src = oldFolder;
argu.Dst = path;
Thread copyThread1 = new Thread(new ParameterizedThreadStart(copy.copyDirectory));
copyThread1.Start(argu);
#endregion
}
}
else
{
ExistPathResult += path + "无\n";
copy.copyStatus.Remove(path.Substring(0,1));
}
}
}
private void timer1_Tick(object sender, EventArgs e)
{
ExistPathResult = string.Empty;
copyThreadHelper.hasFinished = string.Empty;
label3.Text = string.Empty;
Thread th1 = new Thread(ThreadGetPath);
th1.Start();
th1.Join();
richTextBox2.Text = copyThreadHelper.hasFinished;
richTextBox1.Text = ExistPathResult;
label3.Text = copy.ErrMessage;
}
Button_Click#region Button_Click
private void button2_Click(object sender, EventArgs e)
{
this.button2.Enabled = false;
this.button1.Enabled = true;
this.button3.Enabled = true;
this.button4.Enabled = true;
timer1.Stop();
}
private void button3_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Text = folderBrowserDialog1.SelectedPath;
}
}
private void button4_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
textBox2.Text = folderBrowserDialog1.SelectedPath;
}
}
#endregion
private void label4_Click(object sender, EventArgs e)
{
label4.ForeColor = Color.Blue;
label4.Text = label4.Text =="www.cnzhouhai.cn" ? "@小子好黑 2007" : "www.cnzhouhai.cn";
}
}
class copy
{
public static string ErrMessage = string.Empty;
public static Dictionary<string, bool> copyStatus = new Dictionary<string, bool>();
public static void copyDirectory(object argu)
{
string Src = (argu as copyThreadHelper).Src;
string Dst = (argu as copyThreadHelper).Dst;
try
{
string rootPath = Dst.Substring(0, 1);
if (copyStatus.ContainsKey(rootPath))
copyStatus[rootPath] = false;
else
copyStatus.Add(rootPath, false);
String[] Files;
if (Dst[Dst.Length - 1] != Path.DirectorySeparatorChar)
Dst += Path.DirectorySeparatorChar;
if (!Directory.Exists(Dst))
Directory.CreateDirectory(Dst);
Files = Directory.GetFileSystemEntries(Src);
foreach (string Element in Files)
{
if (Directory.Exists(Element))
{
copyThreadHelper argu2 = new copyThreadHelper();
argu2.Src = Element;
argu2.Dst = Dst + Element.Replace(Src, string.Empty).ToString();
Thread copyThread2 = new Thread(new ParameterizedThreadStart(copyDirectory));
copyThread2.Start(argu2);
copyThread2.Join();
}
else
{
File.Copy(Element, Dst + Path.GetFileName(Element), true);
}
}
copyStatus[rootPath] = true;
}
catch (Exception ex)
{
ErrMessage = "出现错误!请查看日志:[WriteCart_log.htm] "+DateTime.Now;
StreamWriter sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory+"/WriteCart_log.htm", true);
sw.WriteLine("<font color='green'>"+DateTime.Now.ToString(" yy年M月d日HH时m分ss秒") +"</font>"+ " 拷贝到 <font color='blue'><b>" + Dst + "</b></font> " + " 出现错误:<font color='red'>" + ex.Message + "</font><br>");
sw.Close();
}
}
}
class copyThreadHelper
{
//参数
public string Src;//源盘
public string Dst;//目标盘
public static string hasFinished=string.Empty;//操作结果
}
//
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading; //
/**/ /*Author:zhouhai*/
/**/ /*2007.11.4*/
namespace WriteCard
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string oldFolder = string.Empty;
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Init and Validate#region Init and Validate
this.button1.Enabled = false;
this.button2.Enabled = true;
this.button3.Enabled = false;
this.button4.Enabled = false;
if (!Directory.Exists(this.textBox1.Text))
{
MessageBox.Show("源文件目录不存在");
return;
}
#endregion
oldFolder = this.textBox1.Text;
timer1.Start();
}
public string ExistPathResult = string.Empty;
public void ThreadGetPath()
{
char Char = textBox2.Text.Substring(0, 1).ToCharArray()[0];
int Int = (int)Char;
for (int i = 0; i < 5; i++)
{
char thePath = (char)(Int + i);
string path = thePath.ToString() + @":\";
if (Directory.Exists(path))
{
//存在盘
ExistPathResult += path + "准备好了\n";
if (copy.copyStatus.Count > 0)
{
if (copy.copyStatus.ContainsKey(path.Substring(0,1)))
{
bool flag=copy.copyStatus[path.Substring(0,1)];
if (flag)
copyThreadHelper.hasFinished += path + "拷贝完了\n";
else
{
copyThreadHelper.hasFinished += path + "正在拷贝中……\n";
}
}
else
{
开始拷贝文件#region 开始拷贝文件
//开始拷贝文件
copyThreadHelper argu = new copyThreadHelper();
argu.Src = oldFolder;
argu.Dst = path;
Thread copyThread1 = new Thread(new ParameterizedThreadStart(copy.copyDirectory));
copyThread1.Start(argu);
#endregion
}
}
else
{
拷贝文件#region 拷贝文件
//开始拷贝文件
copyThreadHelper argu = new copyThreadHelper();
argu.Src = oldFolder;
argu.Dst = path;
Thread copyThread1 = new Thread(new ParameterizedThreadStart(copy.copyDirectory));
copyThread1.Start(argu);
#endregion
}
}
else
{
ExistPathResult += path + "无\n";
copy.copyStatus.Remove(path.Substring(0,1));
}
}
}
private void timer1_Tick(object sender, EventArgs e)
{
ExistPathResult = string.Empty;
copyThreadHelper.hasFinished = string.Empty;
label3.Text = string.Empty;
Thread th1 = new Thread(ThreadGetPath);
th1.Start();
th1.Join();
richTextBox2.Text = copyThreadHelper.hasFinished;
richTextBox1.Text = ExistPathResult;
label3.Text = copy.ErrMessage;
}
Button_Click#region Button_Click
private void button2_Click(object sender, EventArgs e)
{
this.button2.Enabled = false;
this.button1.Enabled = true;
this.button3.Enabled = true;
this.button4.Enabled = true;
timer1.Stop();
}
private void button3_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Text = folderBrowserDialog1.SelectedPath;
}
}
private void button4_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
textBox2.Text = folderBrowserDialog1.SelectedPath;
}
}
#endregion
private void label4_Click(object sender, EventArgs e)
{
label4.ForeColor = Color.Blue;
label4.Text = label4.Text =="www.cnzhouhai.cn" ? "@小子好黑 2007" : "www.cnzhouhai.cn";
}
}
class copy
{
public static string ErrMessage = string.Empty;
public static Dictionary<string, bool> copyStatus = new Dictionary<string, bool>();
public static void copyDirectory(object argu)
{
string Src = (argu as copyThreadHelper).Src;
string Dst = (argu as copyThreadHelper).Dst;
try
{
string rootPath = Dst.Substring(0, 1);
if (copyStatus.ContainsKey(rootPath))
copyStatus[rootPath] = false;
else
copyStatus.Add(rootPath, false);
String[] Files;
if (Dst[Dst.Length - 1] != Path.DirectorySeparatorChar)
Dst += Path.DirectorySeparatorChar;
if (!Directory.Exists(Dst))
Directory.CreateDirectory(Dst);
Files = Directory.GetFileSystemEntries(Src);
foreach (string Element in Files)
{
if (Directory.Exists(Element))
{
copyThreadHelper argu2 = new copyThreadHelper();
argu2.Src = Element;
argu2.Dst = Dst + Element.Replace(Src, string.Empty).ToString();
Thread copyThread2 = new Thread(new ParameterizedThreadStart(copyDirectory));
copyThread2.Start(argu2);
copyThread2.Join();
}
else
{
File.Copy(Element, Dst + Path.GetFileName(Element), true);
}
}
copyStatus[rootPath] = true;
}
catch (Exception ex)
{
ErrMessage = "出现错误!请查看日志:[WriteCart_log.htm] "+DateTime.Now;
StreamWriter sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory+"/WriteCart_log.htm", true);
sw.WriteLine("<font color='green'>"+DateTime.Now.ToString(" yy年M月d日HH时m分ss秒") +"</font>"+ " 拷贝到 <font color='blue'><b>" + Dst + "</b></font> " + " 出现错误:<font color='red'>" + ex.Message + "</font><br>");
sw.Close();
}
}
}
class copyThreadHelper
{
//参数
public string Src;//源盘
public string Dst;//目标盘
public static string hasFinished=string.Empty;//操作结果
}
//
}