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