private void addPerson(string firstname, string lastname, string email) { /// Regex check ob Email möglich ist if (isValidEmail(email)) { SQLCommandBuilder SQLCmd = new SQLCommandBuilder(localConnection); SQLCmd.buildSQLStatement ( SQLCommandType.Distinct, "Person", new SQLCondition[] { new SQLCondition("FirstName", SQLOperator.Equal, firstname), new SQLCondition("LastName", SQLOperator.Equal, lastname, SQLConditionType.And), new SQLCondition("Email", SQLOperator.Equal, email, SQLConditionType.And) } ); SqlDataReader dr = SQLCmd.Command.ExecuteReader(); if (dr.HasRows) { CurrentGroup.Members.Add(new Person()); } else { SQLCmd.buildSQLStatement(SQLCommandType.Insert, "Person", null, new string[] { "FirstName", "LastName", "Email" }, new string[] { firstname, lastname, email }); SQLCmd.Command.ExecuteNonQuery(); } } else { MessageBox.Show("Bitte eine gültige Email Adresse eingeben."); } }
private bool checkPassword(string username, string password) { bool match = false; SQLCommandBuilder SQLCmd = new SQLCommandBuilder(mainWindow.localConnection); using (SQLCmd.Command) { string storedPassword = ""; // Search for user with <username> SQLCmd.buildSQLStatement ( SQLCommandType.Select, "Users", new SQLCondition("UserName", SQLOperator.Equal, username) ); using (SqlDataReader reader = SQLCmd.Command.ExecuteReader()) { if (reader.Read()) { int ord = reader.GetOrdinal("Password"); storedPassword = reader.GetString(ord); int idord = reader.GetOrdinal("UsersID"); mainWindow.UserID = reader.GetString(ord); } } if (GetHashString(password) == storedPassword) { match = true; } } return(match); }
public void saveGroup(string groupName) { // TODO Save group with current name SQLCommandBuilder insert = new SQLCommandBuilder(localConnection); insert.buildSQLStatement(SQLCommandType.Insert, "Groups", new string[] { "GroupName", "User_ID" }, new string[] { groupName, UserID.ToString() }); insert.Command.ExecuteNonQuery(); // TODO add members to group foreach (Person member in CurrentGroup.Members) { insert.buildSQLStatement(SQLCommandType.Insert, "Members", new string[] { "Group_ID", "Person_ID" }, new string[] { "", member.PersonID.ToString() }); insert.Command.ExecuteNonQuery(); } }
private void btn_match_Click(object sender, RoutedEventArgs e) { // TODO add {match current group} and {save final group to events table} logic string eventName = ""; SQLCommandBuilder cmd = new SQLCommandBuilder(localConnection); cmd.buildSQLStatement(SQLCommandType.Insert, "Events", "EventName", eventName); cmd.Command.ExecuteNonQuery(); cmd.buildSQLStatement(SQLCommandType.Insert, "Participants", new string[] { "", "" }, new string[] { "", "" }); foreach (Person p in CurrentGroup.Members) { if (p.Participates) { } } }
private void btn_login_Click(object sender, RoutedEventArgs e) { if (isLoggedIn) { showLogout(); } else { LoginWindow login = new LoginWindow(this); login.ShowDialog(); if (login.SuccessfulLogin) { showLogin(); cb_group.Items.Clear(); // read groups of user SQLCommandBuilder SQLCmd = new SQLCommandBuilder(localConnection); using (SQLCmd.Command) { SQLCmd.buildSQLStatement ( SQLCommandType.Select, "Groups", new SQLCondition("GroupID", SQLOperator.Equal, UserID) ); using (SqlDataReader reader = SQLCmd.Command.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { cb_group.Items.Add(reader.GetString(1)); } } } } } } }
public MainWindow() { InitializeComponent(); setAdminCode(); AdminWindow outputWindow = new AdminWindow(this); for (int i = 0; i < 5; i++) { CurrentGroup.Members.Add(new Person("P" + i, "P" + i, "P" + i)); } try { localConnection.Open(); Console.WriteLine("Connected to -" + localConnection.Database + "- Database"); } catch (Exception e) { Console.WriteLine(e.ToString()); } // TODO load all people SQLCommandBuilder SQLCmd = new SQLCommandBuilder(localConnection); SQLCmd.buildSQLStatement ( SQLCommandType.Select, "Person" ); using (SqlDataReader reader = SQLCmd.Command.ExecuteReader()) { CurrentGroup.Members.Clear(); while (reader.Read()) { CurrentGroup.Members.Add(new Person(reader.GetString(1), reader.GetString(2), reader.GetString(3))); } } //connectDataView(); }
private void cb_group_SelectionChanged(object sender, SelectionChangedEventArgs e) { // TODO add {Load group based on selection} logic // Get Group ID SQLCommandBuilder SQLCmd = new SQLCommandBuilder(localConnection); using (SQLCmd.Command) { SQLCmd.buildSQLStatement ( SQLCommandType.Select, "Groups", new SQLCondition("GroupName", SQLOperator.Equal, cb_group.Text) ); string groupID = ""; using (SqlDataReader reader = SQLCmd.Command.ExecuteReader()) { if (reader.HasRows) { groupID = reader.GetString(0); } } SQLCmd.buildSQLStatement ( SQLCommandType.Select, "Members", new SQLCondition("Group_ID", SQLOperator.Equal, groupID) ); using (SqlDataReader reader = SQLCmd.Command.ExecuteReader()) { CurrentGroup.Members.Clear(); foreach (DataRow row in reader) { CurrentGroup.Members.Add(new Person(row[1].ToString(), row[2].ToString(), row[3].ToString())); } } } }
private void btn_login_Click(object sender, RoutedEventArgs e) { string message = ""; SQLCommandBuilder SQLCmd = new SQLCommandBuilder(mainWindow.localConnection); using (SQLCmd.Command) { // Neuen Benutzer Erstellen if (signup) { // Create new user Logic if (pb_password.Password == pb_password_repeat.Password) { // Password and Username should be longer than 3 characters if (pb_password.Password.Length > 3 && tb_username.Text.Length > 3) { // Check if user exists SQLCmd.buildSQLStatement(SQLCommandType.Select, "Users", new SQLCondition("UserName", SQLOperator.Equal, tb_username.Text)); int exists = SQLCmd.Command.ExecuteNonQuery(); if (exists > 0) { message = "Benutzer existiert bereits."; } else { // Create new user SQLCmd.buildSQLStatement(SQLCommandType.Insert, "Users", new string[] { "UserName", "Password" }, new string[] { tb_username.Text, GetHashString(pb_password.Password) }); SQLCmd.Command.ExecuteNonQuery(); message = "Benutzer '" + tb_username.Text + "' Erstellt"; SuccessfulLogin = true; } } else { message = "Passwort oder Benutzername zu kurz."; } } else { message = "Passwörter stimmen nicht überein."; } } // Login Existing User else { if (checkPassword(tb_username.Text, pb_password.Password)) { message = "Erfolgreich Angemeldet als " + tb_username.Text; SuccessfulLogin = true; } else { message = "Benutzer / Passwort kombination nicht gefunden."; } } } MessageBox.Show(message); if (SuccessfulLogin) { mainWindow.User = tb_username.Text; Close(); } }