private void Form1_Load(object sender, EventArgs e) { using (StreamReader stream = new StreamReader("students.txt")) { string[] str = new string[5]; List <Student> students = new List <Student>(); do { str = stream.ReadLine().Split(':'); Student student = new Student(str[0], str[1], Int32.Parse(str[2]), str[3], str[4]); students.Add(student); } while (!stream.EndOfStream); University.Instance.students = students; } using (StreamReader stream = new StreamReader("vacation pass.txt")) { string[] str = new string[6]; List <VacationPass> vacations = new List <VacationPass>(); do { str = stream.ReadLine().Split(':'); VacationPass vactionPass = new VacationPass(str[0], str[1], str[2], str[3], Int32.Parse(str[4]), Int32.Parse(str[5])); vacations.Add(vactionPass); } while (!stream.EndOfStream); University.Instance.Vacations = vacations; } }
private void Form4_Load(object sender, EventArgs e) { using (StreamReader stream = new StreamReader("vacation pass.txt")) { string[] str = new string[6]; List <VacationPass> vacations = new List <VacationPass>(); do { str = stream.ReadLine().Split(':'); VacationPass vactionPass = new VacationPass(str[0], str[1], str[2], str[3], Int32.Parse(str[4]), Int32.Parse(str[5])); vacations.Add(vactionPass); } while (!stream.EndOfStream); University.Instance.Vacations = vacations; } foreach (VacationPass vacation in University.Instance.Vacations) { vacationList.Items.Add($"{vacation.CountryFrom} - {vacation.CountryTo} : {vacation.Price}"); } if (vacationList.Items.Count > 0) { vacationList.SelectedIndex = 0; } }
private void button1_Click(object sender, EventArgs e) { if (vacationList.SelectedIndex < 0) { MessageBox.Show("Please check the correct entry and try again.", "Error!"); } VacationPass vacationPass = University.Instance.GetVacationPass(vacationList.SelectedItem.ToString()); MessageBox.Show($"You have offer vacation pass to {vacationPass.CountryTo} for {vacationPass.Price}.", "Congrats"); vacationList.SelectedIndex = -1; }
private void vacationList_SelectedValueChanged(object sender, EventArgs e) { if (vacationList.SelectedIndex < 0) { CFromBox.Text = ""; CToBox.Text = ""; AirFromBox.Text = ""; AirToBox.Text = ""; DurationBox.Text = ""; PriceBox.Text = ""; return; } VacationPass vacationPass = University.Instance.GetVacationPass(vacationList.SelectedItem.ToString()); CFromBox.Text = vacationPass.CountryFrom; CToBox.Text = vacationPass.CountryTo; AirFromBox.Text = vacationPass.AirportFrom; AirToBox.Text = vacationPass.AirportTo; DurationBox.Text = vacationPass.Duration.ToString(); PriceBox.Text = vacationPass.Price.ToString(); }