//Cập nhật thông tin nhóm sản phẩm public static bool CapNhatSanPham(NhomSanPhamPublic nhomsanpham) { //ConnectionDataAccess conn = new ConnectionDataAccess(); SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "CapNhatNhomSanPham"; cmd.Parameters.AddWithValue("@MaNSP_NSP", nhomsanpham.MaNSP_NSP); cmd.Parameters.AddWithValue("@TenNSP_NSP", nhomsanpham.TenNSP_NSP); cmd.Parameters.AddWithValue("@DangDung_NSP", (nhomsanpham.DangDung_NSP == true) ? "1" : "0"); cmd.Parameters.AddWithValue("@GhiChu_NSP", nhomsanpham.GhiChu_NSP); return(conn.Execute(cmd)); }
//Import database private void ImportDatabase(string path) { DataTable dt = new DataTable(); dt = UntilitiesBusiness.ImportToDatatable(path); _TongBanGhi = dt.Rows.Count; int i = 0; foreach (DataRow rdt in dt.Rows) { #region 1.Kiểm tra từng bản ghi trong data table if (rdt["MANHOM"].ToString().Equals("")) { _ThatBai++; goto go; } if (UntilitiesBusiness.CheckEist("tbl_NHOMSANPHAM", "MaNSP_NSP", rdt["MANHOM"].ToString().Trim())) { _ThatBai++; goto go; } if (rdt["TENNHOM"].ToString().Equals("")) { _ThatBai++; goto go; } #endregion #region 2. Lấy thông tin NhomSanPhamPublic nsp = new NhomSanPhamPublic(); nsp.MaNSP_NSP = rdt["MANHOM"].ToString(); nsp.TenNSP_NSP = rdt["TENNHOM"].ToString(); nsp.GhiChu_NSP = rdt["GHICHU"].ToString(); nsp.DangDung_NSP = true; #endregion #region 3.Thêm vào csdl NhomSanPhamBusiness.ThemNhomSanPham(nsp); _ThanhCong++; #endregion #region 4. Cập nhật progressbar go: i++; worker.ReportProgress(i * 100 / dt.Rows.Count); #endregion } }
//Nút sửa private void btnSua_Click(object sender, RoutedEventArgs e) { DataRowView dataRow = (DataRowView)dgNhomSanPham.SelectedItem; NhomSanPhamPublic nsp = new NhomSanPhamPublic(); nsp.MaNSP_NSP = dataRow["MaNSP_NSP"].ToString(); nsp.TenNSP_NSP = dataRow["TenNSP_NSP"].ToString(); nsp.DangDung_NSP = (dataRow["DangDung_NSP"].ToString() == "True") ? true : false; nsp.GhiChu_NSP = dataRow["GhiChu_NSP"].ToString(); // nsp.DangDung_NSP = (bool)dataRow["DangDung_NKH"]; NhomSanPhamSuaPresentation wpf = new NhomSanPhamSuaPresentation(); wpf.nhomsanpham = nsp; wpf.SuaNhomSanPham += new EventHandler(SuaNhomSanPham); wpf.ShowDialog(); }
//Sự kiện sửa nhóm sản phẩm public void SuaNhomSanPham(object sender, EventArgs e) { NhomSanPhamSuaPresentation wpf = (NhomSanPhamSuaPresentation)sender; //Lấy thông tin từ wpf con NhomSanPhamPublic nsp = new NhomSanPhamPublic(); nsp = wpf.nhomsanpham; //Thực hiện update if (NhomSanPhamBusiness.CapNhatNhomSanPham(nsp)) { LoadDataToDatagrid(); } else { MessageBox.Show("Cập nhật nhóm sản phẩm thất bại"); } }
//Sự kiện thêm nhóm sản phẩm public void ThemNhomSanPham(object sender, EventArgs e) { NhomSanPhamThemPresentation wpfThemNsp = (NhomSanPhamThemPresentation)sender; //Lấy thông tin từ form con NhomSanPhamPublic nhomsp = new NhomSanPhamPublic(); nhomsp = wpfThemNsp.nhomsanpham; //lưu vào csdl if (NhomSanPhamBusiness.ThemNhomSanPham(nhomsp)) { //Load lại datagrid LoadDataToDatagrid(nhomsp.MaNSP_NSP); } else { MessageBox.Show("Thêm mới thất bại"); } }
//Lấy nhóm sản phẩm cbo public static List <NhomSanPhamPublic> LayNSP() { List <NhomSanPhamPublic> _ListNSP = new List <NhomSanPhamPublic>(); NhomSanPhamPublic _nsp; DataTable _dt = conn.GetDataSet("[Lấy nhóm sản phẩm - sản phẩm]").Tables[0]; _nsp = new NhomSanPhamPublic(); _nsp.MaNSP_NSP = ""; _nsp.TenNSP_NSP = "---Tất cả---"; _ListNSP.Add(_nsp); foreach (DataRow _dr in _dt.Rows) { _nsp = new NhomSanPhamPublic(); _nsp.MaNSP_NSP = _dr["MaNSP_NSP"].ToString(); _nsp.TenNSP_NSP = _dr["TenNSP_NSP"].ToString(); _ListNSP.Add(_nsp); } return(_ListNSP); }
//Lấy nhóm sản phẩm cbo public static List <NhomSanPhamPublic> LayNSP() { List <NhomSanPhamPublic> _ListNSP = new List <NhomSanPhamPublic>(); NhomSanPhamPublic _nsp; DataTable _dt = Conn.GetDataSet("[Lấy nhóm sản phẩm - sản phẩm]").Tables[0]; foreach (DataRow _dr in _dt.Rows) { _nsp = new NhomSanPhamPublic(); _nsp.MaNSP_NSP = _dr["MaNSP_NSP"].ToString(); _nsp.TenNSP_NSP = _dr["TenNSP_NSP"].ToString(); _nsp.DangDung_NSP = (bool)_dr["DangDung_NSP"]; if (!_nsp.DangDung_NSP) { continue; } _ListNSP.Add(_nsp); } return(_ListNSP); }
//Cập nhật nhóm sản phẩm public static bool CapNhatNhomSanPham(NhomSanPhamPublic nhomsanpham) { return(NhomSanPhamDataAccess.CapNhatSanPham(nhomsanpham)); }
//Thêm mới một nhóm sản phẩm public static bool ThemNhomSanPham(NhomSanPhamPublic nhomsanpham) { return(NhomSanPhamDataAccess.ThemNhomSanPham(nhomsanpham)); }