📄 backup_replaceui.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using LengYue;
using System.Threading;
namespace UI
{
/// <summary>
/// BackUp_ReplaceUI 的摘要说明。
/// </summary>
public class BackUp_ReplaceUI : 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.TextBox textBackupFile;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.TextBox textReplaceFile;
private System.ComponentModel.IContainer components=null;
public BackUp_ReplaceUI()
{
//
// 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(BackUp_ReplaceUI));
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.label2 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.textBackupFile = new System.Windows.Forms.TextBox();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.label3 = new System.Windows.Forms.Label();
this.button4 = new System.Windows.Forms.Button();
this.label4 = new System.Windows.Forms.Label();
this.textReplaceFile = new System.Windows.Forms.TextBox();
this.button5 = new System.Windows.Forms.Button();
this.button6 = new System.Windows.Forms.Button();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
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.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl1.Location = new System.Drawing.Point(0, 0);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(424, 197);
this.tabControl1.TabIndex = 0;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.label2);
this.tabPage1.Controls.Add(this.button1);
this.tabPage1.Controls.Add(this.label1);
this.tabPage1.Controls.Add(this.textBackupFile);
this.tabPage1.Controls.Add(this.button2);
this.tabPage1.Controls.Add(this.button3);
this.tabPage1.Location = new System.Drawing.Point(4, 21);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Size = new System.Drawing.Size(416, 172);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "备份数据";
//
// label2
//
this.label2.Location = new System.Drawing.Point(112, 80);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(176, 16);
this.label2.TabIndex = 3;
this.label2.Text = "正在备份数据,请等待......";
//
// button1
//
this.button1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("button1.BackgroundImage")));
this.button1.Location = new System.Drawing.Point(360, 40);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(48, 24);
this.button1.TabIndex = 2;
this.button1.Text = "...";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(16, 40);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(66, 17);
this.label1.TabIndex = 1;
this.label1.Text = "备份路径:";
//
// textBackupFile
//
this.textBackupFile.Location = new System.Drawing.Point(96, 40);
this.textBackupFile.Name = "textBackupFile";
this.textBackupFile.Size = new System.Drawing.Size(256, 21);
this.textBackupFile.TabIndex = 0;
this.textBackupFile.Text = "";
//
// button2
//
this.button2.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("button2.BackgroundImage")));
this.button2.Location = new System.Drawing.Point(96, 112);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(64, 24);
this.button2.TabIndex = 2;
this.button2.Text = "备份";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("button3.BackgroundImage")));
this.button3.Location = new System.Drawing.Point(256, 112);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(64, 24);
this.button3.TabIndex = 2;
this.button3.Text = "取消";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// tabPage2
//
this.tabPage2.Controls.Add(this.label3);
this.tabPage2.Controls.Add(this.button4);
this.tabPage2.Controls.Add(this.label4);
this.tabPage2.Controls.Add(this.textReplaceFile);
this.tabPage2.Controls.Add(this.button5);
this.tabPage2.Controls.Add(this.button6);
this.tabPage2.Location = new System.Drawing.Point(4, 21);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Size = new System.Drawing.Size(416, 172);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "还原数据";
//
// label3
//
this.label3.Location = new System.Drawing.Point(112, 80);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(176, 14);
this.label3.TabIndex = 9;
this.label3.Text = "正在还原数据,请等待......";
//
// button4
//
this.button4.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("button4.BackgroundImage")));
this.button4.Location = new System.Drawing.Point(360, 40);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(48, 24);
this.button4.TabIndex = 8;
this.button4.Text = "...";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(16, 40);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(66, 17);
this.label4.TabIndex = 5;
this.label4.Text = "还原文件:";
//
// textReplaceFile
//
this.textReplaceFile.Location = new System.Drawing.Point(96, 40);
this.textReplaceFile.Name = "textReplaceFile";
this.textReplaceFile.Size = new System.Drawing.Size(256, 21);
this.textReplaceFile.TabIndex = 4;
this.textReplaceFile.Text = "";
//
// button5
//
this.button5.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("button5.BackgroundImage")));
this.button5.Location = new System.Drawing.Point(96, 112);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(64, 24);
this.button5.TabIndex = 6;
this.button5.Text = "还原";
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// button6
//
this.button6.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("button6.BackgroundImage")));
this.button6.Location = new System.Drawing.Point(256, 112);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(64, 24);
this.button6.TabIndex = 7;
this.button6.Text = "取消";
this.button6.Click += new System.EventHandler(this.button3_Click);
//
// saveFileDialog1
//
this.saveFileDialog1.Filter = "bak|*.bak|其它|*.*";
//
// openFileDialog1
//
this.openFileDialog1.Filter = "bak|*.bak|所有|*.*";
//
// BackUp_ReplaceUI
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(424, 197);
this.Controls.Add(this.tabControl1);
this.Name = "BackUp_ReplaceUI";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "数据操作";
this.Load += new System.EventHandler(this.BackUp_ReplaceUI_Load);
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.tabPage2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
public void ShowBackupMess()// 显示提示信息
{
this.label2.Visible=true;
}
public void ShowReplaceMess()// 显示提示信息
{
this.label3.Visible=true;
}
public void BackUP()
{
try
{
//BackupDataBase(要备份的数据库名,备份文件路径)
if(LengYue.OperDB_Lengyue.BackupDataBase("groggeryDB",this.textBackupFile.Text))//备份数据库
{
MessageBox.Show(this,"BackupDataBase==========OK","提示");
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
this.label2.Visible=false;
}
public void Replace()
{
try
{
//ReplaceDataBase(需要还原数据库名,备份文件路径)
if(LengYue.OperDB_Lengyue.ReplaceDataBase("groggeryDB",this.textReplaceFile.Text))//还原数据库
{
MessageBox.Show(this,"ReplaceDataBase==========OK","提示");
}
}
catch(Exception ex)
{
MessageBox.Show("由于:"+ex.Message+",要执行备份,请关闭本程序,运行同目录下的BackUp_ReplaceUI.exe程序进行备份,要关闭本程序吗?");
}
this.label3.Visible=false;
}
private void button1_Click(object sender, System.EventArgs e)//备份路径
{
if(DialogResult.OK==this.saveFileDialog1.ShowDialog(this))
{
this.textBackupFile.Text=this.saveFileDialog1.FileName;
}
}
private void button4_Click(object sender, System.EventArgs e)//还原路径
{
if(DialogResult.OK==this.openFileDialog1.ShowDialog(this))
{
this.textReplaceFile.Text= this.openFileDialog1.FileName;
}
}
private void button2_Click(object sender, System.EventArgs e)//备份
{
Thread th1=new Thread(new ThreadStart(this.BackUP));
th1.IsBackground=true;
th1.Start();
Thread th2=new Thread(new ThreadStart(this.ShowBackupMess));
th2.IsBackground=true;
th2.Start();
}
private void button5_Click(object sender, System.EventArgs e)//还原
{
Thread th1=new Thread(new ThreadStart(this.Replace));
th1.IsBackground=true;
th1.Start();
Thread th2=new Thread(new ThreadStart(this.ShowReplaceMess));
th2.IsBackground=true;
th2.Start();
}
private void button3_Click(object sender, System.EventArgs e)//取消
{
this.Close();
}
private void BackUp_ReplaceUI_Load(object sender, System.EventArgs e)
{
this.label2.Visible=false;
this.label3.Visible=false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -