Exemplo n.º 1
0
        /// <summary>
        /// Manages the field report import and processing functions.
        /// </summary>
        private void RunFieldReport()
        {
            //Validate and assign the job number before opening the file dialog window.  Validation is
            //performed by the JobNumberValidation object upon instantiation.
            JobNumberValidation validationControl = new JobNumberValidation(txtJobNumber.Text, IsSaveOperation: false);

            if (validationControl.IsValidJobNumber && validationControl.HasEstimateData(validationControl.ValidationResult))
            {
                //Grab the validated job number.
                string jobNumber = txtJobNumber.Text;

                OpenFileDialog ImportFieldReportDialog = new OpenFileDialog()
                {
                    Filter = "CSV Files (*.csv)|*.csv",
                    Title  = "Select a Field Report"
                };

                DialogResult importResult = ImportFieldReportDialog.ShowDialog();
                if (importResult == DialogResult.OK)
                {
                    // MAIN PROGRAM
                    // ***************************************************
                    //1.  READ THE CSV FILE INTO MEMORY.
                    //Get the selected file path.
                    string selectedFile = ImportFieldReportDialog.FileName;
                    // Use the CSVHelper to process the file contents and produce a list of SystemReport objects.
                    CSVHelper           csvHelper       = new CSVHelper();
                    List <SystemReport> reportedSystems = csvHelper.GetReportedSystemList(selectedFile);

                    if (reportedSystems != null || reportedSystems.Count != 0)
                    {
                        // ***************************************************
                        //2.  USE THE CLIENT REPORT SERVICE TO RUN AND RETURN THE REPORT OBJECT.
                        //Note:  To get this far, the field report must have already been validated and processed into a List of SystemReport objects.
                        //Create the report service.
                        ClientReportService clientReportService = new ClientReportService(jobNumber, _dataProvider);
                        //Send the field report system list to the report service to generate the full summary report object.
                        //ComparatorReport finishedReport = clientReportService.GetReportSummary(reportedSystems);
                        CostCodeReport costCodeReport = clientReportService.GetCostCodeReportSummary(reportedSystems);


                        // ***************************************************
                        //3.  DISPLAY THE PREFERRED DATA FROM THE REPORT OBJECT.
                        //Send the report object to the data display service.
                        DataDisplayService dataDisplayService = new DataDisplayService();
                        dataDisplayService.DisplayCostCodeReport(costCodeReport);
                    }
                    else
                    {
                        MessageBox.Show("No system data was found in the report. Please check the imported file and verify that Phase Code and Equipment System data are present in the file before trying again.  If problem persists, please contact Technical Support.", "No Data Found", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        throw new Exception("Reporting service returned a blank or null system report list to the Main program without throwing a validation error.  Please check the CSVHelper class to make sure that type conversions are working properly.");
                    }
                }
            }
            else
            {
                //throw new Exception("Validation Failed");
            }
        }