📄 form1.cs
字号:
this.groupBox1.TabIndex = 14;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "数据库查询";
//
// btnCear
//
this.btnCear.Location = new System.Drawing.Point(256, 96);
this.btnCear.Name = "btnCear";
this.btnCear.Size = new System.Drawing.Size(96, 23);
this.btnCear.TabIndex = 7;
this.btnCear.Text = "取消";
this.btnCear.Click += new System.EventHandler(this.btnCear_Click);
//
// groupBox2
//
this.groupBox2.Controls.Add(this.label7);
this.groupBox2.Controls.Add(this.label6);
this.groupBox2.Controls.Add(this.txtOutFile);
this.groupBox2.Controls.Add(this.txtInFile);
this.groupBox2.Controls.Add(this.progressBar1);
this.groupBox2.Controls.Add(this.button2);
this.groupBox2.Controls.Add(this.button3);
this.groupBox2.Location = new System.Drawing.Point(256, 208);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(376, 136);
this.groupBox2.TabIndex = 15;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "数据库操作";
//
// label7
//
this.label7.ForeColor = System.Drawing.Color.Blue;
this.label7.Location = new System.Drawing.Point(8, 64);
this.label7.Name = "label7";
this.label7.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.label7.Size = new System.Drawing.Size(96, 23);
this.label7.TabIndex = 17;
this.label7.Text = "恢复文件名称:";
this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label6
//
this.label6.ForeColor = System.Drawing.Color.Blue;
this.label6.Location = new System.Drawing.Point(8, 32);
this.label6.Name = "label6";
this.label6.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.label6.Size = new System.Drawing.Size(96, 23);
this.label6.TabIndex = 16;
this.label6.Text = "备份文件名称:";
this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// txtOutFile
//
this.txtOutFile.Location = new System.Drawing.Point(136, 64);
this.txtOutFile.Name = "txtOutFile";
this.txtOutFile.Size = new System.Drawing.Size(104, 21);
this.txtOutFile.TabIndex = 15;
this.txtOutFile.Text = "";
//
// txtInFile
//
this.txtInFile.Location = new System.Drawing.Point(136, 32);
this.txtInFile.Name = "txtInFile";
this.txtInFile.Size = new System.Drawing.Size(104, 21);
this.txtInFile.TabIndex = 14;
this.txtInFile.Text = "";
//
// groupBox3
//
this.groupBox3.Controls.Add(this.label4);
this.groupBox3.Controls.Add(this.lstServer);
this.groupBox3.Controls.Add(this.label5);
this.groupBox3.Controls.Add(this.lstDb);
this.groupBox3.Location = new System.Drawing.Point(8, 16);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(232, 328);
this.groupBox3.TabIndex = 16;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "服务器\数据库显示";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(648, 357);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.MaximizeBox = false;
this.Name = "Form1";
this.Text = "数据库备份";
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
baks = new bakServer();
ArrayList list = baks.GetServerList();
for ( int i = 0 ; i < list.Count; i ++ )
{
lstServer.Items.Add(list[i]);
}
if ( list.Count == 0 )
{
MessageBox.Show(baks.Msg(), "操作错误",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
private void button1_Click(object sender, System.EventArgs e)
{
//取指定数据库列表
if ( txtDbName.Text =="" || txtUserName.Text == "" || txtPwd.Text == "")
{
MessageBox.Show("数据库,用户,密码不能为空!!", "操作错误",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
ArrayList lst = baks.GetDbList(txtDbName.Text,txtUserName.Text,txtPwd.Text);
for ( int i = 0 ; i < lst.Count; i ++ )
{
lstDb.Items.Add(lst[i]);
}
if ( lst.Count == 0 )
{
MessageBox.Show(baks.Msg(), "操作错误",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
private void lstServer_SelectedIndexChanged(object sender, System.EventArgs e)
{
txtDbName.Text = lstServer.SelectedItem.ToString();
}
private void lstDb_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
private void button2_Click(object sender, System.EventArgs e)
{
if ( lstDb.Items.Count == 0 )
{
MessageBox.Show("数据库列表不能为空!", "操作错误",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else if( txtInFile.Text =="" )
{
MessageBox.Show("备份文件名称不能为空!", "操作错误",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else if( txtDbName.Text =="" || txtUserName.Text == "" || txtPwd.Text == "" )
{
MessageBox.Show("数据库,用户,密码不能为空!!", "操作错误",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
button3.Enabled = false;
button1.Enabled = false;
btnCear.Enabled = false;
if ( baks.BackUPDB(lstDb.SelectedItem.ToString(),txtInFile.Text,progressBar1,txtDbName.Text,txtUserName.Text,txtPwd.Text) == true )
{
MessageBox.Show("备份成功!", "备份",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
progressBar1.Value = 0;
}
button3.Enabled = true;
button1.Enabled = true;
btnCear.Enabled = true;
}
}
private void button3_Click(object sender, System.EventArgs e)
{
//恢复数据库
if ( lstDb.Items.Count == 0 )
{
MessageBox.Show("数据库列表不能为空!", "操作错误",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else if ( txtOutFile.Text =="" )
{
MessageBox.Show("还原文件名称不能为空!", "操作错误",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else if( txtDbName.Text =="" || txtUserName.Text == "" || txtPwd.Text == "" )
{
MessageBox.Show("数据库,用户,密码不能为空!!", "操作错误",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
button2.Enabled = false;
button1.Enabled = false;
btnCear.Enabled = false;
if ( baks.RestoreDB(lstDb.SelectedItem.ToString(),txtOutFile.Text,progressBar1,txtDbName.Text,txtUserName.Text,txtPwd.Text) == true )
{
MessageBox.Show("恢复成功!", "恢复",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
button2.Enabled = true;
button1.Enabled = true;
btnCear.Enabled = true;
}
}
private void btnCear_Click(object sender, System.EventArgs e)
{
txtDbName.Text ="";
txtUserName.Text ="";
txtPwd.Text ="";
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -