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;

            GlobalMethods.setDrugsPanelVisibility();
            initSortingOptions();

            main.cmbSortingDrugs.ItemsSource       = lstSortingOptions;
            main.cmbSortingDrugs.DisplayMemberPath = "srDescription";
            main.cmbSortingDrugs.SelectedIndex     = 4;
        }
        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.txtLoginEmail.Text        = main.txtEmail.Text;
                main.txtLoginPassword.Password = main.txtPw1.Password;
                main.txtEmail.Text             = "";
                main.txtFirstName.Text         = "";
                main.txtLastName.Text          = "";
                main.txtPw1.Password           = "";
                main.txtPw2.Password           = "";

                LoginOperations.loginTry(main);
            }
        }
        public static void refreshDrugsDataGrid()
        {
            if (GlobalMethods.isA_DoctorLoggedIn() == false)
            {
                return;
            }

            _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);
            //}

            string srSearchTerm = "";

            if (GlobalMethods.main.txtSearchByDrugName.Text.Length > 0)
            {
                srSearchTerm = GlobalMethods.main.txtSearchByDrugName.Text;
            }


            switch (((sortingOption)GlobalMethods.main.cmbSortingDrugs.SelectedItem).whichSort)
            {
            case enWhichSorting.SortByDrugNameAsc:
                //you can optimize your queries like this
                if (string.IsNullOrEmpty(srSearchTerm))
                {
                    _drugsData.TblDrugs.OrderBy(pr => pr.DrugName).Take(100).Load();
                }
                else
                {
                    _drugsData.TblDrugs.Where(pr => pr.DrugName.Contains(srSearchTerm)).OrderBy(pr => pr.DrugName).Take(100).Load();
                }
                break;

            case enWhichSorting.SortByDrugNameDesc:
                _drugsData.TblDrugs.Where(pr => pr.DrugName.Contains(srSearchTerm)).OrderByDescending(pr => pr.DrugName).Take(100).Load();
                break;

            case enWhichSorting.SortByDrugDoseAsc:
                _drugsData.TblDrugs.Where(pr => pr.DrugName.Contains(srSearchTerm)).OrderBy(pr => pr.DoseMg).Take(100).Load();
                break;

            case enWhichSorting.SortByDrugDoseDesc:
                _drugsData.TblDrugs.Where(pr => pr.DrugName.Contains(srSearchTerm)).OrderByDescending(pr => pr.DoseMg).Take(100).Load();
                break;

            case enWhichSorting.SortByDrugIdAsc:
                _drugsData.TblDrugs.Where(pr => pr.DrugName.Contains(srSearchTerm)).OrderBy(pr => pr.DrugId).Take(100).Load();
                break;

            case enWhichSorting.SortByDrugIdDesc:
                _drugsData.TblDrugs.Where(pr => pr.DrugName.Contains(srSearchTerm)).OrderByDescending(pr => pr.DrugId).Take(100).Load();
                break;

            default:
                break;
            }

            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;
                }

                if (GlobalMethods.main.dataGridDrugs.Columns[i].Header.ToString().ToLowerInvariant() == "drugid")
                {
                    GlobalMethods.main.dataGridDrugs.Columns[i].IsReadOnly = true;
                }
            }



            GlobalMethods.main.dataGridDrugs.Items.Refresh();
        }
        internal static void loadReadyDrugData()
        {
            Task.Factory.StartNew(() =>
            {
                using (PMSContext myContext = new PMSContext())
                {
                    myContext.TblDrugs.Load();

                    int irAddedCounter = 0, irProcessedCounter = 0;
                    foreach (var vrLine in File.ReadLines("StaticData\\pddf_2021_04_13.csv"))
                    {
                        irProcessedCounter++;
                        TblDrugs myDrug = new TblDrugs();

                        string srDrugName = vrLine.Split(",")[9];
                        myDrug.DrugName   = srDrugName;
                        var vrSplitVals   = srDrugName.Split(" ");

                        for (int i = 0; i < vrSplitVals.Length; i++)
                        {
                            if (vrSplitVals[i] == "MG")
                            {
                                decimal dcTry = 0;
                                if (decimal.TryParse(vrSplitVals[i - 1], out dcTry))
                                {
                                    myDrug.DoseMg = dcTry;
                                }
                                break;
                            }
                        }

                        bool blAdded = false;

                        if (myDrug.DoseMg != 0)
                        {
                            var vrSelect = myContext.TblDrugs.Local.Where(pr => pr.DrugName == myDrug.DrugName && pr.DoseMg == myDrug.DoseMg).FirstOrDefault();
                            if (vrSelect == null)
                            {
                                //vrSelect = myContext.TblDrugs.Local.Where(pr => pr.DrugName == myDrug.DrugName && pr.DoseMg == myDrug.DoseMg).FirstOrDefault();
                                //if (vrSelect == null)
                                //{
                                myContext.TblDrugs.Add(myDrug);
                                myContext.TblDrugs.Local.Add(myDrug);
                                blAdded = true;
                                irAddedCounter++;
                                //}
                            }
                        }

                        //if (!blAdded)
                        //    continue;



                        if (irProcessedCounter % 100 == 0)
                        {
                            myContext.SaveChanges();
                            setDrugScreenMsg($"so far inserted drugs count: { irAddedCounter.ToString("N0")} , processed: {irProcessedCounter.ToString("N0")}");
                        }
                    }
                }
            });
        }