Пример #1
0
        private new void InitializeComponent()
        {
            panel.Controls.Add(panelChild);

            panel.Dock      = DockStyle.Right;
            panel.Padding   = new Padding(40, 0, 0, 20);
            panel.BackColor = colors.White1;

            // DAO

            PilotDAO pilotDAO = new PilotDAO(Enums.Server.MariaDB);

            BindingSource bindingSource = new BindingSource
            {
                DataSource = pilotDAO.GetAllPilots()
            };

            DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle();

            dataGridViewCellStyle2.Alignment          = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
            dataGridViewCellStyle2.BackColor          = colors.White1;
            dataGridViewCellStyle2.Font               = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            dataGridViewCellStyle2.ForeColor          = System.Drawing.Color.Black;
            dataGridViewCellStyle2.SelectionBackColor = System.Drawing.Color.WhiteSmoke;
            dataGridViewCellStyle2.SelectionForeColor = System.Drawing.Color.Black;
            dataGridViewCellStyle2.WrapMode           = System.Windows.Forms.DataGridViewTriState.False;

            // main controls
            AddElement(new FlatLabelTitle("Pilots", 0, 0));
            AddElement(new FlatButton("Create Pilot"));
            panelChild.Controls[1].Click += new EventHandler(GoToCreate);
            panelChild.Controls[1].Width  = 200;

            AddElement(new DataGridView
            {
                Name       = "dgvPilots",
                DataSource = bindingSource,
                Width      = 975,
                ForeColor  = colors.Black1,

                DefaultCellStyle = dataGridViewCellStyle2,
                ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2,
                RowsDefaultCellStyle          = dataGridViewCellStyle2,
                RowHeadersDefaultCellStyle    = dataGridViewCellStyle2,
                AllowUserToAddRows            = false,
                AllowUserToDeleteRows         = false,
                AutoSizeColumnsMode           = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells,
                AutoSize                    = true,
                BackgroundColor             = colors.White1,
                BorderStyle                 = System.Windows.Forms.BorderStyle.None,
                ColumnHeadersBorderStyle    = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single,
                ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize,
                GridColor                   = System.Drawing.SystemColors.Control,
                RowHeadersBorderStyle       = System.Windows.Forms.DataGridViewHeaderBorderStyle.None,
                MultiSelect                 = false,
                RowHeadersVisible           = false,
                ReadOnly                    = true,
            });
        }
Пример #2
0
        private void UpdatePilotFromAirline(string name, ref ComboBox combo)
        {
            List <string> pilotNames = new PilotDAO(Server.MariaDB).GetAllNamesFromAirline(name);

            foreach (string item in pilotNames)
            {
                combo.Items.Add(item);
            }

            if (combo.Items.Count > 1)
            {
                combo.SelectedIndex = 0;
            }
        }
Пример #3
0
        private void Save(object sender, System.EventArgs e)
        {
            try
            {
                // Use trim for filelds names
                RadioButton myRadio    = (RadioButton)panelChild.Controls[5];
                ComboBox    myCombo    = (ComboBox)panelChild.Controls[3];
                int         airlaineID = new AirlineDAO(Enums.Server.MariaDB).GetID(myCombo.SelectedItem.ToString());

                Pilot piloto = new Pilot
                {
                    Name        = panelChild.Controls[1].Controls[0].Text,
                    Sex         = panelChild.Controls[2].Controls[0].Text,
                    PilotStatus = (myRadio.Checked) ? 1 : 0,
                    AirlineID   = airlaineID
                };

                PilotDAO dao = new PilotDAO(Enums.Server.MariaDB);
                dao.Save(piloto);

                // 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.Pilots);

                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)
            {
                throw new OperationCanceledException("Wrong filed.");
            }
        }
Пример #4
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);
            }
        }