📄 restroreframe.cs
字号:
using System;using System.Collections;using System.ComponentModel;using System.Drawing;using System.Windows.Forms;using System.IO;using System.Data;using System.Data.SqlClient;namespace WindowsApplication{ public class RestroreFrame : System.Windows.Forms.Form { #region 控件声明... private System.ComponentModel.IContainer components = null; #endregion #region 变量声明... private ConnectionData conn=new ConnectionData(); private static string RestroreSql="";
private System.Windows.Forms.OpenFileDialog openFileDialog;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox FileText;
private System.Windows.Forms.Button btnBrower;
private System.Windows.Forms.ImageList imageList;
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.Button btnCancel; #endregion #region 构造函数 public RestroreFrame() { // 该调用是 Windows 窗体设计器所必需的。 InitializeComponent(); // TODO: 在 InitializeComponent 调用后添加任何初始化 } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #endregion #region 设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(RestroreFrame));
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
this.label1 = new System.Windows.Forms.Label();
this.FileText = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.btnBrower = new System.Windows.Forms.Button();
this.imageList = new System.Windows.Forms.ImageList(this.components);
this.btnOK = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// openFileDialog
//
this.openFileDialog.RestoreDirectory = true;
this.openFileDialog.ShowHelp = true;
this.openFileDialog.ShowReadOnly = true;
//
// label1
//
this.label1.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.ForeColor = System.Drawing.Color.Blue;
this.label1.Location = new System.Drawing.Point(8, 64);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 16);
this.label1.TabIndex = 0;
this.label1.Text = "路径:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// FileText
//
this.FileText.BackColor = System.Drawing.Color.White;
this.FileText.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.FileText.Cursor = System.Windows.Forms.Cursors.Hand;
this.FileText.ForeColor = System.Drawing.Color.Blue;
this.FileText.Location = new System.Drawing.Point(72, 64);
this.FileText.Name = "FileText";
this.FileText.ReadOnly = true;
this.FileText.Size = new System.Drawing.Size(176, 21);
this.FileText.TabIndex = 1;
this.FileText.Text = "";
//
// label2
//
this.label2.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(128)), ((System.Byte)(128)), ((System.Byte)(255)));
this.label2.Font = new System.Drawing.Font("宋体", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label2.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label2.Location = new System.Drawing.Point(0, 0);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(360, 40);
this.label2.TabIndex = 2;
this.label2.Text = "系统还原";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// btnBrower
//
this.btnBrower.Cursor = System.Windows.Forms.Cursors.Hand;
this.btnBrower.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnBrower.ForeColor = System.Drawing.Color.Blue;
this.btnBrower.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnBrower.ImageIndex = 0;
this.btnBrower.ImageList = this.imageList;
this.btnBrower.Location = new System.Drawing.Point(264, 64);
this.btnBrower.Name = "btnBrower";
this.btnBrower.Size = new System.Drawing.Size(80, 24);
this.btnBrower.TabIndex = 3;
this.btnBrower.Text = "浏览(&B)";
this.btnBrower.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.btnBrower.Click += new System.EventHandler(this.btnBrower_Click);
//
// imageList
//
this.imageList.ImageSize = new System.Drawing.Size(16, 16);
this.imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList.ImageStream")));
this.imageList.TransparentColor = System.Drawing.Color.Transparent;
//
// btnOK
//
this.btnOK.Cursor = System.Windows.Forms.Cursors.Hand;
this.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnOK.ForeColor = System.Drawing.Color.Blue;
this.btnOK.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnOK.ImageIndex = 2;
this.btnOK.ImageList = this.imageList;
this.btnOK.Location = new System.Drawing.Point(168, 112);
this.btnOK.Name = "btnOK";
this.btnOK.Size = new System.Drawing.Size(80, 24);
this.btnOK.TabIndex = 4;
this.btnOK.Text = "确定(&O)";
this.btnOK.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.btnOK.Click += new System.EventHandler(this.btnOK_Click_1);
//
// btnCancel
//
this.btnCancel.Cursor = System.Windows.Forms.Cursors.Hand;
this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnCancel.ForeColor = System.Drawing.Color.Blue;
this.btnCancel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnCancel.ImageIndex = 1;
this.btnCancel.ImageList = this.imageList;
this.btnCancel.Location = new System.Drawing.Point(264, 112);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(80, 24);
this.btnCancel.TabIndex = 5;
this.btnCancel.Text = "取消(&C)";
this.btnCancel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click_1);
//
// RestroreFrame
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.ClientSize = new System.Drawing.Size(360, 150);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOK);
this.Controls.Add(this.btnBrower);
this.Controls.Add(this.label2);
this.Controls.Add(this.FileText);
this.Controls.Add(this.label1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "RestroreFrame";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "RestroreFrame";
this.Load += new System.EventHandler(this.RestroreFrame_Load);
this.ResumeLayout(false);
} #endregion #region 变量初始化...
private void RestroreFrame_Load(object sender, System.EventArgs e)
{
this.openFileDialog.Filter="*.txt|*.*";
this.openFileDialog.InitialDirectory=Application.ExecutablePath+@"\WindowsApplication\backup\";
}
#endregion
#region 打开文件存入一个字符串...
private void btnBrower_Click(object sender, System.EventArgs e)
{
string path=System.Environment.CurrentDirectory+"\\data\\SystemODBC.mdf";
string pathlog=System.Environment.CurrentDirectory+"\\data\\SystemODBC.log";
try
{
if(this.openFileDialog.ShowDialog().Equals(DialogResult.OK))
{
this.FileText.Text=this.openFileDialog.FileName.ToString().Trim();
RestroreFrame.RestroreSql=" RESTORE DATABASE SystemODBC FROM disk ='"+FileText.Text.Trim()+"'with move SystemODBC to'"+path+"',move SystemODBC to'"+pathlog+"'";
}
}
catch(Exception ewe)
{
MessageBox.Show(this,ewe.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
#endregion
#region 还原数据库...
private void btnOK_Click_1(object sender, System.EventArgs e)
{
try
{
if(this.FileText.Text.Equals(""))
{
MessageBox.Show(this,"此处不能为空!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
int k=conn.ExcuteStrSql(RestroreFrame.RestroreSql);
if(k>0)
{
MessageBox.Show(this,"还原成功!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else
{
MessageBox.Show(this,"还原失败!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
catch(Exception efe)
{
MessageBox.Show(this,efe.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
#endregion
#region 取消还原...
private void btnCancel_Click(object sender, System.EventArgs e)
{
} private void btnCancel_Click_1(object sender, System.EventArgs e)
{
this.FileText.Text="";
this.Close();
} #endregion }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -