public static bool Add(DTO.Ban b) { try { if (Connect.connection.State == ConnectionState.Closed) { Connect.connection.Open(); } else { Connect.connection.Open(); } SqlCommand dc = new SqlCommand(@"insert ban( tenban,tang) values (N'" + b.tenban + "',N'" + b.tentang + "')", Connect.connection); dc.ExecuteNonQuery(); Connect.connection.Close(); return(true); } catch { return(false); } }
private void TaoHoaDonMoi() { // Thêm Hóa Đơn Mới string mahd = DataBus.getInstance().getMaHoaDonMoi(); string maBanMoi ="" ; DTO.Ban currentBan = new DTO.Ban(); for (int i = 0; i < listBanSuDung.Count;i++ ) { if(listBanSuDung[i].tenBan == cbxBan.SelectedItem.ToString()) { maBanMoi = listBanSuDung[i].maBan; } } currentBan = Global.getBanByMaBan(maBanMoi); currentBan.tinhTrang = 2; // Tính tổng tiền tách decimal _tongtien = 0; for (int i = 0; i < dgvMonAn.RowCount; i++) { _tongtien = _tongtien + (int.Parse(dgvMonAn.Rows[i].Cells[0].Value.ToString())) * (decimal.Parse(dgvMonAn.Rows[i].Cells[4].Value.ToString())); } //Tạo hóa đơn mới DTO.HoaDon _HDMoi = new DTO.HoaDon(); _HDMoi.MaHoaDon = mahd; _HDMoi.BanSuDung = currentBan; _HDMoi.BanThanhToan = currentBan; _HDMoi.TongTien = _tongtien; _HDMoi.ThoiGian = DateTime.Now; _HDMoi.DaThanhToan = false; banBUS.updateTinhTrang(currentBan); hdBUS.insertHoaDon(_HDMoi); // Thêm chi tiết hóa đơn mới for (int i = 0; i < dgvMonAn.RowCount; i++) { if ((int.Parse(dgvMonAn.Rows[i].Cells[0].Value.ToString())) != 0) { DTO.CTHoaDon _cthd = new DTO.CTHoaDon(); _cthd.MaCTHoaDon = DataBus.getInstance().getMaCTHoaDonMoi(); DTO.HoaDon _hd = new DTO.HoaDon(); _hd.MaHoaDon = mahd; _cthd.HoaDon = _hd; DTO.MonAn _ma = new DTO.MonAn(); _ma.MaMonAn = dgvMonAn.Rows[i].Cells[1].Value.ToString(); _cthd.MonAn = _ma; _cthd.SoLuong = int.Parse(dgvMonAn.Rows[i].Cells[0].Value.ToString()); _cthd.DaChuanBi = false; _cthd.GhiChu = ""; cthdBUS.insertCTHoaDon(_cthd); } } }