using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace TelBook
{
    using System.Data.OleDb;
    public partial class backre : Form
    {
        public backre()
        {
            InitializeComponent();
        }
        OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|DATA.ACCDB;JET OLEDB:DATABASE PASSWORD=●●●●●●●●●●●●;");

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string CurrentDatabasePath = Environment.CurrentDirectory + @"\data.accdb";
                FolderBrowserDialog fbd = new FolderBrowserDialog();

                if (fbd.ShowDialog() == DialogResult.OK)
                {
                    string PathtobackUp = fbd.SelectedPath.ToString();
                    File.Copy(CurrentDatabasePath, PathtobackUp + @"\BackUp.bk", true);
                    progressBar1.PerformStep();
                    MessageBox.Show("عملیات تهیه نسخه ی پشتیبان با موفقیت انجام شد", "System Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    progressBar1.Value = 0;
                    Application.Exit();
                }

            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message, "System Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                string PathToRestoreDB = Environment.CurrentDirectory + @"\data.accdb";
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Filter = "Database file (*.bk)|*.bk";

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    string Filetorestore = ofd.FileName;
                    File.Copy(Filetorestore, PathToRestoreDB, true);
                    progressBar1.PerformStep();
                    MessageBox.Show("عملیات بازگردانی اطلاعات با موفقیت انجام شد\nبرای اعمال تغیرات نرم افزار مجدد راه اندازی میشود ", "System Info", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);
                    progressBar1.PerformStep();
                    progressBar1.Value = 0;
                    Application.Restart();
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message, "System Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
