protected void PhanLoaiGridView_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "xoa") { string maphanloai = (e.CommandArgument).ToString(); phanloaiBUS.XoaPhanLoai(maphanloai); NapDuLieu(); } else if (e.CommandName == "sua") { PhanLoaiCollection phanloaicoll = new PhanLoaiCollection(); phanloaicoll = phanloaiBUS.TimDSCapNhatPhanLoai(TimTextbox.Text); int index = Convert.ToInt32(e.CommandArgument.ToString()); ViewState["MaPhanLoai"] = phanloaicoll.Index(index).MaPhanLoai; string tenphanloai = phanloaicoll.Index(index).TenPhanLoai; SuaPopup.Show(); SuaTextBox.Text = tenphanloai; } else if (e.CommandName == "chitiet") { PhanLoaiCollection phanloaicoll = new PhanLoaiCollection(); phanloaicoll = phanloaiBUS.TimDSCapNhatPhanLoai(TimTextbox.Text); int index = Convert.ToInt32(e.CommandArgument.ToString()); ViewState["MaPhanLoai"] = phanloaicoll.Index(index).MaPhanLoai; string tenchitiet = phanloaicoll.Index(index).TenPhanLoai; ChiTietPopup.Show(); NapChiTiet(); TenPhanLoaiLabel.Text = tenchitiet; } }
public void NapTheLoai() { TheLoaiDropdown.Items.Clear(); PhanLoaiCollection source = new PhanLoaiCollection(); PhanLoaiBO phanloaiBO = new PhanLoaiBO(); phanloaiBO.TenPhanLoai = "Tất cả"; phanloaiBO.MaPhanLoai = ""; source.Add(phanloaiBO); //add PhanLoaiCollection temp = new PhanLoaiCollection(); temp=phanloaiBUS.TimDSPhanLoai(); for (int i = 0; i < temp.Count; i++) { source.Add(temp.Index(i)); } TheLoaiDropdown.DataSource = source; TheLoaiDropdown.DataTextField = "Tenphanloai"; TheLoaiDropdown.DataValueField = "Maphanloai"; TheLoaiDropdown.DataBind(); }
public PhanLoaiCollection TimDSPhanLoai() { PhanLoaiCollection plColl = new PhanLoaiCollection(); SqlConnection cnn = new SqlConnection(cnnstr); SqlCommand cmd = new SqlCommand("select * from PhanLoai order by TenPhanLoai", cnn); cnn.Open(); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { PhanLoaiBO plBO = new PhanLoaiBO(); plBO.MaPhanLoai = dr["MaPhanLoai"].ToString(); plBO.TenPhanLoai=dr["TenPhanLoai"].ToString(); plColl.Add(plBO); // string mapl = dr["maphanloai"].ToString(); // plColl.Add(Tim1PhanLoai(mapl)); } cnn.Close(); return plColl; }
public PhanLoaiCollection TimDSCapNhatPhanLoai(string tenphanloai) { PhanLoaiCollection phanloaicoll = new PhanLoaiCollection(); SqlConnection cnn = new SqlConnection(cnnstr); string query = "select * from PhanLoai where tenphanloai <> '' "; query += "order by tenphanloai"; SqlCommand cmd = new SqlCommand(query, cnn); if (tenphanloai != "") { query = "select * from PhanLoai where tenphanloai like @tenphanloai and tenphanloai <>''"; query += "order by tenphanloai"; cmd = new SqlCommand(query, cnn); cmd.Parameters.AddWithValue("@tenphanloai", "%" + tenphanloai + "%"); } cnn.Open(); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { PhanLoaiBO phanloaiBO = new PhanLoaiBO(); phanloaiBO.MaPhanLoai = dr["maphanloai"].ToString(); phanloaiBO.TenPhanLoai = dr["tenphanloai"].ToString(); phanloaicoll.Add(phanloaiBO); } cnn.Close(); return phanloaicoll; }