Beispiel #1
0
        ScheduleTrain openEditForm(ScheduleTrain train)
        {
            EditForm editDialog = new EditForm();

            if (train != null)
            {
                ((TextBox)editDialog.Controls["FieldDestinationStation"]).Text  = train.getDestinationStation();
                ((TextBox)editDialog.Controls["FieldNumberTrain"]).Text         = train.getNumberTrain();
                ((MaskedTextBox)editDialog.Controls["FieldDepartureTime"]).Text = train.getDepartureTime().ToString();
                ((MaskedTextBox)editDialog.Controls["FieldArrivalTime"]).Text   = train.getArrivalTime().ToString();
                ((TextBox)editDialog.Controls["FieldTravelPrice"]).Text         = train.getTravelPrice().ToString();
            }

            if (editDialog.ShowDialog(this) == DialogResult.OK)
            {
                ScheduleTrain result = new ScheduleTrain();
                result.setDestinationStation(((TextBox)editDialog.Controls["FieldDestinationStation"]).Text);
                result.setNumberTrain(((TextBox)editDialog.Controls["FieldNumberTrain"]).Text);
                result.setDepartureTime(Convert.ToDateTime(((MaskedTextBox)editDialog.Controls["FieldDepartureTime"]).Text));
                result.setArrivalTime(Convert.ToDateTime(((MaskedTextBox)editDialog.Controls["FieldArrivalTime"]).Text));
                result.setTravelPrice(Convert.ToDouble(((TextBox)editDialog.Controls["FieldTravelPrice"]).Text));
                return(result);
            }

            return(null);
        }
Beispiel #2
0
        private ScheduleTrain getRowData(DataGridViewRow row)
        {
            ScheduleTrain train = new ScheduleTrain();

            train.setDestinationStation(row.Cells[0].Value.ToString());
            train.setNumberTrain(row.Cells[1].Value.ToString());
            train.setDepartureTime(Convert.ToDateTime(row.Cells[2].Value.ToString()));
            train.setArrivalTime(Convert.ToDateTime(row.Cells[3].Value.ToString()));
            train.setTravelPrice(Convert.ToDouble(row.Cells[4].Value.ToString()));
            return(train);
        }
Beispiel #3
0
        public static List <ScheduleTrain> loadFromFile(String fileName)
        {
            List <ScheduleTrain> trains = new List <ScheduleTrain>();

            using (System.IO.BinaryReader binaryReader = new System.IO.BinaryReader(
                       new System.IO.FileStream(fileName, System.IO.FileMode.Open)))
            {
                while (binaryReader.PeekChar() > -1)
                {
                    ScheduleTrain train = new ScheduleTrain();

                    train.setDestinationStation(binaryReader.ReadString());
                    train.setNumberTrain(binaryReader.ReadString());
                    train.setDepartureTime(Convert.ToDateTime(binaryReader.ReadString()));
                    train.setArrivalTime(Convert.ToDateTime(binaryReader.ReadString()));
                    train.setTravelPrice(binaryReader.ReadDouble());

                    trains.Add(train);
                }
            }

            return(trains);
        }