Esempio n. 1
0
        public List<Teacher> GetAllTeachers()
        {
            List<Teacher> teachers = new List<Teacher>();

            comm = new SqlCommand();
            comm.CommandText = "SELECT * FROM Person";
            dbCon = new DbConnection();
            comm.Connection = dbCon.GetConnection();
            comm.Connection.Open();

            comm.CommandType = CommandType.Text;
            SqlDataReader dr = comm.ExecuteReader();

            while (dr.Read())
            {
                Person pers = new Person();
                pers.UserType = Convert.ToInt32(dr["userType"]);

                if (pers.UserType == 1)
                {
                    Teacher teacher = new Teacher();
                    teacher.Id = Convert.ToInt32(dr["pid"]);
                    teacher.Name = dr["name"].ToString();
                    teacher.Email = dr["email"].ToString();
                    teacher.Phone = dr["phone"].ToString();
                    teacher.Subject = dr["subject"].ToString();

                    teachers.Add(teacher);
                }
            }
            comm.Connection.Close();
            return teachers;
        }
Esempio n. 2
0
        public Child GetChild(Person p)
        {
            comm = new SqlCommand();
            comm.CommandText = "SELECT * FROM Child WHERE pid=(@pid)";
            comm.Parameters.AddWithValue("pid", p.Id);
            dbCon = new DbConnection();
            comm.Connection = dbCon.GetConnection();
            comm.Connection.Open();

            comm.CommandType = CommandType.Text;
            SqlDataReader dr = comm.ExecuteReader();

            if (dr.Read() && dr.HasRows)
            {
                Child child = new Child();
                child.Email = p.Email;
                child.Id = p.Id;
                child.Name = p.Name;
                child.Password = p.Password;
                child.Phone = p.Phone;
                child.UserName = p.UserName;
                child.UserType = p.UserType;
                child.Grade = dr["grade"].ToString();
                return child;
            }
            else
            {
                comm.Connection.Close();
                return null;
            }
        }
Esempio n. 3
0
        public Teacher GetTeacher(Person p)
        {
            comm = new SqlCommand();
            comm.CommandText = "SELECT * FROM Teacher WHERE pid=(@pid)";
            comm.Parameters.AddWithValue("pid", p.Id);
            dbCon = new DbConnection();
            comm.Connection = dbCon.GetConnection();
            comm.Connection.Open();

            comm.CommandType = CommandType.Text;
            SqlDataReader dr = comm.ExecuteReader();

            if (dr.Read() && dr.HasRows)
            {
                Teacher teacher = new Teacher();
                teacher.Id = p.Id;
                teacher.Name = p.Name;
                teacher.Password = p.Password;
                teacher.Phone = p.Phone;
                teacher.UserName = p.UserName;
                teacher.UserType = p.UserType;
                teacher.Subject = Convert.ToString(dr["subject"]);
                return teacher;
            }
            else
            {
                comm.Connection.Close();
                return null;
            }
        }
 public Object GetPerson(int id)
 {
     Person p = new Person();
     p.Id = id;
     PersonDb logDb = new PersonDb();
     return logDb.GetPerson(p);
 }
 private Person BuildPerson(SqlDataReader dr)
 {
     Person pers = null;
     try
     {
         pers = new Person();
         pers.Id = Convert.ToInt32(dr["pid"]);
         pers.Name = dr["name"].ToString();
         pers.Phone = dr["phone"].ToString();
         pers.Email = dr["email"].ToString();
         pers.UserType = Convert.ToInt32(dr["userType"]);
         if (pers.UserType == 1)
         {
             pers.Subject = dr["subject"].ToString();
         }
         else
         {
             pers.Grade = dr["grade"].ToString();
         }
     }
     catch
     {
         throw;
     }
     return pers;
 }
        public Person Login(string UserName, string Password)
        {
            Person p = new Person();
            p.UserName = UserName;
            p.Password = Password;
            PersonDb logDb = new PersonDb();

            return logDb.Login(p);
        }
        public Person Login(string user, string password)
        {
            Person pers = new Person();
            pers.User = user;
            pers.Password = password;

            persDb = new PersonDb();

            return persDb.Login(pers);
        }
Esempio n. 8
0
        public Object GetPerson(Person p)
        {
            comm = new SqlCommand();
            comm.CommandText = "SELECT * FROM Person WHERE pid=(@personId)";
            comm.Parameters.AddWithValue("personId", p.Id);
            dbCon = new DbConnection();
            comm.Connection = dbCon.GetConnection();
            comm.Connection.Open();

            comm.CommandType = CommandType.Text;
            SqlDataReader dr = comm.ExecuteReader();

            if (dr.Read() && dr.HasRows)
            {
                Person pers = new Person();
                pers.UserType = Convert.ToInt32(dr["userType"]);

                if (pers.UserType == 1)
                {
                    Teacher teacher = new Teacher();
                    teacher.Id = Convert.ToInt32(dr["pid"]);
                    teacher.Name = dr["name"].ToString();
                    teacher.Email = dr["email"].ToString();
                    teacher.Phone = dr["phone"].ToString();
                    teacher.Subject = dr["subject"].ToString();

                    comm.Connection.Close();
                    return teacher;
                }
                else
                {
                    Child child = new Child();
                    child.Id = Convert.ToInt32(dr["pid"]);
                    child.Name = dr["name"].ToString();
                    child.Email = dr["email"].ToString();
                    child.Phone = dr["phone"].ToString();
                    child.Grade = dr["grade"].ToString();

                    comm.Connection.Close();
                    return child;
                }
            }
            else
            {
                comm.Connection.Close();
                return null;
            }
        }
 public Person Login(Person p)
 {
     string w = "username = '******' AND password = '******'";
     Person pers = this.SingleWhere(w, false);
     return pers;
 }