private void buttonAddTrain_Click(object sender, EventArgs e) { string trainName = textBoxTrainName.Text, trainModel = textBoxTrainModel.Text; if (trainName.Any(char.IsLetterOrDigit) && trainModel.Any(char.IsLetterOrDigit) && trainName.Length < 51 && trainModel.Length < 51) { try { if (Trains.AddTrain(_sqlConnection, trainName, trainModel)) { MessageBox.Show("Pociąg dodano pomyślnie!"); } _trains = Trains.GetAllTrains(_sqlConnection); dataGridViewCourses.DataSource = _trains; comboBoxTrains.Items.Clear(); for (int i = 0; i < _trains.Rows.Count; i++) { comboBoxTrains.Items.Add(_trains.Rows[i][1].ToString()); } textBoxTrainName.Text = ""; textBoxTrainModel.Text = ""; } catch (Exception err) { MessageBox.Show(err.Message); } } else { MessageBox.Show("Pola nie mogą być puste"); } }
private void tabControlCourses_Click(object sender, EventArgs e) { try { _trains = Trains.GetAllTrains(_sqlConnection); comboBoxTrains.Items.Clear(); for (int i = 0; i < _trains.Rows.Count; i++) { comboBoxTrains.Items.Add(_trains.Rows[i][1].ToString()); } _courses = Courses.GetAllCourses(_sqlConnection); comboBoxCourses.Items.Clear(); for (int i = 0; i < _courses.Rows.Count; i++) { comboBoxCourses.Items.Add(_courses.Rows[i][0].ToString()); } comboBoxStations.Items.Clear(); _stations = Stations.GetAllStations(_sqlConnection); for (int i = 0; i < _stations.Rows.Count; i++) { comboBoxStations.Items.Add(_stations.Rows[i][1].ToString()); } } catch (Exception err) { MessageBox.Show(err.Message); } }
private void buttonDisplayAllTrains_Click(object sender, EventArgs e) { try { dataGridViewCourses.DataSource = Trains.GetAllTrains(_sqlConnection); } catch (Exception err) { MessageBox.Show(err.Message); } }