Esempio n. 1
0
        public nhaxuatban LayDuLieuTuForm()
        {
            nhaxuatban nxb = new nhaxuatban()
            {
                MaNhaXuatBan  = txtMaNhaXuatBan.Text,
                TenNhaXuatBan = txtTenNhaXuatBan.Text,
                DiaChi        = txtDiaChi.Text,
                SoDienThoai   = txtSoDienThoai.Text
            };

            return(nxb);
        }
Esempio n. 2
0
        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string maNXB = GridView1.SelectedRow.Cells[0].Text;

            nxb = cn.GetNhaXuatBanByID(maNXB);
            if (nxb != null)
            {
                txtMaNhaXuatBan.Text  = nxb.MaNhaXuatBan;
                txtTenNhaXuatBan.Text = nxb.TenNhaXuatBan;
                txtDiaChi.Text        = nxb.DiaChi;
                txtSoDienThoai.Text   = nxb.SoDienThoai;
            }
            ;
        }
Esempio n. 3
0
 public bool UpdateNhaXuatBan(nhaxuatban nxb)
 {
     using (SqlConnection conn = new SqlConnection(connect))
     {
         string     sql = "update NhaXuatBan set TenNhaXB=@ten,DiaChi=@dc,SDT=@sdt where MaNhaXB=@ma";
         SqlCommand cmd = new SqlCommand(sql, conn);
         cmd.Parameters.AddWithValue("@ma", nxb.MaNhaXuatBan);
         cmd.Parameters.AddWithValue("@ten", nxb.TenNhaXuatBan);
         cmd.Parameters.AddWithValue("@dc", nxb.DiaChi);
         cmd.Parameters.AddWithValue("@sdt", nxb.SoDienThoai);
         conn.Open();
         int count = (int)cmd.ExecuteNonQuery();
         return(count >= 1);
     }
 }
Esempio n. 4
0
 public bool InsertNhaXuatBan(nhaxuatban nxb)
 {
     using (SqlConnection conn = new SqlConnection(connect))
     {
         string     sql = "insert into NhaXuatBan values(@ma,@ten,@dc,@sdt)";
         SqlCommand cmd = new SqlCommand(sql, conn);
         cmd.Parameters.AddWithValue("@ma", nxb.MaNhaXuatBan);
         cmd.Parameters.AddWithValue("@ten", nxb.TenNhaXuatBan);
         cmd.Parameters.AddWithValue("@dc", nxb.DiaChi);
         cmd.Parameters.AddWithValue("@sdt", nxb.SoDienThoai);
         conn.Open();
         int count = (int)cmd.ExecuteNonQuery();
         return(count >= 1);
     }
 }
Esempio n. 5
0
        protected void btnSua_Click(object sender, EventArgs e)
        {
            nxb = LayDuLieuTuForm();
            bool result = cn.UpdateNhaXuatBan(nxb);

            if (result)
            {
                lblThongBao.Text = "Cập nhập thành công";
                DoDuLieuVaoGridView();
            }
            else
            {
                lblThongBao.Text = "Có lỗi";
            }
        }
Esempio n. 6
0
 public nhaxuatban GetNhaXuatBanByID(string maNXB)
 {
     using (SqlConnection conn = new SqlConnection(connect))
     {
         string     sql = "select * from NhaXuatBan where MaNhaXB=@ma";
         SqlCommand cmd = new SqlCommand(sql, conn);
         cmd.Parameters.AddWithValue("@ma", maNXB);
         conn.Open();
         SqlDataReader dr = cmd.ExecuteReader();
         if (dr.Read())
         {
             nhaxuatban nxb = new nhaxuatban()
             {
                 MaNhaXuatBan  = (string)dr["MaNhaXB"],
                 TenNhaXuatBan = (string)dr["TenNhaXB"],
                 DiaChi        = (string)dr["DiaChi"],
                 SoDienThoai   = (string)dr["SDT"]
             };
             return(nxb);
         }
         return(null);
     }
 }
Esempio n. 7
0
        protected void btnThem_Click(object sender, EventArgs e)
        {
            nxb = LayDuLieuTuForm();
            cn  = new chucnang();
            bool exist = cn.CheckMaNhaXuatBan(nxb.MaNhaXuatBan);

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