public static void completeRegister(MainWindow main) { using (PMSContext context = new PMSContext()) { TblUsers myUser = new TblUsers(); myUser.Firstname = main.txtFirstName.Text; myUser.Lastname = main.txtLastName.Text; if (main.txtPw1.Password.ToString() != main.txtPw2.Password.ToString()) { MessageBox.Show("Error! Entered passwords are not matching. Please re-type your password!"); return; } Guid obj = Guid.NewGuid(); myUser.SaltOfPw = obj.ToString(); myUser.UserPw = GlobalMethods.returnUserPw(main.txtPw1.Password.ToString(), myUser.SaltOfPw); if (main.cmbBoxUserRank.SelectedIndex < 1) { MessageBox.Show("Error! Please select your user rank / role first!"); return; } myUser.UserType = (main.cmbBoxUserRank.SelectedItem as TblUserTypes).UserTypeId; myUser.UserEmail = main.txtEmail.Text; myUser.RegisterIp = GlobalMethods.returnUserIp(); try { context.TblUsers.Add(myUser); context.SaveChanges(); } catch (Exception E) { MessageBox.Show("An error has occured while registering. Error is: \n" + E.Message.ToString() + "\n\n" + E?.InnerException?.Message); return; } MessageBox.Show("User has been succcesfully registered"); //do the after register operations main.txtEmail.Text = ""; main.txtFirstName.Text = ""; } }
public static void initApp(MainWindow main) { ObservableCollection <TblUserTypes> userRanks = new ObservableCollection <TblUserTypes>(); userRanks.Add(new TblUserTypes() { UserTypeId = 0, UserTypeName = "Please Pick User Type" }); using (PMSContext context = new PMSContext()) { var vrUserTypes = context.TblUserTypes; foreach (var item in vrUserTypes) { userRanks.Add(item); } } main.cmbBoxUserRank.ItemsSource = userRanks; main.cmbBoxUserRank.DisplayMemberPath = "UserTypeName"; main.cmbBoxUserRank.SelectedIndex = 0; }
public static void refreshDrugsDataGrid() { _drugsData = new PMSContext();//this will refresh local data //this is //_drugsData.TblDrugs.Select(pr => new { DrugId = pr.DrugId, DrugName = pr.DrugName, DrugDose = pr.DoseMg, DeleteButton = "Delete Drug" }).OrderBy(pr => pr.DrugId).Take(100).Load();//load requires using Microsoft.EntityFrameworkCore; reference //var bindingList = _drugsData.TblDrugs.Select(pr => new { DrugId = pr.DrugId, DrugName = pr.DrugName, DrugDose = pr.DoseMg, DeleteButton = "Delete Drug" }).OrderBy(pr => pr.DrugId).Take(100).ToList().ToBindingList(); // this is way of getting anonymous type results from entity framework selection queries //var lstDrugs = _drugsData.TblDrugs.Select(pr => new { DrugId = pr.DrugId, DrugName = pr.DrugName, DrugDose = pr.DoseMg, DeleteButton = "Delete Drug" }).OrderBy(pr => pr.DrugId).Take(100).ToList(); //foreach (var item in lstDrugs) //{ // _drugsData.TblDrugs.Local.Add(item); //} _drugsData.TblDrugs.OrderBy(pr => pr.DrugId).Take(100).Load(); GlobalMethods.main.dataGridDrugs.ItemsSource = _drugsData.TblDrugs.Local.ToBindingList(); GlobalMethods.main.dataGridDrugs.CurrentCellChanged += DataGridDrugs_CurrentCellChanged; for (int i = 0; i < GlobalMethods.main.dataGridDrugs.Columns.Count; i++) { GlobalMethods.main.dataGridDrugs.Columns[i].Width = new DataGridLength(1, DataGridLengthUnitType.Star); //sets each column to strech equally if (GlobalMethods.main.dataGridDrugs.Columns[i].Header.ToString().ToLowerInvariant() == "tblprescriptions") { GlobalMethods.main.dataGridDrugs.Columns[i].Visibility = System.Windows.Visibility.Hidden; } } GlobalMethods.main.dataGridDrugs.Items.Refresh(); }