步步为盈
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

272 lines
8.3 KiB

2 years ago
using BBWY.Client.Helpers;
using BBWY.Client.Models.PackTask;
2 years ago
using BBWY.Client.ViewModels;
2 years ago
using BBWY.Common.Models;
2 years ago
using GalaSoft.MvvmLight.Messaging;
2 years ago
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
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;
using WebSocketSharp;
namespace BBWY.Client.Views.PackTask
{
/// <summary>
/// WareHouseList.xaml 的交互逻辑
/// </summary>
public partial class WareHouseList : Page
{
public WareHouseList()
{
InitializeComponent();
2 years ago
this.Loaded += Load;
2 years ago
}
//private void WareHouseList_Unloaded(object sender, RoutedEventArgs e)
//{
// Messenger.Default.Unregister("AcceptGlobalContext");
//}
GlobalContext globalContext;
public void LoadShops(GlobalContext globalContext)
{
this.globalContext = globalContext;
shops = globalContext.User.ShopList.Select(s => s.ShopName).ToList();
departments=globalContext.User.DepartmentList.Select(s=>s.Name).ToList();
2 years ago
}
private void Load(object sender, RoutedEventArgs e)
{
2 years ago
try
{
var model = (App.Current.Resources["Locator"] as ViewModelLocator).Main;
2 years ago
LoadShops(model.GlobalContext);
}
catch
{
}
2 years ago
//try
//{
// var applicationPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
// var builder = new ConfigurationBuilder().SetBasePath(applicationPath).AddJsonFile("BBWYAppSettings.json", false, true);
// var Configuration = builder.Build();
2 years ago
// QKApiHost = Configuration.GetSection("QKApiHost").Value;
2 years ago
// if (QKApiHost.IsNullOrEmpty()) QKApiHost = "http://qiku.qiyue666.com";
2 years ago
// HttpClientHelper helper = new HttpClientHelper(QKApiHost);
2 years ago
// string url = $"{QKApiHost}/api/PackTask/GetAllDepartment";//获取所有数据
// var data = helper.Get(url);
2 years ago
// var res = JsonConvert.DeserializeObject<ApiResponse<UserDepartment[]>>(data);
// //创建一个ListBoxIem
// if (res.Success)
// {
// if (res.Data != null && res.Data.Count() > 0)
// {
// foreach (var department in res.Data)
// {
// if (!departments.Contains(department.DePartmentName))
// {
// departments.Add(department.DePartmentName);
// }
// }
// }
// }
//}
//catch (Exception)
//{
//}
2 years ago
2 years ago
}
2 years ago
public string QKApiHost { get; set; }
2 years ago
public void SelectionChangeCommand(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;
tb.Text = content.Content.ToString();
tipBox.Visibility = Visibility.Collapsed;
}
catch (Exception)
{
2 years ago
2 years ago
}
2 years ago
2 years ago
}
List<string> departments = new List<string>();
2 years ago
List<string> shops = new List<string>();
2 years ago
private void tb_TextChanged(object sender, TextChangedEventArgs e)
{
if (tipBox != null)
try
2 years ago
{
var textBoxt = (TextBox)sender;
//创建一个ListBox
2 years ago
if (tipBox != null && tipBox.Items.Count > 0)
{
tipBox.Items.Clear();
2 years ago
}
2 years ago
if (departments.Count <= 0)
2 years ago
{
if (QKApiHost.IsNullOrEmpty()) QKApiHost = "http://qiku.qiyue666.com";
HttpClientHelper helper = new HttpClientHelper(QKApiHost);
string url = $"{QKApiHost}/api/PackTask/GetAllDepartment";//获取所有数据
var data = helper.Get(url);
var res = JsonConvert.DeserializeObject<ApiResponse<UserDepartment[]>>(data);
//创建一个ListBoxIem
if (res.Success)
2 years ago
{
if (res.Data != null && res.Data.Count() > 0)
2 years ago
{
foreach (var department in res.Data)
2 years ago
{
if (!departments.Contains(department.DePartmentName))
{
departments.Add(department.DePartmentName);
}
2 years ago
}
2 years ago
}
}
}
if (string.IsNullOrEmpty(textBoxt.Text))
2 years ago
{
tipBox.Visibility = Visibility.Collapsed;
return;
2 years ago
}
foreach (var department in departments)
{
if (department.Contains(textBoxt.Text))
{
ListBoxItem item = new ListBoxItem();
Label lb = new Label();
lb.Content = department;
item.Content = lb;
tipBox.Items.Add(item);
}
2 years ago
}
2 years ago
tipBox.Visibility = Visibility.Visible;
}
catch (Exception)
{
2 years ago
2 years ago
}
2 years ago
2 years ago
}
2 years ago
private void tbShop_TextChanged(object sender, TextChangedEventArgs e)
{
try
{
var textBoxt = (TextBox)sender;
//创建一个ListBox
if (tipBoxShop != null && tipBoxShop.Items.Count > 0)
{
tipBoxShop.Items.Clear();
}
if (shops.Count <= 0)
{
if (globalContext != null)
LoadShops(globalContext);
}
if (string.IsNullOrEmpty(textBoxt.Text))
{
tipBoxShop.Visibility = Visibility.Collapsed;
return;
}
foreach (var department in shops)
{
if (department.Contains(textBoxt.Text))
{
ListBoxItem item = new ListBoxItem();
Label lb = new Label();
lb.Content = department;
item.Content = lb;
tipBoxShop.Items.Add(item);
}
}
if (tipBoxShop != null)
tipBoxShop.Visibility = Visibility.Visible;
2 years ago
}
catch (Exception)
{
}
}
private void tipBoxShop_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;
tbShop.Text = content.Content.ToString();
tipBoxShop.Visibility = Visibility.Collapsed;
}
catch (Exception)
{
}
}
2 years ago
}
}