private void checkClosingState(object sender, EventArgs e) { if (IsLoggingOut == true) { //open login window after user logs out this.Close(); MainWindow loginw = new MainWindow(); if (IsLoaded == false) { IsLoggingOut = false; loginw.ShowDialog(); checkClosing.Stop(); } } if (BackToMain == true) { MainCP ac = new MainCP(); FFhost.Navigate(ac); if (AccountsTable.IsAdmin() == true) { this.Title = "لوحه المدراء"; } else if (AccountsTable.IsAdmin() == false) { this.Title = "لوحه الموظفين"; MeSe.Visibility = Visibility.Collapsed; MIAddEMP.Visibility = Visibility.Collapsed; MILOGLOG.Visibility = Visibility.Collapsed; MISM.Visibility = Visibility.Collapsed; } BackToMain = false; } }
private void DeleteM_Click(object sender, RoutedEventArgs e) { if (MName.Text == "" || MPrice.Text == "" || MExist.Text == "") { MessageBox.Show("لا يمكن اتمام عمليه الحذف"); return; } try { if (AccountsTable.IsAdmin() == true) { new MySqlCommand(MySqlCommandType.DELETE).Delete("medics", "id", ItemId).Execute(); Clear(); Console.WriteLine("Delete '" + MName.Text + " - " + ItemId.ToString() + "' now we're talking"); MessageBox.Show("تم حذف الدواء"); } else { Console.WriteLine(AccountsTable.UserName + "was trying to Delete '" + MName.Text + " - " + ItemId.ToString()); MessageBox.Show("يجب ان تكون مدير لتستطيع الحذف"); } } catch (Exception ex) { Core.SaveException(ex); } }
private void DeleteButton_Click(object sender, RoutedEventArgs e) { if (BillsNoList.SelectedIndex != -1) { if (AccountsTable.IsAdmin() == true) { try { new MySqlCommand(MySqlCommandType.DELETE).Delete("bills", "ID", BillsNoList.SelectedItem.ToString()).Execute(); Console.WriteLine("Delete bill #'" + BillsNoList.SelectedItem.ToString() + "' i hope you don't regret it"); MessageBox.Show("تم حذف الفاتورة"); BillsNoList.SelectedIndex = -1; BillContent.Text = "لم يتم اختيار اى فواتير"; } catch (Exception ex) { Kernel.Core.SaveException(ex); } } } else { MessageBox.Show("اختار فاتورة اولا ليتم حذفها"); } }
private void Page_Loaded(object sender, RoutedEventArgs e) { ReloadList(); if (AccountsTable.IsAdmin() == false) { AdminPCB.IsChecked = false; AdminPCB.Visibility = Visibility.Hidden; DelB.Visibility = Visibility.Hidden; } }
private void Page_Loaded(object sender, RoutedEventArgs e) { LoadList(); if (AccountsTable.IsAdmin() == false) { AdminPCB.IsChecked = false; AdminPCB.Visibility = Visibility.Hidden; RUState.IsReadOnly = true; RUState.IsEditable = false; RUState.Text = "موظف"; } }
private void PCP_Closing(object sender, System.ComponentModel.CancelEventArgs e) { Config co = new Config(); co.Read(false, false, true, false); AccountsTable.LoginOut = true; AccountsTable.IsAdmin(); if (co.AccountsLog == "1") { MySqlCommand cmd = new MySqlCommand(MySqlCommandType.UPDATE); cmd.Update("logs").Set("LogoutDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Set("Online", 0).Where("Online", 1).Execute(); } }
private void PCP_Loaded(object sender, RoutedEventArgs e) { if (AccountsTable.IsAdmin() == true) { this.Title = "لوحه المدراء"; } else if (AccountsTable.IsAdmin() == false) { this.Title = "لوحه الموظفين"; MeSe.Visibility = Visibility.Collapsed; MIAddEMP.Visibility = Visibility.Collapsed; MILOGLOG.Visibility = Visibility.Collapsed; MISM.Visibility = Visibility.Collapsed; } checkClosing.Interval = TimeSpan.FromMilliseconds(100); checkClosing.Tick += checkClosingState; checkClosing.Start(); }
private void Page_Loaded(object sender, RoutedEventArgs e) { WelMsg.Content = "اهلا بك يا " + AccountsTable.UserName; BillNo.Text = BillsTable.BillNO.ToString(); SearchBox.Focus(); if (AccountsTable.IsAdmin() == false) { MName.IsReadOnly = true; MSS.IsReadOnly = true; MType.IsEditable = false; MType.IsReadOnly = true; MExist.IsReadOnly = true; MPrice.IsReadOnly = true; } //custom UI changes for XP if (Environment.OSVersion.Version.Build <= 2600) { Client.FontSize = 10; } LoadSup(); }
/// <summary> /// Load || Refresh the users list after make changes to them /// </summary> void ReloadList() { UNList.Items.Clear(); if (AccountsTable.IsAdmin() == true) { MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT); cmd.Select("accounts"); MySqlReader r = new MySqlReader(cmd); while (r.Read()) { UNList.Items.Add(r.ReadString("Username")); } } else { MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT); cmd.Select("accounts").Where("Username", AccountsTable.UserName); MySqlReader r = new MySqlReader(cmd); if (r.Read()) { UNList.Items.Add(r.ReadString("Username")); } } }
/// <summary> /// Console commands that makes user do stuff /// </summary> /// <param name="command">the command</param> public static void CommandsAI(string command) { if (command == null) { return; } GSLog += command; if (command.StartsWith("#")) { string[] data = command.Split(' '); IniFile file = new IniFile(Paths.SetupConfigPath); if (AccountsTable.IsAdmin()) { switch (data[0]) { //TODO add more and more and more commands for admins #region Add new account case "#addacc": { try { MySqlCommand cmd = new MySqlCommand(MySqlCommandType.INSERT); cmd.Insert("accounts") .Insert("Username", data[1]) .Insert("Password", Core.GetSHAHashData(data[2])) .Insert("State", data[3]) .Insert("Phone", data[4]) .Execute(); WriteLine("You add a new user " + data[1]); } catch (Exception e) { WriteLine("There is something wrong maybe the username is already used."); Core.SaveException(e); } break; } #endregion #region Add new drug case "#adddrug": { try { MySqlCommand cmd = new MySqlCommand(MySqlCommandType.INSERT); cmd.Insert("medics") .Insert("Name", data[1]) .Insert("Barcode", data[2]) .Insert("ScientificName", data[3]) .Insert("Supplier", data[4]) .Insert("ExpirationDate", data[5]) .Insert("Type", data[6]) .Insert("Total", Convert.ToDecimal(data[7])) .Insert("BPrice", Convert.ToDecimal(data[8])) .Insert("SPrice", Convert.ToDecimal(data[9])) .Insert("Notes", data[10]).Execute(); WriteLine(AccountsTable.UserName + " add " + data[6] + " " + data[1] + " which each cost " + data[7]); } catch (Exception e) { WriteLine("There is something wrong maybe the drug is already exist."); Core.SaveException(e); } break; } #endregion #region Delete table or database case "#Drop": { if (data[1] == "db") { string Ddb = "DROP DATABASE IF EXISTS `" + Core.INIDecrypt(file.ReadString("MySql", "Database")) + "`;"; using (var conn = DataHolder.MySqlConnection) { using (MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand()) { cmd.Connection = conn; conn.Open(); string db = MySql.Data.MySqlClient.QueryExpress.ExecuteScalarStr(cmd, Ddb); if (string.IsNullOrEmpty(db)) { return; } conn.Dispose(); conn.Close(); File.Delete(Paths.SetupConfigPath); } } } else if (data[1] == "table") { string Dtab = "DROP TABLE `" + data[2] + "`;"; try { using (var conn = DataHolder.MySqlConnection) { using (MySql.Data.MySqlClient.MySqlCommand mCmd = new MySql.Data.MySqlClient.MySqlCommand(Dtab, conn)) { mCmd.ExecuteNonQuery(); } conn.Close(); } } catch (Exception e) { WriteLine("Maybe you entered a wrong table name"); Core.SaveException(e); } } break; } #endregion #region Insert medics to the table case "#import": { try { Thread th = new Thread(() => { var newPath = data[1].Contains("~") ? data[1].Replace("~", " ") : data[1]; Write("Importing [----------] " + progress + "%"); IsProgressing = true; var lines = File.ReadAllLines(newPath).Count(); var currentLine = 0; using (StreamReader sr = File.OpenText(newPath)) { StringBuilder sb = new StringBuilder(); while (sb.Append(sr.ReadLine()).Length > 0) { retry: try { MySqlCommand cmd = new MySqlCommand(MySqlCommandType.INSERT) { Command = sb.ToString() }; cmd.Execute(); } catch { sb.Replace("INSERT INTO `medics`", "INSERT IGNORE INTO `medics`"); goto retry; } finally { progress = (currentLine * 100) / lines; currentLine++; sb.Clear(); } } sr.Dispose(); sr.Close(); } WriteLine("The file is well imported"); }); th.Start(); } catch (Exception e) { WriteLine("Are you 100% sure that is a MySQL file/n" + e); } IsProgressing = false; break; } #endregion #region Delete config folder case "#deltemp": { if (data.Length >= 2) { if (data[1] == "-all") { try { if ( Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\PPHMW")) { Directory.Delete(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\PPHMW"); WriteLine("You just deleted everything the program stand for \nI hope you are happy"); } } catch (Exception e) { WriteLine("Maybe the folder isn't there so stop trying to delete it"); Core.SaveException(e); } } } else { try { if ( File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\PPHMW\\BackupConfig.ini")) { File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\PPHMW\\BackupConfig.ini"); } if ( File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\PPHMW\\Configuration.ini")) { File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\PPHMW\\Configuration.ini"); } WriteLine("You just deleted the config files"); } catch (Exception e) { WriteLine("Maybe the files are not there so stop trying to delete them"); Core.SaveException(e); } } break; } #endregion case "#help": { WriteLine("Here is some Commands\r#addacc Username Password State(type 2 for admin - 1 for employee) PhoneNumber(could be empty -type null-)\r#adddrug Name Barcode(Could be empty -type null-) ScientificName(Could be empty -type null-) Supplier(Could be empty -type null-) ExpirationDate(should be yyyy/mm/dd) Type(type 1 for syrup - 2 for tab - 3 Injection - 4 for Cream/Ointments - 0 for other) Total(must be numbers) BPrice(must be numbers) SPrice(must be numbers) Notes(Could be empty -type null-)\r#Drop db (to delete your database good luck with that)\r#Drop table tablename (delete a spacific table to ruin the database)\r#import path (type the full path for the sql file to import it like c:\\meds.sql)\r#deltemp (type '-all' to delete the config folder with backups files like #deltemp -all)"); break; } default: { WriteLine("This command shall not execute"); break; } } } else { switch (data[0]) { //TODO add more and more and more commands for the rest #region Delete config folder case "#deltemp": { try { if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\PPHMW\\BackupConfig.ini")) { File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\PPHMW\\BackupConfig.ini"); } if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\PPHMW\\Configuration.ini")) { File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\PPHMW\\Configuration.ini"); } WriteLine("You just deleted the config files"); } catch (Exception e) { WriteLine("Maybe the files are not there so stop trying to delete them"); Core.SaveException(e); } break; } #endregion case "#help": { WriteLine("Here is some Commands\r#deltemp delete the config files"); break; } default: { WriteLine("This command shall not execute"); break; } } } } else { WriteLine("You must start your command with # like #help ."); } }
private void EdtB_Click(object sender, RoutedEventArgs e) { // Be able to change any user password without knowing the old one because of Admin privileges if (AccountsTable.IsAdmin() == true && AdminPCB.IsChecked == true) { if (NUP1.Password == NUP2.Password) { try { MySqlCommand cmd2 = new MySqlCommand(MySqlCommandType.UPDATE); cmd2.Update("accounts").Set("Password", Kernel.Core.GetSHAHashData(NUP1.Password)).Where("Username", UNList.SelectedItem.ToString()).Execute(); Label1.Content = "تم تغيير كلمه المرور بنجاح."; Label1.Foreground = Brushes.Green; Label1.Visibility = Visibility.Visible; Console.WriteLine("You just changed " + UNList.SelectedItem + " password"); } catch (Exception ex1) { Label1.Content = "ليس هناك حساب بهذا الاسم."; Label1.Foreground = Brushes.Red; Label1.Visibility = Visibility.Visible; Kernel.Core.SaveException(ex1); } } else { Label1.Content = "كلمة المرور الجديدة و اعادتها غير متطابقين"; Label1.Foreground = Brushes.Red; Label1.Visibility = Visibility.Visible; } } //Change the user password after typing the right old one without Admin privileges else { try { MySqlCommand cmd1 = new MySqlCommand(MySqlCommandType.SELECT); cmd1.Select("accounts").Where("Username", UNList.SelectedItem.ToString()).And("Password", OUP.Text).Execute(); MySqlReader r = new MySqlReader(cmd1); if (r.Read()) { if (NUP1.Password == NUP2.Password) { try { MySqlCommand cmd2 = new MySqlCommand(MySqlCommandType.UPDATE); cmd2.Update("accounts").Set("Password", Kernel.Core.GetSHAHashData(NUP1.Password)).Where("Username", UNList.SelectedItem.ToString()).Execute(); Label1.Content = "تم تغيير كلمه المرور بنجاح."; Label1.Foreground = Brushes.Green; Label1.Visibility = Visibility.Visible; Console.WriteLine(UNList.SelectedItem.ToString() + " password has changed"); } catch (Exception ex2) { Label1.Content = "ليس هناك حساب بهذا الاسم."; Label1.Foreground = Brushes.Red; Label1.Visibility = Visibility.Visible; Kernel.Core.SaveException(ex2); } } else { Label1.Content = "كلمة المرور الجديدة و اعادتها غير متطابقين"; Label1.Foreground = Brushes.Red; Label1.Visibility = Visibility.Visible; } } else { Label1.Content = "خطأ فى كلمة المرور القديمه"; Label1.Foreground = Brushes.Red; Label1.Visibility = Visibility.Visible; } } catch (Exception ex3) { Kernel.Core.SaveException(ex3); } } }
private void UpdateM_Click(object sender, RoutedEventArgs e) { if (MName.Text == "" || MPrice.Text == "" || MExist.Text == "" || MEX.Text == "") { MessageBox.Show("لا يمكن اتمام عمليه التحديث بسبب وجود حقل مهم فارغ"); return; } try { switch (MType.Text) { case "شرب": Ptype = 1; break; case "اقراص": Ptype = 2; break; case "حقن": Ptype = 3; break; case "كريم/مرهم": Ptype = 4; break; case "اخرى": Ptype = 0; break; } if (AccountsTable.IsAdmin() == true) { MySqlCommand cmd = new MySqlCommand(MySqlCommandType.UPDATE); cmd.Update("medics") .Set("Name", MName.Text) .Set("ScientificName", MSS.Text) .Set("ExpirationDate", MEX.Text) .Set("Supplier", MSUP.Text) .Set("Type", Ptype) .Set("Total", MExist.Text) .Set("SPrice", MPrice.Text) .Set("Notes", MNotes.Text); cmd.Where("Id", ItemId).And("Name", MName.Text).Execute(); Console.WriteLine("update the '" + MName.Text + " - " + ItemId.ToString() + "' drug I hope you are not high"); MessageBox.Show("تم التحديث"); } else { MySqlCommand cmd = new MySqlCommand(MySqlCommandType.UPDATE); cmd.Update("medics") .Set("Notes", MNotes.Text); cmd.Where("Name", MName.Text).Execute(); Console.WriteLine("Update '" + MName.Text + " - " + ItemId.ToString() + "' Notes, I noticed what you did there"); MessageBox.Show("تم التحديث ملاحظات الدواء"); } } catch (Exception ex) { Core.SaveException(ex); } }
private void EdtB_Click(object sender, RoutedEventArgs e) { byte state; switch (RUState.Text) { case "مدير": state = 2; break; case "موظف": state = 1; break; case "مجهول": state = 0; break; default: MessageBox.Show("اختار صلاحيات المستخدم"); return; } // Be able to change any user state without knowing the his password because of Admin privileges if (AccountsTable.IsAdmin() == true && AdminPCB.IsChecked == true) { try { MySqlCommand cmd2 = new MySqlCommand(MySqlCommandType.UPDATE); cmd2.Update("accounts").Set("State", state).Set("Phone", PHN.Text).Where("Username", UNList.SelectedItem.ToString()).Execute(); Label1.Content = "تم تغيير الحالة."; Label1.Foreground = Brushes.Green; Label1.Visibility = Visibility.Visible; Console.WriteLine("You just changed " + UNList.SelectedItem + " States"); } catch (Exception ex1) { Label1.Content = "ليس هناك حساب بهذا الاسم."; Label1.Foreground = Brushes.Red; Label1.Visibility = Visibility.Visible; Kernel.Core.SaveException(ex1); } } //Change the user state after typing the password without Admin privileges else { try { MySqlCommand cmd1 = new MySqlCommand(MySqlCommandType.SELECT); cmd1.Select("accounts").Where("Username", UNList.SelectedItem.ToString()).And("Password", Kernel.Core.GetSHAHashData(UP.Password)).Execute(); MySqlReader r = new MySqlReader(cmd1); if (r.Read()) { try { MySqlCommand cmd2 = new MySqlCommand(MySqlCommandType.UPDATE); cmd2.Update("accounts").Set("State", state).Set("Phone", PHN.Text).Where("Username", UNList.SelectedItem.ToString()).Execute(); Label1.Content = "تم تغيير الحالة بنجاح."; Label1.Foreground = Brushes.Green; Label1.Visibility = Visibility.Visible; Console.WriteLine(UNList.SelectedItem.ToString() + " changed his states"); } catch (Exception ex2) { Label1.Content = "ليس هناك حساب بهذا الاسم."; Label1.Foreground = Brushes.Red; Label1.Visibility = Visibility.Visible; Kernel.Core.SaveException(ex2); } } else { Label1.Content = "خطأ فى كلمة المرور"; Label1.Foreground = Brushes.Red; Label1.Visibility = Visibility.Visible; } } catch (Exception ex3) { Kernel.Core.SaveException(ex3); } } }