コード例 #1
0
        private void Save(object sender, System.EventArgs e)
        {
            try
            {
                ComboBox myCombo  = (ComboBox)panelChild.Controls[2];
                ComboBox myCombo2 = (ComboBox)panelChild.Controls[12];
                ComboBox myCombo3 = (ComboBox)panelChild.Controls[13];

                ComboBox myCombo4 = (ComboBox)panelChild.Controls[16];
                ComboBox myCombo5 = (ComboBox)panelChild.Controls[18];
                ComboBox myCombo6 = (ComboBox)panelChild.Controls[20];

                DateTime departureDate  = DateTime.Parse(panelChild.Controls[6].Text);
                DateTime arrivalDate    = DateTime.Parse(panelChild.Controls[9].Text);
                TimeSpan twentyFourHour = new TimeSpan(24, 0, 0);
                TimeSpan departureHour  = TimeSpan.Parse(panelChild.Controls[7].Controls[0].Text);
                TimeSpan arrivalHour    = TimeSpan.Parse(panelChild.Controls[10].Controls[0].Text);
                TimeSpan flightHour     = (departureHour > arrivalHour) ? (twentyFourHour - departureHour) + arrivalHour : arrivalHour - departureHour;

                AirlineDAO  airlineDAO  = new AirlineDAO(Server.MariaDB);
                AirplaneDAO airplaneDAO = new AirplaneDAO(Server.MariaDB);
                PilotDAO    pilotDAO    = new PilotDAO(Server.MariaDB);

                Flight flight = new Flight
                {
                    Type          = myCombo.SelectedItem.ToString(),
                    Origin        = panelChild.Controls[3].Controls[0].Text,
                    Destiny       = panelChild.Controls[4].Controls[0].Text,
                    DepartureDate = departureDate.ToString(),
                    DepartureHour = departureHour.ToString(),
                    ArrivalDate   = arrivalDate.ToString(),
                    ArrivalHour   = arrivalHour.ToString(),
                    FlightTime    = flightHour.ToString(),
                    Pist          = int.Parse(myCombo2.SelectedItem.ToString()),
                    FlightStatus  = myCombo3.SelectedItem.ToString(),
                    AirlineID     = airlineDAO.GetID(myCombo4.SelectedItem.ToString()),
                    AirplaneID    = airplaneDAO.GetID(myCombo5.SelectedItem.ToString()),
                    PilotID       = pilotDAO.GetID(myCombo6.SelectedItem.ToString()),
                };

                FlightDAO dao = new FlightDAO(Enums.Server.MariaDB);
                dao.Save(flight);

                // Button is the last child
                panelChild.Controls[panelChild.Controls.Count - 1].Enabled = false;

                FlatPanel parentPanel = (FlatPanel)panel.Parent;
                Control   toolbar     = parentPanel.Controls[0];

                MenuSection menuController = new MenuSection(0);
                menuController.ShowPanel(ref parentPanel, Enums.ItemMenuType.Flight);

                PanelAdjustment();

                void PanelAdjustment()
                {
                    parentPanel.Controls[1].Dock   = DockStyle.None;
                    toolbar.Controls[0].Width      = parentPanel.Width;
                    parentPanel.Controls[1].Top    = toolbar.Top + toolbar.Height;
                    parentPanel.Controls[1].Width  = parentPanel.Width;
                    parentPanel.Controls[1].Height = parentPanel.Height - toolbar.Height;
                }
            }
            catch (Exception error)
            {
                MessageBox.Show(error.Message);
            }
        }