public NhaXuatBanCollection TimDSNhaXuatBan(string tennxb) { NhaXuatBanCollection nxbColl = new NhaXuatBanCollection(); SqlConnection cnn = new SqlConnection(cnnstr); string query = "select * from nhaxuatban where tennxb <> '' "; query += "order by tennxb"; SqlCommand cmd = new SqlCommand(query, cnn); if (tennxb != "") { query = "select * from nhaxuatban where tennxb like @tennxb and tennxb <>''"; query += "order by tennxb"; cmd = new SqlCommand(query, cnn); cmd.Parameters.AddWithValue("@tennxb", "%" + tennxb + "%"); } cnn.Open(); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { NhaXuatBanBO nxbBO = new NhaXuatBanBO(); nxbBO.MaNXB = dr["manxb"].ToString(); nxbBO.TenNXB = dr["tennxb"].ToString(); nxbColl.Add(nxbBO); } cnn.Close(); return nxbColl; }
public void NapDSNXB() { NhaXuatBanCollection nxb1= new NhaXuatBanCollection(); NhaXuatBanCollection nxb2 = new NhaXuatBanCollection(); NhaXuatBanCollection temp = new NhaXuatBanCollection(); temp = nhaxuatbanBUS.TimDSNhaXuatBan(""); NhaXuatBanBO nhaxuatbanBO = new NhaXuatBanBO(); nhaxuatbanBO.TenNXB = "..."; nhaxuatbanBO.MaNXB = ""; nxb1.Add(nhaxuatbanBO); nxb2.Add(nhaxuatbanBO); for (int i = 0; i < temp.Count; i++) { nxb1.Add(temp.Index(i)); nxb2.Add(temp.Index(i)); } NhaxuatbanMoiDropdown.DataSource = nxb1; NhaxuatbanMoiDropdown.DataTextField = "tennxb"; NhaxuatbanMoiDropdown.DataValueField = "manxb"; NhaxuatbanMoiDropdown.DataBind(); NhaXuatBanSuaDropDown.DataSource = nxb2; NhaXuatBanSuaDropDown.DataTextField = "tennxb"; NhaXuatBanSuaDropDown.DataValueField = "manxb"; NhaXuatBanSuaDropDown.DataBind(); }
protected void NhaxuatbanGridView_RowCommand(object sender, GridViewCommandEventArgs e) { //nếu bấm nút xóa ==>xóa ngay if (e.CommandName == "xoa") { string manxb= (e.CommandArgument).ToString(); nxbBUS.XoaNhaXuatBan(manxb); NapDuLieu(); } //nếu bấm nút sửa ==>bật popup sửa else if (e.CommandName == "sua") { //lấy source hiện tại của NhaXuatBanGridView NhaXuatBanCollection nxbColl= new NhaXuatBanCollection(); nxbColl = nxbBUS.TimDSNhaXuatBan(TimTextbox.Text); //Lấy index dòng đang chọn int index = Convert.ToInt32(e.CommandArgument.ToString()); ViewState["manxb"] = nxbColl.Index(index).MaNXB; string tennxb= nxbColl.Index(index).TenNXB; SuaPopup.Show(); SuaTextBox.Text = tennxb; } }