Beispiel #1
0
        public MyRegistry()
        {
            Action someMethod = new Action(() =>
            {
                QLNhanSuEntities ql = new QLNhanSuEntities();
                var nv = ql.ChamCongs.Where(s => s.TrangThai == null && s.Ngay == DateTime.Today);
                foreach (var b in nv)
                {
                    b.TrangThai = "Nghỉ";

                    Nghi nhanVienNghi       = new Nghi();
                    nhanVienNghi.MaNhanVien = b.MaNhanVien;
                    nhanVienNghi.NgayNghi   = DateTime.Today;
                    nhanVienNghi.Phep       = false;
                    nhanVienNghi.NgaySua    = DateTime.Now;
                    nhanVienNghi.GhiChu     = "Hôm nay nghỉ";
                    ql.Nghis.Add(nhanVienNghi);
                }
                ql.SaveChanges();
            });

            this.Schedule(someMethod).ToRunEvery(0).Days().At(10, 00);


            Action taophat = new Action(() =>
            {
                DateTime B                    = DateTime.Now;
                QLNhanSuEntities ql           = new QLNhanSuEntities();
                var mocThoiGian16h            = DateTime.Today.AddHours(16);
                var listNhanVienNghiKhongPhep = ql.Nghis.Where(x => x.Phep == false && x.NgayNghi == DateTime.Today.Date);
                //var nv = ql.ChamCongs.Where(s => s.TrangThai == "Nghỉ" && s.Ngay == DateTime.Today);
                foreach (var b in listNhanVienNghiKhongPhep)
                {
                    var ct_PhatNhanVienNghi = ql.Ct_Phat.Where(x => x.LoaiPhat.TenLoaiPhat == "Nghỉ" && x.MaNhanVien == b.MaNhanVien && x.NgayPhat == mocThoiGian16h).SingleOrDefault();
                    if (ct_PhatNhanVienNghi == null)
                    {
                        var tenphat = ql.LoaiPhats.Where(s => s.TenLoaiPhat == "Nghỉ" && s.TrangThai == true).SingleOrDefault();
                        if (tenphat != null)
                        {
                            Ct_Phat phat    = new Ct_Phat();
                            phat.MaNhanVien = b.MaNhanVien;
                            phat.MaLoaiPhat = tenphat.MaLoaiPhat;
                            phat.NgayPhat   = DateTime.Today.AddHours(16);
                            phat.NguoiPhat  = "Hệ thống";
                            phat.NguoiSua   = "Hệ thống";
                            phat.NgaySua    = DateTime.Today.AddHours(16);
                            phat.TrangThai  = true;
                            ql.Ct_Phat.Add(phat);
                        }
                    }
                }
                ql.SaveChanges();
            });

            this.Schedule(taophat).ToRunEvery(0).Days().At(16, 00);
            //DateTime B = DateTime.Now;
        }
 public ActionResult Edit([Bind(Include = "MaCTPhat,MaNhanVien,MaLoaiPhat,TrangThai,NguoiSua,NgaySua,NguoiPhat,NgayPhat")] Ct_Phat ct_Phat)
 {
     if (ModelState.IsValid)
     {
         db.Entry(ct_Phat).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.MaLoaiPhat = new SelectList(db.LoaiPhats.Where(x => x.TrangThai == true), "MaLoaiPhat", "TenLoaiPhat", ct_Phat.MaLoaiPhat);
     ViewBag.MaNhanVien = new SelectList(db.NhanViens, "MaNhanVien", "HoTen", ct_Phat.MaNhanVien);
     return(View(ct_Phat));
 }
        public ActionResult Create([Bind(Include = "MaCTPhat,MaNhanVien,MaLoaiPhat,TrangThai,NguoiSua,NgaySua,NguoiPhat,NgayPhat")] Ct_Phat ct_Phat)
        {
            if (ModelState.IsValid)
            {
                db.Ct_Phat.Add(ct_Phat);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.MaLoaiPhat = new SelectList(db.LoaiPhats, "MaLoaiPhat", "TenLoaiPhat", ct_Phat.MaLoaiPhat);
            ViewBag.MaNhanVien = new SelectList(db.NhanViens, "MaNhanVien", "HoTen", ct_Phat.MaNhanVien);
            return(View(ct_Phat));
        }
        //public ActionResult Search(string loaiTimKiem, string tenTimKiem, int? page)
        //{
        //    try
        //    {
        //        IQueryable<Ct_Phat> ct_P;
        //        QLNhanSuEntities db = new QLNhanSuEntities();
        //        if (loaiTimKiem == "MaNhanVien")
        //        {

        //            int tenTimKiem_int;
        //            int.TryParse(tenTimKiem, out tenTimKiem_int);
        //            ct_P = db.Ct_Phat.Where(x => x.NhanVien.MaNhanVien.ToString().StartsWith(tenTimKiem) || tenTimKiem == null).Include(c => c.NhanVien).Include(c => c.LoaiPhat);
        //            return View("Index", ct_P.ToList().ToPagedList(page ?? 1, 10));
        //        }
        //        else if (loaiTimKiem == "TenNhanVien")
        //        {

        //            ct_P = db.Ct_Phat.Where(x => x.NhanVien.HoTen.Contains(tenTimKiem) || tenTimKiem == null).Include(c => c.NhanVien).Include(c => c.LoaiPhat);
        //            return View("Index", ct_P.ToList().ToPagedList(page ?? 1, 10));
        //        }
        //        else
        //        {
        //            ct_P = db.Ct_Phat.Where(x => x.NhanVien.PhongBan.TenPB.Contains(tenTimKiem) || tenTimKiem == null).Include(c => c.NhanVien).Include(c => c.LoaiPhat);
        //            return View("Index", ct_P.ToList().ToPagedList(page ?? 1, 10));
        //        }
        //    }
        //    catch
        //    {
        //        this.AddNotification("Có lỗi xảy ra. Vui lòng thực hiện tìm kiếm lại!", NotificationType.ERROR);
        //        return View("Index", db.Ct_Phat.OrderBy(x => x.NhanVien.HoTen).ToList().ToPagedList(page ?? 1, 10));
        //    }
        //}

        // GET: Ct_Phat/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Ct_Phat ct_Phat = db.Ct_Phat.Find(id);

            if (ct_Phat == null)
            {
                return(HttpNotFound());
            }
            return(View(ct_Phat));
        }
        // GET: Ct_Phat/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Ct_Phat ct_Phat = db.Ct_Phat.Find(id);

            if (ct_Phat == null)
            {
                return(HttpNotFound());
            }
            ViewBag.MaLoaiPhat = new SelectList(db.LoaiPhats.Where(x => x.TrangThai == true), "MaLoaiPhat", "TenLoaiPhat", ct_Phat.MaLoaiPhat);
            ViewBag.MaNhanVien = new SelectList(db.NhanViens, "MaNhanVien", "HoTen", ct_Phat.MaNhanVien);
            return(View(ct_Phat));
        }
        public ActionResult Delete(List <Ct_Phat> ct_Phats)
        {
            try
            {
                db.Configuration.ValidateOnSaveEnabled = false;
                var checkIsChecked = ct_Phats.Where(x => x.IsChecked == true).FirstOrDefault();
                if (checkIsChecked == null)
                {
                    this.AddNotification("Vui lòng chọn chi tiết phạt để xóa!", NotificationType.ERROR);
                    return(RedirectToAction("Index"));
                }
                foreach (var item in ct_Phats)
                {
                    if (item.IsChecked == true)
                    {
                        int     maCTPhat = item.MaCTPhat;
                        Ct_Phat ct_Phat  = db.Ct_Phat.Where(x => x.MaCTPhat == maCTPhat).SingleOrDefault();
                        if (ct_Phat != null)
                        {
                            ct_Phat.TrangThai = false;
                            if (Session["TenNhanVien"] == null)
                            {
                                ct_Phat.NguoiSua = "Ẩn danh";
                                ct_Phat.NgaySua  = DateTime.Now;
                            }
                            else
                            {
                                ct_Phat.NguoiSua = Session["TenNhanVien"].ToString();
                                ct_Phat.NgaySua  = DateTime.Now;
                            }
                            ct_Phat.NgaySua = DateTime.Now;
                            db.SaveChanges();
                        }
                    }
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                this.AddNotification("Không thể xóa vì chi tiết phạt này đã và đang được sử dụng!", NotificationType.ERROR);
                return(RedirectToAction("Index"));
            }
        }
        public ActionResult CheckIn()
        {
            var maNhanVien = Session["MaNhanVien"].ToString();
            var ngayHomNay = DateTime.Today;
            var nhanVien   = db.ChamCongs.Where(x => x.MaNhanVien.ToString().Equals(maNhanVien) && x.Ngay == ngayHomNay).SingleOrDefault();

            if (nhanVien != null)
            {
                nhanVien.ThoiGianVao = DateTime.Now.TimeOfDay;
                TimeSpan thoiGianVaoQuyDinh  = DateTime.Parse("8:00 AM").TimeOfDay;
                TimeSpan thoiGianKhongChoVao = DateTime.Parse("10:00 AM").TimeOfDay;
                if (nhanVien.ThoiGianVao < thoiGianVaoQuyDinh)
                {
                    nhanVien.TrangThai = "Đúng giờ";
                }
                else if (nhanVien.ThoiGianVao < thoiGianKhongChoVao && nhanVien.ThoiGianVao > thoiGianVaoQuyDinh)
                {
                    nhanVien.TrangThai = "Đi trễ";
                    var tenphat = db.LoaiPhats.Where(s => s.TenLoaiPhat == "Đi trễ" && s.TrangThai == true).SingleOrDefault();
                    if (tenphat != null)
                    {
                        Ct_Phat phat = new Ct_Phat();
                        phat.MaNhanVien = nhanVien.MaNhanVien;
                        phat.MaLoaiPhat = tenphat.MaLoaiPhat;
                        phat.NgayPhat   = DateTime.Now;
                        phat.NguoiPhat  = "Hệ thống";
                        phat.NguoiSua   = "Hệ thống";
                        phat.NgaySua    = DateTime.Now;
                        phat.TrangThai  = true;
                        db.Ct_Phat.Add(phat);
                        db.SaveChanges();
                    }
                }
                else
                {
                    this.AddNotification("Không được check in vì đã quá giờ quy định.", NotificationType.WARNING);
                    return(RedirectToAction("ChamCongNgay"));
                }
                db.SaveChanges();
            }
            return(RedirectToAction("ChamCongNgay"));
        }
Beispiel #8
0
        public ActionResult ThemPhatNhanVien(FormCollection form)
        {
            var listNhanVien = TempData["listNhanVien"] as List <NhanVien>;

            foreach (var item in listNhanVien)
            {
                if (item.IsChecked == true)
                {
                    var chitietPhat = new Ct_Phat();
                    chitietPhat.MaNhanVien = item.MaNhanVien;
                    chitietPhat.MaLoaiPhat = Convert.ToInt32(form["MaLoaiPhat"]);
                    chitietPhat.TrangThai  = true;
                    chitietPhat.NguoiSua   = form["NguoiSua"].ToString();
                    chitietPhat.NgaySua    = DateTime.Now;
                    chitietPhat.NguoiPhat  = form["NguoiSua"].ToString();
                    chitietPhat.NgayPhat   = DateTime.Now;
                    db.Ct_Phat.Add(chitietPhat);
                    db.SaveChanges();
                }
            }
            return(RedirectToAction("Index"));
        }
Beispiel #9
0
        protected void Application_Start()
        {
            DateTime B      = DateTime.Now;
            DateTime dayOfW = DateTime.Today;

            JobManager.Initialize(new MyRegistry());
            QLNhanSuEntities ql = new QLNhanSuEntities();

            if (dayOfW.DayOfWeek != DayOfWeek.Saturday && dayOfW.DayOfWeek != DayOfWeek.Sunday)
            {
                var chamcong = ql.ChamCongs.Where(s => s.Ngay == B.Date).FirstOrDefault();
                if (chamcong == null)
                {
                    var nhanvien = ql.NhanViens.Where(s => s.TrangThai == true && s.MaNhanVien != 1001);
                    foreach (var nv in nhanvien)
                    {
                        //ChamCong cham = new ChamCong();
                        //cham.MaNhanVien = nv.MaNhanVien;
                        //cham.Ngay = B;
                        //ql.ChamCongs.Add(cham);
                        ChamCong cham = new ChamCong();
                        cham.MaNhanVien = nv.MaNhanVien;
                        cham.Ngay       = B;
                        ql.ChamCongs.Add(cham);
                    }
                    ql.SaveChanges();
                }
            }


            int month, year;

            if (B.Month == 1)
            {
                month = 12;
                year  = B.Year - 1;
            }
            else
            {
                month = B.Month - 1;
                year  = B.Year;
            }
            var      day           = DateTime.DaysInMonth(year, month);
            DateTime ngayCuoiThang = new DateTime(year, month, day);
            var      luong         = ql.LuongThangs.Where(s => s.ThangNam.Month.ToString() == month.ToString() && s.ThangNam.Year.ToString() == year.ToString()).FirstOrDefault();

            if (luong == null)
            {
                var nhanvien = ql.NhanViens.Where(s => s.TrangThai == true && s.MaNhanVien != 1001);
                foreach (var nv in nhanvien)
                {
                    int gtthuong  = 0;
                    int gtphat    = 0;
                    int giolam    = 0;
                    int giotangca = 0;
                    var thuong    = ql.Ct_Thuong.Where(s => s.NgaySua.Month == month && s.NgaySua.Year == year && s.MaNhanVien == nv.MaNhanVien);
                    foreach (var t in thuong)
                    {
                        var giatrithuong = ql.LoaiThuongs.Where(s => s.MaLoaiThuong == t.MaLoaiThuong).SingleOrDefault();
                        gtthuong = gtthuong + giatrithuong.GiaTri;
                    }
                    var phat = ql.Ct_Phat.Where(s => s.NgaySua.Month == month && s.NgaySua.Year == year && s.MaNhanVien == nv.MaNhanVien);
                    foreach (var t in phat)
                    {
                        var giatriphat = ql.LoaiPhats.Where(s => s.MaLoaiPhat == t.MaLoaiPhat).SingleOrDefault();
                        gtphat = gtphat + giatriphat.GiaTri;
                    }
                    var cc = ql.ChamCongs.Where(s => s.MaNhanVien == nv.MaNhanVien && s.Ngay.Month.ToString() == month.ToString() && s.Ngay.Year.ToString() == year.ToString() && s.TrangThai != null);
                    if (cc.Count() == 0)
                    {
                    }
                    else
                    {
                        foreach (var c in cc)
                        {
                            giolam    = (int)(giolam + c.ThoiGianLamViec);
                            giotangca = (int)(giotangca + c.ThoiGianTangCa);
                        }
                    }
                    var luongcoban = ql.LuongCoBans.Where(s => s.MaNhanVien == nv.MaNhanVien && s.TrangThai == true).SingleOrDefault();
                    if (luongcoban != null)
                    {
                        LuongThang l = new LuongThang();
                        l.MaLuongCoBan   = luongcoban.MaLuongCoBan;
                        l.ThangNam       = ngayCuoiThang;
                        l.TongGioLamViec = giolam;
                        l.TongGioTangCa  = giotangca;
                        l.TongThuong     = gtthuong;
                        l.TongPhat       = gtphat;
                        l.HeSoLuong      = luongcoban.NhanVien.ChucVu.HeSoChucVu;
                        l.PhuCap         = luongcoban.NhanVien.ChucVu.PhuCap;
                        ql.LuongThangs.Add(l);
                    }
                }
                ql.SaveChanges();
            }

            //sau 10h nếu app đc khởi động mà chấm công hôm nay, những ai chưa chấm công nếu trạng thái là null, thì thay thành "Nghỉ"
            //đồng thời thêm nhân viên đó vào bảng nghỉ
            TimeSpan thoiGianKhongChoVao = DateTime.Parse("10:00 AM").TimeOfDay;

            if (DateTime.Now.TimeOfDay > thoiGianKhongChoVao)
            {
                var nvList = ql.ChamCongs.Where(s => s.TrangThai == null && s.Ngay == DateTime.Today).ToList();
                if (nvList.Count > 0)
                {
                    foreach (var b in nvList)
                    {
                        b.TrangThai = "Nghỉ";

                        //thêm dữ liệu nhân viên nghỉ vào bảng Nghỉ
                        Nghi nhanVienNghi = new Nghi();
                        nhanVienNghi.MaNhanVien = b.MaNhanVien;
                        nhanVienNghi.NgayNghi   = DateTime.Today;
                        nhanVienNghi.Phep       = false;
                        nhanVienNghi.NgaySua    = DateTime.Now;
                        nhanVienNghi.GhiChu     = "Hôm nay nghỉ";
                        ql.Nghis.Add(nhanVienNghi);
                    }
                    ql.SaveChanges();
                }
            }

            //kiểm tra sau 16h nếu nhân viên nghỉ thì thêm phạt nhân viên đó, mà nếu đã có phạt rồi thì ko phạt nữa
            TimeSpan thoiGianThemPhatNhanVienNghi = DateTime.Parse("04:00 PM").TimeOfDay;
            var      mocThoiGian16h = DateTime.Today.AddHours(16);

            if (DateTime.Now.TimeOfDay > thoiGianThemPhatNhanVienNghi)
            {
                //list chấm công nhân viên có trạng thái nghỉ không phép trong ngày hôm nay
                var nvChamCongList = ql.Nghis.Where(x => x.Phep == false && x.NgayNghi == DateTime.Today.Date).ToList();
                foreach (var b in nvChamCongList)
                {
                    var ct_PhatNhanVienNghi = ql.Ct_Phat.Where(x => x.LoaiPhat.TenLoaiPhat == "Nghỉ" && x.MaNhanVien == b.MaNhanVien && x.NgayPhat == mocThoiGian16h).SingleOrDefault();
                    if (ct_PhatNhanVienNghi == null)
                    {
                        var tenphat = ql.LoaiPhats.Where(s => s.TenLoaiPhat == "Nghỉ" && s.TrangThai == true).SingleOrDefault();
                        if (tenphat != null)
                        {
                            Ct_Phat phat = new Ct_Phat();
                            phat.MaNhanVien = b.MaNhanVien;
                            phat.MaLoaiPhat = tenphat.MaLoaiPhat;
                            phat.NgayPhat   = DateTime.Today.AddHours(16);
                            phat.NguoiPhat  = "Hệ thống";
                            phat.NguoiSua   = "Hệ thống";
                            phat.NgaySua    = DateTime.Today.AddHours(16);
                            phat.TrangThai  = true;
                            ql.Ct_Phat.Add(phat);
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                ql.SaveChanges();
            }
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }