Пример #1
0
        private void SaveToReportFile()
        {
            if (m_CurrentReportFile == null)
            {
                // Is there a report form currently opened?
                // If no then ask the user to append to an existing report or create a new one
                frmChooseReportFile reportFileForm = new frmChooseReportFile();
                if (reportFileForm.ShowDialog(this.ParentForm) != DialogResult.OK)
                {
                    return;
                }

                if (reportFileForm.IsNewReport)
                {
                    frmMPCObserver frmObserver = new frmMPCObserver(frmMPCObserver.MPCHeaderSettingsMode.NewMPCReport);
                    if (frmObserver.ShowDialog(ParentForm) == DialogResult.Cancel)
                    {
                        return;
                    }

                    if (saveFileDialog.ShowDialog(ParentForm) != DialogResult.OK)
                    {
                        return;
                    }

                    MPCObsHeader header = frmObserver.Header;
                    header.NET = tbxNetCode.Text;

                    m_CurrentReportFile = new MPCReportFile(saveFileDialog.FileName, header, () => m_RovingObservatoryProvider.GetRovingObsLocation());

                    TangraConfig.Settings.RecentFiles.NewRecentFile(RecentFileType.MPCReport, saveFileDialog.FileName);
                    TangraConfig.Settings.Save();
                }
                else
                {
                    m_CurrentReportFile = new MPCReportFile(reportFileForm.ReportFileName, () => m_RovingObservatoryProvider.GetRovingObsLocation());

                    if (m_CurrentReportFile.Header.NET != tbxNetCode.Text)
                    {
                        MessageBox.Show(
                            string.Format("The selected observation file uses {0} rather than {1}. Pelase select a different observation file or change the used catalog.",
                                          m_CurrentReportFile.Header.NET, tbxNetCode.Text), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                        m_CurrentReportFile = null;
                        return;
                    }
                }
            }

            if (m_CurrentReportFile != null)
            {
                foreach (string line in tbxMeasurements.Lines)
                {
                    string lineToAdd = line;
                    if (TangraConfig.Settings.Astrometry.ExportHigherPositionAccuracy && lineToAdd.Length > 80)
                    {
                        // Remove the extra signifficant digit from the RA/DE in high precision mode as those
                        // cannot be reported to the MPC with the current OBS format

                        //          1         2         3         4         5         6         7         8
                        //0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
                        //     K15FB7W  n2015 04 01.51040713 03 21.038 -41 43 17.18          13.5 R      E28 0.12 0.12
                        //        3200  n2017 12 06.78359306 15 58.559 +41 46 52.33          11.9 R      619 0.10 0.10

                        lineToAdd =
                            line.Substring(0, 38) +
                            double.Parse(line.Substring(38, 6), CultureInfo.InvariantCulture).ToString("00.00") +
                            line.Substring(44, 8) +
                            double.Parse(line.Substring(52, 5), CultureInfo.InvariantCulture).ToString("00.0") +
                            line.Substring(57);
                    }

                    m_CurrentReportFile.AddObservation(lineToAdd);
                }

                m_CurrentReportFile.Save();

                m_CurrentReportFile.Present(this);

                AstrometryContext.Current.CurrentReportFile = m_CurrentReportFile;
            }
        }
        private void SaveToReportFile()
        {
            if (m_CurrentReportFile == null)
            {
                // Is there a report form currently opened?
                // If no then ask the user to append to an existing report or create a new one
                frmChooseReportFile reportFileForm = new frmChooseReportFile();
                if (reportFileForm.ShowDialog(this.ParentForm) != DialogResult.OK)
                {
                    return;
                }

                if (reportFileForm.IsNewReport)
                {
                    frmMPCObserver frmObserver = new frmMPCObserver(frmMPCObserver.MPCHeaderSettingsMode.NewMPCReport);
                    if (frmObserver.ShowDialog(ParentForm) == DialogResult.Cancel)
                    {
                        return;
                    }

                    if (saveFileDialog.ShowDialog(ParentForm) != DialogResult.OK)
                    {
                        return;
                    }

                    MPCObsHeader header = frmObserver.Header;
                    header.NET          = tbxNetCode.Text;
                    m_CurrentReportFile = new MPCReportFile(saveFileDialog.FileName, header);

                    TangraConfig.Settings.RecentFiles.NewRecentFile(RecentFileType.MPCReport, saveFileDialog.FileName);
                    TangraConfig.Settings.Save();
                }
                else
                {
                    m_CurrentReportFile = new MPCReportFile(reportFileForm.ReportFileName);

                    if (m_CurrentReportFile.Header.NET != tbxNetCode.Text)
                    {
                        MessageBox.Show(
                            string.Format("The selected observation file uses {0} rather than {1}. Pelase select a different observation file or change the used catalog.",
                                          m_CurrentReportFile.Header.NET, tbxNetCode.Text), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                        m_CurrentReportFile = null;
                        return;
                    }
                }
            }

            if (m_CurrentReportFile != null)
            {
                foreach (string line in tbxMeasurements.Lines)
                {
                    m_CurrentReportFile.AddObservation(line);
                }

                m_CurrentReportFile.Save();

                m_CurrentReportFile.Present(this);

                AstrometryContext.Current.CurrentReportFile = m_CurrentReportFile;
            }
        }