コード例 #1
0
        //Backup
        private void simpleButton4_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            string LastBackupFolder = CurrDp.GetVariable <string>("System",
                                                                  "LastBackupFolder", string.Empty);

            fbd.SelectedPath = LastBackupFolder;
            fbd.Description  = "Pilih Folder yang digunakan untuk membackup Database :";
            if (fbd.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            CurrDp.SetVariable("System", "LastBackupFolder", fbd.SelectedPath);

            Type EngineType = BaseFramework.DpEngine.DictEngine[comboBoxEdit1.Text];

            if (EngineType.Equals(typeof(SqlServerPersistance)))
            {
                string FileName = string.Concat(fbd.SelectedPath, "\\",
                                                ((SqlServerPersistance)CurrDp).DatabaseName,
                                                "_", DateTime.Today.ToString("yyyy_MM_dd"), ".bak");

                if (File.Exists(FileName))
                {
                    XtraMessageBox.Show(string.Concat(
                                            "File Tujuan Backup '", FileName,
                                            "' sudah ada. Hapus File tersebut untuk melanjutkan !"),
                                        "Error Backup Database",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                    return;
                }

                try
                {
                    using (new FormWaitCursor())
                    {
                        CurrDp.ExecuteNonQuery(string.Concat(
                                                   "BACKUP DATABASE [",
                                                   ((SqlServerPersistance)CurrDp).DatabaseName,
                                                   "] TO DISK = '", FileName, "'"));
                    }
                    XtraMessageBox.Show(string.Concat(
                                            "Backup Database ",
                                            ((SqlServerPersistance)CurrDp).DatabaseName,
                                            " telah sukses dilakukan di File '", FileName,
                                            "' !"), "Konfirmasi Backup Database",
                                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                catch (Exception ex)
                {
                    XtraMessageBox.Show(ex.Message, "Error Backup Database",
                                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            else
            {
                XtraMessageBox.Show("Backup untuk database " + comboBoxEdit1.Text + "belum didukung !",
                                    "Konfirmasi Backup Database", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
            }
        }