Ejemplo 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");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Processes the estimate data and saves it to the database.
        /// </summary>
        private void RecordEstimateToDatabase()
        {
            //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: true);

            if (validationControl.IsValidJobNumber)
            {
                if (!validationControl.IsDuplicateEstimate)
                {
                    EstimateHelper estimateHelper = new EstimateHelper(Globals.ThisAddIn.Application);
                    //Try to activate the 'Main Form' tab of the Estimate sheet.  If the attempt is successful, then the process for saving estimate data
                    //will move ahead.  Otherwise, an error message will be shown to the user.
                    if (estimateHelper.CalibratePosition())
                    {
                        List <SystemEstimate> systemEstimateList = estimateHelper.PopulateSystemList();
                        if (systemEstimateList.Count > 0 && systemEstimateList != null)
                        {
                            try
                            {
                                EstimateRecordingService recordingService = new EstimateRecordingService(txtJobNumber.Text);
                                recordingService.Commit(systemEstimateList);
                                MessageBox.Show("The estimate for Job Number: " + txtJobNumber.Text + " was successfully saved.", "Estimate Saved");
                            }
                            catch (Exception)
                            {
                                throw;
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("To save Estimate data, the user must have the Estimate workbook open and be on the 'MainForm' tab.");
                    }
                }
                else
                {
                    MessageBox.Show("Sorry, but an estimate for this job already exists.");
                }
            }
        }