private List <ProductRegion> GetRegionPageContent(int unitId) { if ((File.Exists(cacheFile) == true && File.GetLastWriteTime(cacheFile).Day < DateTime.Now.Day) || !File.Exists(cacheFile)) { Regions = RestApi.GetProductRegionList(); SerializeObject(Regions, cacheFile); } else { Regions = DeserializeObject(cacheFile); } return(Regions.FindAll(x => x.Unit_id == unitId)); }
public MainPage() { InitializeComponent(); #region base ProductUnits = RestApi.GetProductUnitList(); var title = new Label() { Text = "Участки производства", FontFamily = "Arial", FontSize = 25, TextColor = Color.White, Margin = new Thickness(5, 0, 0, 0) }; listView = new SfListView() { ItemsSource = ProductUnits, ItemSpacing = new Thickness(5, 5, 5, 5), ItemTemplate = new DataTemplate(() => { var label = new Button { BackgroundColor = Color.FromHex("#5990c6"), BorderWidth = 1, TextColor = Color.White, FontAttributes = FontAttributes.Bold, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Button)), FontFamily = "Arial", HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.CenterAndExpand, CornerRadius = 7 }; label.SetBinding(Button.TextProperty, "Name"); return(label); }) }; listView.SelectionChanging += ListView_SelectionChanging; mainStackLayout.Children.Add(title); mainStackLayout.Children.Add(listView); Content = mainStackLayout; #endregion }
private async void ListView_SelectionChanging(object sender, ItemSelectionChangingEventArgs e) { if (scanPage != null && scanPage.scanner != null && scanPage.scanner.Result != null) { ProductRegion needItem = (ProductRegion)e.AddedItems[0]; if (e.AddedItems.Count > 0 && e.AddedItems[0] == Regions[0]) { e.Cancel = true; } bool result = await DisplayAlert("Подтвердить действие", "Добавить изделие?", "Да", "Нет"); if (result) { string statusRequest = RestApi.NewProductEvent(scanPage.scanner.Result.Text, needItem.Region_id); Message(statusRequest); } } }