public static void SaveHistory(EmployeeEntity employeetity, int departid, IEmployee_History _iplEmployee_History)
        {
            var EmpHis = new Employee_HistoryEntity(); //lưu lại lịch sử đổi phòng

            //trường hợp department ko thay đổi htif ko cập nhập
            if (employeetity.DepartmentId != departid)
            {
                EmpHis.Position     = employeetity.Position;
                EmpHis.DepartmentId = departid;
                EmpHis.EmployeeId   = employeetity.Id;
                EmpHis.TimeIn       = DateTime.Now;
                //EmpHis.TimeOut = DateTime.Now;
                EmpHis.Note = "Chuyển sang từ " + employeetity.DepartmentName;
                var emphId = _iplEmployee_History.Insert(EmpHis);

                IplDepartment depart    = new IplDepartment();
                var           tmpdepart = depart.ViewDetail(departid);

                string departmentTo = tmpdepart.Name;



                EmpHis = _iplEmployee_History.SelectByPositionDepartment(employeetity.Id, employeetity.Position, employeetity.DepartmentId); //sửa lịch sử cũ
                if (EmpHis != null)
                {
                    EmpHis.TimeOut = DateTime.Now;
                    EmpHis.Note    = "Chuyển sang " + departmentTo;
                    var updateEmpHis = _iplEmployee_History.Update(EmpHis);
                }
            }
        }
        public List <Employee_HistoryEntity> ListHistory(int IdEmployee, string[] arrDepartment, string[] arrPosition)
        {
            //List all employee_department theo IdEmployee
            List <Employee_Department>    ListHistory = _iplEmployee.ListDetail(IdEmployee);
            List <Employee_HistoryEntity> listHistory = new List <Employee_HistoryEntity>();

            for (int i = 0; i < arrDepartment.Count(); i++)
            {
                var countDepartment = ListHistory.Where(x => x.IdDepartment == int.Parse(arrDepartment[i])).FirstOrDefault();
                //Thêm mới phòng ban hoặc chuyển phòng
                if (countDepartment == null)
                {
                    var a = new Employee_HistoryEntity
                    {
                        EmployeeId   = IdEmployee,
                        TimeIn       = DateTime.Now,
                        DepartmentId = int.Parse(arrDepartment[i]),
                        Position     = int.Parse(arrPosition[i]),
                    };
                    listHistory.Add(a);
                }
                else
                {
                    //Chuyển chức
                    if (countDepartment.IdPosition != int.Parse(arrPosition[i]))
                    {
                        PositionEntity namePosition = _iplPosition.ViewDetail(int.Parse(arrPosition[i]));
                        var            a            = new Employee_HistoryEntity
                        {
                            EmployeeId   = IdEmployee,
                            TimeIn       = DateTime.Now,
                            DepartmentId = int.Parse(arrDepartment[i]),
                            Position     = int.Parse(arrPosition[i]),
                        };
                        listHistory.Add(a);
                    }
                    else
                    {
                        //ko có thay đổi
                    }
                }
            }
            return(listHistory);
        }
Ejemplo n.º 3
0
        public ActionResult EditEmployee_History(int?id)
        {
            var iplPosition = SingletonIpl.GetInstance <IplPosition>();
            var allPosition = iplPosition.ListAll();

            ViewData["Position"] = allPosition;

            var iplDepartment = SingletonIpl.GetInstance <IplDepartment>();
            var allDepartment = iplDepartment.ListAll();

            ViewData["Department"] = allDepartment;

            Employee_HistoryEntity entity = new Employee_HistoryEntity();

            if (id != null)
            {
                entity = _iplEmployee_history.ViewDetail((int)id);
            }
            return(View(entity));
        }
Ejemplo n.º 4
0
        public ActionResult Save(Employee_HistoryEntity model)
        {
            var entity = new Employee_HistoryEntity();

            var iplPosition = SingletonIpl.GetInstance <IplPosition>();
            var allPosition = iplPosition.ListAll();

            ViewData["Position"] = allPosition;

            var iplDepartment = SingletonIpl.GetInstance <IplDepartment>();
            var allDepartment = iplDepartment.ListAll();

            ViewData["Department"] = allDepartment;


            if (model.Id > 0)
            {
                var sess = SessionSystem.GetUser();
                Logs.logs("Sửa lịch sử nhân sự", "Truy cập vào trang Employee_History", "/Employee_History/EditEmployee_History", sess.UserId);
                entity = _iplEmployee_history.ViewDetail(model.Id);
                if (entity != null && entity.Id > 0)
                {
                    entity.EmployeeId   = model.EmployeeId;
                    entity.DepartmentId = model.DepartmentId;
                    entity.Position     = model.Position;
                    entity.TimeIn       = model.TimeIn;
                    entity.TimeOut      = model.TimeOut;
                    entity.Note         = model.Note;
                    var retVal = _iplEmployee_history.Update(entity);
                    if (retVal)
                    {
                        return(RedirectToAction("Index", "Employee_History"));
                    }
                }
            }

            ViewBag.Msg = ConstantMsg.ErrorProgress;
            return(View("EditEmployee_History", model));
        }
        //[AuthorizeUser(ModuleName = "Employee", AccessLevel = Constants.Save)]
        public ActionResult Save(EmployeeEntity model, FormCollection form)
        {
            if (ModelState.IsValid)
            {
                EmployeeEntity entity       = _iplEmployee.ViewDetail(model.Id);
                var            DepartmentId = form["DepartmentId"];
                var            PositionId   = form["Position"];
                string[]       arrayDepartment;
                string[]       arrayPosition;
                arrayDepartment = DepartmentId.Split(',');
                arrayPosition   = PositionId.Split(',');
                var      DispatchWorkId = form["DispatchWork"];
                string[] arrayDispatchWork;
                arrayDispatchWork = DispatchWorkId.Split(',');

                #region Sửa Employee
                if (model.Id > 0)
                {
                    var sess = SessionSystem.GetUser();
                    Logs.logs("Sửa nhân sự", "Truy cập vào trang Employee", "/Employee/CreateEmployee", sess.UserId);
                    #region Sửa lịch sử Chức Vụ, Phòng Ban
                    if (DepartmentId != null && PositionId != null && arrayDepartment.Count() > 0 && arrayPosition.Count() == arrayDepartment.Count())
                    {
                        //ListHistory là list thêm mới, sửa phòng, chức
                        List <Employee_HistoryEntity> listHistory = ListHistory(model.Id, arrayDepartment, arrayPosition);
                        //ListHistoryOld lấy ra thằng TimeOut = null và IdDepartment và IdPosition không có trong param hoặc bị xóa
                        List <Employee_HistoryEntity> EmpHisOld = ListHistoryOld(model.Id, arrayDepartment, arrayPosition);
                        if (listHistory != null && listHistory.Count() == 0 && EmpHisOld != null && EmpHisOld.Count() > 0)
                        {
                            foreach (var item in EmpHisOld)
                            {
                                var listHistoryOld = _iplEmployee_History.SelectByPositionDepartment(item.EmployeeId, item.Position, item.DepartmentId);
                                if (listHistoryOld != null)
                                {
                                    listHistoryOld.TimeOut = DateTime.Now;
                                    var updateEmpHis = _iplEmployee_History.Update(listHistoryOld);
                                }
                            }
                        }
                        if (listHistory != null && listHistory.Count() > 0)
                        {
                            //Lưu thời gian nghỉ
                            foreach (var item in EmpHisOld)
                            {
                                var listHistoryOld = _iplEmployee_History.SelectByPositionDepartment(item.EmployeeId, item.Position, item.DepartmentId);
                                if (listHistoryOld != null)
                                {
                                    listHistoryOld.TimeOut = DateTime.Now;
                                    var updateEmpHis = _iplEmployee_History.Update(listHistoryOld);
                                }
                            }
                            foreach (var item in listHistory)
                            {
                                var EmpHis = new Employee_HistoryEntity();
                                EmpHis.Position     = item.Position;
                                EmpHis.DepartmentId = item.DepartmentId;
                                EmpHis.EmployeeId   = model.Id;
                                EmpHis.TimeIn       = DateTime.Now;
                                EmpHis.Note         = item.Note != null ? item.Note : form["Department" + item.DepartmentId];
                                _iplEmployee_History.Insert(EmpHis);
                            }
                        }
                        //Xóa liên kết cũ
                        _iplEmployee.DeleteDepartment(model.Id);
                        //Lưu liên kết mới
                        for (int i = 0; i < arrayDepartment.Count(); i++)
                        {
                            Employee_Department a = new Employee_Department();
                            a.IdDepartment = int.Parse(arrayDepartment[i]);
                            a.IdEmployee   = model.Id;
                            a.IdPosition   = int.Parse(arrayPosition[i]);
                            _iplEmployee.InsertDepartment(a);
                        }
                    }
                    else
                    {
                        ReturnFalse(model.Id);
                        ViewBag.ErrPosition = "Chức vụ và phòng ban phải tương đồng.";
                        return(View("CreateEmployee", model));
                    }
                    #endregion
                    #region Sửa Công Việc
                    if (DispatchWorkId != null)
                    {
                        //Xóa liên kết cũ
                        _iplEmployee.DeleteWork(model.Id);
                        //Lưu liên kết mới
                        foreach (var item in arrayDispatchWork)
                        {
                            Employee_DispatchWork a = new Employee_DispatchWork();
                            a.IdDispatchWork = int.Parse(item);
                            a.IdEmployee     = model.Id;
                            _iplEmployee.InsertDispatchWork(a);
                        }
                    }
                    else
                    {
                        ReturnFalse(model.Id);
                        ViewBag.ErrDispatchWork = "Công việc không được để trống.";
                        return(View("CreateEmployee", model));
                    }
                    #endregion
                    if (entity != null && entity.Id > 0)
                    {
                        entity.FirstName            = model.FirstName;
                        entity.LastName             = model.LastName;
                        entity.Phone                = model.Phone;
                        entity.Address              = model.Address;
                        entity.AcademicLevel        = model.AcademicLevel;
                        entity.Birthday             = model.Birthday;
                        entity.Gender               = model.Gender;
                        entity.IsActive             = model.IsActive;
                        entity.Position             = model.Position;
                        entity.DepartmentId         = model.DepartmentId;
                        entity.WageAgreement        = model.WageAgreement;
                        entity.ProbationaryFromDate = model.ProbationaryFromDate;
                        entity.ProbationaryToDate   = model.ProbationaryToDate;
                        entity.WorkFromDate         = model.WorkFromDate;
                        entity.WorkToDate           = model.WorkToDate;

                        if (model.file != null && model.file.ContentLength > 0)
                        {
                            if (!Utility.CheckImageFormat(model.file.FileName))
                            {
                                ViewBag.msgUpload = ConstantMsg.ErrorImageFormat;
                                return(View(model));
                            }
                            var retUpload = Upload.upload(_imagePath, model.file, 250, 250);
                            entity.PicturePath = retUpload.pathThumb;
                        }
                        var retVal = _iplEmployee.Update(entity);

                        if (retVal)
                        {
                            return(RedirectToAction("Index", "Employee"));
                        }
                    }
                }
                #endregion
                #region Thêm mới Employee
                else
                {
                    var sess = SessionSystem.GetUser();
                    Logs.logs("Thêm nhân sự", "Truy cập vào trang Employee", "/Employee/CreateEmployee", sess.UserId);
                    if (model.file != null && model.file.ContentLength > 0)
                    {
                        if (!Utility.CheckImageFormat(model.file.FileName))
                        {
                            ViewBag.msgUpload = ConstantMsg.ErrorImageFormat;
                            return(View(model));
                        }
                        var retUpload = Upload.upload(_imagePath, model.file, 250, 250);
                        model.PicturePath = retUpload.pathThumb;
                    }
                    var empId = _iplEmployee.Insert(model);

                    if (empId > 0)
                    {
                        for (int i = 0; i < arrayDepartment.Count(); i++)
                        {
                            var EmpHis = new Employee_HistoryEntity();
                            EmpHis.Position     = int.Parse(arrayPosition[i]);
                            EmpHis.DepartmentId = int.Parse(arrayDepartment[i]);
                            EmpHis.EmployeeId   = empId;
                            EmpHis.TimeIn       = DateTime.Now;
                            EmpHis.Note         = "Bắt đầu làm việc";
                            _iplEmployee_History.Insert(EmpHis);

                            var employee_Department = new Employee_Department();
                            employee_Department.IdDepartment = int.Parse(arrayDepartment[i]);
                            employee_Department.IdEmployee   = empId;
                            employee_Department.IdPosition   = int.Parse(arrayPosition[i]);
                            _iplEmployee.InsertDepartment(employee_Department);
                        }
                        //Lưu liên kết mới
                        foreach (var item in arrayDispatchWork)
                        {
                            Employee_DispatchWork a = new Employee_DispatchWork();
                            a.IdDispatchWork = int.Parse(item);
                            a.IdEmployee     = empId;
                            _iplEmployee.InsertDispatchWork(a);
                        }
                        return(RedirectToAction("Index", "User", new { id = empId }));
                    }
                }
                #endregion
            }
            ReturnFalse(model.Id);
            return(View("CreateEmployee", model));
        }