private void LoadData(string swhere) { try { NhomSanPhamClient client = new NhomSanPhamClient(); BindingSource bds = new BindingSource(); bds.DataSource = client.NhomSanPham_Search(swhere); dgv_DanhMucNhomSP.DataSource = bds.DataSource; FormatGrid(); } catch (Exception ex) { throw ex; } }
private void LoadNhomSanPham() { try { NhomSanPhamClient client = new NhomSanPhamClient(); BindingSource bds = new BindingSource(); bds.DataSource = client.NhomSanPham_GetData(); cbo_NhomSanPham.DataSource = bds.DataSource; cbo_NhomSanPham.ValueMember = "MaNhomSanPham"; cbo_NhomSanPham.DisplayMember = "TenNhomSanPham"; } catch (Exception ex) { throw ex; } }
private void btn_CapNhat_Click(object sender, EventArgs e) { try { if (!Checknull()) { NhomSanPhamClient client = new NhomSanPhamClient(); NhomSanPham nsp = new NhomSanPham(); nsp.MaNhomSanPham = Convert.ToInt32(txt_MaNhomSP.Text); nsp.TenNhomSanPham = txt_TenNhomSP.Text; //Cập nhật thông tin if (!string.IsNullOrEmpty(ProductGroupID)) { if (client.NhomSanPham_Update(nsp)) { MessageBox.Show("Cập nhật nhóm sản phẩm thành công"); LoadData(""); } else { MessageBox.Show("Cập nhật nhóm sản phẩm thất bại"); } } else { if (client.NhomSanPham_Insert(nsp)) { MessageBox.Show("Thêm nhóm sản phẩm thành công"); LoadData(""); } else { MessageBox.Show("Thêm nhóm sản phẩm thất bại"); } } txt_MaNhomSP.ReadOnly = true; txt_TenNhomSP.ReadOnly = true; btn_CapNhat.Visible = false; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
//Nút xoá private void pic_Xoa_Click(object sender, EventArgs e) { try { NhomSanPhamClient client = new NhomSanPhamClient(); if (!string.IsNullOrEmpty(txt_MaNhomSP.Text)) { if (client.NhomSanPham_Delete(Convert.ToInt32(txt_MaNhomSP.Text))) { MessageBox.Show("Xoá nhóm sản phẩm thành công"); LoadData(""); } else { MessageBox.Show("Xoá nhóm sản phẩm thất bại"); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }