void GetClasses() { Ado ado = new Ado(); ado.Connect(); var query = $"Select * From Classes"; ado.Adapter = new SqlDataAdapter(query, ado.Cnx); ado.Adapter.Fill(ado.DataSet); ado.Disconnect(); ClassFilter.SelectedValuePath = "Class Id"; ClassFilter.DisplayMemberPath = "Class Name"; ClassFilter.ItemsSource = ado.DataSet.Tables[0].DefaultView; }
void GetUsers() { Task.Run(() => { adonet.DataSet.Tables.Clear(); //userstable.Items.Clear(); }); adonet.Connect(); var query = $"Select u.[User Id], u.[Full Name], u.Email, r.[Role Name],c.[Class Name],c.[Id Class] From Users u INNER JOIN Roles r ON u.[Role Id]= r.[Role Id] Left JOIN Classes c On u.[Class Id] = c.[Id Class]; "; adonet.Adapter = new SqlDataAdapter(query, adonet.Cnx); adonet.Adapter.Fill(adonet.DataSet); adonet.Disconnect(); userstable.ItemsSource = adonet.DataSet.Tables[0].DefaultView; }
public override bool Login(string email, string password) { try { Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$"); Match match = regex.Match(email); //Check if Email Entered if (email.Length == 0) { error = "Please enter your email."; return(false); } //Check if it's a valid email else if (!match.Success) { error = "Please Enter a valid email address."; return(false); } else { //Open Connection Adonet.Connect(); //Check for user from DB Adonet.Adapter = new SqlDataAdapter($"Select * from Users Where Email ='{email}' and Password ='******'", Adonet.Cnx); //Fill DataSet with the result Adonet.Adapter.Fill(Adonet.DataSet1, "User"); //Close Cnx Adonet.Disconnect(); //If their is a result if (Adonet.DataSet1.Tables["User"].Rows.Count > 0) { //Collect user information RoleId = Convert.ToInt32(Adonet.DataSet1.Tables["User"].Rows[0][5]); UserId = Convert.ToInt32(Adonet.DataSet1.Tables["User"].Rows[0][0]); UserName = Adonet.DataSet1.Tables["User"].Rows[0][1].ToString().Trim(); UserEmail = Adonet.DataSet1.Tables["User"].Rows[0][2].ToString().Trim(); //Check if its a Staff Or Student Then they can have a Class Id if (RoleId > 2) { ClassId = Convert.ToInt32(Adonet.DataSet1.Tables["User"].Rows[0][6].ToString().Trim()); } return(true); } else { error = "Sorry, user not found !"; return(false); } } } catch (Exception ex) { MessageBox.Show(ex + String.Empty); return(false); } }