Ejemplo n.º 1
0
        public tacgia LayDuLieuTuForm()
        {
            tacgia tg = new tacgia()
            {
                MaTacGia  = txtMaTacGia.Text,
                TenTacGia = txtTenTacGia.Text
            };

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

            tg = cn.GetTacGiaByID(maTacGia);
            if (tg != null)
            {
                txtMaTacGia.Text  = tg.MaTacGia;
                txtTenTacGia.Text = tg.TenTacGia;
            }
        }
Ejemplo n.º 3
0
 public bool UpdateTacGia(tacgia tg)
 {
     using (SqlConnection conn = new SqlConnection(connect))
     {
         string     sql = "update TacGia set TenTacGia=@ten where MaTacGia=@ma";
         SqlCommand cmd = new SqlCommand(sql, conn);
         cmd.Parameters.AddWithValue("@ma", tg.MaTacGia);
         cmd.Parameters.AddWithValue("@ten", tg.TenTacGia);
         conn.Open();
         int count = (int)cmd.ExecuteNonQuery();
         return(count >= 1);
     }
 }
Ejemplo n.º 4
0
 public bool InsertTacGia(tacgia tg)
 {
     using (SqlConnection conn = new SqlConnection(connect))
     {
         string     sql = "insert into TacGia values(@ma,@ten)";
         SqlCommand cmd = new SqlCommand(sql, conn);
         cmd.Parameters.AddWithValue("@ma", tg.MaTacGia);
         cmd.Parameters.AddWithValue("@ten", tg.TenTacGia);
         conn.Open();
         int count = (int)cmd.ExecuteNonQuery();
         return(count >= 1);
     }
 }
Ejemplo n.º 5
0
        protected void btnSua_Click(object sender, EventArgs e)
        {
            tg = LayDuLieuTuForm();
            bool result = cn.UpdateTacGia(tg);

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

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