private void btnIn_Click(object sender, EventArgs e) { try { int sodong = dgvSP.Rows.Count - 1; if (ttkh() && sodong > 0) { if (!ktkh) { khachhangbll.ThemKhachHang(ref error, txtSDT.Text, txtHoTen.Text, txtDiaChi.Text); dskh = khachhangbll.TimKhachHang(ref error, txtSDT.Text); idkh = Convert.ToInt32(dskh.Tables[0].Rows[0]["idKH"].ToString()); } //insert hóa đơn hoadonBLL.ThemHoaDon(ref error, idkh, idnv, Convert.ToDouble(txtTongTien.Text), DateTime.Now); //Insert Hóa Đơn chi tiết for (int i = 0; i < sodong; i++) { int idsp = Convert.ToInt32(dgvSP.Rows[i].Cells[0].Value.ToString()); int soluongsp = Convert.ToInt32(dgvSP.Rows[i].Cells[2].Value.ToString()); double dongia = Convert.ToDouble(dgvSP.Rows[i].Cells[3].Value.ToString()); //Thêm hóa đơn chi tiết hoadonBLL.ThemCTHoaDon(ref error, idsp, soluongsp, dongia); //Trừ trong kho spbll.SuaSLSP(ref error, idsp, soluongsp * -1); //Nếu hạn bảo hành lớn không if (Convert.ToInt32(dgvSP.Rows[i].Cells[4].Value.ToString()) > 0) { //Thêm bảo hành spbll.ThemBaoHanh(ref error, idsp, idkh, GetDate(Convert.ToInt32(dgvSP.Rows[i].Cells[4].Value.ToString()))); } } MessageBox.Show("Xuất hàng thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); this.Close(); f.Show(); } else { MessageBox.Show("Vui lòng xem lại thông tin khách hàng hoặc đơn hàng rỗng", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } }catch (Exception excep) { MessageBox.Show(excep.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } }
private void btnThem1_Click(object sender, EventArgs e) { hoadon.MaHD = txbMaHD1.Text; hoadon.NgayLap = dtpNgayLap.Value; hoadon.MaNV = ((CBBItem)cbxNhanVien.Items[cbxNhanVien.SelectedIndex]).Value; if (HoaDonBLL.ThemHoaDon(hoadon)) { MessageBox.Show(" Thêm thành công "); HienThiDanhSachHoaDon(); } else { MessageBox.Show(" Thêm thất bại "); } }
private void btnTaoHoaDon_Click(object sender, EventArgs e) { if (currentKhachHang == null) { MessageBox.Show("Vui lòng chọn một khách hàng."); return; } if (gioHang.Count == 0) { MessageBox.Show("Vui lòng thêm sản phẩm khách hàng mua vào giỏ hàng."); return; } try { //thêm hóa đơn vào csdl HoaDon hd = new HoaDon() { SoPhieu = txtSoPhieu.Text, MaNhanVien = currentUser.MaNhanVien, MaKhachhang = currentKhachHang.MaKhachHang, NgayLapPhieu = DateTime.Now, GhiChu = txtGhiChu.Text }; HoaDonBLL hdBLL = new HoaDonBLL(); hdBLL.ThemHoaDon(hd); } catch (Exception ex) { MessageBox.Show("Lỗi đưa hóa đơn vào CSDL:\nChi tiết lỗi:" + ex.Message); return; } //thêm các sản phẩm của hóa đơn(giỏ hàng) vào csdl ThemGioHangVaoCSDL(); MessageBox.Show("Tạo hóa đơn thành công."); frmOrder_Load(); }
private void btnGoiMon_Click(object sender, EventArgs e) { if (lbMaBan.Text == "") { MessageBox.Show("Bạn hãy chọn bàn cần gọi món!"); return; } if (tinhTrang.Equals("Trống")) { string err = ""; if (dbHoaDon.ThemHoaDon(lbMaNVTN.Text, lbMaBan.Text, ref err)) { maHD = lbMaHD.Text = dbHoaDon.MaHDChuaTT(lbMaBan.Text); frmGoiMon fGoiMon = new frmGoiMon(); fGoiMon.ShowDialog(); dgvGoiMon.DataSource = dbHoaDon.LayDSGoiMon(lbMaBan.Text); fpnlPhongLanh.Controls.Clear(); fpnlSanVuon.Controls.Clear(); LoadBan(); } else { MessageBox.Show(err, "Đã xảy ra lỗi khi thêm hóa đơn!"); return; } } else { maHD = lbMaHD.Text; frmGoiMon fGoiMon = new frmGoiMon(); fGoiMon.ShowDialog(); dgvGoiMon.DataSource = dbHoaDon.LayDSGoiMon(lbMaBan.Text); fpnlPhongLanh.Controls.Clear(); fpnlSanVuon.Controls.Clear(); LoadBan(); } }