private void ThemHoaDon() { DTO.HoaDon hoadon = new DTO.HoaDon() { Ma = txtMaHD.Text, Khachhangma = txtMaKH.Text, Nhanvienma = txtMaNV.Text, Ngaylap = dtpNgayLap.Value, Tongtien = decimal.Parse(labTongTien.Text.Split(' ')[2]) }; if (hoadon.Them() == 1) { for (int i = 0; i < dgvCTHD.Rows.Count; i++) { DTO.ChiTietHoaDon chitiet = new DTO.ChiTietHoaDon() { Hoadonma = hoadon.Ma, Mathangma = dgvCTHD.Rows[i].Cells[0].Value.ToString(), Soluong = (double)dgvCTHD.Rows[i].Cells[3].Value, Giaban = (decimal)dgvCTHD.Rows[i].Cells[4].Value }; chitiet.Them(); DTO.MatHang.Update_SoLuongMatHang(chitiet.Mathangma); } Clear_InputHoaDon(); MessageBox.Show("Đã thêm", "", MessageBoxButtons.OK); } }
private void btnThemHD_Click(object sender, EventArgs e) { hoadon = new DTO.HoaDon { MaHD = txtMaHD.Text, MaKH = Int32.Parse(cmbKhachHang.SelectedValue.ToString()), MaNV = Int32.Parse(cmbNhanVien.SelectedValue.ToString()), }; // kiểm tra chi tiết if (DsChiTiet.Count <= 0) { MessageBox.Show("Không có chi tiết nào trong hóa đơn.\nVui lòng kiểm tra lại"); return; } // gọi hàm thêm của Bus BanHangBUS.ThemHoaDon(hoadon, DsChiTiet); MessageBox.Show(BanHangBUS.Message); if (BanHangBUS.IsSuccess) { // Viết phần hiển thị màn hình In chổ này try { DsChiTiet = new List <DTO.ChiTietHoaDon>(); dgvChiTiet.DataSource = DsChiTiet; dgvChiTiet.Refresh(); maHD = TaoMaHD(); ResetControls(); chitiet = null; } catch { } } }
private void dgvChiTiet_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { try { int rowIndex = e.RowIndex; string id = dgvChiTiet.Rows[rowIndex].Cells[1].Value.ToString(); chitiet = DsChiTiet.Find(ct => ct.MaSach == id); if (chitiet == null) { return; } txtSoLuong.Text = chitiet.SoLuong.ToString(); cmbSach.SelectedValue = chitiet.MaSach; } catch (Exception er) { } }
private void btnThemCT_Click(object sender, EventArgs e) { if (!CheckDetail()) { return; } chitiet = new DTO.ChiTietHoaDon { MaHD = maHD, MaSach = cmbSach.SelectedValue.ToString(), SoLuong = Int32.Parse(txtSoLuong.Text), DonGia = DsSach.Find(s => s.MaSach == cmbSach.SelectedValue.ToString()).GiaBanLe, TenSach = DsSach.Find(s => s.MaSach == cmbSach.SelectedValue.ToString()).TenSach }; chitiet.DonGia = BanHangBUS.TinhDonGia(Int32.Parse(cmbKhachHang.SelectedValue.ToString()), chitiet); BindingSource binding = new BindingSource(); binding.Clear(); if (DsChiTiet.Find(ct => ct.MaSach == chitiet.MaSach) == null) { DsChiTiet.Add(chitiet); } else { DialogResult res = MessageBox.Show("Bạn vừa thêm một sách đã có trong hóa đơn\n Bạn có muốn cập nhật số lượng hay không?", "Thông báo", MessageBoxButtons.YesNo); if (res == DialogResult.No) { return; } DsChiTiet.Find(ct => ct.MaSach == chitiet.MaSach).SoLuong = chitiet.SoLuong; } binding.DataSource = DsChiTiet; dgvChiTiet.DataSource = binding; //dgvChiTiet.Refresh(); try { //dgvChiTiet.DataSource = new List<DTO.ChiTietHoaDon>(); txtSoLuong.Text = "0"; cmbSach.SelectedIndex = 0; chitiet = null; txtTongTien.Text = DsChiTiet.Sum(ct => ct.ThanhTien).ToString("0,0"); } catch { } }
private void btnXoaHD_Click(object sender, EventArgs e) { DialogResult res = MessageBox.Show("Bạn có chắc muốn xóa hóa đơn này không?\n" + "Chú ý: sau khi xóa tất cả các chi tiết sẽ bị xóa theo!", "Thông báo", MessageBoxButtons.YesNo); if (res == DialogResult.No) { return; } try { DsChiTiet = new List <DTO.ChiTietHoaDon>(); dgvChiTiet.DataSource = DsChiTiet; dgvChiTiet.Refresh(); maHD = TaoMaHD(); ResetControls(); chitiet = null; } catch { } }
private void btnXoaCT_Click(object sender, EventArgs e) { if (chitiet == null) { return; } DsChiTiet.Remove(chitiet); try { dgvChiTiet.DataSource = new List <DTO.ChiTietHoaDon>(); dgvChiTiet.Refresh(); dgvChiTiet.DataSource = DsChiTiet; dgvChiTiet.Refresh(); txtSoLuong.Text = "0"; cmbSach.SelectedIndex = 0; chitiet = null; txtTongTien.Text = DsChiTiet.Sum(ct => ct.ThanhTien).ToString("0,0"); } catch { } }
private void SuaHoaDon() { DTO.HoaDon hoadon = new DTO.HoaDon() { Ma = txtMaHD.Text, Khachhangma = txtMaKH.Text, Nhanvienma = txtMaNV.Text, Ngaylap = dtpNgayLap.Value, Tongtien = decimal.Parse(labTongTien.Text.Split(' ')[2]) }; if (hoadon.Sua() == 1) { //them sua chi tiet for (int i = 0; i < dgvCTHD.Rows.Count; i++) { DTO.ChiTietHoaDon chitiet = new DTO.ChiTietHoaDon() { Hoadonma = hoadon.Ma, Mathangma = dgvCTHD.Rows[i].Cells[0].Value.ToString(), Soluong = (double)dgvCTHD.Rows[i].Cells[3].Value, Giaban = (decimal)dgvCTHD.Rows[i].Cells[4].Value }; DataRow[] rows = tb_chitietcu.Select(string.Format("[Mã mặt hàng] = '{0}'", dgvCTHD.Rows[i].Cells[0].Value.ToString())); if (rows.Length > 0) { if ((double)rows[0].ItemArray[4] != chitiet.Soluong) { chitiet.Sua(); } } else { chitiet.Them(); } DTO.MatHang.Update_SoLuongMatHang(chitiet.Mathangma); } //xoa chi tiet bool xoa; for (int i = 0; i < tb_chitietcu.Rows.Count; i++) { xoa = true; for (int j = 0; j < dgvCTHD.Rows.Count; j++) { if (dgvCTHD.Rows[j].Cells[0].Value.ToString() == tb_chitietcu.Rows[i].ItemArray[0].ToString()) { xoa = false; break; } } if (xoa) { DTO.ChiTietHoaDon.Xoa(tb_chitietcu.Rows[i].ItemArray[0].ToString(), txtMaHD.Text); DTO.MatHang.Update_SoLuongMatHang(tb_chitietcu.Rows[i].ItemArray[0].ToString()); } } Clear_InputHoaDon(); MessageBox.Show("Đã sửa", "", MessageBoxButtons.OK); pnlThemHD.Visible = false; pnlXemHD.Visible = true; } }