Files
xxcpzs/XXCpzs/Views/PageCustomerSelect.xaml.cs
2020-04-03 11:55:02 +08:00

59 lines
1.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using XXCpzs.Models;
using XXCpzs.Services;
using XXCpzs.ViewModels;
namespace XXCpzs.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class PageCustomerSelect : ContentPage
{
SearchViewModel ViewModel;
private UserInfo userInfo;
public PageCustomerSelect(UserInfo userInfo)
{
InitializeComponent();
this.userInfo = userInfo;
this.BindingContext = ViewModel = new SearchViewModel(userInfo.uid, this);
searchResults.ItemsSource = CustomerDataService.GetSearchResults(searchBar.Text);
}
void OnTextChanged(object sender, TextChangedEventArgs e)
{
searchResults.ItemsSource = CustomerDataService.GetSearchResults(e.NewTextValue);
}
private async void searchResults_ItemSelectedAsync(object sender, SelectedItemChangedEventArgs e)
{
if (e.SelectedItem != null)
{
Customer customer = e.SelectedItem as Customer;
bool response = await DisplayAlert("Item Selected", customer.company, "Yes", "No");
if (response)
{
MessagingCenter.Send(this, "SelectCustomer", customer);
await Navigation.PopModalAsync();
}
}
}
private async void Button_Clicked(object sender, EventArgs e)
{
await Navigation.PushModalAsync(new NavigationPage(new PageAddCustomer(userInfo)));
}
public void Refresh()
{
searchResults.ItemsSource = CustomerDataService.GetSearchResults(searchBar.Text);
}
}
}