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 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; } }
public bool AddAccount(Account obj) { try { AccountsDbEntities db = new AccountsDbEntities(); AccountsTable dbObj = new AccountsTable(); dbObj.FirstName = obj.FirstName; dbObj.LastName = obj.LastName; dbObj.Contact = obj.Contact; dbObj.Email = obj.Email; db.AccountsTables.Add(dbObj); db.SaveChanges(); Console.WriteLine("IN the controller try"); return(true); } catch (Exception ex) { Console.WriteLine("IN the controller catch"); return(false); } }
void ReleaseDesignerOutlets() { if (AccountsTable != null) { AccountsTable.Dispose(); AccountsTable = null; } if (AvatarImage != null) { AvatarImage.Dispose(); AvatarImage = null; } if (FetchButton != null) { FetchButton.Dispose(); FetchButton = null; } if (NameTextField != null) { NameTextField.Dispose(); NameTextField = null; } if (LoadingIndicator != null) { LoadingIndicator.Dispose(); LoadingIndicator = null; } }
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 = "موظف"; } }
public ApplicationDbContext(DbContextOptions options) : base(options) { CategoriesTable.Add(new Category { Description = "Sci-fi" }); CategoriesTable.Add(new Category { Description = "History" }); AuthorizationLevelsTable.Add(new AuthorizationLevel { Name = "Admin" }); AuthorizationLevelsTable.Add(new AuthorizationLevel { Name = "Librarian" }); AuthorizationLevelsTable.Add(new AuthorizationLevel { Name = "User" }); SaveChanges(); var librarian = AuthorizationLevelsTable.Where(x => x.Name == "Librarian").FirstOrDefault(); var user = AuthorizationLevelsTable.Where(x => x.Name == "User").FirstOrDefault(); user.WhoHasTheLevel.Add(new Account { Name = "Alice" }); user.WhoHasTheLevel.Add(new Account { Name = "Bob" }); user.WhoHasTheLevel.Add(new Account { Name = "Cecilia" }); SaveChanges(); var servadac = new Book { Title = "Hector Servadac", WhenLent = DateTime.Now }; var alice = AccountsTable.Where(x => x.Name == "Alice").FirstOrDefault(); alice.BorrowedBooks.Add(servadac); SaveChanges(); var scifi = CategoriesTable.Where(x => x.Description == "Sci-fi").FirstOrDefault(); var now = DateTime.Now; var catEvent = new CategorizationEvent { When = now }; scifi.Events.Add(catEvent); servadac.Categorized.Add(catEvent); SaveChanges(); }
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(); }
private void LoginB_Click(object sender, RoutedEventArgs e) { if (UN.Text != "" || UP.Password != "") { AccountsTable.UserName = UN.Text; AccountsTable.UserPassword = Kernel.Core.GetSHAHashData(UP.Password); if (AccountsTable.UserLogin()) { CP cp = new CP(); cp.Show(); this.Hide(); } else { UP.Focus(); } } else { MessageBox.Show("ادخل اسم المستخدم او كلمه المرور", "خطا", MessageBoxButton.OK, MessageBoxImage.Warning); } }
/// <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")); } } }
private void LoginB_Click_1(object sender, EventArgs e) { if (UN.Text == "") { MessageBox.Show("لم تدخل اسم المستخدم"); } else if (UP.Text == "") { MessageBox.Show("لم تدخل كلمه المرور"); } else { AccountsTable.UserName = UN.Text; AccountsTable.UserPassword = Program.GetSHAHashData(UP.Text); if (AccountsTable.UserLogin()) { this.Hide(); } else { UP.Focus(); } } }
public TransferCommandHandler(IAccountsContext context) { _accountsTable = new AccountsTable(context); _transactionsTable = new TransactionsTable(context); }
public FindAccountQueryHandler(IAccountsContext context) { _table = new AccountsTable(context); }
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); } } }
/// <summary> /// The first thing that program is going to do after showing up /// like checking for database connection etc /// </summary> public static void StartUp_Engine() { if (!EngineOn) { try { IniFile file2 = new IniFile(Paths.BackupConfigPath); if (!File.Exists(Paths.SetupConfigPath)) { IsSetup = true; Set set = new Set { Title = "تنصيب البرنامج" }; set.ShowDialog(); } Config co = new Config(); co.Read(true); DataHolder.CreateConnection(co.DbUserName, co.DbUserPassword, co.DbName, co.Hostname); string ver = co.Version; if (Convert.ToInt16(ver) < Convert.ToInt16(Assembly.GetExecutingAssembly().GetName().Version.ToString().Replace(".", ""))) { IsSetup = true; //IsUpgrading = true; Set set = new Set { Title = "ترقية البرنامج" }; set.ShowDialog(); } if (!IsSetup) { co.Read(true, true); if (AccountsTable.CountUsers() == 0) { IsSetup = true; NoAccount = true; Set set = new Set { Title = "تنصيب البرنامج" }; View.Pages.Setup.IsInstallCompleted = true; set.ShowDialog(); } BillsTable.LBN(); MySqlCommand cmd = new MySqlCommand(MySqlCommandType.UPDATE); cmd.Update("logs").Set("Online", 0).Where("Online", 1).Execute(); sb = INIDecrypt(file2.ReadString("Settings", "Backup")); tb = INIDecrypt(file2.ReadString("Settings", "TakeBackup")); st = INIDecrypt(file2.ReadString("Settings", "Type")); stt = INIDecrypt(file2.ReadString("Settings", "Time")); std = INIDecrypt(file2.ReadString("Settings", "Date")); #region database logs if (co.AccountsLog == "0") { View.Pages.Settings.IsRecAcc = false; } else if (co.AccountsLog == "1") { View.Pages.Settings.IsRecAcc = true; } if (co.DrugsLog == "0") { View.Pages.Settings.IsRecMed = false; } else if (co.DrugsLog == "1") { View.Pages.Settings.IsRecMed = true; } #endregion #region automatic backup system if (File.Exists(Paths.BackupConfigPath)) { try { if (Convert.ToByte(sb) == 1) { if (Convert.ToByte(st) == 1) { string[] time = stt.Split(':'); if (Convert.ToByte(tb) == 0) { if (DateTime.Now.Date == Convert.ToDateTime(std)) { if (DateTime.Now.Hour - Convert.ToByte(time[0]) == 0 && DateTime.Now.Minute - Convert.ToByte(time[1]) >= 0) { BackUp.Backup("PROPHMW"); file2.Write("Settings", "TakeBackup", "1"); tb = "1"; Console.WriteLine("Daily backup has been taken"); } if (DateTime.Now.Hour - Convert.ToByte(time[0]) >= 1) { BackUp.Backup("PROPHMW"); file2.Write("Settings", "TakeBackup", "1"); tb = "1"; Console.WriteLine("Daily backup has been taken"); } } } else { if (DateTime.Now.Date > Convert.ToDateTime(std)) { file2.Write("Settings", "TakeBackup", "0"); tb = "0"; Console.WriteLine("Daily backup has been reset"); } } } else if (Convert.ToByte(st) == 2) { if (Convert.ToByte(tb) == 0) { if (Convert.ToByte(stt) <= Convert.ToByte(DateTime.Now.DayOfWeek)) { BackUp.Backup("PROPHMW"); file2.Write("Settings", "TakeBackup", "1"); tb = "1"; Console.WriteLine("Weekly backup has been taken"); } } else { if (Convert.ToByte(stt) > Convert.ToByte(DateTime.Now.DayOfWeek)) { file2.Write("Settings", "TakeBackup", "0"); tb = "0"; Console.WriteLine("Weekly backup has been reset"); } } } else if (Convert.ToByte(st) == 3) { if (Convert.ToByte(tb) == 0) { if (Convert.ToByte(stt) <= Convert.ToByte(DateTime.Now.Day)) { BackUp.Backup("PROPHMW"); file2.Write("Settings", "TakeBackup", "1"); tb = "1"; Console.WriteLine("Monthly backup has been taken"); } } else { if (Convert.ToByte(stt) > Convert.ToByte(DateTime.Now.Day)) { file2.Write("Settings", "TakeBackup", "0"); tb = "0"; Console.WriteLine("Monthly backup has been reset"); } } } } } catch (Exception e) { Console.WriteLine("Check the automatic backup system in the core"); SaveException(e); File.Delete(Paths.BackupConfigPath); } } #endregion EngineOn = true; } } catch (Exception ex) { SaveException(ex); if (File.Exists(Paths.SetupConfigPath)) { File.Delete(Paths.SetupConfigPath); } if (File.Exists(Paths.BackupConfigPath)) { File.Delete(Paths.BackupConfigPath); } Console.WriteLine("Program configuration files has been deleted \r\n now we are goning to shutdown your PC"); } } }
public CloseAccountCommandHandler(IAccountsContext context) { _table = new AccountsTable(context); }
public async Task AddTimeline(AccountsTable account) { await this.accountsTable.InsertAsync(account); }
/// <summary> /// POST: api/Messages /// Receive a message from a user and reply to it /// </summary> public async Task <HttpResponseMessage> Post([FromBody] Activity activity) { if (activity.Type == ActivityTypes.Message) { var userMessage = activity.Text; var userName = ""; string endOutput = "Hello"; bool SentGreeting = false; ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); // State Client StateClient stateClient = activity.GetStateClient(); BotData userData = await stateClient.BotState.GetUserDataAsync(activity.ChannelId, activity.From.Id); // calculate something for us to return int length = (activity.Text ?? string.Empty).Length; // LUIS HttpClient client = new HttpClient(); var luisURL = "https://api.projectoxford.ai/luis/v2.0/apps/a118c892-898f-41b2-abf4-904c826613cf?subscription-key=3c04249ae37341989e1d95c41d0cbf24&q="; string x = await client.GetStringAsync(new Uri(luisURL + activity.Text + "&verbose=true")); luis.RootObject rootObject; rootObject = JsonConvert.DeserializeObject <luis.RootObject>(x); // exhange rate string xchange = await client.GetStringAsync(new Uri("http://api.fixer.io/latest?base=NZD")); exchange.RootObject exchangeObject; exchangeObject = JsonConvert.DeserializeObject <exchange.RootObject>(xchange); double aus = exchangeObject.rates.AUD; double usd = exchangeObject.rates.USD; string intent = rootObject.topScoringIntent.intent; // return our reply to the user if (intent == "GetTransaction") { List <AccountsTable> accounts = await AzureManager.AzureManagerInstance.GetTransaction(); List <string> transaction = new List <string>(); int i = -1; foreach (AccountsTable t in accounts) { transaction.Add("[" + t.Date + "] Cheque " + t.Cheque + ", Savings " + t.Savings + ", Credit " + t.Credit + "\n\n"); i += 1; } Activity reply = activity.CreateReply(transaction[i]); await connector.Conversations.ReplyToActivityAsync(reply); } else if (intent == "GetBalance") { var entityAccount = rootObject.entities[0].entity; double balance = 0; if (entityAccount.ToLower().Equals("savings")) { List <AccountsTable> accounts = await AzureManager.AzureManagerInstance.GetTransaction(); foreach (AccountsTable t in accounts) { balance += t.Savings; } } else if (entityAccount.ToLower().Equals("cheque")) { List <AccountsTable> accounts = await AzureManager.AzureManagerInstance.GetTransaction(); foreach (AccountsTable t in accounts) { balance += t.Cheque; } } else if (entityAccount.ToLower().Equals("credit")) { List <AccountsTable> accounts = await AzureManager.AzureManagerInstance.GetTransaction(); foreach (AccountsTable t in accounts) { balance += t.Credit; } } endOutput = balance.ToString(); Activity reply = activity.CreateReply("$" + endOutput); await connector.Conversations.ReplyToActivityAsync(reply); } else if (intent == "Greeting") { // calculate something for us to return if (userData.GetProperty <bool>("SentGreeting")) { endOutput = "Hello again"; } else { endOutput = "Hello, Welcome to Contoso Bank."; userData.SetProperty <bool>("SentGreeting", true); await stateClient.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, userData); userName = rootObject.entities[0].entity; } // return our reply to the user Activity infoReply = activity.CreateReply(endOutput); await connector.Conversations.ReplyToActivityAsync(infoReply); } else if (intent == "Transfer") { string entityMoney = ""; double money = 0; string entityToAccount = ""; string entityFromAccount = ""; // JSON check if (rootObject.entities[2].type == "number") { // convert string to double entityMoney = rootObject.entities[2].entity; money = Convert.ToDouble(entityMoney); } if (rootObject.entities[0].type == "Account::ToAccount") { entityToAccount = rootObject.entities[0].entity; } if (rootObject.entities[1].type == "Account::FromAccount") { entityFromAccount = rootObject.entities[1].entity; } // From Cheque account if (entityFromAccount.ToLower().Equals("cheque")) { if (entityToAccount.ToLower().Equals("savings")) { AccountsTable account = new AccountsTable() { Cheque = 0 - money, Savings = money, Date = DateTime.Now }; await AzureManager.AzureManagerInstance.AddTimeline(account); endOutput = "New transaction made [" + account.Date + "] $" + money + " From Cheque to Savings."; } else if (entityToAccount.ToLower().Equals("credit")) { AccountsTable account = new AccountsTable() { Cheque = 0 - money, Credit = money, Date = DateTime.Now }; await AzureManager.AzureManagerInstance.AddTimeline(account); endOutput = "New transaction made [" + account.Date + "] $" + money + " From Cheque to Credit."; } else { endOutput = "Error"; } } // From Savings account else if (entityFromAccount.ToLower().Equals("savings")) { if (entityToAccount.ToLower().Equals("cheque")) { AccountsTable account = new AccountsTable() { Savings = 0 - money, Cheque = money, Date = DateTime.Now }; await AzureManager.AzureManagerInstance.AddTimeline(account); endOutput = "New transaction made [" + account.Date + "] $" + money + " From Savings to Cheque."; } else if (entityToAccount.ToLower().Equals("credit")) { AccountsTable account = new AccountsTable() { Savings = 0 - money, Credit = money, Date = DateTime.Now }; await AzureManager.AzureManagerInstance.AddTimeline(account); endOutput = "New transaction made [" + account.Date + "] $" + money + " From Savings to Credit."; } else { endOutput = "Error"; } } // From Credit account else if (entityFromAccount.ToLower().Equals("credit")) { if (entityToAccount.ToLower().Equals("savings")) { AccountsTable account = new AccountsTable() { Credit = 0 - money, Savings = money, Date = DateTime.Now }; await AzureManager.AzureManagerInstance.AddTimeline(account); endOutput = "New transaction made [" + account.Date + "] $" + money + " From Credit to Savings."; } else if (entityToAccount.ToLower().Equals("cheque")) { AccountsTable account = new AccountsTable() { Credit = 0 - money, Cheque = money, Date = DateTime.Now }; await AzureManager.AzureManagerInstance.AddTimeline(account); endOutput = "New transaction made [" + account.Date + "] $" + money + " From Credit to Cheque."; } else { endOutput = "Error"; } } else { endOutput = "Please rephrase"; } Activity reply = activity.CreateReply(endOutput); await connector.Conversations.ReplyToActivityAsync(reply); } else if (intent == "GetExchangeRate") { var currency = ""; var country = ""; string entityRates = rootObject.entities[0].entity; if (entityRates.ToLower().Equals("australia")) { currency = "AUD: $" + aus; country = "Australia"; } else if (entityRates.ToLower().Equals("america")) { currency = "USD: $" + usd; country = "America"; } Activity replyToConversation = activity.CreateReply(); replyToConversation.Recipient = activity.From; replyToConversation.Type = "message"; replyToConversation.Attachments = new List <Attachment>(); List <CardImage> cardImages = new List <CardImage>(); cardImages.Add(new CardImage(url: "http://www.currencysymbols.in/images/currency-world.jpg")); ThumbnailCard plCard = new ThumbnailCard() { Title = country, Subtitle = "NZD: $1.00 = " + currency, Images = cardImages }; Attachment plAttachment = plCard.ToAttachment(); replyToConversation.Attachments.Add(plAttachment); await connector.Conversations.SendToConversationAsync(replyToConversation); } else if (intent == "None") { endOutput = "User data cleared"; Activity reply = activity.CreateReply(endOutput); await stateClient.BotState.DeleteStateForUserAsync(activity.ChannelId, activity.From.Id); await connector.Conversations.ReplyToActivityAsync(reply); SentGreeting = false; } else { endOutput = "Please rephrase"; Activity reply = activity.CreateReply(endOutput); await connector.Conversations.ReplyToActivityAsync(reply); } } else { HandleSystemMessage(activity); } var response = Request.CreateResponse(HttpStatusCode.OK); return(response); }
public CreateAccountCommandHandler(IAccountsContext context, IOptions <AccountOptions> accountOptions) { _table = new AccountsTable(context); _accountOptions = accountOptions.Value ?? throw new ArgumentNullException(nameof(accountOptions)); }
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); } }
public EditAccountCommandHandler(IAccountsContext context) { _accountsTable = new AccountsTable(context); }
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); } } }
public GetAccountsQueryHandler(IAccountsContext context) { _table = new AccountsTable(context); }
/// <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 ."); } }
public RefillCommandHandler(IAccountsContext context) { _table = new AccountsTable(context); }