private void switchEmail(object sender, RoutedEventArgs e) { EmailSystem es = new EmailSystem(this.username, this.accessLevel, this.pID); es.Show(); this.Hide(); }
private void tryLogin() { int r = -1; try { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); String procedure = "UNI_CheckUsername"; SqlCommand command = new SqlCommand(procedure, conn); command.CommandType = System.Data.CommandType.StoredProcedure; var returnParameter = command.Parameters.Add("@ReturnVal", System.Data.SqlDbType.Int); returnParameter.Direction = System.Data.ParameterDirection.ReturnValue; SqlParameter pIDParam = new SqlParameter("@pid", System.Data.SqlDbType.Int); pIDParam.Value = Int32.Parse(pID.Text); command.Parameters.Add(pIDParam); SqlParameter usernameParam = new SqlParameter("@username", System.Data.SqlDbType.VarChar); usernameParam.Value = (username.Text); command.Parameters.Add(usernameParam); SqlParameter passwordParam = new SqlParameter("@password", System.Data.SqlDbType.VarChar); passwordParam.Value = (password.Text); command.Parameters.Add(passwordParam); command.ExecuteNonQuery(); r = Convert.ToInt32(returnParameter.Value); switch (r) { case 1: //success procedure = "UNI_CheckType"; command = new SqlCommand(procedure, conn); command.CommandType = System.Data.CommandType.StoredProcedure; returnParameter = command.Parameters.Add("@ReturnVal", System.Data.SqlDbType.Int); returnParameter.Direction = System.Data.ParameterDirection.ReturnValue; pIDParam = new SqlParameter("@pid", System.Data.SqlDbType.Int); pIDParam.Value = Int32.Parse(pID.Text); command.Parameters.Add(pIDParam); command.ExecuteNonQuery(); int s = Convert.ToInt32(returnParameter.Value); switch (s) { case 0: this.identity = 0; break; case 1: this.identity = 1; break; case 2: this.identity = 2; break; } Console.WriteLine(this.identity); this.Hide(); if (c == 0) { MainWindow mw = new MainWindow(this.username.Text, this.identity, Convert.ToInt32(pID.Text)); mw.results.Text = "Login Successful! Welcome."; mw.Show(); } else if (c == 1) { EmailSystem es = new EmailSystem(this.username.Text, this.identity, Convert.ToInt32(pID.Text)); //es.results.Text = "Login Successful! Welcome."; es.Show(); } break; case 2: //invalid password result.Text = "You have entered an incorrect username/password"; break; case 0: //invalid username result.Text = "You have entered an incorrect username/password"; break; case 3: //invalid pID result.Text = "You have entered an incorrect pID"; break; } conn.Close(); } } catch (SqlException se) { } catch (FormatException) { result.Text = "You have entered values in an incorrect format."; } }