private void Task1About_Load(object sender, EventArgs e) { if (File.Exists("train.dat")) { using (FileStream fs = new FileStream("train.dat", FileMode.OpenOrCreate)) { Task2 t2 = this.Owner as Task2; BinaryFormatter formatter = new BinaryFormatter(); List <Task2.Train> newTrain = (List <Task2.Train>)formatter.Deserialize(fs); label1.Text = label1.Text + "\nLastDest:" + newTrain[t2.train.Count - 1].dest + ",\nLastDate:" + newTrain[t2.train.Count - 1].date; Console.ReadLine(); } } }
private void button1_Click(object sender, EventArgs e) { StreamReader f = new StreamReader("file.txt", true); string s = f.ReadToEnd(); String[] xy = s.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); Task2 t2 = this.Owner as Task2; if (t2 != null) { string[] split; int l; try { t2.train.Clear(); t2.listBox1.Items.Clear(); for (int i = 0; i < xy.Length; i++) { l = t2.train.Count; split = xy[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); t2.train.Add(new Task2.Train()); var tr = t2.train[l]; tr.dest = split[0]; tr.date = split[1]; tr.numTr = Convert.ToInt32(split[2]); t2.train[l] = tr; string str = tr.dest + "\t" + tr.date + "\t" + tr.numTr; t2.listBox1.Items.Add(str); } } catch (FormatException er) { Console.WriteLine(er.Message); } } this.Close(); f.Close(); }
private void button1_Click(object sender, EventArgs e) { Task2 t2 = this.Owner as Task2; if (t2 != null) { t2.listBox1.Items.Clear(); if (radioButton1.Checked) { for (int i = 0; i < t2.train.Count; i++) { for (int j = i; j < t2.train.Count; j++) { if (String.Compare(t2.train[i].dest, t2.train[j].dest) > 0) { var t = t2.train[j]; t2.train[j] = t2.train[i]; t2.train[i] = t; } } } } else if (radioButton2.Checked) { for (int i = 0; i < t2.train.Count; i++) { for (int j = i; j < t2.train.Count; j++) { if (String.Compare(t2.train[i].date, t2.train[j].date) > 0) { var t = t2.train[j]; t2.train[j] = t2.train[i]; t2.train[i] = t; } } } } else if (radioButton3.Checked) { for (int i = 0; i < t2.train.Count; i++) { for (int j = i; j < t2.train.Count; j++) { if (t2.train[i].numTr > t2.train[j].numTr) { var t = t2.train[j]; t2.train[j] = t2.train[i]; t2.train[i] = t; } } } } else { MessageBox.Show("Not selected"); } for (int i = 0; i < t2.train.Count; i++) { t2.listBox1.Items.Add(t2.train[i].dest + " " + t2.train[i].date + " " + t2.train[i].numTr); } this.Close(); } }
private void button2_Click(object sender, EventArgs e) { Task2 task2 = new Task2(); task2.ShowDialog(); }
private void button1_Click(object sender, EventArgs e) { Task2 t2 = this.Owner as Task2; if (t2 != null) { if (radioButton1.Checked) { if (dest.Text == "") { MessageBox.Show("Not input"); return; } for (int i = 0; i < t2.train.Count; i++) { if (dest.Text == t2.train[i].dest) { MessageBox.Show(t2.train[i].dest + " " + t2.train[i].date + " " + t2.train[i].numTr); return; } } MessageBox.Show("Not found"); return; } else if (radioButton2.Checked) { if (date.Text == "") { MessageBox.Show("Not input"); return; } for (int i = 0; i < t2.train.Count; i++) { if (date.Text == t2.train[i].date) { MessageBox.Show(t2.train[i].dest + " " + t2.train[i].date + " " + t2.train[i].numTr); return; } } MessageBox.Show("Not found"); return; } else if (radioButton3.Checked) { if (numTr.Text == "") { MessageBox.Show("Not input"); return; } int num = Convert.ToInt32(numTr.Text); for (int i = 0; i < t2.train.Count; i++) { if (num == t2.train[i].numTr) { MessageBox.Show(t2.train[i].dest + " " + t2.train[i].date + " " + t2.train[i].numTr); return; } } MessageBox.Show("Not found"); return; } MessageBox.Show("Nothing choose"); } }