|
@@ -142,7 +142,7 @@ namespace RaspisKusach.Pages
|
|
|
new ErrorWindow("Маршрут с таким названием или id не найден").ShowDialog();
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
int stationId;
|
|
|
if (Functions.IsOnlyDigits(RoutesStationsIdStationBox.Text) && cnt.db.Stations.Select(item => item.IdStation).Contains(Convert.ToInt32(RoutesStationsIdStationBox.Text)))
|
|
|
stationId = Convert.ToInt32(RoutesStationsIdStationBox.Text);
|
|
@@ -150,7 +150,18 @@ namespace RaspisKusach.Pages
|
|
|
stationId = cnt.db.Routes.Where(item => item.Name == RoutesStationsIdStationBox.Text).Select(item => item.IdRoute).FirstOrDefault();
|
|
|
else
|
|
|
{
|
|
|
- new ErrorWindow("Станция с таким названием или id не найден").ShowDialog();
|
|
|
+ new ErrorWindow("Станция с таким названием или id не найдена").ShowDialog();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(Functions.IsHHMMTimeSpanFromString(RoutesStationsStopTimeBox.Text))
|
|
|
+ {
|
|
|
+ new ErrorWindow("Строка с временем остановки имела неверный формат").ShowDialog();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(Functions.IsHHMMTimeSpanFromString(RoutesStationsTravelTimeBox.Text))
|
|
|
+ {
|
|
|
+ new ErrorWindow("Строка с временем пути имела неверный формат").ShowDialog();
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -159,8 +170,8 @@ namespace RaspisKusach.Pages
|
|
|
IdRouteStation = cnt.db.RoutesStations.Select(p => p.IdRouteStation).DefaultIfEmpty(0).Max() + 1,
|
|
|
IdRoute = routeId,
|
|
|
IdStation = stationId,
|
|
|
- //StopTime = RoutesStationsStopTimeBox.Text,
|
|
|
- //TravelTime = RoutesStationsTravelTimeBox.Text
|
|
|
+ StopTime = new TimeSpan(Convert.ToInt32(RoutesStationsStopTimeBox.Text.Substring(0, 2)), Convert.ToInt32(RoutesStationsStopTimeBox.Text.Substring(3, 2)), 0),
|
|
|
+ TravelTime = new TimeSpan(Convert.ToInt32(RoutesStationsTravelTimeBox.Text.Substring(0, 2)), Convert.ToInt32(RoutesStationsTravelTimeBox.Text.Substring(3, 2)), 0),
|
|
|
});
|
|
|
cnt.db.SaveChanges();
|
|
|
}
|
|
@@ -171,7 +182,39 @@ namespace RaspisKusach.Pages
|
|
|
}
|
|
|
private void CarriagesAddButton_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
+ try
|
|
|
+ {
|
|
|
+ int trainId;
|
|
|
+ if (Functions.IsOnlyDigits(CarriagesIdTrainBox.Text) && cnt.db.Trains.Select(item => item.IdTrain).Contains(Convert.ToInt32(CarriagesIdTrainBox.Text)))
|
|
|
+ trainId = Convert.ToInt32(CarriagesIdTrainBox.Text);
|
|
|
+ else if (cnt.db.Trains.Select(item => item.Name).Contains(CarriagesIdTrainBox.Text))
|
|
|
+ trainId = cnt.db.Trains.Where(item => item.Name == CarriagesIdTrainBox.Text).Select(item => item.IdTrain).FirstOrDefault();
|
|
|
+ else
|
|
|
+ {
|
|
|
+ new ErrorWindow("Поезд с таким названием или id не найден").ShowDialog();
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
+ if (Functions.IsOnlyDigits(CarriagesPlacesBox.Text))
|
|
|
+ {
|
|
|
+ new ErrorWindow("Строка с количеством мест имела неверный формат").ShowDialog();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ cnt.db.Carriages.Add(new Carriages()
|
|
|
+ {
|
|
|
+ IdCarriage = cnt.db.Carriages.Select(p => p.IdCarriage).DefaultIfEmpty(0).Max() + 1,
|
|
|
+ IdTrain = trainId,
|
|
|
+ Places = Convert.ToInt32(CarriagesPlacesBox.Text),
|
|
|
+ Category = CarriagesCategoryBox.Text
|
|
|
+ });
|
|
|
+ cnt.db.SaveChanges();
|
|
|
+ new ErrorWindow("Успешно").ShowDialog();
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ new ErrorWindow(ex.Message).ShowDialog();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|