private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { (sender as BackgroundWorker)?.ReportProgress(5); Config co = new Config(); Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) delegate() { co.Hostname = DbHost.Text; co.DbName = DbName.Text; co.DbUserName = DbUser.Text; co.DbUserPassword = DbPass.Text; co.AccountsLog = "1"; co.DrugsLog = "1"; co.Write(true, true); }); (sender as BackgroundWorker)?.ReportProgress(30); if (!Directory.Exists(Paths.BackupsPath)) { Directory.CreateDirectory(Paths.BackupsPath); } (sender as BackgroundWorker)?.ReportProgress(40); Dispatcher.Invoke((Action)(() => { DataHolder.CreateConnection(co.DbUserName, co.DbUserPassword, co.Hostname); CreateDB.Createdb(co.DbName); DataHolder.CreateConnection(co.DbUserName, co.DbUserPassword, co.DbName, co.Hostname); })); (sender as BackgroundWorker)?.ReportProgress(60); Dispatcher.Invoke((Action)(CreateDB.CreateTables)); (sender as BackgroundWorker)?.ReportProgress(95); }
//database private void SetB1_Click(object sender, RoutedEventArgs e) { Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) delegate() { BackUp.NewDbBackup(); MessageBox.Show("تم اخذ نسخه احتياطيه من القاعده القديمه"); DataHolder.CreateConnection(co.DbUserName, co.DbUserPassword, co.Hostname); CreateDB.Createdb(co.DbName, DbName.Text); co.Write(); MessageBox.Show("تم الحفظ سيتم غلق البرنامج الان"); Environment.Exit(0); }); }
private void Install_Click(object sender, EventArgs e) { try { IniFile file = new IniFile(Constants.SetupConfigPath); if (this.Text == "تنصيب البرنامج") { if (!File.Exists(Constants.SetupConfigPath)) { file.Write("MySql", "Host", DBHost.Text); file.Write("MySql", "Username", DBUser.Text); file.Write("MySql", "Password", DBPass.Text); file.Write("MySql", "Database", DBName.Text); file.Write("Upgrade", "Version", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString().Replace(".", "")); if (!Directory.Exists(Application.StartupPath + @"BackUp\")) { Directory.CreateDirectory(Application.StartupPath + @"\BackUp\"); } DataHolder.CreateConnection(Program.INIDecrypt(file.ReadString("MySql", "Username")), Program.INIDecrypt(file.ReadString("MySql", "Password")), Program.INIDecrypt(file.ReadString("MySql", "Host"))); CreateDB.Createdb(DBName.Text); DataHolder.CreateConnection(Program.INIDecrypt(file.ReadString("MySql", "Username")), Program.INIDecrypt(file.ReadString("MySql", "Password")), Program.INIDecrypt(file.ReadString("MySql", "Database")), Program.INIDecrypt(file.ReadString("MySql", "Host"))); CreateDB.CreateTables(); MessageBox.Show("تم تنصيب الاعدادات\nمن فضلك انشاء حساب جديد لتتمكن من الدخول"); Register reg = new Register(); reg.ShowDialog(); this.Close(); } } else if (this.Text == "اعدادات البرنامج") { if (File.Exists(Constants.SetupConfigPath)) { BackUp.NewDbBackup(); DataHolder.CreateConnection(Program.INIDecrypt(file.ReadString("MySql", "Username")), Program.INIDecrypt(file.ReadString("MySql", "Password")), Program.INIDecrypt(file.ReadString("MySql", "Host"))); CreateDB.Createdb(file.ReadString("MySql", "Database"), DBName.Text); file.Write("MySql", "Host", DBHost.Text); file.Write("MySql", "Username", DBUser.Text); file.Write("MySql", "Password", DBPass.Text); file.Write("MySql", "Database", DBName.Text); DataHolder.CreateConnection(Program.INIDecrypt(file.ReadString("MySql", "Username")), Program.INIDecrypt(file.ReadString("MySql", "Password")), Program.INIDecrypt(file.ReadString("MySql", "Database")), Program.INIDecrypt(file.ReadString("MySql", "Host"))); BackUp.NewDbRestore(); BillsTable.LBN(); MessageBox.Show("تم تغيير الاعدادات"); } } } catch (Exception ee) { Program.SaveException(ee); } }