Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {     //for the fare put a default minimum value
            try
            { //validation to check if null or not
                var controls = new[] { txtSrc.Text, txtVia.Text, txtDest.Text, txtMod.Text };
                if (!controls.All(x => string.IsNullOrEmpty(x)))
                {
                    //ADD VALIDATION FOR DATE- check if dates are in the future
                    if ((this.dtpDept.Value.Date > DateTime.Today.Date) && (this.dtpArrive.Value.Date > DateTime.Today.Date))
                    {//date validation 2
                        if (this.dtpDept.Value.Date < this.dtpArrive.Value.Date)
                        {
                            //button to save
                            FlightClass fl = new FlightClass();
                            fl.SourceLocation = txtSrc.Text;
                            fl.Via            = txtVia.Text;
                            fl.DestLocation   = txtDest.Text;
                            fl.DepartDate     = dtpDept.Value.Date;
                            fl.DepartTime     = dtpDept.Value.ToShortTimeString();
                            fl.ArrivalDate    = dtpArrive.Value.Date;
                            fl.ArrivalTime    = dtpArrive.Value.ToShortTimeString();
                            fl.PlaneName      = txtMod.Text; //try to put combo box from plane table
                            fl.Fare           = int.Parse(numFare.Text);

                            fl.addFlight();
                            MessageBox.Show("Flight for " + fl.PlaneName + " on " + fl.DepartDate + " added", "Success!");
                        }
                        else
                        {//date validation 2 end
                            MessageBox.Show("Departure date should be before the arrival date", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                    else
                    {//date validation end
                        MessageBox.Show("Arrival Date or Departure date cannot be set as past date or current date", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                else
                {//not null validation end
                    MessageBox.Show("Make sure all fields are filled", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception Error :" + ex.Message);
            }
        }
        private void FlightSchedule_Load(object sender, EventArgs e)
        {
            //load the current flights

            FlightClass flight = new FlightClass();

            dataGridView1.DataSource = flight.flightSchedule();

            flight.dbcon.CloseConnection();

            this.Refresh();

            //here i check if there are flights or no, if there are NO flight it means one row so display this message
            if (dataGridView1.Rows.Count == 1)
            {
                MessageBox.Show("There are no flights for today", "No flights", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
        }