public FlightListPageViewModel() { _dispatcher = Dispatcher.CurrentDispatcher; FlightList = new ObservableCollection <FlightListPageModel>(); string querry = "select idflight, DateTimeDeparture, DateTimeArrive, FreePlacesCount, ticketPrice, CityArrivecity_idCity, city.cityName from flight join route, city where(route_idroute = idroute && CityDeparture_city_idCity = idCity)"; DataTable dt = new DataTable(); SqlCommands sqlCommands = new SqlCommands(); dt = sqlCommands.ExecuteCommand(querry); FlightListPageModel flight; for (int i = 0; i < dt.Rows.Count; i++) { flight = new FlightListPageModel(); flight.FlightId = (int)dt.Rows[i][0]; flight.DepartureCity = dt.Rows[i][6].ToString(); flight.DepartureDateTime = dt.Rows[i][1].ToString(); flight.ArriveDateTime = dt.Rows[i][2].ToString(); flight.UnoccupiedPlacesCount = (int)dt.Rows[i][3]; flight.FlightPrice = (int)dt.Rows[i][4]; FlightList.Add(flight); } querry = "select idflight, city.cityName from flight join route, city where(route_idroute = idroute && CityArrivecity_idCity = idCity)"; dt = sqlCommands.ExecuteCommand(querry); for (int i = 0; i < dt.Rows.Count; i++) { foreach (FlightListPageModel flightItem in FlightList) { if ((int)dt.Rows[i][0] == flightItem.FlightId) { flightItem.ArriveCity = dt.Rows[i][1].ToString(); } } } InfoUpdate(); }
private void FlightListAdd(FlightListPageModel flight) { FlightList.Add(flight); }
//Обновление данных private async void InfoUpdate() { await Task.Factory.StartNew(() => { Action actionClear; Action <FlightListPageModel> actionAdd; SqlCommands sqlCommands = new SqlCommands(); DataTable dt = new DataTable(); string querry; while (true) { querry = "select * from flight"; dt = sqlCommands.ExecuteCommand(querry); if (dt.Rows.Count == FlightList.Count) { foreach (FlightListPageModel flight in FlightList) { querry = "select FreePlacesCount from flight where (idflight = @Param1)"; dt = sqlCommands.ExecuteCommand(querry, flight.FlightId.ToString()); flight.UnoccupiedPlacesCount = (int)dt.Rows[0][0]; } } else { actionClear = new Action(FlightListClear); querry = "select idflight, DateTimeDeparture, DateTimeArrive, FreePlacesCount, ticketPrice, CityArrivecity_idCity, city.cityName from flight join route, city where(route_idroute = idroute && CityDeparture_city_idCity = idCity)"; dt = new DataTable(); sqlCommands = new SqlCommands(); dt = sqlCommands.ExecuteCommand(querry); FlightListPageModel flight; for (int i = 0; i < dt.Rows.Count; i++) { flight = new FlightListPageModel(); flight.FlightId = (int)dt.Rows[i][0]; flight.DepartureCity = dt.Rows[i][6].ToString(); flight.DepartureDateTime = dt.Rows[i][1].ToString(); flight.ArriveDateTime = dt.Rows[i][2].ToString(); flight.UnoccupiedPlacesCount = (int)dt.Rows[i][3]; flight.FlightPrice = (int)dt.Rows[i][4]; actionAdd = new Action <FlightListPageModel>(FlightListAdd); } querry = "select idflight, city.cityName from flight join route, city where(route_idroute = idroute && CityArrivecity_idCity = idCity)"; dt = sqlCommands.ExecuteCommand(querry); for (int i = 0; i < dt.Rows.Count; i++) { foreach (FlightListPageModel flightItem in FlightList) { if ((int)dt.Rows[i][0] == flightItem.FlightId) { flightItem.ArriveCity = dt.Rows[i][1].ToString(); } } } } Thread.Sleep(5000); } }); }