193 lines
6.7 KiB
C#
193 lines
6.7 KiB
C#
using _29WxOrderWpf.Utils;
|
|
using AllBase.Helper;
|
|
using AllBase.Model.DBModel;
|
|
using AllBase.Model.Result;
|
|
using NaiBa.Util.Extension;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
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 _29WxOrderWpf.Ctrls.ShopCtrls
|
|
{
|
|
/// <summary>
|
|
/// ShopListCtrl.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class ShopListCtrl : UserControl
|
|
{
|
|
public bool? IsAcceptChoiceShop { get; set; } = false;
|
|
CheckBox chkSelectAll = null;
|
|
public ShopListCtrl()
|
|
{
|
|
InitializeComponent();
|
|
DataContext = this;
|
|
}
|
|
|
|
private void shopListCtrl_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
this.lbxShop.ItemsSource = GlobalConfig.ShopLoginList;
|
|
|
|
Task.Run(() => {
|
|
while(MainWindow.Instance.hasReadShop == false)
|
|
{
|
|
Thread.Sleep(100);
|
|
}
|
|
|
|
Dispatcher.Invoke(new Action(() => {
|
|
cmbGroup.Items.Clear();
|
|
cmbGroup.Items.Add("");
|
|
foreach (var group in GlobalConfig.ShopLoginList.Select(s => s.GroupName).Distinct())
|
|
{
|
|
if (!string.IsNullOrEmpty(group))
|
|
this.cmbGroup.Items.Add(group);
|
|
}
|
|
cmbNotes.Items.Clear();
|
|
cmbNotes.Items.Add("");
|
|
foreach (var notes in GlobalConfig.ShopLoginList.Select(s => s.Notes).Distinct())
|
|
{
|
|
if (!string.IsNullOrEmpty(notes))
|
|
this.cmbNotes.Items.Add(notes);
|
|
}
|
|
|
|
}));
|
|
});
|
|
|
|
}
|
|
|
|
private void dgShopHeader_ColumnDisplayIndexChanged(object sender, DataGridColumnEventArgs e)
|
|
{
|
|
}
|
|
|
|
private void dgShopHeader_LayoutUpdated(object sender, EventArgs e)
|
|
{
|
|
foreach (var item in lbxShop.Items)
|
|
{
|
|
ListBoxItem container = (ListBoxItem)lbxShop.ItemContainerGenerator.ContainerFromIndex(lbxShop.Items.IndexOf(item));
|
|
if (container != null)
|
|
{
|
|
// 找到grid控件并修改列大小
|
|
Grid grid = UiCtrlUtils.FindVisualChild<Grid>(container, "gridListItem");
|
|
if (grid != null)
|
|
{
|
|
for(int i = 0; i< grid.ColumnDefinitions.Count; i++)
|
|
{
|
|
if (dgShopHeader.Columns.Count > i)
|
|
{
|
|
// 最后一列因滚动条变窄,已在表头补偿
|
|
if (i == grid.ColumnDefinitions.Count - 1)
|
|
grid.ColumnDefinitions[i].Width = new GridLength(Math.Max(0, dgShopHeader.Columns[i].ActualWidth - 0));
|
|
else
|
|
grid.ColumnDefinitions[i].Width = new GridLength(dgShopHeader.Columns[i].ActualWidth);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ChkSelectAll_Checked(object sender, RoutedEventArgs e)
|
|
{
|
|
foreach (var shop in GlobalConfig.ShopLoginList.ToList())
|
|
{
|
|
//shop.IsSelect = ((sender as CheckBox)?.IsChecked).ParseToBool();
|
|
shop.IsSelect = true;
|
|
}
|
|
}
|
|
|
|
private void ChkSelectAll_Unchecked(object sender, RoutedEventArgs e)
|
|
{
|
|
foreach (var shop in GlobalConfig.ShopLoginList.ToList())
|
|
{
|
|
//shop.IsSelect = ((sender as CheckBox)?.IsChecked).ParseToBool();
|
|
shop.IsSelect = false;
|
|
}
|
|
}
|
|
|
|
private void ChkSelectAll_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
chkSelectAll = sender as CheckBox;
|
|
}
|
|
|
|
private void CheckBox_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
chkSelectAll.Checked -= ChkSelectAll_Checked;
|
|
chkSelectAll.Unchecked -= ChkSelectAll_Unchecked;
|
|
if (GlobalConfig.ShopLoginList.All(s => s.IsSelect))
|
|
chkSelectAll.IsChecked = true;
|
|
else if (GlobalConfig.ShopLoginList.All(s => !s.IsSelect))
|
|
chkSelectAll.IsChecked = false;
|
|
else
|
|
chkSelectAll.IsChecked = null;
|
|
chkSelectAll.Checked += ChkSelectAll_Checked;
|
|
chkSelectAll.Unchecked += ChkSelectAll_Unchecked;
|
|
}
|
|
|
|
private void cmbNotes_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void cmbGroup_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void btnSearch_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
ObservableCollection<ShopLoginInfo> shops = new ObservableCollection<ShopLoginInfo>();
|
|
foreach (var shop in GlobalConfig.ShopLoginList)
|
|
{
|
|
if (!shop.ShopAccount.ParseToString().Contains(txtShopName.Text))
|
|
continue;
|
|
if (!shop.GroupName.ParseToString().Contains(cmbGroup.Text))
|
|
continue;
|
|
if (!shop.Notes.ParseToString().Contains(cmbNotes.Text))
|
|
continue;
|
|
|
|
shops.Add(shop);
|
|
}
|
|
this.lbxShop.ItemsSource = shops;
|
|
}
|
|
|
|
private void btnRestore_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
txtShopName.Text = "";
|
|
cmbNotes.Text = "";
|
|
cmbGroup.Text = "";
|
|
this.lbxShop.ItemsSource = GlobalConfig.ShopLoginList;
|
|
}
|
|
|
|
private void btnRefreshShop_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
MainWindow.Instance.GetServerShop();
|
|
}
|
|
|
|
private void btnCancelSelectShop_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.IsAcceptChoiceShop = false;
|
|
MainWindow.Instance.gridUser.Visibility = Visibility.Hidden;
|
|
}
|
|
|
|
|
|
private void btnApplySelectShop_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.IsAcceptChoiceShop = true;
|
|
MainWindow.Instance.gridUser.Visibility = Visibility.Hidden;
|
|
}
|
|
}
|
|
}
|