using BBWY.Client.APIServices; using BBWY.Client.Helpers; using BBWY.Client.Models.PackTask; using BBWY.Client.ViewModels.PackTask; using BBWY.Common.Models; using BBWY.Controls; using GalaSoft.MvvmLight.Messaging; using HandyControl.Controls; using Microsoft.Extensions.Configuration; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace BBWY.Client.Views.PackTask { /// /// Consumable.xaml 的交互逻辑 /// public partial class Consumable : Page { public ConsumableViewModel model; // public ConsumableService consumableService; public Consumable() { //this.consumableService = consumableService; InitializeComponent(); // model = new ConsumableViewModel(consumableService); //model.ReflashDatas = GetList; //this.DataContext = model; var applicationPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var builder = new ConfigurationBuilder().SetBasePath(applicationPath).AddJsonFile("BBWYAppSettings.json", false, true); var Configuration = builder.Build(); QKApiHost = Configuration.GetSection("QKApiHost").Value; Messenger.Default.Register(this, message => { GetList(); }); } string QKApiHost = ""; List consumables = new List(); private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { var list = (ListBox)sender; if (list.Items.Count <= 0) { return; } var value = (ListBoxItem)list.SelectedValue; var content = (Label)value.Content; consumableName.Text = content.Content.ToString(); tipBox.Visibility = Visibility.Collapsed; } catch (Exception) { } } private void consumableName_TextChanged(object sender, TextChangedEventArgs e) { try { var textBoxt = (BTextBox)sender; //创建一个ListBox if (tipBox != null && tipBox.Items.Count > 0) { tipBox.Items.Clear(); } if (consumables.Count <= 0) { GetList(); } if (string.IsNullOrEmpty(textBoxt.Text)) { tipBox.Visibility = Visibility.Collapsed; return; } foreach (var department in consumables) { if (department.Contains(textBoxt.Text)) { ListBoxItem item = new ListBoxItem(); Label lb = new Label(); lb.Content = department; item.Content = lb; tipBox.Items.Add(item); } } tipBox.Visibility = Visibility.Visible; } catch (Exception) { } } /// /// 刷新数据 /// private void GetList() { HttpClientHelper helper = new HttpClientHelper(QKApiHost); string url = $"{QKApiHost}/api/Consumable/SearchAll";//获取所有数据 var data = helper.Get(url); var res = JsonConvert.DeserializeObject>(data); //创建一个ListBoxIem if (res.Success) { if (res.Data != null && res.Data.Count() > 0) { consumables = new List(); foreach (var department in res.Data) { if (!consumables.Contains(department.Name)) { consumables.Add(department.Name); } } } } } } }