📄 frmdatacopy.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
namespace 毕业生信息管理系统
{
/// <summary>
/// frmDataCopy 的摘要说明。
/// </summary>
public class frmDataCopy : System.Windows.Forms.Form
{
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtDataPath;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button btnCopy;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button btnCome;
private System.Windows.Forms.Button btnLiulan;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public frmDataCopy()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmDataCopy));
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.button3 = new System.Windows.Forms.Button();
this.btnCopy = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.txtDataPath = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.button2 = new System.Windows.Forms.Button();
this.btnCome = new System.Windows.Forms.Button();
this.btnLiulan = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.tabPage2.SuspendLayout();
this.SuspendLayout();
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Location = new System.Drawing.Point(16, 16);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(304, 168);
this.tabControl1.TabIndex = 0;
//
// tabPage1
//
this.tabPage1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(192)));
this.tabPage1.Controls.Add(this.button3);
this.tabPage1.Controls.Add(this.btnCopy);
this.tabPage1.Controls.Add(this.button1);
this.tabPage1.Controls.Add(this.txtDataPath);
this.tabPage1.Controls.Add(this.label1);
this.tabPage1.Location = new System.Drawing.Point(4, 21);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Size = new System.Drawing.Size(296, 143);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "数据备份";
//
// button3
//
this.button3.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button3.ForeColor = System.Drawing.Color.Red;
this.button3.Location = new System.Drawing.Point(176, 96);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(88, 24);
this.button3.TabIndex = 4;
this.button3.Text = "退出";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// btnCopy
//
this.btnCopy.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.btnCopy.ForeColor = System.Drawing.Color.Red;
this.btnCopy.Location = new System.Drawing.Point(32, 96);
this.btnCopy.Name = "btnCopy";
this.btnCopy.Size = new System.Drawing.Size(80, 24);
this.btnCopy.TabIndex = 3;
this.btnCopy.Text = "备份";
this.btnCopy.Click += new System.EventHandler(this.btnCopy_Click);
//
// button1
//
this.button1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button1.ForeColor = System.Drawing.Color.Red;
this.button1.Location = new System.Drawing.Point(224, 48);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(64, 24);
this.button1.TabIndex = 2;
this.button1.Text = "浏览";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// txtDataPath
//
this.txtDataPath.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.txtDataPath.ForeColor = System.Drawing.Color.Magenta;
this.txtDataPath.Location = new System.Drawing.Point(80, 48);
this.txtDataPath.Name = "txtDataPath";
this.txtDataPath.Size = new System.Drawing.Size(136, 23);
this.txtDataPath.TabIndex = 1;
this.txtDataPath.Text = "";
//
// label1
//
this.label1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.ForeColor = System.Drawing.Color.Blue;
this.label1.Location = new System.Drawing.Point(8, 40);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 32);
this.label1.TabIndex = 0;
this.label1.Text = "保存路径:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// tabPage2
//
this.tabPage2.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(255)), ((System.Byte)(255)));
this.tabPage2.Controls.Add(this.button2);
this.tabPage2.Controls.Add(this.btnCome);
this.tabPage2.Controls.Add(this.btnLiulan);
this.tabPage2.Controls.Add(this.textBox1);
this.tabPage2.Controls.Add(this.label2);
this.tabPage2.Location = new System.Drawing.Point(4, 21);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Size = new System.Drawing.Size(296, 143);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "数据恢复";
//
// button2
//
this.button2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button2.ForeColor = System.Drawing.Color.Magenta;
this.button2.Location = new System.Drawing.Point(176, 96);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(88, 24);
this.button2.TabIndex = 9;
this.button2.Text = "退出";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// btnCome
//
this.btnCome.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.btnCome.ForeColor = System.Drawing.Color.Magenta;
this.btnCome.Location = new System.Drawing.Point(32, 96);
this.btnCome.Name = "btnCome";
this.btnCome.Size = new System.Drawing.Size(80, 24);
this.btnCome.TabIndex = 8;
this.btnCome.Text = "恢复";
this.btnCome.Click += new System.EventHandler(this.btnCome_Click);
//
// btnLiulan
//
this.btnLiulan.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.btnLiulan.ForeColor = System.Drawing.Color.Red;
this.btnLiulan.Location = new System.Drawing.Point(224, 40);
this.btnLiulan.Name = "btnLiulan";
this.btnLiulan.Size = new System.Drawing.Size(64, 24);
this.btnLiulan.TabIndex = 7;
this.btnLiulan.Text = "选择";
this.btnLiulan.Click += new System.EventHandler(this.btnLiulan_Click);
//
// textBox1
//
this.textBox1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.textBox1.ForeColor = System.Drawing.Color.Magenta;
this.textBox1.Location = new System.Drawing.Point(88, 40);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(128, 21);
this.textBox1.TabIndex = 6;
this.textBox1.Text = "";
//
// label2
//
this.label2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label2.ForeColor = System.Drawing.Color.Blue;
this.label2.Location = new System.Drawing.Point(8, 32);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(80, 32);
this.label2.TabIndex = 5;
this.label2.Text = "数据库路径:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// folderBrowserDialog1
//
this.folderBrowserDialog1.SelectedPath = "C:\\";
//
// frmDataCopy
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(192)));
this.ClientSize = new System.Drawing.Size(336, 198);
this.Controls.Add(this.tabControl1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "frmDataCopy";
this.Text = "数据备份";
this.Load += new System.EventHandler(this.frmDataCopy_Load);
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.tabPage2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void btnLiulan_Click(object sender, System.EventArgs e) //浏览按钮
{
this.folderBrowserDialog1.ShowDialog();
this.textBox1.Text=this.folderBrowserDialog1.SelectedPath+"\\Student.mdb";
}
private void btnCome_Click(object sender, System.EventArgs e) //删除按钮
{
if( !File.Exists(""+this.textBox1.Text.ToString()+""))
{
MessageBox.Show("备份数据库不存在!!!");
}
else
{
try
{
File.Copy(""+this.textBox1.Text.ToString()+"", ".\\Student.mdb", true );
MessageBox.Show("恭喜你!恢复成功!");
}
catch( IOException ixp )
{
MessageBox.Show("恢复失败!");
throw new Exception(ixp.ToString());
}
}
}
private void button1_Click(object sender, System.EventArgs e) //浏览按钮
{
this.folderBrowserDialog1.ShowDialog();
this.txtDataPath.Text=this.folderBrowserDialog1.SelectedPath+"\\Student.mdb";
}
private void btnCopy_Click(object sender, System.EventArgs e) //备份按钮
{
if( !File.Exists(".\\Student.mdb") )
{
MessageBox.Show("源数据库不存在!!!");
}
else
{
try
{
File.Copy(".\\Student.mdb", ""+this.txtDataPath.Text.ToString()+"", true );
MessageBox.Show("恭喜你!备份成功!");
}
catch(IOException ixp )
{
MessageBox.Show("备份失败!");
throw new Exception(ixp.ToString());
}
}
}
private void button3_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void frmDataCopy_Load(object sender, System.EventArgs e) //权限设置
{
this.textBox1.Enabled=false;
this.txtDataPath.Enabled=false;
user myUser = user.InitUser();
if(myUser.isPublicUser == false)
{
this.btnLiulan.Enabled=false;
this.button1.Enabled=false;
this.btnCopy.Enabled=false;
this.btnCome.Enabled=false;
}
if(myUser.isPublicUser==true)
{
this.btnLiulan.Enabled=true;
this.button1.Enabled=true;
this.btnCopy.Enabled=true;
this.btnCome.Enabled=true;
}
}
private void button2_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -