/************************************************************************************************************************/

        /// <summary>
        /// Metoda pokazująca szczegóły startu zaznaczonego na aktywnej liście.
        /// </summary>
        private void ShowSelecterLaunchDetails()
        {
            var selected = activeList.SelectedItems;

            if (selected.Count == 1)
            {
                using (var context = new LaunchContext())
                {
                    ListViewItem item = selected[0];
                    activeLaunch = context.launches.Find(int.Parse(item.Text));

                    launchNameDetail.Text          = activeLaunch.name;
                    rocketFullLabelDetail.Text     = activeLaunch.rocketFullName;
                    statusLabelDetail.Text         = activeLaunch.status;
                    launchProviderLabelDetail.Text = activeLaunch.launchProvider;
                    launchPadLocDetail.Text        = activeLaunch.location;
                    windowStartDetail.Text         = activeLaunch.windowStart.ToString();
                    windowEndDetail.Text           = activeLaunch.windowEnd.ToString();

                    if (activeLaunch.favourite)
                    {
                        favCheckBox.Checked = true;
                    }
                    else
                    {
                        favCheckBox.Checked = false;
                    }
                }
            }
        }
Exemplo n.º 2
0
        /************************************************************************************************************************/

        /// <summary>
        /// Obsługa przerwania po kliknięciu przycisku "Edit launch" - edycja wybranego lotu, zapisanie zmian w bazie i aktualizacja listy.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void editButton_Click(object sender, EventArgs e)
        {
            DialogForm dialogForm = new DialogForm();

            dialogForm.editedLaunch = activeLaunch;

            if (dialogForm.ShowDialog() == DialogResult.OK)
            {
                activeLaunch = dialogForm.editedLaunch;
            }
            else
            {
                return;
            }

            using (var context = new LaunchContext())
            {
                Launch launch = context.launches.Find(activeLaunch.LaunchId);
                launch.Clone(activeLaunch);

                context.SaveChanges();
            }

            ListReload();
        }
        /// <summary>
        /// Przeładowanie (odświerzenie) na nowo wierszy w liście.
        /// </summary>
        private void ListReload()
        {
            bool favOnly = false;

            if (activeList == favLaunchesList)
            {
                favOnly = true;
            }

            activeList.Items.Clear();

            using (var context = new LaunchContext())
            {
                foreach (Launch launch in context.launches.ToArray())
                {
                    if (favOnly && !launch.favourite)
                    {
                        continue;
                    }
                    activeList.Items.Add(new ListViewItem(launch.ShortData));
                }
            }

            if (activeList.Items.Count > 0)
            {
                activeList.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
            }
            else
            {
                activeList.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            }
            activeList.Columns[0].Width = 0;

            ListCheckButtons();
        }
        /************************************************************************************************************************/

        /// <summary>
        /// Metoda odpowiedzialna za dodawanie startu do ulubionych lub usuwanie go stamtąd.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void favCheckBox_Click(object sender, EventArgs e)
        {
            using (var context = new LaunchContext())
            {
                Launch launch = context.launches.Find(activeLaunch.LaunchId);
                launch.favourite = !launch.favourite;
                context.SaveChanges();
                favLaunchesList.Items.Add(new ListViewItem(launch.ShortData));
            }
            if (tabsControl.SelectedIndex == 0)
            {
                ListReload();
            }
        }
        /************************************************************************************************************************/

        /// <summary>
        /// Przerwanie pochodzące od timera. Celem jego jest wyświetlenie powiadomienia o ulubionych startach,
        /// do których pozostało mniej niż 15 minut.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        private void NotifyCheckInTimer(Object source, ElapsedEventArgs e)
        {
            Action timerUpdate = () => {
                using (var context = new LaunchContext())
                {
                    String msg    = "";
                    bool   notify = false;
                    foreach (ListViewItem launchItem in favLaunchesList.Items)
                    {
                        Launch launch = context.launches.Find(int.Parse(launchItem.Text));
                        try
                        {
                            var timeToStart = DateTime.Now.Subtract(launch.windowStart).Days;

                            if (timeToStart >= -1 && timeToStart < 1)
                            {
                                timeToStart = DateTime.Now.Subtract(launch.windowStart).Minutes;

                                if (timeToStart >= -15 && !alreadyNotyfied.Contains(launch))
                                {
                                    if (timeToStart <= 0)
                                    {
                                        notify = true;
                                        alreadyNotyfied.Add(launch);
                                        msg = launch.name;
                                        break;
                                    }
                                }
                            }
                        }
                        catch
                        {
                            return;
                        }
                    }

                    if (notify == true)
                    {
                        LaunchAlert alert = new LaunchAlert();
                        alert.showAlert(msg);
                    }
                }
            };

            Invoke(new Action(timerUpdate));
        }
Exemplo n.º 6
0
        /************************************************************************************************************************/

        /// <summary>
        /// Obsługa przerwania po kliknięciu przycisku "Add launch" - dodawanie nowego lotu do bazy, potem aktualizacja listy.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void addButton_Click(object sender, EventArgs e)
        {
            addButton.Enabled = false;
            Launch launch = new Launch();

            DialogForm dialogForm = new DialogForm();

            if (dialogForm.ShowDialog() == DialogResult.OK)
            {
                launch = dialogForm.editedLaunch;

                using (var context = new LaunchContext())
                {
                    context.launches.Add(launch);
                    context.SaveChanges();
                }
            }
            this.ListReload();
            addButton.Enabled = true;
        }
Exemplo n.º 7
0
        /************************************************************************************************************************/

        /// <summary>
        /// Obsługa przerwania po kliknięciu przycisku "Remove launch" - usunięcie wybranego lotu, zapisanie zmian w bazie i aktualizacja listy.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void removeButton_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure?", "Remove launches", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

            if (result != DialogResult.OK)
            {
                return;
            }

            using (var context = new LaunchContext())
            {
                foreach (ListViewItem item in activeList.SelectedItems)
                {
                    Launch launchToRemove = context.launches.Find(int.Parse(item.Text));
                    context.launches.Remove(launchToRemove);
                }
                context.SaveChanges();
            }
            this.ListReload();
        }
Exemplo n.º 8
0
        /// <summary>
        /// Obsługa przerwania po naciśnięciu przycisku "update from web" - Pobiera poprzez APIParser odpowiednie dane i wczytuje je do bazy danych
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void updateFromWebButton_Click(object sender, EventArgs e)
        {
            updateFromWebButton.Enabled = false;
            this.Enabled       = false;
            this.UseWaitCursor = true;

            api.getApiResponse();
            var launches = api.parseLaunchRequest();

            updateProgressBar.Value = 50;

            using (var context = new LaunchContext())
            {
                bool alreadyExist;
                foreach (var launchInApi in launches)
                {
                    alreadyExist = false;
                    foreach (Launch launchInDataBase in context.launches.ToArray())
                    {
                        if (launchInDataBase == launchInApi)
                        {
                            alreadyExist = true;
                        }
                    }

                    if (!alreadyExist)
                    {
                        context.launches.Add(launchInApi);
                    }
                }
                context.SaveChanges();

                updateProgressBar.Value = 75;
            }

            this.ListReload();
            updateProgressBar.Value = 100;

            this.UseWaitCursor = false;
            this.Enabled       = true;
        }