private void btnXoa_Click(object sender, EventArgs e) { var context = new CaPheContext(); var sanPham = new Query_SanPham(); if (txtTen.Text.Replace(" ", "") != "") { DialogResult dialogResult = MessageBox.Show("Bạn có xóa món này chứ!", "Thêm sản phẩm", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) { var tenMon = txtTen.Text; SanPhamId = int.Parse(gvMenu.GetRowCellValue(gvMenu.FocusedRowHandle, gvMenu.Columns[0]).ToString()); if (sanPham.Delete_Mon(tenMon, SanPhamId)) { MessageBox.Show("Đã xóa sản phẩm"); Load_Menu(); } else { MessageBox.Show("Sản phẩm không tồn tại!"); } } } else { MessageBox.Show("Xin nhập thêm thông tin!", "Thêm sản phẩm", MessageBoxButtons.OK, MessageBoxIcon.Information); } ClearInfor(); }
public NhanVien GetNhanVien(CaPheContext context) { var nv = (from nhanvien in context.NhanViens where nhanvien.NhanVienId.Equals(Global.NhanVienID) select nhanvien).FirstOrDefault(); return(nv); }
public int KiemTra(CaPheContext context, string cmnd) { var sp = (from nv in context.NhanViens where nv.CMND.Contains(cmnd) select nv.NhanVienId).SingleOrDefault(); return(sp); }
public int GetIdDanhMuc(string TenDanhMuc, CaPheContext caPheContext) { int sp = (from item in caPheContext.LoaiSanPhams where item.TenLoaiSanPham.ToUpper().Trim() == (TenDanhMuc.ToUpper()) select item.LoaiSanPhamId).SingleOrDefault(); return(sp); }
public bool KiemTraNgay(CaPheContext context, DateTime date) { var query = (from hoadon in context.HoaDons where DbFunctions.TruncateTime(hoadon.NgayLap) == date select hoadon).ToList(); if (query.Count > 0) { return(true); } return(false); }
public void CapNhatTrangThaiHoaDon(int ID_HoaDon, CaPheContext context, double tongtien) { var hd = (from hoadon in context.HoaDons where hoadon.HoaDonId == ID_HoaDon select hoadon).ToList(); foreach (var hoadon in hd) { hoadon.TongGia = tongtien; hoadon.TinhTrang = 1; context.Entry(hoadon).State = EntityState.Modified; context.SaveChanges(); } }
public double TinhTongDoanhThu(CaPheContext context, double doanhthu, DateTime date1, DateTime date2) { doanhthu = 0; var hoaDons = (from hoadon in context.HoaDons where DbFunctions.TruncateTime(hoadon.NgayLap) >= date1.Date && DbFunctions.TruncateTime(hoadon.NgayLap) <= date2.Date && hoadon.TinhTrang.Equals(1) select hoadon).ToList(); foreach (var hd in hoaDons) { doanhthu += hd.TongGia; } return(doanhthu); }
public bool Delete_NV(CaPheContext context, string cmnd) { int id = KiemTra(context, cmnd); Query_TaiKhoan taiKhoan = new Query_TaiKhoan(); if (id != 0) { taiKhoan.Delete_TaiKhoan(id); var nhanvien = (from item in context.NhanViens where item.NhanVienId.Equals(id) select item).FirstOrDefault(); context.NhanViens.Remove(nhanvien); context.SaveChanges(); return(true); } return(false); }
public bool Update_NV(CaPheContext context, int id, string hoten, string quequan, string chucvu, string cmnd, string sdt, DateTime ngaysinh, DateTime ngayvaolam, byte[] image) { if (id != 0) { var nhanvien = (from item in context.NhanViens where item.NhanVienId.Equals(id) select item).FirstOrDefault(); nhanvien.QueQuan = quequan; nhanvien.HoTenNV = hoten; nhanvien.ChucVu = chucvu; nhanvien.SDT_NV = sdt; nhanvien.CMND = cmnd; nhanvien.NgaySinh = ngaysinh; nhanvien.NgayVaoLam = ngayvaolam; context.SaveChanges(); return(true); } return(false); }
private void btnSua_Click(object sender, EventArgs e) { //if (picImage.Image == null) //{ // XtraMessageBox.Show("Bạn chưa UpLoad hình!"); // return; //} var contextt = new CaPheContext(); if (txtHoTen.Text.Replace(" ", "") != "" && txtSDT.Text.Replace(" ", "") != "" && txtCMND.Text.Replace(" ", "") != "" && txtChucVu.Text.Replace(" ", "") != "") { DialogResult dialogResult = MessageBox.Show("Bạn có muốn cập nhật nhân viên này chứ!", "Cập nhật nhân viên ", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) { int id = int.Parse(gvNhanVien.GetRowCellValue(gvNhanVien.FocusedRowHandle, gvNhanVien.Columns[7]).ToString()); hoten = txtHoTen.Text; quequan = txtQueQuan.Text; chucvu = txtChucVu.Text; sdt = txtSDT.Text; cmnd = txtCMND.Text; ngaysinh = Convert.ToDateTime(dtpNgaySinh.Value); ngayvaolam = Convert.ToDateTime(dtpNgayVaoLam.Value); // hinh = ConvertImageToBinary(picImage.Image); if (nv.Update_NV(contextt, id, hoten, quequan, chucvu, cmnd, sdt, ngaysinh, ngayvaolam, hinh)) { MessageBox.Show("Đã cập nhật nhân viên"); } else { MessageBox.Show("Nhân viên chưa được cập nhật!"); } } Load_NV(); ClearInfo(); clearTaiKhoanInfor(); } else { MessageBox.Show("Vui lòng điền hết thông tin", "Cập Nhật Nhan vien", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public bool Add_NV(CaPheContext context, string hoten, string quequan, string chucvu, string cmnd, string sdt, DateTime ngaysinh, DateTime ngayvaolam, byte[] image) { if (KiemTra(context, cmnd) == 0) { var nhanvien = new NhanVien() { HoTenNV = hoten, QueQuan = quequan, ChucVu = chucvu, SDT_NV = sdt, CMND = cmnd, NgaySinh = ngaysinh, NgayVaoLam = ngayvaolam, Picture = image }; context.NhanViens.Add(nhanvien); context.SaveChanges(); return(true); } return(false); }
private void simpleButton1_Click(object sender, EventArgs e) { Global.connect = textBox1.Text; CaPheContext context = new CaPheContext(Global.connect); using (SqlConnection cnn = new SqlConnection(Global.connectionstring)) { try { cnn.Open(); frLogin fr = new frLogin(); fr.ShowDialog(); this.Close(); cnn.Close(); } catch (Exception ex) { MessageBox.Show("Không thể kết nối đến Server! "); MessageBox.Show(ex.Message); } } }
public int LayNhanVienIDbyCMND(CaPheContext caPheContext, string CMND) { return((from item in caPheContext.NhanViens where item.CMND.Equals(CMND) select item.NhanVienId).SingleOrDefault()); }
public string LayTenNhanVienbyNhanVienID(int NhanVienID, CaPheContext caPheContext) { return((from item in caPheContext.NhanViens where item.NhanVienId.Equals(NhanVienID) select item.HoTenNV).SingleOrDefault()); }