public int Update(Data.Models.PreventiveMaintenance PM)
        {
            Data.Models.PreventiveMaintenance oldPM = _PMRepository.Table.FirstOrDefault(w => w.Id == PM.Id);

            if (oldPM != null)
            {
                oldPM.Description = PM.Description;
                //oldPM.LineId = PM.LineId;
                //oldPM.MachineId = PM.MachineId;
                oldPM.Checkpoints      = PM.Checkpoints;
                oldPM.ShutdownRequired = PM.ShutdownRequired;
                //oldPM.ScheduleType = PM.ScheduleType;
                //oldPM.ShutdownRequired = PM.ShutdownRequired;
                //oldPM.ScheduleStartDate = PM.ScheduleStartDate;
                oldPM.ScheduleEndDate = PM.ScheduleEndDate;
                //oldPM.NextReviewDate = PM.NextReviewDate;
                //oldPM.WorkId = PM.WorkId;
                oldPM.UpdatedOn         = PM.UpdatedOn;
                oldPM.UpdatedBy         = PM.UpdatedBy;
                oldPM.WorkDescription   = PM.WorkDescription;
                oldPM.PreferredVendorId = PM.PreferredVendorId;
                //oldPM.Interval = PM.Interval;
                oldPM.Severity      = PM.Severity;
                oldPM.IsObservation = PM.IsObservation;
                _PMRepository.Update(oldPM);
                return(oldPM.Id);
            }
            else
            {
                return(0);
            }
        }
Beispiel #2
0
        public JsonResult GetPMById(int Id)
        {
            PreventiveMaintenanceViewModel model = new PreventiveMaintenanceViewModel();

            Data.Models.PreventiveMaintenance objPM = this._pmServices.GetForId(Id);

            if (objPM != null)
            {
                model.SiteId            = 1;
                model.MachineId         = objPM.MachineId;
                model.PlantId           = objPM.PlantId;
                model.LineId            = objPM.LineId;
                model.MachineId         = objPM.MachineId;
                model.Description       = objPM.Description;
                model.Checkpoints       = objPM.Checkpoints;
                model.ScheduleType      = objPM.ScheduleType;
                model.Interval          = objPM.Interval;
                model.ShutdownRequired  = Convert.ToString(objPM.ShutdownRequired);
                model.ScheduleStartDate = objPM.ScheduleStartDate;
                model.ScheduleEndDate   = objPM.ScheduleEndDate;
                model.UserId            = this._userService.GetAllByUserAssignments(objPM.Id);
                model.WorkDescription   = objPM.WorkDescription;
                model.Severity          = objPM.Severity;
                model.IsObservation     = objPM.IsObservation;
                // model.PreferredVendorId = objPM.PreferredVendorId;
                // model.VendorCategoryId = objPM.Vendor.CategoryId;

                //model.WorkName = objPM.PreventiveWorkDescription.Description;
            }
            return(Json(model, JsonRequestBehavior.AllowGet));
        }
        public int[] Delete(int[] ids, DateTime deletedon, int userId)
        {
            List <int> PMIds = new List <int>();

            foreach (int id in ids)
            {
                //var existingHistrory = this._PRHRepository.Table.FirstOrDefault(f => f.PreventiveId == id && (f.ReviewDate != null || f.HoldId != null));
                //if (existingHistrory == null)
                //{
                //    var HoldHistory = _PHHRepository.Table.Where(w => w.PreventiveId == id);
                //    _PHHRepository.Delete(HoldHistory);
                //    var ReviewHistory = _PRHRepository.Table.Where(w => w.PreventiveId == id);
                //    _PRHRepository.Delete(ReviewHistory);
                //    var UserAssignment = _UARepository.Table.Where(w => w.PreventiveMaintenanceId == id);
                //    _UARepository.Delete(UserAssignment);
                //    Data.Models.PreventiveMaintenance PreventiveMaintenance = _PMRepository.Table.FirstOrDefault(w => w.Id == id);
                //    _PMRepository.Delete(PreventiveMaintenance);
                //}
                //else
                //{
                Data.Models.PreventiveMaintenance existingPM = _PMRepository.Table.FirstOrDefault(w => w.Id == id);
                existingPM.IsDeleted   = true;
                existingPM.IsDeletedOn = deletedon;
                existingPM.IsDeletedBy = userId;
                _PMRepository.Update(existingPM);
                //}
            }
            return(PMIds.ToArray());
        }
 public void UpdateIsObservation(int PMId, bool IsObservation)
 {
     Data.Models.PreventiveMaintenance oldPM = _PMRepository.Table.Where(w => w.Id == PMId).FirstOrDefault();
     if (oldPM != null)
     {
         oldPM.IsObservation = IsObservation;
         _PMRepository.Update(oldPM);
     }
 }
Beispiel #5
0
        public ActionResult UpdateLastReviewDate(int PMId, DateTime reviewDate)
        {
            PreventiveMaintenanceViewModel model = new PreventiveMaintenanceViewModel();

            Data.Models.PreventiveMaintenance objPM = this._pmServices.GetForId(model.Id);
            if (objPM != null)
            {
                model.LastReviewDate = objPM.LastReviewDate;
            }

            return(View(model));
        }
        public int UpdateNextReviewDate(int PMId, int holdId, int holdValue)
        {
            Data.Models.PreventiveMaintenance existingPM = _PMRepository.Table.FirstOrDefault(w => w.Id == PMId);
            if (existingPM != null)
            {
                DateTime nextReviewDate = DateTime.UtcNow.Date;

                switch (existingPM.ScheduleType)
                {
                case 1:
                    nextReviewDate = existingPM.NextReviewDate.AddDays(holdValue);     // Days
                    break;

                case 2:
                    nextReviewDate = existingPM.NextReviewDate.AddDays(holdValue * 7);     // Weeks
                    break;

                case 3:
                    nextReviewDate = existingPM.NextReviewDate.AddMonths(holdValue);     // Months
                    break;

                case 4:
                    nextReviewDate = existingPM.NextReviewDate.AddYears(holdValue);     // Years
                    break;
                }

                var existingHistrory = this._PRHRepository.Table.FirstOrDefault(f => f.PreventiveId == PMId && f.ScheduledReviewDate == existingPM.NextReviewDate);
                existingHistrory.HoldId = holdId;

                existingPM.NextReviewDate = nextReviewDate;
                _PMRepository.Update(existingPM);
                return(existingPM.Id);
            }
            else
            {
                return(0);
            }
        }
Beispiel #7
0
        public JsonResult SavePM(PreventiveMaintenance PreventiveMaintenance, List <int> UserIds)
        {
            var result = new { Success = "true", Message = "Success" };

            try
            {
                PreventiveMaintenance PMobj = new Data.Models.PreventiveMaintenance();

                if (PreventiveMaintenance.Id == 0)
                {
                    if (PreventiveMaintenance.ScheduleStartDate == null)
                    {
                        result = new { Success = "false", Message = "Schedule start date is required!" };
                        return(Json(result, JsonRequestBehavior.AllowGet));
                    }

                    if (PreventiveMaintenance.ScheduleStartDate.Value.Date < DateTime.Now.Date)
                    {
                        result = new { Success = "false", Message = "Schedule start date can not be past date!" };
                        return(Json(result, JsonRequestBehavior.AllowGet));
                    }

                    //DateTime nextReviewDate = DateTime.UtcNow;
                    //if (PreventiveMaintenance.ScheduleType == 1)
                    //{
                    //    nextReviewDate = DateTime.UtcNow.AddDays(PreventiveMaintenance.Interval);
                    //}
                    //else if (PreventiveMaintenance.ScheduleType == 2)
                    //{
                    //    nextReviewDate = DateTime.UtcNow.AddDays(7 * (PreventiveMaintenance.Interval));
                    //}
                    //else if (PreventiveMaintenance.ScheduleType == 3)
                    //{
                    //    nextReviewDate = DateTime.UtcNow.AddMonths(PreventiveMaintenance.Interval);
                    //}
                    //else if (PreventiveMaintenance.ScheduleType == 4)
                    //{
                    //    nextReviewDate = DateTime.UtcNow.AddYears(PreventiveMaintenance.Interval);
                    //}
                    PreventiveMaintenance.CreatedBy = HttpContext.User.Identity.GetUserId <int>();
                    PreventiveMaintenance.CreatedOn = DateTime.UtcNow;
                    //PreventiveMaintenance.UpdatedBy = HttpContext.User.Identity.GetUserId<int>();
                    //PreventiveMaintenance.UpdatedOn= DateTime.UtcNow;
                    PreventiveMaintenance.NextReviewDate = PreventiveMaintenance.ScheduleStartDate.Value.Date; //nextReviewDate.Date;
                    PreventiveMaintenance.IsDeleted      = false;
                    PreventiveMaintenance.Id             = this._pmServices.Add(PreventiveMaintenance);
                }
                else
                {
                    //PreventiveMaintenance.CreatedBy = HttpContext.User.Identity.GetUserId<int>();
                    //PreventiveMaintenance.CreatedOn = DateTime.Now;
                    PreventiveMaintenance.UpdatedBy = HttpContext.User.Identity.GetUserId <int>();
                    PreventiveMaintenance.UpdatedOn = DateTime.UtcNow;
                    this._pmServices.Update(PreventiveMaintenance);
                }

                this._uaServices.DeleteUA(PreventiveMaintenance.Id, UserIds);

                foreach (int id in UserIds)
                {
                    this._uaServices.Add(new UserAssignment
                    {
                        PreventiveMaintenanceId = PreventiveMaintenance.Id,
                        UserId = id
                    });
                }
            }
            catch (Exception ex)
            {
                string exceptionMsg = base.ProcessException(ex);
                result = new { Success = "false", Message = exceptionMsg };
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
 public int Add(Data.Models.PreventiveMaintenance PM)
 {
     _PMRepository.Insert(PM);
     return(PM.Id);
 }
        public void UpdateReviewDate(int PMId, string Note, int userId, DateTime ReviewDate, bool isOverDue)
        {
            Data.Models.PreventiveMaintenance existingPM = _PMRepository.Table.FirstOrDefault(w => w.Id == PMId);

            if (existingPM != null)
            {
                DateTime lastReviewDate = DateTime.UtcNow;
                DateTime nextReviewDate = existingPM.NextReviewDate;

                if (isOverDue)
                {
                    nextReviewDate = DateTime.UtcNow.Date;
                }

                if (existingPM.ScheduleType == 1) // Daily
                {
                    nextReviewDate = nextReviewDate.AddDays(1 * (existingPM.Interval));
                }
                else if (existingPM.ScheduleType == 2) // Weekly
                {
                    nextReviewDate = nextReviewDate.AddDays(7 * (existingPM.Interval));
                }
                else if (existingPM.ScheduleType == 3) //Monthly
                {
                    nextReviewDate = nextReviewDate.AddMonths(1 * (existingPM.Interval));
                }
                else if (existingPM.ScheduleType == 4) // Yearly
                {
                    nextReviewDate = nextReviewDate.AddYears(1 * (existingPM.Interval));
                }
                else if (existingPM.ScheduleType == 6)//Hourly
                {
                    nextReviewDate = nextReviewDate.AddHours(1 * (existingPM.Interval));
                }
                else // Shutdown
                {
                    nextReviewDate = System.Data.SqlTypes.SqlDateTime.MinValue.Value;
                }

                var existingHistrory = this._PRHRepository.Table.FirstOrDefault(f => f.PreventiveId == PMId && f.ScheduledReviewDate == ReviewDate && (f.ShutdownId == null || f.ShutdownId == f.PreventiveMaintenance.PreventiveReviewHistories.Max(m => m.ShutdownId)));


                if (existingHistrory == null)
                {
                    this._PRHRepository.Insert(new Data.Models.PreventiveReviewHistory {
                        PreventiveId = PMId, Notes = Note, ReviewBy = userId, ReviewDate = lastReviewDate, ScheduledReviewDate = ReviewDate, IsLaps = false, IsOverdue = false
                    });
                }
                else
                {
                    existingHistrory.Notes      = Note;
                    existingHistrory.ReviewBy   = userId;
                    existingHistrory.ReviewDate = lastReviewDate;
                    //existingHistrory.ScheduledReviewDate = existingPM.NextReviewDate;
                    this._PRHRepository.Update(existingHistrory);
                }

                existingPM.LastReviewDate = lastReviewDate;
                existingPM.NextReviewDate = nextReviewDate;
                _PMRepository.Update(existingPM);

                if (isOverDue)
                {
                    //DateTime dtToday = DateTime.UtcNow.Date;
                    //var allData = from a in this._PMRepository.Table
                    //              where a.Id == PMId
                    //              select a;

                    //var preventiveData = this._PMRepository.Table.FirstOrDefault(w => w.Id == PMId);
                    var preventiveHistory = this._PRHRepository.Table.Where(w => w.PreventiveId == PMId && w.ScheduledReviewDate > ReviewDate).OrderBy(o => o.ScheduledReviewDate).ToArray();

                    for (int i = 0; i < preventiveHistory.Length; i++)
                    {
                        var preventiveReviewHistory = preventiveHistory[i];

                        preventiveReviewHistory.ScheduledReviewDate = nextReviewDate;
                        this._PRHRepository.Update(preventiveReviewHistory);
                        //if (existingPM.ScheduleType == 1) // Daily
                        //{
                        //    nextReviewDate = nextReviewDate.AddDays(1 * (existingPM.Interval));
                        //}
                        /*else*/
                        if (existingPM.ScheduleType == 2) // Weekly
                        {
                            nextReviewDate = nextReviewDate.AddDays(7 * (existingPM.Interval));
                        }
                        else if (existingPM.ScheduleType == 3) //Monthly
                        {
                            nextReviewDate = nextReviewDate.AddMonths(1 * (existingPM.Interval));
                        }
                        else if (existingPM.ScheduleType == 4) // Yearly
                        {
                            nextReviewDate = nextReviewDate.AddYears(1 * (existingPM.Interval));
                        }
                        else if (existingPM.ScheduleType == 6)//Hourly
                        {
                            nextReviewDate = nextReviewDate.AddHours(1 * (existingPM.Interval));
                        }
                        else // Shutdown
                        {
                            nextReviewDate = System.Data.SqlTypes.SqlDateTime.MinValue.Value;
                        }
                    }
                }

                //if (existingPM.ScheduleType != 5) // Shutdown
                //    this._PRHRepository.Insert(new Data.Models.PreventiveReviewHistory { PreventiveId = PMId, Notes = null, ReviewBy = null, ReviewDate = null, ScheduledReviewDate = nextReviewDate });
            }
        }
        public void VerifyNextReviewDate(int PMId, int scheduleType, int interval, DateTime reviewDate)
        {
            DateTime nextReviewDate = DateTime.UtcNow.Date;
            DateTime dateCompare    = DateTime.UtcNow.Date;

            switch (scheduleType)
            {
            case 1:     // Daily
                dateCompare    = DateTime.UtcNow.Date.AddDays(-1 * (interval - 1));
                nextReviewDate = reviewDate.AddDays(1 * interval);
                break;

            case 2:     // Weekly
                int      delta  = DayOfWeek.Monday - DateTime.UtcNow.Date.DayOfWeek;
                DateTime monday = DateTime.UtcNow.Date.AddDays(delta);
                dateCompare    = monday.AddDays(-7 * (interval - 1));
                nextReviewDate = reviewDate.AddDays(7 * interval);
                break;

            case 3:     // Monthly
                DateTime firstDayofMonth = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 1);
                dateCompare    = firstDayofMonth.AddMonths(-1 * (interval - 1));
                nextReviewDate = reviewDate.AddMonths(1 * interval);
                break;

            case 4:     // Yearly
                DateTime firstDayofYear = new DateTime(DateTime.UtcNow.Year, 1, 1);
                dateCompare    = firstDayofYear.AddYears(-1 * (interval - 1));
                nextReviewDate = reviewDate.AddYears(1 * interval);
                break;

            case 5:    //Shutdown
                break;
            }

            if (scheduleType != 5)
            {
                if (!this._PRHRepository.Table.Any(f => f.PreventiveId == PMId && f.ScheduledReviewDate == reviewDate))
                {
                    this._PRHRepository.Insert(new Data.Models.PreventiveReviewHistory {
                        PreventiveId = PMId, Notes = null, ReviewBy = null, ReviewDate = null, ScheduledReviewDate = reviewDate
                    });
                }

                if (!this._PRHRepository.Table.Any(f => f.PreventiveId == PMId && f.ScheduledReviewDate == nextReviewDate))
                {
                    this._PRHRepository.Insert(new Data.Models.PreventiveReviewHistory {
                        PreventiveId = PMId, Notes = null, ReviewBy = null, ReviewDate = null, ScheduledReviewDate = nextReviewDate
                    });
                }

                if (nextReviewDate < dateCompare)
                {
                    VerifyNextReviewDate(PMId, scheduleType, interval, nextReviewDate);
                }
                else
                {
                    Data.Models.PreventiveMaintenance existingPM = _PMRepository.Table.FirstOrDefault(w => w.Id == PMId);
                    existingPM.NextReviewDate = dateCompare;
                    _PMRepository.Update(existingPM);
                }
            }
        }