public static void saveDrugChanges() { if (GlobalMethods.isA_DoctorLoggedIn() == false) { return; } _drugsData.SaveChanges(); setDrugScreenMsg("Changes (update/delete/add) are saved at the database."); }
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); } }
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")}"); } } } }); }