Exemplo n.º 1
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (Checked())
     {
         Models.Setting setting = Class.Json.GetSetting();
         Models.BackUp  BackUp  = new Models.BackUp()
         {
             UuId            = System.Guid.NewGuid().ToString("N"),
             DataBase        = tbxDataBase.Text.Trim(),
             Username        = tbxUsername.Text.Trim(),
             Password        = tbxPassword.Text.Trim(),
             Path            = $"{tbxPath.Text.Trim()}\\",
             IsLogs          = setting.IsLogs,
             LogPath         = setting.IsLogs ? $"{setting.LogsPath}\\" : "",
             Type            = Models.BackType.备份,
             Times           = (Models.ExcTimes) int.Parse(cbxTimes.SelectedValue.ToString()),
             IsUse           = rbtnYes.Checked,
             PostTime        = DateTime.Now,
             LastExecuteTime = DateTime.MinValue,
             NextExecuteTime = DateTime.Now.AddMinutes(5)
         };
         Class.Json.SaveBackUp(BackUp);
         this.DialogResult = DialogResult.OK;
         this.Close();
     }
 }
Exemplo n.º 2
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (Checked())
     {
         string         now     = DateTime.Now.ToString("yyyyMMddHHms");
         string         cmd     = $@"imp {tbxUsername.Text.Trim()}/{tbxPassword.Text.Trim()}@{tbxDataBase.Text.Trim()} file={tbxPath.Text.Trim()} fromuser={tbxFromuser.Text.Trim()} touser={tbxUsername.Text.Trim()}";
         Models.Setting setting = Class.Json.GetSetting();
         if (setting.IsLogs)
         {
             cmd += $" log={setting.LogsPath}\\Imp_{tbxUsername.Text.Trim()}_{now}.log";
         }
         Cmd      = cmd;
         FilePath = tbxPath.Text.Trim();
         BackUp   = new Models.BackUp()
         {
             DataBase = tbxDataBase.Text.Trim(),
             Username = tbxUsername.Text.Trim(),
             Password = tbxPassword.Text.Trim(),
             Path     = $"{tbxPath.Text.Trim()}\\{tbxUsername.Text.Trim()}_{now}.dmp",
             IsLogs   = setting.IsLogs,
             LogPath  = setting.IsLogs ? $"{setting.LogsPath}\\{tbxUsername.Text.Trim()}_{now}.log" : "",
             Type     = Models.BackType.导入
         };
         this.DialogResult = DialogResult.OK;
         this.Close();
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// 线程里运行
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="filePath"></param>
        /// <param name="backUp"></param>
        /// <param name="logsfolder"></param>
        private void ThreadRun(string cmd, string filePath, Models.BackUp backUp, string logsfolder)
        {
            FilePath   = filePath;
            Cmd        = cmd;
            LogsFolder = logsfolder;
            BackUp     = backUp;
            bool isSuccess = false;

            fm_Loading           = new Fm_Loading();
            IsExceing            = true;
            tsslStatus.Text      = $@"状态:正在{logsfolder}...";
            tsslStatus.ForeColor = Color.Black;

            fm_Loading = new Fm_Loading();
            Thread th = new Thread(new ThreadStart(RunCmd));

            th.Start();

            IsExceing            = false;
            isSuccess            = fm_Loading.ShowDialog() == DialogResult.OK;
            tsslStatus.Text      = isSuccess ? $@"状态:{logsfolder}成功" : $@"状态:{logsfolder}失败";
            tsslStatus.ForeColor = isSuccess ? Color.Green : Color.Red;
            if (isSuccess && BackUp.Type != Models.BackType.导入)
            {
                EmailTitle = $"Oracle数据库{logsfolder}:{BackUp.Username}";
                EmailBody  = Newtonsoft.Json.JsonConvert.SerializeObject(BackUp);
                Thread thA = new Thread(new ThreadStart(SendMail));
                thA.Start();
            }
        }
Exemplo n.º 4
0
        private void dgvData_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            DataView view = (DataView)this.dgvData.DataSource;
            DataRow  dr   = (DataRow)view[this.dgvData.CurrentCell.RowIndex].Row;

            Models.BackUp backUp = new Models.BackUp()
            {
                UuId            = dr["UuId"].ToString(),
                DataBase        = dr["DataBase"].ToString(),
                Username        = dr["Username"].ToString(),
                Password        = dr["Password"].ToString(),
                Path            = dr["Path"].ToString(),
                IsLogs          = bool.Parse(dr["IsLogs"].ToString()),
                LogPath         = dr["LogPath"].ToString(),
                Type            = Models.BackType.备份,
                Times           = (Models.ExcTimes) int.Parse(dr["Times"].ToString()),
                IsUse           = bool.Parse(dr["IsUse"].ToString()),
                PostTime        = DateTime.Parse(dr["PostTime"].ToString()),
                LastExecuteTime = DateTime.Parse(dr["LastExecuteTime"].ToString()),
                NextExecuteTime = DateTime.Parse(dr["NextExecuteTime"].ToString())
            };
            if (dgvData.Columns[e.ColumnIndex].Name == "Use")
            {
                backUp.IsUse = !backUp.IsUse;
                Class.Json.EditBackUp(backUp);
                LoadBackUpList();
            }
            if (dgvData.Columns[e.ColumnIndex].Name == "Del")
            {
                if (MessageBox.Show(@"确认是否删除?", @"删除", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    Class.Json.DelBackUp(backUp.UuId);
                    LoadBackUpList();
                }
            }
            if (dgvData.Columns[e.ColumnIndex].Name == "Execute")
            {
                string now = DateTime.Now.ToString("yyyyMMddHHms");
                string cmd = $"exp {backUp.Username}/{backUp.Password}@{backUp.DataBase} file={backUp.Path}\\Backup_{backUp.Username}_{now}.dmp";
                if (backUp.IsLogs)
                {
                    cmd += $" log={backUp.LogPath}\\Backup_{backUp.Username}_{now}.log";
                }
                ThreadRun(cmd, $"{backUp.Path}\\Backup_{backUp.Username}_{now}.dmp", backUp, "手动备份");
                LoadBackUpList();
            }
        }
Exemplo n.º 5
0
        private void timerBackUp_Tick(object sender, EventArgs e)
        {
            DateTime thisTime = DateTime.Now;
            var      backUp   = BackUps.Find(x =>
                                             x.NextExecuteTime <thisTime.AddSeconds(2) && x.NextExecuteTime> thisTime.AddSeconds(-2));

            if (backUp != null && backUp.IsUse)
            {
                if (IsExceing)
                {
                    return;
                }
                BackUp = backUp;
                BackUpAuto();
                LoadBackUpList();
            }
        }