コード例 #1
0
 private void BackupData()
 {
     if (clsUtil.GetApproval(m_user, UserAccess.Manager))
     {
         string directory = Path.GetDirectoryName(Application.ExecutablePath);
         directory = directory.Substring(0, directory.LastIndexOf("\\"));
         string backup   = directory + "\\iPOSBackup";
         string filename = string.Format("{0}\\backup_{1:yyyMMdd_HHmm}.mdb", backup, DateTime.Now);
         if (!Directory.Exists(backup))
         {
             Directory.CreateDirectory(backup);
         }
         dbConnect con    = new dbConnect();
         string    dbName = con.GetDatabaseName();
         con.Close();
         try
         {
             File.Copy(dbName, filename, true);
             MessageBox.Show(string.Format("Backup was saved successfully to {0}", filename), "Backup", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Backup Failed", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         }
     }
 }