Example #1
0
        private void InitializeConfirmationLabel()
        {
            int      tempAIRAC = Convert.ToInt32(YearComboBox.Text.Substring(2, 2) + Convert.ToInt32(CycleComboBox.Text).ToString("D2"));
            DateTime tempStart = CycleInfo.CycleDateFromAIRAC(tempAIRAC).Date;
            DateTime tempEnd   = CycleInfo.CycleDateFromAIRAC(tempAIRAC).AddDays(28).Date;
            string   cr        = Environment.NewLine;

            ConfirmationLabel.Text = "AIRAC: " + tempAIRAC.ToString() + cr +
                                     "Cycle Dates: " + cr + tempStart.ToShortDateString() + " - " + tempEnd.Date.ToShortDateString();
            if (tempEnd < DateTime.Now.Date)
            {
                ConfirmationLabel.Text += cr + "*** Outdated Cycle ***";
            }
            ConfirmationLabel.Refresh();
        }
Example #2
0
        private void InitializeYearComboBox()
        {
            YearComboBox.Items.Clear();
            for (int i = 2017; i <= DateTime.Now.Year; i++)
            {
                YearComboBox.Items.Add(i);
            }
            DateTime currentCycleDate = CycleInfo.CycleDateFromAIRAC(CycleInfo.CurrentAIRAC).Date;
            DateTime nextCycleDate    = currentCycleDate.AddDays(28).Date;

            if (nextCycleDate.Year > DateTime.Now.Year)
            {
                YearComboBox.Items.Add(nextCycleDate.Year.ToString());
            }
            YearComboBox.SelectedItem = currentCycleDate.Year;
        }
Example #3
0
        private void InitializeCycleComboBox()
        {
            // Three conditions: previous year, current year, future year
            DateTime currentCycleDate = CycleInfo.CycleDateFromAIRAC(CycleInfo.CurrentAIRAC).Date;
            DateTime nextCycleDate = currentCycleDate.AddDays(28).Date;
            int      curYear = DateTime.Now.Year;
            int      selectedYear = Convert.ToInt32(YearComboBox.SelectedItem);
            int      lastCycle; int firstCycle = 11; //  2017 first archive is cycle 11

            CycleComboBox.Items.Clear();
            if (selectedYear < curYear)
            {
                lastCycle = Convert.ToInt32(CycleInfo.AIRACfromDate(DateTime.Parse("12/31/" + selectedYear.ToString())).ToString(CultureInfo.InvariantCulture).Substring(2, 2));
                if (selectedYear != 2017)
                {
                    firstCycle = 1;
                }
                for (int i = firstCycle; i < lastCycle; i++)
                {
                    CycleComboBox.Items.Add(i);
                }
                CycleComboBox.SelectedIndex = 0;
            }
            if (selectedYear == curYear)
            {
                lastCycle = Convert.ToInt32(CycleInfo.AIRACfromDate(DateTime.Now.Date).ToString(CultureInfo.InvariantCulture).Substring(2, 2));
                for (int i = 1; i <= lastCycle; i++)
                {
                    CycleComboBox.Items.Add(i);
                }
                CycleComboBox.SelectedItem = lastCycle;
                if (nextCycleDate.Year == DateTime.Now.Year)
                {
                    CycleComboBox.Items.Add(lastCycle + 1);
                }
            }
            if (selectedYear > curYear)
            {
                CycleComboBox.Items.Add(1);
                CycleComboBox.SelectedIndex = 0;
            }
        }
Example #4
0
        private void OKButton_Click(object sender, EventArgs e)
        {
            MyButtonCancel.Enabled = false;
            MyButtonCancel.Visible = false;
            int tempAIRAC = Convert.ToInt32(YearComboBox.Text.Substring(2, 2) + Convert.ToInt32(CycleComboBox.Text).ToString("D2"));

            CycleInfo.CycleDateFromAIRAC(tempAIRAC, true);
            if (!CleanDataFolder())
            {
                InitializeConfirmationLabel();
                Close();        // Must have a clean data folder to place data
            }
            // Set up values for the download;
            string        newCycleDate = CycleInfo.CycleStart.Date.ToString("yyyy'-'MM'-'dd");
            DirectoryInfo di;

            di          = Directory.CreateDirectory(FolderMgt.DataFolder + "\\28DaySubscription_Effective_" + newCycleDate + "\\");
            extractPath = di.FullName;
            string URL = "https://nfdc.faa.gov/webContent/28DaySub/28DaySubscription_Effective_" + newCycleDate + ".zip";

            downloadsPath = "28DaySubscription_Effective_" + newCycleDate + ".zip";
            downloadsPath = Path.GetTempPath() + downloadsPath;
            // If the zipfile is already downloaded, delete it (safer as it may be corrupted)
            if (File.Exists(downloadsPath))
            {
                File.Delete(downloadsPath);
            }
            OKButton.Text    = "Downloading FAA files";
            OKButton.Enabled = false;
            // Start the download
            WebClient wc = new WebClient();

            wc.DownloadProgressChanged += (s, f) =>
            {
                progressBar1.Value = f.ProgressPercentage;
            };
            wc.DownloadFileCompleted += (s, g) =>
            {
                // Unless I messed up, there cannot be a data subdirectory by this name, so create it
                OKButton.Text = "Extracting files...";
                OKButton.Refresh();
                try
                {
                    ZipFile.ExtractToDirectory(downloadsPath, extractPath);
                    OKButton.Enabled       = false;
                    OKButton.Visible       = false;
                    ContinueButton.Enabled = true;
                    ContinueButton.Visible = true;
                    downloadComplete       = true;
                    if (File.Exists(downloadsPath))
                    {
                        File.Delete(downloadsPath);
                    }
                }
                catch
                {
                    string msg = "Extraction failed. (Usually because there is already extracted data.) " +
                                 "Retry after manually removing all subscription files from the target folder. " +
                                 "You can extract manually to the target folder, then reselect the data folder to update the datafiles." + cr +
                                 " (" + di.FullName + ")";
                    SCTcommon.SendMessage(msg);
                    DialogResult = DialogResult.Abort;
                }
            };
            try
            {
                wc.DownloadFileAsync(new System.Uri(URL), downloadsPath);
                while (!downloadComplete)
                {
                    Application.DoEvents();
                }
                downloadComplete = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }