checkform.cs
来自「初学Csharp」· CS 代码 · 共 318 行
CS
318 行
using System;
using System.Drawing;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using System.IO;
namespace SourceManager
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class CheckForm : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.ListBox listBox2;
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components;
private OleDbConnection connection;
private StringCollection ErrPath;
private StringCollection ErrFile;
public CheckForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
ErrPath=new StringCollection();
ErrFile=new StringCollection();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#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();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.listBox1 = new System.Windows.Forms.ListBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.listBox2 = new System.Windows.Forms.ListBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.listBox1);
this.groupBox1.Location = new System.Drawing.Point(8, 16);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(400, 152);
this.groupBox1.TabIndex = 2;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "目录检查结果";
//
// listBox1
//
this.listBox1.HorizontalScrollbar = true;
this.listBox1.ItemHeight = 12;
this.listBox1.Location = new System.Drawing.Point(16, 16);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(368, 124);
this.listBox1.TabIndex = 0;
//
// groupBox2
//
this.groupBox2.Controls.Add(this.listBox2);
this.groupBox2.Location = new System.Drawing.Point(8, 176);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(400, 168);
this.groupBox2.TabIndex = 3;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "源文件检查结果";
//
// listBox2
//
this.listBox2.HorizontalScrollbar = true;
this.listBox2.ItemHeight = 12;
this.listBox2.Location = new System.Drawing.Point(16, 18);
this.listBox2.Name = "listBox2";
this.listBox2.Size = new System.Drawing.Size(368, 136);
this.listBox2.TabIndex = 1;
//
// button1
//
this.button1.Location = new System.Drawing.Point(96, 360);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(72, 24);
this.button1.TabIndex = 4;
this.button1.Text = "修复目录";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(168, 360);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(72, 24);
this.button2.TabIndex = 5;
this.button2.Text = "修复文件";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(240, 360);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(72, 24);
this.button3.TabIndex = 6;
this.button3.Text = "关闭";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 2000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// CheckForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(416, 397);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Name = "CheckForm";
this.Text = "一致性检查";
this.Load += new System.EventHandler(this.CheckForm_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
//目录修复
//创建没有找到的目录
int i=0;
string str;
string appPath;
for(i=0;i<ErrPath.Count;i++)
{
str=ErrPath[i];
appPath=Application.StartupPath+"\\source\\"+str;
try
{
Directory.CreateDirectory(appPath);
}
catch (Exception ee)
{
MessageBox.Show("错误:"+ee.ToString(),"错误");
}
}
}
private void button2_Click(object sender, System.EventArgs e)
{
//文件修复
//删除信息记录
string sqlstr,str;
int i;
OleDbCommand command=new OleDbCommand();
command.Connection=connection;
for(i=0;i<ErrFile.Count;i++)
{
str=ErrFile[i];
sqlstr="delete from SourceInfo where DIRECTORY='"+str+"'";
try
{
connection.Open();
command.CommandText=sqlstr;
command.ExecuteNonQuery();
}
catch (OleDbException ee)
{
MessageBox.Show("错误:"+ee.ToString(),"错误");
connection.Close();
return;
}
finally
{
connection.Close();
}
}
}
private void CheckForm_Load(object sender, System.EventArgs e)
{
//
string sqlstr;
OleDbCommand command=new OleDbCommand();
command.Connection=connection;
////////////////////////////
sqlstr="select * from LanguageInfo";
OleDbDataReader DataReader;
StateForm statefrm=new StateForm();
//statefrm.Parent=this;
statefrm.label1.ForeColor= Color.Red;
statefrm.label1.Text="正在进行目录检查...";
statefrm.label1.ForeColor= Color.Green;
statefrm.Show();
#region 目录检查
connection.Open();
string path,temp;
string appPath=Application.StartupPath;
command.CommandText=sqlstr;
DataReader=command.ExecuteReader();
try
{
while(DataReader.Read())
{
path=DataReader.GetString(1);
temp=appPath+"\\source\\"+path;
if(!Directory.Exists(temp))
{
//添加错误信息
ErrPath.Add(path);
this.listBox1.Items.Add(path);
}
}
}
catch(OleDbException ee)
{
MessageBox.Show (ee.Message,"错误!");
}
DataReader.Close();
if(this.listBox1.Items.Count==0)
{
this.listBox1.Items.Add("目录信息正确");
}
#endregion
///
statefrm.label2.ForeColor= Color.Red;
statefrm.label2.Text="正在进行文件检查...";
statefrm.label2.ForeColor=Color.Green;
#region 文件检查
sqlstr="select DIRECTORY from SourceInfo";
command.CommandText=sqlstr;
DataReader=command.ExecuteReader();
try
{
while(DataReader.Read())
{
path=DataReader.GetString(0);
temp=appPath+"\\source\\"+path;
if(!File.Exists(temp))
{
//添加错误信息
ErrFile.Add(path);
this.listBox2.Items.Add(path);
}
}
}
catch(OleDbException ee)
{
MessageBox.Show (ee.Message,"错误!");
}
if(this.listBox2.Items.Count==0)
{
this.listBox2.Items.Add("文件信息正确");
}
DataReader.Close();
#endregion
connection.Close();
statefrm.Close();
}
private void timer1_Tick(object sender, System.EventArgs e)
{
}
public void SetConnection(OleDbConnection conn)
{
connection=conn;
}
private void button3_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?