Ejemplo n.º 1
0
        public loaisach LayDuLieuTuForm()
        {
            loaisach ls = new loaisach()
            {
                MaLoai      = txtMaLoaiSach.Text,
                TenLoaiSach = txtTenLoaiSach.Text
            };

            return(ls);
        }
Ejemplo n.º 2
0
        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string maLoai = GridView1.SelectedRow.Cells[0].Text;

            ls = cn.GetLoaiSachByID(maLoai);
            if (ls != null)
            {
                txtMaLoaiSach.Text  = ls.MaLoai;
                txtTenLoaiSach.Text = ls.TenLoaiSach;
            }
        }
Ejemplo n.º 3
0
 public bool UpdateLoaiSach(loaisach ls)
 {
     using (SqlConnection conn = new SqlConnection(connect))
     {
         string     sql = "update LoaiSach set TenLoaiSach=@ten where MaLoai=@ma";
         SqlCommand cmd = new SqlCommand(sql, conn);
         cmd.Parameters.AddWithValue("@ma", ls.MaLoai);
         cmd.Parameters.AddWithValue("@ten", ls.TenLoaiSach);
         conn.Open();
         int count = (int)cmd.ExecuteNonQuery();
         return(count >= 1);
     }
 }
Ejemplo n.º 4
0
 public bool InsertLoaiSach(loaisach ls)
 {
     using (SqlConnection conn = new SqlConnection(connect))
     {
         string     sql = "insert into LoaiSach values(@ma,@ten)";
         SqlCommand cmd = new SqlCommand(sql, conn);
         cmd.Parameters.AddWithValue("@ma", ls.MaLoai);
         cmd.Parameters.AddWithValue("@ten", ls.TenLoaiSach);
         conn.Open();
         int count = (int)cmd.ExecuteNonQuery();
         return(count >= 1);
     }
 }
Ejemplo n.º 5
0
        protected void btnSua_Click(object sender, EventArgs e)
        {
            ls = LayDuLieuTuForm();
            bool result = cn.UpdateLoaiSach(ls);

            if (result)
            {
                lblThongBao.Text = "Cập nhập thành công";
                DoDuLieuVaoGridView();
            }
            else
            {
                lblThongBao.Text = "Có lỗi";
            }
        }
Ejemplo n.º 6
0
 public loaisach GetLoaiSachByID(string maLoai)
 {
     using (SqlConnection conn = new SqlConnection(connect))
     {
         string     sql = "select * from LoaiSach where MaLoai=@ma";
         SqlCommand cmd = new SqlCommand(sql, conn);
         cmd.Parameters.AddWithValue("@ma", maLoai);
         conn.Open();
         SqlDataReader dr = cmd.ExecuteReader();
         if (dr.Read())
         {
             loaisach ls = new loaisach()
             {
                 MaLoai      = (string)dr["MaLoai"],
                 TenLoaiSach = (string)dr["TenLoaiSach"]
             };
             return(ls);
         }
         return(null);
     }
 }
Ejemplo n.º 7
0
        protected void btnThem_Click(object sender, EventArgs e)
        {
            ls = LayDuLieuTuForm();
            cn = new chucnang();
            bool exist = cn.CheckMaLoaiSach(ls.MaLoai);

            if (exist)
            {
                lblThongBao.Text = "Tác Giả này đã có";
            }
            else
            {
                bool result = cn.InsertLoaiSach(ls);
                if (result)
                {
                    lblThongBao.Text = "Thêm thành công";
                    DoDuLieuVaoGridView();
                }
                else
                {
                    lblThongBao.Text = "Có lỗi";
                }
            }
        }