Пример #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;
        }
Пример #2
0
        protected void grvNghi_DeleteCommand(object sender, GridCommandEventArgs e)
        {
            var  iD = (e.Item as GridDataItem).GetDataKeyValue("IDNghiPhep").ToString();
            int  id = Convert.ToInt32(iD);
            Nghi ng = _entities.Nghis.Where(d => d.IDNghiPhep == id).First();

            _entities.Nghis.DeleteObject(ng);
            _entities.SaveChanges();
            iDNghi = null;
        }
Пример #3
0
 public ActionResult Edit([Bind(Include = "MaNhanVien,NgayNghi,Phep,NguoiDuyet,NgaySua,GhiChu")] Nghi nghi)
 {
     if (ModelState.IsValid)
     {
         db.Entry(nghi).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.MaNhanVien = new SelectList(db.NhanViens, "MaNhanVien", "HoTen", nghi.MaNhanVien);
     return(View(nghi));
 }
Пример #4
0
        // GET: Nghi/Details/5
        public ActionResult Details(int?id, DateTime?ngayNghi)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Nghi nghi = db.Nghis.Where(x => x.MaNhanVien == id && x.NgayNghi == ngayNghi).SingleOrDefault();

            if (nghi == null)
            {
                return(HttpNotFound());
            }
            return(View(nghi));
        }
Пример #5
0
        // GET: Nghi/Edit/5
        public ActionResult Edit(int?id, DateTime?ngayNghi)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Nghi nghi = db.Nghis.Where(x => x.MaNhanVien == id && x.NgayNghi == ngayNghi).SingleOrDefault();

            if (nghi == null)
            {
                return(HttpNotFound());
            }
            ViewBag.MaNhanVien = new SelectList(db.NhanViens, "MaNhanVien", "HoTen", nghi.MaNhanVien);
            return(View(nghi));
        }
Пример #6
0
        public ActionResult DuyetPhep(List <Nghi> nghis, FormCollection form)
        {
            try
            {
                db.Configuration.ValidateOnSaveEnabled = false;
                var checkIsChecked = nghis.Where(x => x.IsChecked == true).FirstOrDefault();
                if (checkIsChecked == null)
                {
                    this.AddNotification("Vui lòng chọn nhân viên để duyệt!", NotificationType.ERROR);
                    return(RedirectToAction("Index"));
                }

                foreach (var item in nghis)
                {
                    if (item.IsChecked == true)
                    {
                        Nghi nghi = db.Nghis.Where(x => x.MaNhanVien == item.MaNhanVien && x.NgayNghi == item.NgayNghi).SingleOrDefault();
                        if (nghi != null)
                        {
                            if (nghi.Phep)
                            {
                                nghi.Phep       = false;
                                nghi.NguoiDuyet = form["NguoiDuyet"].ToString();
                                nghi.NgaySua    = DateTime.Now;
                                db.SaveChanges();
                            }
                            else
                            {
                                nghi.Phep       = true;
                                nghi.NguoiDuyet = form["NguoiDuyet"].ToString();
                                nghi.NgaySua    = DateTime.Now;
                                db.SaveChanges();
                            }
                        }
                    }
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                this.AddNotification("Có lỗi xảy ra. Vui lòng thử lại!", NotificationType.ERROR);
                return(RedirectToAction("Index"));
            }
        }
Пример #7
0
        protected void RadToolBar1_ButtonClick(object sender, RadToolBarEventArgs e)
        {
            switch (e.Item.Value)
            {
            case "Save":
                if (txtDenNgay.SelectedDate == null || txtTuNgay.SelectedDate <= txtDenNgay.SelectedDate)
                {
                    if (iDNghi == null)
                    {
                        Nghi ng = new Nghi();
                        ng.IDNhanVien = userid;
                        ng.IDLoaiNghi = Convert.ToInt32(cboLoaiNghi.SelectedValue);
                        ng.TuNgay     = txtTuNgay.SelectedDate;
                        ng.DenNgay    = txtDenNgay.SelectedDate;
                        if (lbSoNgayXinNghi.Text != "")
                        {
                            ng.SoNgayDaNghi = Convert.ToInt32(lbSoNgayXinNghi.Text);
                        }
                        ng.LyDoNghi = txtLyDo.Text;
                        ng.DuocNghi = null;
                        if (cboNhanVienBanGiao.SelectedValue == "")
                        {
                            ng.IDNhanVienBanGiao = null;
                        }
                        else
                        {
                            ng.IDNhanVienBanGiao = Convert.ToInt32(cboNhanVienBanGiao.SelectedValue);
                        }
                        ng.NguoiTao = ng.NguoiCapNhat = userid;
                        ng.NgayTao  = ng.NgayCapNhat = DateTime.Now;
                        _entities.AddToNghis(ng);
                        _entities.SaveChanges();
                        grvNghi.Rebind();
                        RadWindowManager1.RadAlert("Thêm thông tin thành công", 285, 100, "Thông báo", null);
                    }
                    else
                    {
                        Nghi ng = _entities.Nghis.Where(d => d.IDNghiPhep == iDNghi).First();
                        if (ng.DuocNghi == null)
                        {
                            ng.IDLoaiNghi = Convert.ToInt32(cboLoaiNghi.SelectedValue);
                            ng.TuNgay     = txtTuNgay.SelectedDate;
                            ng.DenNgay    = txtDenNgay.SelectedDate;
                            if (lbSoNgayXinNghi.Text != "")
                            {
                                ng.SoNgayDaNghi = Convert.ToInt32(lbSoNgayXinNghi.Text);
                            }
                            ng.LyDoNghi = txtLyDo.Text;
                            if (cboNhanVienBanGiao.SelectedValue == "")
                            {
                                ng.IDNhanVienBanGiao = null;
                            }
                            else
                            {
                                ng.IDNhanVienBanGiao = Convert.ToInt32(cboNhanVienBanGiao.SelectedValue);
                            }
                            ng.NguoiCapNhat = userid;
                            ng.NgayCapNhat  = DateTime.Now;
                            _entities.SaveChanges();
                            grvNghi.Rebind();
                            RadWindowManager1.RadAlert("Sửa thông tin thành công", 285, 100, "Thông báo", null);
                        }
                    }
                }
                else
                {
                    lbSoNgayXinNghi.Text = "Lỗi: thời gian xin nghỉ không hợp lý";
                }
                break;

            case "Reset":
                cboLoaiNghi.SelectedIndex        = -1;
                cboNhanVienBanGiao.SelectedIndex = -1;
                txtTuNgay.Clear();
                txtDenNgay.Clear();
                lbSoNgayXinNghi.Text = "";
                txtLyDo.Text         = "";
                lbSoNgayXinNghi.Text = "";
                iDNghi = null;
                ToogleControl(null);
                break;

            case "Report":
                RadWindowManager1.RadAlert("Chức năng chưa hoàn thiện", 285, 100, "Lỗi", "");
                break;
            }
        }
Пример #8
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);
        }