Exemplo n.º 1
0
        public GiangVienDTO findById(string ma)
        {
            conn.Open();

            string     sql = "select * from giangvien where id_GV = @ma";
            SqlCommand cmd = new SqlCommand(sql, conn);

            cmd.Parameters.AddWithValue("ma", ma);
            SqlDataReader dr = cmd.ExecuteReader();

            GiangVienDTO gv = null;

            while (dr.Read())
            {
                gv = GiangVienMapper.map(dr);
            }
            conn.Close();
            return(gv);
        }
Exemplo n.º 2
0
        public List <GiangVienDTO> findByName(string ten)
        {
            conn.Open();
            List <GiangVienDTO> gvs = new List <GiangVienDTO>();
            string     sql          = "select * from giangvien where ten_GV like concat('%',@ten,'%')";
            SqlCommand cmd          = new SqlCommand(sql, conn);

            cmd.Parameters.AddWithValue("ten", ten);
            SqlDataReader dr = cmd.ExecuteReader();

            GiangVienDTO gv = null;

            while (dr.Read())
            {
                gv = GiangVienMapper.map(dr);
                gvs.Add(gv);
            }
            conn.Close();
            return(gvs);
        }
Exemplo n.º 3
0
        public List <GiangVienDTO> getAll(string sortBy = null, string sortType = null)
        {
            if (sortBy == "ghichu_GV")
            {
                sortBy = "CAST(" + sortBy + " AS NVARCHAR(100))";
            }
            List <GiangVienDTO> gvs = new List <GiangVienDTO>();

            conn.Open();
            string     sql = "";
            SqlCommand cmd;

            if (sortBy != null && sortType != null)
            {
                sql = "select * from giangvien order by " + sortBy + " " + sortType;
                cmd = new SqlCommand(sql, conn);
                //cmd.Parameters.AddWithValue("sort", sortBy);
                //cmd.Parameters.AddWithValue("type", sortType);
            }
            else
            {
                sql = "select * from giangvien";
                cmd = new SqlCommand(sql, conn);
            }


            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                GiangVienDTO gv = GiangVienMapper.map(dr);
                gvs.Add(gv);
            }
            conn.Close();
            return(gvs);
        }