Beispiel #1
0
        public static async Task <bool> CreateBackUp(string dbName, string fileName, BackUpSettingBussines cls)
        {
            try
            {
                var path           = Path.Combine(cls.BackUpAddress, fileName);
                var command        = @"BACKUP DATABASE " + dbName + "  TO Disk='" + path + "'";
                var dataConnection = new SqlConnection(Properties.Resources.ConnectionString);
                if (dataConnection.State != ConnectionState.Open)
                {
                    dataConnection.Open();
                }
                var cmd = new SqlCommand {
                    Connection = dataConnection, CommandText = command
                };
                cmd.ExecuteNonQuery();
                cls.LastBackUpDate = DateConvertor.M2SH(DateTime.Now);
                cls.LastBackUpTime = DateTime.Now.Hour + ":" + DateTime.Now.Minute;
                await cls.SaveAsync();

                RaiseEvent();

                if (cls.IsSendInTelegram)
                {
                    await SendBackUpToTelegram(path);
                }
                return(true);
            }
            catch (Exception e)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(e);
                return(false);
            }
        }
        private async void btnFinish_Click(object sender, EventArgs e)
        {
            try
            {
                btnFinish.Enabled = false;
                if (cls.Guid == Guid.Empty)
                {
                    cls.Guid     = Guid.NewGuid();
                    cls.DateSabt = DateConvertor.M2SH(DateTime.Now);
                }

                cls.BackUpAddress    = txtAddress.Text;
                cls.AutoBackUp       = chbAuto.Checked;
                cls.Status           = true;
                cls.IsSendInTelegram = chbIsSentToTelegram.Checked;
                cls.AutoTime         = txtAutoSecond.Text.ParseToInt() * 60;
                cls.IsSendInEmail    = chbIsSendToEmail.Checked;
                cls.EmailAddress     = txtEmailAddress.Text;
                await cls.SaveAsync();

                WebErrorLog.ErrorInstence.StartErrorLog("اطلاعات ذخیره شد", true);
                SetData();
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
            }
            finally
            {
                btnFinish.Enabled = true;
            }
        }