public override async Task OnResume() { await base.OnResume(); HttpResponseMessage res; try { res = await _apiClient.Execute(HttpMethod.Get, Urls.URI + Urls.PLACES); }catch { await _dialogService.Value.DisplayAlertAsync("Connection Failed...", "", "Ok"); return; } Response <Collection <PlaceItemSummary> > resp = await _apiClient.ReadFromResponse <Response <Collection <PlaceItemSummary> > >(res); if (resp.IsSuccess) { Dictionary <int, PlaceItemSummary> placeById = PlaceList.ToDictionary(x => x.Id, x => x); foreach (PlaceItemSummary place in resp.Data) { if (!placeById.ContainsKey(place.Id)) { place.SelectPlaceCommand = SelectPlaceCommand; PlaceList.Add(place); } } } else if (PlaceList.Count == 0) { await _dialogService.Value.DisplayAlertAsync("Échec de récupération de la liste", "", "OK"); } }
private void addPlaceButtonClick() { if (PlaceNameData != null && PlaceInfoData != null) { PlaceModel temp = new PlaceModel(); temp.Name = PlaceNameData; temp.Information = PlaceInfoData; temp.DateStart = PlaceDSData.ToString("dd/MM/yyyy"); temp.DateFinish = PlaceDFData.ToString("dd/MM/yyyy"); PlaceList.Add(temp); } else { MessageBox.Show("Vui lòng nhập đủ thông tin trước khi thêm!!!"); } PlaceNameData = null; PlaceInfoData = null; PlaceDSData = DateTime.Now; PlaceDFData = DateTime.Now; OnPropertyChanged(nameof(PlaceList)); OnPropertyChanged(nameof(PlaceNameData)); OnPropertyChanged(nameof(PlaceInfoData)); OnPropertyChanged(nameof(PlaceDSData)); OnPropertyChanged(nameof(PlaceDFData)); }
private async Task ExecuteRefresh() { try { MaterialViewModel c = SelectedPlace; var mats = await _warehouse.DBService.GetPlacesMaterialID(_excludeWout); PlaceList.Clear(); foreach (var p in mats) { PlaceList.Add(new MaterialViewModel { Location = p.Location, ID = p.ID, Size = p.Size, Weight = p.Weight }); } foreach (var mvm in PlaceList) { mvm.Initialize(_warehouse); } // RaisePropertyChanged("PlaceList"); if (c != null) { SelectedPlace = PlaceList.FirstOrDefault(p => p.ID == c.ID); } } catch (Exception e) { _warehouse.AddEvent(Database.Event.EnumSeverity.Error, Database.Event.EnumType.Exception, string.Format("{0}.{1}: {2}", this.GetType().Name, (new StackTrace()).GetFrame(0).GetMethod().Name, e.Message)); } }
public void AddPlaceForTrip(object o) { var parameter = (object[])o; List <string> Data = new List <string>(); foreach (var x in parameter) { if (x.GetType().Equals(typeof(DateTime))) { DateTime y = (DateTime)x; Data.Add(y.ToString("dd/MM/yyyy")); } else { Data.Add(x.ToString()); } } PlaceModel temp = new PlaceModel(); temp.Name = Data[0]; temp.Information = Data[1]; temp.DateStart = Data[2]; temp.DateFinish = Data[3]; Trip.AddPlace(temp); PlaceList.Add(temp); OnPropertyChanged(nameof(Trip)); }
/// <summary>Update Data event, runs every time</summary> /// <param name="something"></param> private async void UpdateData(string something) { using (var db = new MainDbContext()) { var places = await db.Locations.Where(loc => loc.Devices.Count > 0).Include(loc => loc.CropCycles).ToListAsync(); var cropTypeCache = await db.CropTypes.ToListAsync(); foreach (var cropType in cropTypeCache) { if (_cropTypeCache.Any(ct => ct.Key.Equals(cropType.Name.ToLower())) == false) { var pair = new KeyValuePair <string, CropType>(cropType.Name.ToLower(), cropType); _cropTypeCache.Add(pair); } } foreach (var loc in places) { var tuple = PlaceList.FirstOrDefault(ct => ct.Location.Equals(loc)); if (tuple == null) { tuple = new PlaceTuple { Location = loc }; PlaceList.Add(tuple); } var runningCropCycle = loc.CropCycles.FirstOrDefault(cc => cc.EndDate == null); if (runningCropCycle != null) { tuple.DisplayName = loc.Name + " - already monitoring " + runningCropCycle.CropTypeName + " of variety " + runningCropCycle.CropVariety; tuple.IsVacant = false; } else { tuple.DisplayName = loc.Name + " - Avaliable"; tuple.IsVacant = true; } } OnPropertyChanged(nameof(PlaceList)); } }
private void Init(DataTemplate template) { Random random = new Random(DateTime.Now.Millisecond); foreach (var info in _mapPointsInfo) { var mapPointViewModel = new MapPointViewModel(info) { Count = _mapNameToCount[info.Name] }; mapPointViewModel.Zoom = Zoom; mapPointViewModel.MapPointColor = new SolidColorBrush(Color.FromRgb( (byte)random.Next(1, 255), (byte)random.Next(1, 255), (byte)random.Next(1, 255))); PlaceList.Add(mapPointViewModel); _mapNameToMapPoint.Add(mapPointViewModel.Name, mapPointViewModel); var mapCustomElement = new MapCustomElement() { Content = mapPointViewModel, ContentTemplate = template, }; _mapNameToMapElement.Add(info.Name, mapCustomElement); mapCustomElement.MouseLeftButtonDown += OnMapCustomElementClick; BindingOperations.SetBinding(mapCustomElement, MapCustomElement.LocationProperty, new Binding("Location") { Source = mapPointViewModel }); MapElements.Add(mapCustomElement); } }