Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
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();
            }
        }