private void RefreshHangHoa() { using (HangHoaBUS bus = new HangHoaBUS()) dataGridView1.DataSource = bus.ListHangHoa(); }
private void dataGridView1_SelectionChanged(object sender, EventArgs e) { if (!dataGridView1.Focused) { dataGridView1.ClearSelection(); tabNoHeader1.Visible = false; return; } if (tabNoHeader1.Visible && tabNoHeader1.SelectedIndex == 1) return; foreach (Control c in tabThem.Controls) errorProvider1.SetError(c, string.Empty); tabNoHeader1.SelectedIndex = 0; tabNoHeader1.Visible = true; btnThem.Text = @"Sửa"; using (HangHoaBUS bus = new HangHoaBUS()) { string tennhanghoa = dataGridView1.CurrentRow?.Cells[0].Value.ToString(); HangHoaDTO info = bus.LoadHangHoa(tennhanghoa); txtTenHangHoa.Text = info.TenHangHoa; txtGiaBan.Text = info.GiaBan.ToString(); txtDonViTinh.Text = info.DonViTinh; txtSoLuongTon.Text = info.SoLuongTon.ToString(); txtGhiChu.Text = info.GhiChu; } }
private void btnThem_Click(object sender, EventArgs e) { foreach (var c in from MaterialSingleLineTextField c in tabThem.Controls.OfType<MaterialSingleLineTextField>() where c != txtGhiChu select c) errorProvider1.SetError(c, string.IsNullOrWhiteSpace(c.Text) ? "Bạn không được để trống thông tin này" : string.Empty); if (tabThem.Controls.OfType<MaterialSingleLineTextField>().Any(c => errorProvider1.GetError(c) != string.Empty)) return; try { using (HangHoaBUS bus = new HangHoaBUS()) { HangHoaDTO info = new HangHoaDTO { TenHangHoa = txtTenHangHoa.Text, GiaBan = Convert.ToInt32(txtGiaBan.Text), DonViTinh = txtDonViTinh.Text, SoLuongTon = Convert.ToInt32(txtSoLuongTon.Text), GhiChu = txtGhiChu.Text }; if (dataGridView1.SelectedRows.Count == 0) bus.InsertHangHoa(info); else { string tenhanghoa = dataGridView1.SelectedRows[0].Cells[0].Value.ToString(); bus.EditHangHoa(info, tenhanghoa); } } } catch (SqlException ex) { if (ex.Number == DbConnection.MssqlEng002627) errorProvider1.SetError(txtTenHangHoa, "Hàng hóa đã tồn tại"); else throw; } RefreshHangHoa(); }
private void btnXoa_Click(object sender, EventArgs e) { if (dataGridView1.CurrentRow == null) return; using (HangHoaBUS bus = new HangHoaBUS()) { if (new XacNhan { Text = @"Bạn có chắc chắn muốn xóa hàng hóa " + dataGridView1.CurrentRow.Cells[0].Value }.ShowDialog() == DialogResult.Yes) { string tenhanghoa = dataGridView1.CurrentRow.Cells[0].Value.ToString(); bus.DeleteHangHoa(tenhanghoa); } } RefreshHangHoa(); }
private void QuanLyBan_Load(object sender, EventArgs e) { using (HangHoaBUS bus = new HangHoaBUS()) dataGridView2.DataSource = bus.ListHangHoa2(); using (KhuVucBUS bus = new KhuVucBUS()) { foreach (DataRow row in bus.ListKhuVuc().Rows) { var group = new ListViewGroup(row["TenKhuVuc"].ToString()); listView1.Groups.Add(group); foreach (DataRow r in bus.ListBan(row["TenKhuVuc"].ToString()).Rows) listView1.Items.Add(new ListViewItem(r["TenBan"].ToString(), bus.IsAvailable(r["MaSoBan"].ToString()) ? 0 : 1, group)).Tag = r["MaSoBan"]; listView1.Items[0].Selected = true; } } using (QuanLyBanBUS bus = new QuanLyBanBUS()) txtSoHoaDon.Text = bus.GetSoHoaDon().ToString(); }