private void btnAdd_Click(object sender, EventArgs e) { //txtSoDienThoai.rul if (dxValidationProvider1.Validate()) { current = prepareHoiVien(); if (isThem) { if (HoiVienController.Add(current) == CODE_RESULT_RETURN.ThanhCong) { DialogResult = DialogResult.OK; Close(); } else { MessageBox.Show("Có lỗi khi thêm"); } } else { if (HoiVienController.Update(current) == CODE_RESULT_RETURN.ThanhCong) { DialogResult = DialogResult.OK; Close(); } else { MessageBox.Show("Có lỗi khi cập nhật"); } } } }
public FrmGiaHan(HoiVien hv = null, bool isGYM = true) { InitializeComponent(); this.hoiVien = hv; DataFiller.fillGoiCombo(cbbGiaHanGoi,isGYM ? 1 : 2, hoiVien.PhongTap.MaPhongTap); cbbGiaHanGoi_SelectedIndexChanged(null, null); }
public FrmGiaHan(HoiVien hv = null, bool isGYM = true) { if (hoiVien == null) { InitializeComponent(); this.hoiVien = hv; DataFiller.fillGoiCombo(cbbGiaHanGoi, isGYM ? 1 : 2, hoiVien.PhongTap.MaPhongTap); DataFiller.fillGiamGiaCombo(cbbGiamGia, chuaNgayHienTai:true, append: true); cbbGiaHanGoi_SelectedIndexChanged(null, null); } }
public static bool IsKhongRangBuoc(HoiVien g) { using (var db = DBContext.GetContext()) { var phieuThus = db.PhieuThu.Include(p => p.HoiVien).FirstOrDefault(p => p.HoiVien.MaHoiVien == g.MaHoiVien); if (phieuThus != null) return false; var his = db.HistoryHoiVien.Include(p => p.HoiVien).FirstOrDefault(p => p.HoiVien.MaHoiVien == g.MaHoiVien); if (his != null) return false; return true; } }
public FrmHoiVienEdit(HoiVien h = null) { InitializeComponent(); current = h; if (current != null) { Text = "Chỉnh sửa hội viên"; loadField(); isThem = false; cbbPhong.Enabled = false; } else { isThem = true; getMa(); } cbbPhong.Properties.NullText = "Chọn một phòng tập"; DataFiller.fillPhongCombo(cbbPhong); }
public FrmHoiVienEdit(HoiVien h = null) { InitializeComponent(); pictureEdit1.Properties.SizeMode = PictureSizeMode.Stretch; current = h; if (current != null) { Text = "Chỉnh sửa hội viên"; loadField(); isThem = false; cbbPhong.Enabled = false; btnAdd.Text = "Cập nhật"; } else { isThem = true; // getMa(); } cbbPhong.Properties.NullText = "Chọn một phòng tập"; DataFiller.fillPhongCombo(cbbPhong); }
internal static CODE_RESULT_RETURN Add(HoiVien hv) { using (var context = DBContext.GetContext()) { var ds = (from e in context.HoiVien where e.MaThe == hv.MaThe select e).SingleOrDefault(); if (ds != null) return CODE_RESULT_RETURN.MaTrung; else { var phong = context.PhongTap.Find(hv.PhongTap.MaPhongTap); hv.PhongTap = phong; context.HoiVien.Add(hv); context.SaveChanges(); return CODE_RESULT_RETURN.ThanhCong; } } }
internal static CODE_RESULT_RETURN updateNgayHetHan(HoiVien hoiVien) { using (var context = DBContext.GetContext()) { var pt = context.HoiVien.FirstOrDefault(p => p.MaGYM == hoiVien.MaGYM); if (pt != null) { pt.NgayHetHanGYM = hoiVien.NgayHetHanGYM; pt.NgayHetHanSauNa = hoiVien.NgayHetHanSauNa; pt.GiaHanCuoiGYM = DateTime.Now; pt.GiaHanCuoiSauna = DateTime.Now; context.SaveChanges(); return CODE_RESULT_RETURN.ThanhCong; } return CODE_RESULT_RETURN.ThatBai; } }
internal static CODE_RESULT_RETURN Update(HoiVien hv) { using (var db = DBContext.GetContext()) { var hvc = db.HoiVien.FirstOrDefault(h => h.MaGYM == hv.MaGYM); if (hvc != null) { hvc.NgayHetHanGYM = hv.NgayHetHanGYM; hvc.NgaySinh = hv.NgaySinh; //hvc.MaSauna = hv.MaSauna; hvc.TenHoiVien = hv.TenHoiVien; hvc.Anh = hv.Anh; ; hvc.DiaChi = hv.DiaChi; hvc.GioiTinh = hv.GioiTinh; hvc.SoDienThoai = hv.SoDienThoai; if (hv.PhongTap != null) { var phongMoi = db.PhongTap.FirstOrDefault(p => p.MaPhongTap == hv.PhongTap.MaPhongTap); hvc.PhongTap = phongMoi; } db.SaveChanges(); return CODE_RESULT_RETURN.ThanhCong; } return CODE_RESULT_RETURN.ThatBai; } }
void yeuCauInPhieu(bool isGYM, HoiVien hoiVien = null) { var tenPhieu = isGYM ? "GYM" : "Sauna"; HistoryHoiVien hs = null; //Truong hop in tren Grid if (hoiVien == null) { if (dataGridView1.SelectedRows.Count > 0) { hs = (HistoryHoiVien)dataGridView1.SelectedRows[0].DataBoundItem; hoiVien = hs.HoiVien; } else { DialogUtils.ShowMessage("Vui lòng chọn bản ghi muốn in phiếu"); return; } } //Truong hop in hoi vien hien tai else { hs = HistoryHoiVienController.GetHisToDay(hoiVien.MaThe); if (hs == null) { DialogUtils.ShowError("Vui lòng check in trước khi in"); return; } } if ((hoiVien.NgayHetHanGYM < DateTime.Now && isGYM) || (hoiVien.NgayHetHanSauNa < DateTime.Now && !isGYM)) { DialogUtils.ShowMessage("Thẻ này đã hết hạn " + tenPhieu); //NTHNV022loadData(); return; } try { if ((isGYM && hs.IsDaInGYM) || (!isGYM && hs.IsDaInSauna)) { DialogUtils.ShowMessage("Đã in phiếu " + tenPhieu + " cho thẻ này trong ngày hôm nay"); return; } var r = HistoryHoiVienController.InPhieuCoCapNhat(hs, isGYM); if (r == CODE_RESULT_RETURN.ThatBai) { DialogUtils.ShowMessage("Có lỗi khi ghi dữ liệu"); } else { loadGrid(); } } catch (Exception ex) { DialogUtils.ShowError("Lỗi. Chi tiết: " + ex.Message); } }
void wipeCard() { loadDefault(); var st = ""; if (!string.IsNullOrEmpty(txtMa.Text)) st = txtMa.Text.Trim(); else if (hv != null) st = hv.MaThe; var his = HistoryHoiVienController.GetHisToDay(st); bool checkedIn = false; if (his != null) { checkedIn = true; } hv = HoiVienController.GetByMaHoiVien(st); if (hv != null) { lblThongBao.Text = ""; //kiem tra gym if (hv.NgayHetHanGYM > DateTime.Now) { validCardGYM = KetQuaCheckin.TheHopLe; } if (hv.NgayHetHanSauNa > DateTime.Now) { validCardSauna = KetQuaCheckin.TheHopLe; } var hs = new HistoryHoiVien() { HoiVien = hv, ThoiGian = DateTime.Now, IsDaInGYM = false, IsDaInSauna = false }; txtMa.Text = ""; if (!checkedIn) { if (HistoryHoiVienController.Add(hs) == CODE_RESULT_RETURN.ThanhCong) { lblThongBao.Text = "Checkin thành công"; } else { DialogUtils.ShowError("Có lỗi khi checkin"); } } else { lblThongBao.Text = "Hội viên này đã checkin"; } loadData(); } else { lblThongBao.Text = "Không tồn tại mã thẻ này"; loadDefault(); } }
HoiVien prepareHoiVien() { HoiVien hv = new HoiVien() { TenHoiVien = txtHoTen.Text.Trim(), GioiTinh = radNam.Checked, NgaySinh = datNgaySinh.DateTime, SoDienThoai = txtSoDienThoai.Text.Trim(), DiaChi = txtDiaChi.Text, MaGYM = txtMaHoiVien.Text, NgayHetHanGYM = DateTime.Now, NgayHetHanSauNa = DateTime.Now, }; if (isHaveFile) { String fileName = opd.FileName; Bitmap bmp = new Bitmap(fileName); FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); byte[] bimage = new byte[fs.Length]; fs.Read(bimage, 0, Convert.ToInt32(fs.Length)); fs.Close(); byte[] Photo = bimage; hv.Anh = Photo; } var phong = (PhongTap)cbbPhong.GetSelectedDataRow(); hv.PhongTap = phong; return hv; }
private void btnDangKy_Click(object sender, EventArgs e) { var ggGym = (GiamGia)cbbGiamGiaGYM.SelectedItem; var ggSauna = (GiamGia)cbbGiamGiaSauna.SelectedItem; errorProvider1.Clear(); lblThanhCong.Visible = false; #region validate dxErrorProvider1.ClearErrors(); if (txtMaThe.Text == "") { errorProvider1.SetError(txtMaThe, "Mã thẻ không được trống"); txtMaThe.Focus(); return; } if (txtHoTen.Text == "") { errorProvider1.SetError(txtHoTen, "Họ tên không được trống"); txtHoTen.Focus(); return; } var g1 = (GoiTap)cbbGoiGym.SelectedItem; var g2 = (GoiTap)cbbGoiSauna.SelectedItem; if (g1.MaGoiTap == -1 && g2.MaGoiTap == -1) { DialogUtils.ShowMessage("Cần chọn ít nhất gói GYM hoặc gói Sauna"); return; } // if (txtHoTen.Text == "") { dxErrorProvider1.SetError(txtHoTen, "Họ tên không được trống"); txtHoTen.Focus(); return; } if (txtMaThe.Text == "") { dxErrorProvider1.SetError(txtHoTen, "Mã thẻ không được trống"); txtHoTen.Focus(); return; } #endregion validate hoiVienHienTai = new HoiVien() { TenHoiVien = txtHoTen.Text.Trim(), MaThe = txtMaThe.Text.Trim(), PhongTap = Login1.GetPhongHienTai(), NgayGioDangKy = DateTime.Now, NgaySinh = new DateTime(1900, 1, 1), IsDangKyNhanh = true, }; var r = HoiVienController.Add(hoiVienHienTai); if (r == CODE_RESULT_RETURN.ThatBai) { DialogUtils.ShowError("Có lỗi khi tạo hội viên"); return; } if (r == CODE_RESULT_RETURN.MaTrung) { errorProvider1.SetError(txtMaThe, "Mã thẻ này đã tồn tại trong hệ thống"); txtMaThe.Focus(); return; } if (g1.MaGoiTap != -1) { PhieuThu pt = new PhieuThu() { GoiTap = g1, HoiVien = hoiVienHienTai, NgayLap = DateTime.Now, NhanVien = Login1.TaiKhoanHienTai, SoTien = g1.Gia, PhanTramGiam = ggGym.PhanTramGiam, TenGiamGia =ggGym.MaGiamGia!=""? ggGym.TenGiamGia:"" }; tienGym = pt.TienSauGiam; PhieuThuController.Add(pt); } if (g2.MaGoiTap != -1) { PhieuThu pt = new PhieuThu() { GoiTap = g2, HoiVien = hoiVienHienTai, NgayLap = DateTime.Now, NhanVien = Login1.TaiKhoanHienTai, SoTien = g2.Gia, PhanTramGiam = ggSauna.PhanTramGiam, TenGiamGia =ggSauna.MaGiamGia != "" ? ggSauna.TenGiamGia :"" }; tienSauna = pt.TienSauGiam; PhieuThuController.Add(pt); } if (r == CODE_RESULT_RETURN.ThanhCong) { loadData(); //DialogUtils.ShowMessage("Đăng ký nhanh hoàn tất"); lblThanhCong.Visible = true; lblThanhCong.Text = "Đăng ký nhanh hoàn tất"; } else if (r == CODE_RESULT_RETURN.MaTrung) { lblThanhCong.Visible = true; lblThanhCong.Text = "Mã hội viên này đã tồn tại"; //DialogUtils.ShowError("Mã hội viên này đã tồn tại"); return; } }
private void btnAdd_Click(object sender, EventArgs e) { errorProvider1.Clear(); if (txtHoTen.Text == "") { errorProvider1.SetError(txtHoTen, "Họ tên không được rỗng"); txtHoTen.Focus(); return; } if (datNgaySinh.Value.Year == 1900) { errorProvider1.SetError(datNgaySinh, "Chưa chọn ngày sinh"); datNgaySinh.Focus(); return; } // int so; //if (txtSoDienThoai.Text == "" && !int.TryParse(txtSoDienThoai.Text, out so)) //{ // errorProvider1.SetError(txtSoDienThoai, "Số điện thoại không hợp lệ"); // txtSoDienThoai.Focus(); // return; //} if (txtMaHoiVien.Text == "") { errorProvider1.SetError(txtHoTen, "Mã hội viên không được trống"); txtMaHoiVien.Focus(); return; } current = prepareHoiVien(); if (isThem) { if (HoiVienController.Add(current) == CODE_RESULT_RETURN.ThanhCong) { DialogResult = DialogResult.OK; Close(); } else { MessageBox.Show("Có lỗi khi thêm"); } } else { if (HoiVienController.Update(current) == CODE_RESULT_RETURN.ThanhCong) { DialogResult = DialogResult.OK; Close(); } else { MessageBox.Show("Có lỗi khi cập nhật"); } } }
void wipeCard() { bool validCard = false; loadDefault(); var st = txtMa.Text; hv = HoiVienController.CheckIn(txtMa.Text, isGYM); if (hv != null) { #region GYM if (isGYM) { if (hv.NgayHetHanGYM > DateTime.Now) { validCard = true; var hs = new HistoryHoiVien() { HoiVien = hv, IsSauna = !isGYM, ThoiGian = DateTime.Now }; HistoryHoiVienController.Add(hs); MessageBox.Show("Checkin thành công"); } loadData(); if (validCard) { lblKetQua.ForeColor = Color.Green; lblKetQua.Text = "Thẻ hợp lệ"; var delta = Convert.ToInt32(Math.Ceiling((hv.NgayHetHanGYM - DateTime.Now).TotalDays)); if (delta <= 7) { lblThongBao.Visible = true; lblThongBao.ForeColor = Color.Purple; lblThongBao.Text = "Còn " + delta + " ngày là hết hạn"; } } else { lblKetQua.ForeColor = Color.Red; lblKetQua.Text = "Thẻ đã hết hạn"; } } #endregion GYM #region SAUNA else { if (hv != null) { if (hv.NgayHetHanSauNa > DateTime.Now) { validCard = true; var hs = new HistoryHoiVien() { HoiVien = hv, IsSauna = !isGYM, ThoiGian = DateTime.Now }; HistoryHoiVienController.Add(hs); MessageBox.Show("Checkin thành công"); } loadData(); if (validCard) { lblKetQua.ForeColor = Color.Green; lblKetQua.Text = "Thẻ hợp lệ"; var delta = Convert.ToInt32(Math.Ceiling((hv.NgayHetHanSauNa - DateTime.Now).TotalDays)); if (delta <= 7) { lblThongBao.Visible = true; lblThongBao.ForeColor = Color.Purple; lblThongBao.Text = "Còn " + delta + " ngày là hết hạn"; } } else { lblKetQua.ForeColor = Color.Red; lblKetQua.Text = "Thẻ đã hết hạn"; } } else { lblKetQua.ForeColor = Color.Red; lblKetQua.Text = "Không có tài khoản này"; } #endregion SAUNA if (hv != null) { lblTen.Text = hv.TenHoiVien; } else lblTen.Text = ""; } } else { lblKetQua.ForeColor = Color.Red; lblKetQua.Text = "Không có tài khoản này"; } }