private void FrmThongTinNhaHang_Load(object sender, EventArgs e) { THONGTINNHAHANG tt = db.THONGTINNHAHANGs.FirstOrDefault(); if (tt == null) { return; } txtTenNhaHang.Text = tt.TEN; txtDiaChi.Text = tt.DIACHI; }
private void btnLuu_Click(object sender, EventArgs e) { if (txtTenNhaHang.Text == "") { MessageBox.Show("Tên nhà hàng không được để trống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (txtDiaChi.Text == "") { MessageBox.Show("Địa chỉ của bạn không được để trống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } THONGTINNHAHANG tt = db.THONGTINNHAHANGs.FirstOrDefault(); if (tt == null) { tt = new THONGTINNHAHANG(); tt.TEN = txtTenNhaHang.Text; tt.DIACHI = txtDiaChi.Text; db.THONGTINNHAHANGs.Add(tt); } else { tt.TEN = txtTenNhaHang.Text; tt.DIACHI = txtDiaChi.Text; } try { db.SaveChanges(); MessageBox.Show("Thay đổi thông tin nhà hàng thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } catch { MessageBox.Show("Thay đổi thông tin nhà hàng thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void FrmRpHoaDon_Load(object sender, EventArgs e) { // CHi tiết hóa đơn int i = 0; hOADONBindingSource.DataSource = db.CHITIETHOADONs.Where(p => p.HOADONID == hd.ID).ToList() .Select(p => new { STT = ++i, MatHang = db.MATHANGs.Where(k => k.ID == p.MATHANGID).FirstOrDefault().TEN, SoLuong = p.SOLUONG, DonGia = ((int)p.DONGIA).ToString("N0"), ThanhTien = ((int)p.THANHTIEN).ToString("N0"), DonViTinh = db.MATHANGs.Where(k => k.ID == p.MATHANGID).FirstOrDefault().DONVITINH }) .ToList(); int tKhuyenMai = (int)((float)hd.TONGTIEN / 100.0 * khuyenmai); int tThanhToan = ((int)hd.TONGTIEN - tKhuyenMai); THONGTINNHAHANG thongtin = db.THONGTINNHAHANGs.FirstOrDefault(); ReportParameter[] listPara = new ReportParameter[] { new ReportParameter("MaHoaDon", hd.MAHOADON), new ReportParameter("NgayBan", ((DateTime)hd.NGAYNHAP).ToString("dd/MM/yyyy")), new ReportParameter("NhanVienBanHang", db.NHANVIENs.Where(p => p.ID == hd.NHANVIENID).FirstOrDefault().TEN), new ReportParameter("TongTien", ((int)hd.TONGTIEN).ToString("N0")), new ReportParameter("TenNhaHang", thongtin.TEN), new ReportParameter("DiaChi", thongtin.DIACHI), new ReportParameter("KhuyenMai", tKhuyenMai.ToString("N0")), new ReportParameter("ThanhToan", tThanhToan.ToString("N0")), new ReportParameter("PhanTramKhuyenMai", khuyenmai + "%") }; this.rpViewerHoaDon.LocalReport.SetParameters(listPara); this.rpViewerHoaDon.LocalReport.Refresh(); this.rpViewerHoaDon.RefreshReport(); this.rpViewerHoaDon.RefreshReport(); }