//Tìm public List <LoaiSanPhamDTO> GetLoaiSPWK(string MaLSP) { string sql = "SELECT * FROM LoaiSanPham WHERE MaLoaiSanPham = '" + MaLSP + "'"; List <LoaiSanPhamDTO> list = new List <LoaiSanPhamDTO>(); Connect(); string TenLSP; try { SqlDataReader rd = myExecuteDataReader(sql); while (rd.Read()) { MaLSP = rd[0].ToString(); TenLSP = rd[1].ToString(); LoaiSanPhamDTO lsp = new LoaiSanPhamDTO(MaLSP, TenLSP); list.Add(lsp); } rd.Close(); return(list); } catch (SqlException ex) { throw ex; } }
private void btnTimsp_Click(object sender, EventArgs e) { try { SanPhamDTO sp = new SanPhamDTO(); LoaiSanPhamDTO loaisp = new LoaiSanPhamDTO(); if (cbxTimTheoSP.SelectedIndex == 0) { sp.ma_sp = txtTimTheosp.Text; if (SanPhamBUS.Search_MaSP(sp).Rows.Count == 0) { MessageBox.Show("Không có thông tin bạn cần tìm", "Thông báo", MessageBoxButtons.OK); } else { dgvSanPham.DataSource = SanPhamBUS.Search_MaSP(sp); } } if (cbxTimTheoSP.SelectedIndex == 1) { loaisp.ten_loai_sp = txtTimTheosp.Text; if (SanPhamBUS.Search_LoaiSP(loaisp).Rows.Count == 0) { MessageBox.Show("Không có thông tin bạn cần tìm", "Thông báo", MessageBoxButtons.OK); } else { dgvSanPham.DataSource = SanPhamBUS.Search_LoaiSP(loaisp); } } if (cbxTimTheoSP.SelectedIndex == 2) { sp.ten_sp = txtTimTheosp.Text; if (SanPhamBUS.Search_TenSP(sp).Rows.Count == 0) { MessageBox.Show("Không có thông tin bạn cần tìm", "Thông báo", MessageBoxButtons.OK); } else { dgvSanPham.DataSource = SanPhamBUS.Search_TenSP(sp); } } if (cbxTimTheoSP.SelectedIndex == 3) { sp.hang_san_xuat = txtTimTheosp.Text; if (SanPhamBUS.Search_HSXSP(sp).Rows.Count == 0) { MessageBox.Show("Không có thông tin bạn cần tìm", "Thông báo", MessageBoxButtons.OK); } else { dgvSanPham.DataSource = SanPhamBUS.Search_HSXSP(sp); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
protected void grvDSLoaiSP_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "ChonLoaiSP") { string maLoaiSP = e.CommandArgument.ToString(); LoaiSanPhamDTO loaisp = LoaiSanPhamBUS.LayThongTinLoaiSanPham(maLoaiSP); if (loaisp != null) { txtMaLoaiSP.Text = loaisp.MaLoaiSP; txtTenLoaiSP.Text = loaisp.TenLoaiSP; chkTrangThai.Checked = loaisp.TrangThai; GiaoDienThem(false); } } if (e.CommandName == "XoaLoaiSP") { string maLoaiSP = e.CommandArgument.ToString(); if (TaiKhoanBUS.XoaTK(maLoaiSP)) { XoaForm(); LoadDSLoaiSanPham(); } else { Response.Write("<script>alert('Xóa tài khoản thất bại');</script>"); } } }
private void FormChonSanPham_Load(object sender, EventArgs e) { List <SanPhamDTO> sanPhamDTO = new List <SanPhamDTO>(); sanPhamDTO = SanPhamBUS.SelectSanPhamAll(); for (int i = 0; i < sanPhamDTO.Count; i++) { dataGridView_ChoSanPham.Rows.Add(i + 1, sanPhamDTO[i].MaSanPham, sanPhamDTO[i].TenSanPham, LoaiSanPhamBUS.SelectLoaiSanPhamById(sanPhamDTO[i].MaLoaiSanPham).TenLoaiSanPham, false); } List <LoaiSanPhamDTO> lstcbspDTO = LoaiSanPhamBUS.SelectLoaiSanPhamAll(); LoaiSanPhamDTO all = new LoaiSanPhamDTO(); all.MaLoaiSanPham = "Tất cả"; all.TenLoaiSanPham = "Tất cả"; lstcbspDTO.Insert(0, all); comboBoxLoaiSanPham.DisplayMember = "TenLoaiSanPham"; comboBoxLoaiSanPham.ValueMember = "TenLoaiSanPham"; comboBoxLoaiSanPham.DataSource = lstcbspDTO; comboBoxLoaiSanPham.SelectedIndex = 0; }
private void btXoa_Click(object sender, EventArgs e) { string MaLSP; MaLSP = txtMaloai.Text; LoaiSanPhamDTO lsp = new LoaiSanPhamDTO(MaLSP); if (string.IsNullOrEmpty(txtMaloai.Text)) { MessageBox.Show("Vui lòng nhập mã LSP cần xoá", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int numOfRows = loaisanphamBUS.Delete(lsp); if (numOfRows == 0) { MessageBox.Show("Không tìm được để xoá", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Xóa thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } GridLoaiSP.DataSource = loaisanphamBUS.GetLoaiSP(); }
private void btThem_Click(object sender, EventArgs e) { try { string MaLSP, TenLSP; MaLSP = txtMaloai.Text; TenLSP = txtTenloai.Text; LoaiSanPhamDTO lsp = new LoaiSanPhamDTO(MaLSP, TenLSP); if (string.IsNullOrEmpty(txtMaloai.Text)) { MessageBox.Show("Vui lòng nhập mã loại sản phẩm cần thêm", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } int numOfRows = loaisanphamBUS.Add(lsp); if (numOfRows > 0) { MessageBox.Show("Thêm thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); Reset(); } GridLoaiSP.DataSource = loaisanphamBUS.GetLoaiSP(); } catch (SqlException ex) { MessageBox.Show("Thêm thất bại, mã loại bị trùng\n" + ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); Reset(); } }
private void btSua_Click(object sender, EventArgs e) { string maloai, tenloai; maloai = txtMaloai.Text; tenloai = txtTenloai.Text; LoaiSanPhamDTO lsp = new LoaiSanPhamDTO(maloai, tenloai); try { int num = loaisanphamBUS.Update(lsp); if (num > 0) { MessageBox.Show("Sửa thành công", "Sửa", MessageBoxButtons.OK, MessageBoxIcon.Information); GridLoaiSP.DataSource = loaisanphamBUS.GetLoaiSP(); } else { MessageBox.Show("Không tìm được để sửa", "Sửa", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (SqlException ex) { MessageBox.Show("Lỗi hệ thống\n" + ex.Message, "Sửa", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public static bool ThemLoaiSp(LoaiSanPhamDTO lsp) { string query = "INSERT INTO dbo.LoaiSanPham (TenLoaiSP) VALUES (@TenLoaiSP)"; SqlParameter[] param = new SqlParameter[1]; param[0] = new SqlParameter("@TenLoaiSP", lsp.TenLoaiSP); return(DataProvider.ExecuteInsertQuery(query, param) == 1); }
public static LoaiSanPhamDTO ConvertToDTO(DataRow dr) { LoaiSanPhamDTO lsp = new LoaiSanPhamDTO(); lsp.MaLoaiSP = dr["MaLoaiSP"].ToString(); lsp.TenLoaiSP = dr["TenLoaiSP"].ToString(); return(lsp); }
public static bool UpdateLoaiSanPhamById(LoaiSanPhamDTO loaiSanPhamDTO) { List <SqlParameter> sqlParamas = new List <SqlParameter>(); sqlParamas.Add(new SqlParameter("@MaLoaiSanPham", loaiSanPhamDTO.MaLoaiSanPham)); sqlParamas.Add(new SqlParameter("@TenLoaiSanPham", loaiSanPhamDTO.TenLoaiSanPham)); return(DataProvider.ExecuteNoneQuery("usp_UpdateLoaiSanPhamById ", sqlParamas)); }
public void SetUp() { GetLSP = new List <LoaiSanPhamDTO>(); lspDAO = new LoaiSanPhamDAO(); lsp1 = new LoaiSanPhamDTO("1TCCM", "Thờ cúng chó mèo"); lsp2 = new LoaiSanPhamDTO("2PTCM", "Phẫu thuật chó mèo"); lsp3 = new LoaiSanPhamDTO("3LCM", "Lẩu chó mèo"); }
public static int ThemLoaiSP(LoaiSanPhamDTO dto) { if (LoaiSanPhamDAO.KiemTraTonTai(dto.MaLoaiSP)) { return(-1); } return(LoaiSanPhamDAO.ThemLoaiSP(dto)); }
public static Boolean Update(LoaiSanPhamDTO loaiSanPhamDTO) { if (LoaiSanPhamDAO.IsExist(loaiSanPhamDTO.MaLoaiSP)) { return(LoaiSanPhamDAO.Update(loaiSanPhamDTO)); } return(false); }
public static LoaiSanPhamDTO ConvertToDTO(DataRow dr) { LoaiSanPhamDTO loaiSP = new LoaiSanPhamDTO(); loaiSP.MaLoaiSP = dr["MaLoaiSP"].ToString(); loaiSP.TenLoaiSP = dr["TenLoaiSP"].ToString(); loaiSP.TrangThai = Convert.ToBoolean(dr["TrangThai"]); return(loaiSP); }
private static LoaiSanPhamDTO ConvertToDTO(DataRow dr) { LoaiSanPhamDTO result = new LoaiSanPhamDTO(); result.MaLoaiSP = Convert.ToString(dr["MaLoaiSP"]); result.TenLoaiSP = Convert.ToString(dr["TenLoaiSP"]); result.TrangThai = Convert.ToBoolean(dr["TrangThai"]); return(result); }
public static bool CapNhatLSP(LoaiSanPhamDTO lsp, string id) { string query = "UPDATE dbo.LoaiSanPham SET TenLoaiSP=@TenLoaiSP WHERE MaLoaiSP=@ID"; SqlParameter[] param = new SqlParameter[2]; param[0] = new SqlParameter("@TenLoaiSP", lsp.TenLoaiSP); param[1] = new SqlParameter("@ID", id); return(DataProvider.ExecuteUpdateQuery(query, param) == 1); }
public static Boolean Update(LoaiSanPhamDTO loaiSanPhamDTO) { String query = "UPDATE LoaiSanPham SET TenLoaiSP = @TenLoaiSP, TrangThai = @TrangThai WHERE MaLoaiSP = @MaLoaiSP"; SqlParameter[] param = new SqlParameter[3]; param[0] = new SqlParameter("@MaLoaiSP", loaiSanPhamDTO.MaLoaiSP); param[1] = new SqlParameter("@TenLoaiSP", loaiSanPhamDTO.TenLoaiSP); param[2] = new SqlParameter("@TrangThai", loaiSanPhamDTO.TrangThai); return(DataProvider.ExecuteUpdateQuery(query, param) == 1); }
public static Boolean Insert(LoaiSanPhamDTO loaiSanPhamDTO) { String query = "INSERT INTO LoaiSanPham (MaLoaiSP, TenLoaiSP, TrangThai) VALUES (@MaLoaiSP, @TenLoaiSP, @TrangThai)"; SqlParameter[] param = new SqlParameter[3]; param[0] = new SqlParameter("@MaLoaiSP", loaiSanPhamDTO.MaLoaiSP); param[1] = new SqlParameter("@TenLoaiSP", loaiSanPhamDTO.TenLoaiSP); param[2] = new SqlParameter("@TrangThai", loaiSanPhamDTO.TrangThai); return(DataProvider.ExecuteInsertQuery(query, param) == 1); }
public static bool ThemLoaiSP(LoaiSanPhamDTO loaisp) { string query = "insert into LoaiSanPham (MaLoaiSP,TenLoaiSP,TrangThai) values (@MaLoaiSP,@TenLoaiSP,@TrangThai)"; SqlParameter[] param = new SqlParameter[3]; param[0] = new SqlParameter("@MaLoaiSP", loaisp.MaLoaiSP); param[1] = new SqlParameter("@TenLoaiSP", loaisp.TenLoaiSP); param[2] = new SqlParameter("@TrangThai", loaisp.TrangThai); return(DataProvider.ExecuteInsertQuery(query, param) == 1); }
public static bool SuaLoaiSP(LoaiSanPhamDTO loaisp) { string query = "update LoaiSanPham set TenLoaiSP = @TenLoaiSP, TrangThai = @TrangThai where MaLoaiSP = @MaLoaiSP"; SqlParameter[] param = new SqlParameter[3]; param[0] = new SqlParameter("@TenLoaiSP", loaisp.TenLoaiSP); param[1] = new SqlParameter("@TrangThai", loaisp.TrangThai); param[2] = new SqlParameter("@MaLoaiSP", loaisp.MaLoaiSP); return(DataProvider.ExecuteUpdateQuery(query, param) == 1); }
public int Add(LoaiSanPhamDTO loaisanpham) { try { return(loaisanphamDAO.Add(loaisanpham)); } catch (SqlException ex) { throw ex; } }
public static bool SuaLoaiSP(LoaiSanPhamDTO loaisp) { if (!LoaiSanPhamDAO.KTMaLoaiSPTonTai(loaisp.MaLoaiSP)) { return(false); } else { return(LoaiSanPhamDAO.SuaLoaiSP(loaisp)); } }
private void buttonYes_Click(object sender, EventArgs e) { bool flag = true; if (dataGridView_QuanLyLoaiSanPham.Rows[Index].Cells["ColTenLoaiSanPham"].Value == null) { MessageBox.Show("Tên loại sản phẩm không được để trống"); dataGridView_QuanLyLoaiSanPham.CurrentCell = dataGridView_QuanLyLoaiSanPham.Rows[Index].Cells["ColTenLoaiSanPham"]; dataGridView_QuanLyLoaiSanPham.BeginEdit(true); flag = false; } if (flag) { LoaiSanPhamDTO lspDTO = new LoaiSanPhamDTO(); lspDTO.TenLoaiSanPham = dataGridView_QuanLyLoaiSanPham.Rows[Index].Cells["ColTenLoaiSanPham"].Value.ToString(); if (Status == 1)//Them tham so { lspDTO.MaLoaiSanPham = LoaiSanPhamBUS.CreateLoaiSanPhamId(); dataGridView_QuanLyLoaiSanPham.Rows[Index].Cells["ColMaLoaiSanPham"].Value = lspDTO.MaLoaiSanPham; dataGridView_QuanLyLoaiSanPham.Rows[Index].Cells["ColSTT"].Value = (Index + 1).ToString(); if (LoaiSanPhamBUS.InsertLoaiSanPham(lspDTO)) { dataGridView_QuanLyLoaiSanPham.Rows[Index].ReadOnly = true; MessageBox.Show("Thêm thành công"); } else { dataGridView_QuanLyLoaiSanPham.Rows.RemoveAt(Index); MessageBox.Show("Thêm thất bại"); } } else if (Status == 2) { lspDTO.MaLoaiSanPham = dataGridView_QuanLyLoaiSanPham.Rows[Index].Cells["ColMaLoaiSanPham"].Value.ToString(); if (LoaiSanPhamBUS.UpdateLoaiSanPhamById(lspDTO)) { dataGridView_QuanLyLoaiSanPham.Rows[Index].ReadOnly = true; MessageBox.Show("Cập nhật thành công"); } else { MessageBox.Show("Cập nhật thất bại"); dataGridView_QuanLyLoaiSanPham.Rows[Index].Cells["ColTenLoaiSanPham"].Value = BackupLoaiSanPhamDTO.TenLoaiSanPham; dataGridView_QuanLyLoaiSanPham.Rows[Index].ReadOnly = true; } } Reset(); } }
protected void btncapnhat(object sender, RepeaterCommandEventArgs e) { if (e.CommandName == "ChonTK") { string ID = e.CommandArgument.ToString(); LoaiSanPhamDTO lsp = LoaiSanPhamBUS.LayDSLoaiSanPhamID(ID); txtid.Text = lsp.MaLoaiSP; txttenloai.Text = lsp.TenLoaiSP; txtid.Enabled = false; } }
public static int CapNhatLoaiSP(LoaiSanPhamDTO dto) { string query = "UPDATE LoaiSanPham SET TenLoaiSP=@tenlsp,TrangThai=@trangthai WHERE MaLoaiSP=@malsp"; List <SqlParameter> param = new List <SqlParameter>() { new SqlParameter("malsp", dto.MaLoaiSP), new SqlParameter("tenlsp", dto.TenLoaiSP), new SqlParameter("trangthai", dto.TrangThai) }; return(DataProvider.ExecuteUpdateQuery(query, param.ToArray())); }
public static int ThemLoaiSP(LoaiSanPhamDTO dto) { string query = "INSERT INTO LoaiSanPham VALUES(@malsp,@tenlsp,@trangthai)"; List <SqlParameter> param = new List <SqlParameter>() { new SqlParameter("malsp", dto.MaLoaiSP), new SqlParameter("tenlsp", dto.TenLoaiSP), new SqlParameter("trangthai", dto.TrangThai) }; return(DataProvider.ExecuteInsertQuery(query, param.ToArray())); }
public int GetIDByLoaiSP(string tenLSP) { string query = "SELECT * FROM dbo.LoaiSanPham WHERE TenLoaiSanPham = N'" + tenLSP + "'"; DataTable table = DataProvider.Instance.ExecuteQuery(query); foreach (DataRow item in table.Rows) { LoaiSanPhamDTO sp = new LoaiSanPhamDTO(item); return(sp.ID); } return(0); }
public string GetLoaiSP(string tenLoaiSanPham) { string query = "SELECT * FROM dbo.LoaiSanPham WHERE TenLoaiSanPham = N'" + tenLoaiSanPham + "'"; DataTable table = DataProvider.Instance.ExecuteQuery(query); foreach (DataRow item in table.Rows) { LoaiSanPhamDTO sp = new LoaiSanPhamDTO(item); return(sp.TenloaiSanPham); } return(string.Empty); }
public string layDanhMuc(string tenLSP) { string query = "Select * From LoaiSanPham where TenLoaiSanPham = N'" + tenLSP + "' "; DataTable table = DataProvider.Instance.ExecuteQuery(query); foreach (DataRow item in table.Rows) { LoaiSanPhamDTO acc = new LoaiSanPhamDTO(item); return(acc.DanhMuc); } return(string.Empty); }
public string GetDanhMucSPByID(int idLoai) { string query = "SELECT * FROM dbo.LoaiSanPham WHERE id = N'" + idLoai + "'"; DataTable table = DataProvider.Instance.ExecuteQuery(query); foreach (DataRow item in table.Rows) { LoaiSanPhamDTO sp = new LoaiSanPhamDTO(item); return(sp.DanhMuc); } return(string.Empty); }