⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbrecover.cs

📁 程序设计语言上机考试系统
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class DBRecover : Form
    {
        baseclass.BaseOperate boperate = new baseclass.BaseOperate();
        public DBRecover()
        {
            InitializeComponent();
        }

        #region  数据还原
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (txtRecover.Text.Trim() == "" && txtDSPath.Text.Trim() == "")
                MessageBox.Show("请选择数据源!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            else
            {
                SqlConnection sqlcon = boperate.getcon();
                try
                {
                    if (sqlcon.State == ConnectionState.Open)
                    {
                        sqlcon.Close();
                    }
                    boperate.getcom("backup log test1 to disk='" + txtRecover.Text.Trim()
                                    + "' use master restore database db_CRM from disk='" + txtRecover.Text.Trim() + "'");
                    MessageBox.Show("数据还原成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
        #endregion

        private void btnCel_Click(object sender, EventArgs e)
        {
            openFileDialog1.InitialDirectory = Application.StartupPath.Trim();
            openFileDialog1.Filter = "bak files (*.bak)|*.bak";
            openFileDialog1.RestoreDirectory = true;
            openFileDialog1.ShowDialog();
            txtRecover.Text = openFileDialog1.FileName.ToString().Trim();
        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnOpen_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                txtDSPath.Text = folderBrowserDialog1.SelectedPath.ToString().Trim();
            else
                txtDSPath.Text = "";
        }

        #region  数据备份
        private void btnCopy_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtDSPath.Text.Trim() == "")
                    MessageBox.Show("请选择路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                else
                {
                    if (File.Exists(txtDSPath.Text.Trim() + ".bak"))
                    {
                        MessageBox.Show("该文件已经存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        txtDSPath.Text = "";
                        txtDSPath.Focus();
                    }
                    else
                    {
                        string time = DateTime.Now.ToString().Substring(0, 8);
                        boperate.getcom("backup database test1 to disk='" + txtDSPath.Text.Trim() +  time + ".bak'");
                        MessageBox.Show("数据备份成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        #endregion

        #region 调整窗口大小
        private void expandableSplitter1_Click(object sender, EventArgs e)
        {
            if (this.Height > 300)
                this.Height = 220;
            else
                this.Height = 374;
        }
        #endregion
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -