コード例 #1
0
        protected void btnLuuUser_Click(object sender, EventArgs e)
        {
            DTOUser dtond = new DTOUser();

            dtond.ID = txtID.Text;
            dtond.MK = txtMK.Text;
            dtond.HTuser = txtHoTen.Text;

            DTONhomQuyen dtonq = new DTONhomQuyen();
            dtonq.MaNQ = int.Parse(ddlNhomQ.SelectedValue);
            dtonq.NhomQ = ddlNhomQ.SelectedItem.ToString();
            dtond.dtoNhomQ = dtonq;

            DAO_Entity daond = new DAO_Entity();
            if (KiemTraNhap() == "")
            {
                daond.ThemUser(dtond);
                Response.Redirect("~/QLBophan_Admin/QLUser/User.aspx");
            }
            else
            {
                ThemUser.Visible = true;
                lbLoi.Text = KiemTraNhap();
            }
        }
コード例 #2
0
        //DAOLayThongTinSua
        public DTOUser LayTTNDTheoMa(string maSua)
        {
            ketnoi.TaoKetNoi();
            DTOUser dtond = null;
            try
            {
                string lenh = "select ND.TenDN, ND.MatKhau, ND.HoTenuser, NQ.NhomQuyen from NguoiDung ND, NhomQuyen NQ where ND.MaDN = @madn ND.MaNhomQ = NQ.MaNhomQ";
                ketnoi.LenhKetNoi = new SqlCommand(lenh, ketnoi.KetNoi);

                ketnoi.LenhKetNoi.Parameters.Add("@madn", SqlDbType.Int);
                ketnoi.LenhKetNoi.Parameters["@madn"].Value = maSua;

                DataTable bang = new DataTable();
                ketnoi.TichHopCSDL = new SqlDataAdapter(ketnoi.LenhKetNoi);
                ketnoi.TichHopCSDL.Fill(bang);
                DataRow dong = bang.Rows[0];
                dtond = new DTOUser(dong);
            }
            catch (Exception)
            {


            }
            finally
            {
                ketnoi.DongKetNoi();
            }
            return dtond;
        }
コード例 #3
0
        //Lay thong tin Nhóm Quyền do vao ListBox 29/03/2015
        //public List<DTONhomQuyen> LayDSNhomQuyen()
        //{
        //    List<DTONhomQuyen> ds = new List<DTONhomQuyen>();
        //    string lenh = "select * from NhomQuyen";
        //    ketnoi.TaoKetNoi();
        //    DataTable bang = new DataTable();
        //    try
        //    {
        //        ketnoi.LenhKetNoi = new SqlCommand(lenh, ketnoi.KetNoi);
        //        ketnoi.TichHopCSDL = new SqlDataAdapter(ketnoi.LenhKetNoi);
        //        ketnoi.TichHopCSDL.Fill(bang);
        //        foreach (DataRow dongDL in bang.Rows)
        //        {
        //            DTONhomQuyen dtonq = new DTONhomQuyen(dongDL);
        //            ds.Add(dtonq);
        //        }
        //    }
        //    catch (Exception)
        //    {

        //        throw;
        //    }
        //    finally
        //    {
        //        ketnoi.DongKetNoi();
        //    }
        //    return ds;
        //}

        public List<DTOUser> TimTheoTenUser(string tenTim)
        {
            List<DTOUser> dsTim = new List<DTOUser>();
            string lenh = "select * from User U, NhomQuyen NQ where U.MaNhomQ = NQ.MaNhomQ and U.HoTenUser like @ht";
            ketnoi.TaoKetNoi();
            DataTable bang = new DataTable();
            try
            {
                ketnoi.LenhKetNoi = new SqlCommand(lenh, ketnoi.KetNoi);
                ketnoi.LenhKetNoi.Parameters.Add("@ht", SqlDbType.NVarChar);
                ketnoi.LenhKetNoi.Parameters["@ht"].Value = "%" + tenTim + "%";

                ketnoi.TichHopCSDL = new SqlDataAdapter(ketnoi.LenhKetNoi);
                ketnoi.TichHopCSDL.Fill(bang);
                foreach (DataRow dongDL in bang.Rows)
                {
                    DTOUser dtond = new DTOUser(dongDL);
                    dsTim.Add(dtond);
                }
            }
            catch (Exception)
            {

            }
            finally
            {
                ketnoi.DongKetNoi();
            }
            return dsTim;
        }
コード例 #4
0
        public DTOUser LayTTUserTheoMa(string maSua)
        {
            ketnoi.TaoKetNoi();
            DTOUser dtond = null;
            try
            {
                string lenh = "select NQ.MaNhomQ,NQ.NhomQuyen,ND.IDUser,ND.MatKhau,ND.HoTenUser from User ND,NhomQuyen NQ where ND.IDUser = @id and NQ.MaNhomQ=ND.MaNhomQ ";
                ketnoi.LenhKetNoi = new SqlCommand(lenh, ketnoi.KetNoi);

                ketnoi.LenhKetNoi.Parameters.Add("@id", SqlDbType.Int);
                ketnoi.LenhKetNoi.Parameters["@id"].Value = maSua;

                DataTable bang = new DataTable();
                ketnoi.TichHopCSDL = new SqlDataAdapter(ketnoi.LenhKetNoi);
                ketnoi.TichHopCSDL.Fill(bang);
                DataRow dong = bang.Rows[0];
                dtond = new DTOUser(dong);
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                ketnoi.DongKetNoi();
            }
            return dtond;
        }
コード例 #5
0
        // Sua TT User
        public bool SuaUser(DTOUser dtond)
        {
            bool ketqua = false;
            ketnoi.TaoKetNoi();
            try
            {
                string lenh = "update User set MatKhau= @mk, HoTenUser = @ht, MaNhomQ = @manq where IDUser=@id";
                ketnoi.LenhKetNoi = new SqlCommand(lenh, ketnoi.KetNoi);

                ketnoi.LenhKetNoi.Parameters.Add("@id", SqlDbType.Int);
                ketnoi.LenhKetNoi.Parameters.Add("@mk", SqlDbType.VarChar);
                ketnoi.LenhKetNoi.Parameters.Add("@ht", SqlDbType.NVarChar);
                ketnoi.LenhKetNoi.Parameters.Add("@manq", SqlDbType.Int);

                ketnoi.LenhKetNoi.Parameters["@id"].Value = dtond.ID;
                ketnoi.LenhKetNoi.Parameters["@mk"].Value = dtond.MK;
                ketnoi.LenhKetNoi.Parameters["@ht"].Value = dtond.HTuser;
                ketnoi.LenhKetNoi.Parameters["@manq"].Value = dtond.dtoNhomQ.MaNQ;//@malkh thi phai gan vao "MaLKH", sao lai gan cho dtoLoaiKh

                if (ketnoi.LenhKetNoi.ExecuteNonQuery() != 0)
                    ketqua = true;
            }
            catch (Exception)
            {

            }
            finally
            {
                ketnoi.DongKetNoi();
            }
            return ketqua;
        }
コード例 #6
0
        public bool ThemUser(DTOUser dtond)
        {
            bool ketqua = false;
            ketnoi.TaoKetNoi();
            try
            {
                string lenh = "insert into User(IDUser, MatKhau, HoTenUser, MaNhomQ) values (@id, @mk, @ht, @manq)";
                ketnoi.LenhKetNoi = new SqlCommand(lenh, ketnoi.KetNoi);

                ketnoi.LenhKetNoi.Parameters.Add("@id", SqlDbType.VarChar);
                ketnoi.LenhKetNoi.Parameters.Add("@mk", SqlDbType.VarChar);
                ketnoi.LenhKetNoi.Parameters.Add("@ht", SqlDbType.NVarChar);
                ketnoi.LenhKetNoi.Parameters.Add("@manq", SqlDbType.Int);

                ketnoi.LenhKetNoi.Parameters["@id"].Value = dtond.ID;
                ketnoi.LenhKetNoi.Parameters["@mk"].Value = dtond.MK;
                ketnoi.LenhKetNoi.Parameters["@ht"].Value = dtond.HTuser;
                ketnoi.LenhKetNoi.Parameters["@manq"].Value = dtond.dtoNhomQ.MaNQ;

                if (ketnoi.LenhKetNoi.ExecuteNonQuery() != 0)
                    ketqua = true;
            }
            catch (Exception)
            {


            }
            finally
            {
                ketnoi.DongKetNoi();
            }
            return ketqua;
        }
コード例 #7
0
        //DAONguoiDung
        public List<DTOUser> TaoDSUser()
        {
            List<DTOUser> ds = new List<DTOUser>();
            string lenh = "Select * from User ND, NhomQuyen NQ where ND.MaNhomQ=NQ.MaNhomQ";
            ketnoi.TaoKetNoi();
            DataTable bang = new DataTable();
            try
            {
                ketnoi.LenhKetNoi = new SqlCommand(lenh, ketnoi.KetNoi);
                //dong bo lenh ket noi voi du lieu trong database
                ketnoi.TichHopCSDL = new SqlDataAdapter(ketnoi.LenhKetNoi);
                ketnoi.TichHopCSDL.Fill(bang);
                foreach (DataRow dongDL in bang.Rows)
                {
                    DTOUser dtond = new DTOUser(dongDL);
                    ds.Add(dtond);
                }
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                ketnoi.DongKetNoi();
            }
            return ds;
        }