public static string LoadUser(string name, string surname, out User user) { user = null; if (con == null) return "Connection is not initialized"; try { SqlCommand command2 = new SqlCommand("Select * from UserTBL where UserTBL.Name='" + name + "' AND UserTBL.Surname='" + surname + "';", con); SqlDataReader sdr1 = command2.ExecuteReader(); while (sdr1.Read()) { user = new User(); user.ID = (int)sdr1["User_ID"]; user.Name = sdr1["Name"].ToString(); user.Surname = sdr1["Surname"].ToString(); } sdr1.Close(); } catch (Exception e) { return e.ToString(); } if (user == null) { return "0 record loaded"; } return "1 record loaded"; }
public User login() { jmeno.IsEnabled = false; prijmeni.IsEnabled = false; User user; try { DB.LoadUser(jmeno.Text, prijmeni.Text, out user); if (user == null) { if (jmeno.Text.Length < 1) { jmeno.IsEnabled = true; prijmeni.IsEnabled = true; errorMsg.Text = "Please enter your name"; errorMsg.Foreground = Brushes.Red; errorAnim.Begin(); return null; } else if (prijmeni.Text.Length < 1) { jmeno.IsEnabled = true; prijmeni.IsEnabled = true; errorMsg.Text = "Please enter your surname"; errorMsg.Foreground = Brushes.Red; errorAnim.Begin(); return null; } user = new User(jmeno.Text, prijmeni.Text); DB.InsertUser(ref user); errorMsg.Text = "Registered as a new user"; errorMsg.Foreground = Brushes.Green; succAnim.Begin(); wait = true; return user; } else { return user; } } catch { jmeno.IsEnabled = true; prijmeni.IsEnabled = true; errorMsg.Text = "An error has occurred"; errorMsg.Foreground = Brushes.Red; errorAnim.Begin(); return null; } return null; }
public static string InsertUser(ref User item) { SqlCommand command = new SqlCommand("Insert Into UserTBL (Name, Surname) values('" + item.Name + "', '" + item.Surname + "');", con); string s = ExecuteCommand(command); SqlCommand command2 = new SqlCommand("Select * from UserTBL where UserTBL.Name='" + item.Name + "' AND UserTBL.Surname='" + item.Surname + "';", con); SqlDataReader sdr1 = command2.ExecuteReader(); while (sdr1.Read()) { item.ID = (int)sdr1["User_ID"]; } sdr1.Close(); return s; }
void SwitchMode() { if (curMode == UIMode.Login) { LoginPage loginPage = contentPanel.Children[0] as LoginPage; curUser = loginPage.login(); if (curUser != null) if (!loginPage.Wait) curMode = UIMode.QuizSelection; else return; } else if (curMode == UIMode.QuizSelection) { if (List.SelectedItem != null) { curMode = UIMode.Questionary; currentQuiz = (List.SelectedItem as ListBoxItem).Tag as Quiz; } } else if (curMode == UIMode.Questionary) { curMode = UIMode.ResultsView; } else if (curMode == UIMode.ResultsView) { curMode = UIMode.QuizSelection; } fadeout.Begin(); }