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); }
void editCurrentRow() { if (TrainDataView.CurrentRow != null) { ScheduleTrain train = openEditForm(getRowData(TrainDataView.CurrentRow)); if (train != null) { setRowData(TrainDataView.CurrentRow, train); } } }
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); }
void addNewRow() { ScheduleTrain train = openEditForm(null); if (train != null) { DataGridViewRow row = new DataGridViewRow(); setRowData(row, train); TrainDataView.Rows.Add(row); } }
private void setRowData(DataGridViewRow row, ScheduleTrain train) { if (row.Cells.Count == 0) { row.CreateCells(TrainDataView); } row.Cells[0].Value = train.getDestinationStation(); row.Cells[1].Value = train.getNumberTrain(); row.Cells[2].Value = train.getDepartureTime(); row.Cells[3].Value = train.getArrivalTime(); row.Cells[4].Value = train.getTravelPrice(); }
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); }