Esempio n. 1
0
        public static void UpdateReportValidation(WorkScheduleImportTemplateModel workScheduleTemplate, List <WorkShiftModel> availableWorkshiftList, string currentAgencyId, ReportValidationModel repotValidationModel)
        {
            string        returnMessage;
            List <string> validUnitList          = new List <string>();
            List <string> validStationIdList     = new List <string>();
            List <int>    validEmployeeIdNumList = new List <int>();
            List <string> validEmployeeIdList    = new List <string>();

            List <WorkScheduleUnitModel> workScheduleUnitList = new List <WorkScheduleUnitModel>();

            validUnitList          = UnitBusiness.GetActiveUnitsId(currentAgencyId);
            validStationIdList     = CadBusiness.GetCadStationList(currentAgencyId).Select(cs => cs.StationId).ToList <string>();
            validEmployeeIdNumList = GetEmployeeIds(currentAgencyId);

            foreach (int emp in validEmployeeIdNumList)
            {
                validEmployeeIdList.Add(emp.ToString());
            }

            List <DateTime> dateTimeListFromWorkSchedule      = workScheduleTemplate.WorkScheduleForUnitList.Where(ws => ws.ShiftDate.HasValue).Select(ws => ws.ShiftDate.Value).Distinct().ToList <DateTime>();
            List <string>   workshifLabelListfromWorkSchedule = workScheduleTemplate.WorkScheduleForUnitList.Select(ws => ws.WorkshiftLabel).Distinct().ToList <string>();

            workScheduleTemplate.UpdateReportValidationBasedOnNewData(ref repotValidationModel, validStationIdList, validEmployeeIdList, validUnitList, availableWorkshiftList);

            foreach (DateTime date in dateTimeListFromWorkSchedule)
            {
                foreach (WorkShiftModel workShift in availableWorkshiftList.Where(ws => workshifLabelListfromWorkSchedule.Contains(ws.Label)))
                {
                    workScheduleUnitList = WorkScheduleBusiness.GetWorkScheduleList(null, date, workShift, WorkShiftModel.ShiftTime.Forward, (int)FilterTypeEnum.ALL, out returnMessage)
                                           .Where(uf => uf.Driver != null || uf.Doctor != null || uf.Nurse != null || uf.FirstAuxiliar != null || uf.SecondAuxiliar != null || uf.ThirdAuxiliar != null)
                                           .ToList <WorkScheduleUnitModel>();
                    workScheduleTemplate.UpdateReportValidationBasedOnOldData(ref repotValidationModel, availableWorkshiftList, workScheduleUnitList);
                }
            }

            repotValidationModel.JoinIdsOfReportValidationList();

            UpdateWorkScheduleWithErrors(repotValidationModel, workScheduleTemplate);

            if (repotValidationModel.ReportValidationItemList.Count == 0)
            {
                repotValidationModel.AddReportItem(WorkScheduleValidationType.VALIDATED, Properties.Resources.ALERT_MESSAGE_WHEN_NO_ERRORS);
            }
        }
Esempio n. 2
0
        /*public Dictionary<WorkScheduleValidationType, WorkScheduleValidationTypeMessage> ValidationsByType {
         *  get { return _validationsByType; }
         *  set
         *  {
         *      _validationsByType = value;
         *      OnPropertyChanged("ValidationsByType");
         *  }
         * }*/

        #endregion

        #region Métodos

        public void LoadValidation_DoWork(object sender, DoWorkEventArgs e)
        {
            if (IsLoading)
            {
                return;
            }

            try
            {
                EnableLoadingProgress("Validando escala");
                string agencyId = "SAMU";
                WorkScheduleImported = new WorkScheduleImportTemplateModel();
                RevortValidationList = new ObservableCollection <ReportValidationItemModel>();

                if (this.IsPeriodicWorkSchedule)
                {
                    if (!ValidatePeriodicWorkScheduleFilter())
                    {
                        DisableLoadingProgress();
                        return;
                    }
                }

                //WorkScheduleImported.WorkScheduleForUnitList

                List <WorkScheduleForUnitModel> workScheduleList = UnitForceMapBusiness.ExtractWorkSchedule(this.FullPathFile).ToList <WorkScheduleForUnitModel>();

                if (this.IsPeriodicWorkSchedule)
                {
                    bool hasError = false;

                    if (workScheduleList.Where(ws => String.IsNullOrEmpty(ws.DateFrequence)).Count() > 0)
                    {
                        DisableLoadingProgress();
                        MessageBox.Show("A frequência de datas deve ser informada em todas as escalas da planilha.\nFavor verificar a planilha de importação.");
                        return;
                    }

                    CompleteWithPeriodicWorkSchedule(workScheduleList, ref hasError);

                    if (hasError || (IsUpdatingWorkSchedule && !ValidateUpdatingWorkSchedule()))
                    {
                        DisableLoadingProgress();
                        return;
                    }
                }
                else
                {
                    WorkScheduleImported.WorkScheduleForUnitList = workScheduleList;
                }

                ReportValidation = new ReportValidationModel();
                ReportValidationBusiness.UpdateReportValidation(WorkScheduleImported, _workShiftList, agencyId, ReportValidation);



                if (IsUpdatingWorkSchedule)
                {
                    this.ReportValidation.ReportValidationItemList.RemoveAll(
                        r => r.WorkScheduleValidationType == WorkScheduleValidationType.CONFLICT_WITH_PREVIOUS_DATA ||
                        r.WorkScheduleValidationType == WorkScheduleValidationType.DATA_SHOULD_BE_FILLED ||
                        r.WorkScheduleValidationType == WorkScheduleValidationType.INVALID_CREW_FORMATION);
                }



                EnableImporting = !ReportValidationBusiness.AreThereErrorMessages(this.ReportValidation);
            }
            catch (SheetNotFoundException exception)
            {
                WorkScheduleImported.WorkScheduleForUnitList = new List <WorkScheduleForUnitModel>();
                ReportValidation = new ReportValidationModel();
                EnableImporting  = false;

                ReportValidation.AddReportItem(WorkScheduleValidationType.SHEET_NAME_NOT_FOUND, WorkScheduleImportTemplateModel.WORK_SCHEDULE_MAIN_SHEET_NAME.ToUpper());
            }
            catch (Exception exception)
            {
                WorkScheduleImported.WorkScheduleForUnitList = new List <WorkScheduleForUnitModel>();
                ReportValidation = new ReportValidationModel();
                EnableImporting  = false;

                MessageBox.Show(String.Format("Erro durante a validação do arquivo: {0}", exception.Message));
                //ShowMessage(String.Format("Erro durante a validação do arquivo: {0}", exception.Message));

                return;
            }
            finally
            {
                DisableLoadingProgress();
            }
        }
Esempio n. 3
0
        public void LoadValidation_DoWork(object sender, DoWorkEventArgs e)
        {
            if (IsLoading)
            {
                return;
            }

            try
            {
                EnableLoadingProgress(Properties.Resources.DIALOG_MESSAGE_VALIDATING_WORK_SCHEDULE);
                WorkScheduleImported = new WorkScheduleImportTemplateModel();
                RevortValidationList = new ObservableCollection <ReportValidationItemModel>();

                if (this.IsPeriodicWorkSchedule)
                {
                    if (!ValidatePeriodicWorkScheduleFilter())
                    {
                        DisableLoadingProgress();
                        return;
                    }
                }

                List <ImportableWorkScheduleUnitModel> workScheduleList = ImportableWorkScheduleBusiness.ExtractWorkSchedule(this.FullPathFile).ToList <ImportableWorkScheduleUnitModel>();

                if (this.IsPeriodicWorkSchedule)
                {
                    bool hasError = false;

                    if (workScheduleList.Where(ws => String.IsNullOrEmpty(ws.DateFrequence)).Count() > 0)
                    {
                        DisableLoadingProgress();
                        MessageBox.Show(Properties.Resources.ALERT_MESSAGE_MISSED_DATE_FREQUENCE);
                        return;
                    }

                    CompleteWithPeriodicWorkSchedule(workScheduleList, ref hasError);

                    if (hasError || (IsUpdatingWorkSchedule && !ValidateUpdatingWorkSchedule()))
                    {
                        DisableLoadingProgress();
                        return;
                    }
                }
                else
                {
                    WorkScheduleImported.WorkScheduleForUnitList = workScheduleList;
                }

                ReportValidation = new ReportValidationModel();
                ReportValidationBusiness.UpdateReportValidation(WorkScheduleImported, _workShiftList, Properties.Settings.Default.AGENCY_ID, ReportValidation);



                if (IsUpdatingWorkSchedule)
                {
                    this.ReportValidation.ReportValidationItemList.RemoveAll(
                        r => r.WorkScheduleValidationType == WorkScheduleValidationType.CONFLICT_WITH_PREVIOUS_DATA ||
                        r.WorkScheduleValidationType == WorkScheduleValidationType.DATA_SHOULD_BE_FILLED ||
                        r.WorkScheduleValidationType == WorkScheduleValidationType.INVALID_CREW_FORMATION);
                }



                EnableImporting = !ReportValidationBusiness.AreThereErrorMessages(this.ReportValidation);
            }
            catch (SheetNotFoundException exception)
            {
                WorkScheduleImported.WorkScheduleForUnitList = new List <ImportableWorkScheduleUnitModel>();
                ReportValidation = new ReportValidationModel();
                EnableImporting  = false;

                ReportValidation.AddReportItem(WorkScheduleValidationType.SHEET_NAME_NOT_FOUND, ImportableWorkScheduleBusiness.GetWorkScheduleSheetName().ToUpper());
            }
            catch (Exception exception)
            {
                WorkScheduleImported.WorkScheduleForUnitList = new List <ImportableWorkScheduleUnitModel>();
                ReportValidation = new ReportValidationModel();
                EnableImporting  = false;

                MessageBox.Show(String.Format("{0}: {1}", Properties.Resources.ALERT_MESSAGE_ERROR_FILE_VALIDATING, exception.Message));
                return;
            }
            finally
            {
                DisableLoadingProgress();
            }
        }