Пример #1
0
        void readDataFromFile()
        {
            var result = MessageBox.Show("Load data from file?", "", MessageBoxButtons.YesNo);

            if (result == System.Windows.Forms.DialogResult.Yes)
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                if (!openFileDialog.ShowDialog().Equals(DialogResult.OK))
                {
                    return;
                }

                List <ScheduleTrain> trains = ScheduleTrainFileLoader.loadFromFile(openFileDialog.FileName);

                TrainDataView.Rows.Clear();

                foreach (ScheduleTrain train in trains)
                {
                    TrainDataView.Rows.Add(
                        train.getDestinationStation(),
                        train.getNumberTrain(),
                        train.getDepartureTime(),
                        train.getArrivalTime(),
                        train.getTravelPrice());
                }
            }
        }
Пример #2
0
        void writeDataToFile()
        {
            var result = MessageBox.Show("Write data to file?", "", MessageBoxButtons.YesNo);

            if (result == System.Windows.Forms.DialogResult.Yes)
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                if (!openFileDialog.ShowDialog().Equals(DialogResult.OK))
                {
                    return;
                }
                string filename = openFileDialog.FileName;
                ScheduleTrainFileLoader.saveToFile(filename, getTrainsFromTable());
            }
        }