写卡程序

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

        
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

            oldFolder 
= this.textBox1.Text;

            timer1.Start();
        }



        
public string ExistPathResult = string.Empty;
        
public void ThreadGetPath()
        
{
            
char Char = textBox2.Text.Substring(01).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
                        
{
                            
开始拷贝文件
                        }

                    }

                    
else
                    
{
                        
拷贝文件
                    }


                }

                
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

        
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<stringbool> copyStatus = new Dictionary<stringbool>();
        
public static void copyDirectory(object argu)
        
{
            
string Src = (argu as copyThreadHelper).Src;
            
string Dst = (argu as copyThreadHelper).Dst;
            
try
            
{
                
string rootPath = Dst.Substring(01);

                
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;//操作结果
    }

    
//
}

posted on 2007-11-04 19:01  小子好黑  阅读(550)  评论(2编辑  收藏  举报

导航