using PdmSwPlugin.Commmon.Util.UI;
|
using PdmSwPlugin.Common.Entity;
|
using PdmSwPlugin.Common.Util.Http;
|
using System;
|
using System.Collections.Generic;
|
using System.Collections.ObjectModel;
|
using System.Net.Http;
|
using System.Timers;
|
using System.Windows;
|
|
namespace PdmSwPlugin.MaterialSelect
|
{
|
/// <summary>
|
/// 分部类,主要是与web交互的方法
|
/// </summary>
|
public partial class MaterialSelectControl
|
{
|
|
private Timer _timerCache;
|
public Timer TimerCache
|
{
|
get => _timerCache;
|
set => RaiseAndSetIfChanged(ref _timerCache, value);
|
}
|
|
/// <summary>
|
/// 业务类型字段变更后,查询AutoSelect
|
/// </summary>
|
/// <param name="value">变更后的字符</param>
|
private void SelectBussinessType()
|
{
|
/// 使用延时函数,避免太过频繁的向web发送查询请求
|
long interval = 500;
|
Timer timer = TimerCache;
|
if (timer != null)
|
{
|
timer.Interval = interval;
|
return;
|
}
|
|
TimerCache = new Timer(interval);
|
timer = TimerCache;
|
timer.Elapsed += (sender, e) =>
|
{
|
timer.Enabled = false;
|
string value = PartBussinesstypeName;
|
|
if (string.IsNullOrEmpty(value))
|
{
|
Dispatcher.Invoke(new Action(delegate
|
{
|
btInput.IsDropDownOpen = false;
|
btInput.ItemsSource = new ObservableCollection<string>();
|
TimerCache = null;
|
}));
|
return;
|
}
|
HttpClient c = clientCreator.GetClient();
|
Result<ObservableCollection<BusinessType>> result =
|
c.GetSyncAction<ObservableCollection<BusinessType>>("openApi/wpf/bt/list", new BusinessType()
|
{
|
no = value
|
});
|
ObservableCollection<BusinessType> bts = result.result;
|
if (bts != null && bts.Count > 0)
|
{
|
ObservableCollection<string> btNames = new ObservableCollection<string>();
|
Dictionary<string, string> btDict = new Dictionary<string, string>();
|
foreach (BusinessType bt in bts)
|
{
|
btDict.Add(bt.name, bt.id);
|
btNames.Add(bt.name);
|
}
|
Dispatcher.Invoke(new Action(delegate
|
{
|
btInput.ItemsSource = btNames;
|
BtCache = btDict;
|
btInput.IsDropDownOpen = true;
|
TimerCache = null;
|
}));
|
}
|
else
|
{
|
Dispatcher.Invoke(new Action(delegate
|
{
|
TimerCache = null;
|
}));
|
}
|
};
|
timer.Enabled = true;
|
}
|
|
/// <summary>
|
/// 查询物料异步函数
|
/// </summary>
|
/// <param name="pageNo">第几页</param>
|
/// <param name="pageSize">查几条</param>
|
private async void HttpSelectPartWithSpec(long pageNo, long pageSize)
|
{
|
if (Loading)
|
{
|
MessageBox.Show("请等待...", "提示");
|
return;
|
}
|
MaskAdorner.ShowMask(table);
|
try
|
{
|
string url = $"openApi/wpf/material/list-with-spec/{pageNo}/{pageSize}";
|
string partBussinesstype = string.IsNullOrWhiteSpace(PartBussinesstypeName)
|
? null
|
: (BtCache == null ? ""
|
: BtCache.ContainsKey(PartBussinesstypeName) ? BtCache[PartBussinesstypeName] : "");
|
|
HttpClient c = clientCreator.GetClient();
|
Result<Page<PdmPart>> result =
|
await c.PostAsyncAction<Page<PdmPart>>(url, new PdmPart()
|
{
|
partNo = PartNo,
|
partModel = PartModel,
|
partBrandName = PartBrandName,
|
partBussinesstype = partBussinesstype,
|
specs = (ObservableCollection<PartSpec>)specTable.ItemsSource,
|
column = Column,
|
order = Order
|
});
|
Page<PdmPart> pageList = result.HandleResult();
|
UpdatePage(result.result);
|
}
|
catch (Exception e)
|
{
|
MessageBox.Show("查询物料失败!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
Logger.Error("查询物料失败!异常:{0}", e);
|
}
|
finally
|
{
|
MaskAdorner.HideMask(table);
|
}
|
}
|
|
/// <summary>
|
/// 查询规格列表
|
/// </summary>
|
/// <param name="businessTypeName">业务类型拼接名称</param>
|
private async void SelectBussinesstypeSpec()
|
{
|
string businessTypeName = SelectedBtName;
|
if (businessTypeName == null)
|
{
|
specTable.ItemsSource = new ObservableCollection<PartSpec>();
|
return;
|
}
|
try
|
{
|
HttpClient c = clientCreator.GetClient();
|
Result<ObservableCollection<PartSpec>> result =
|
await c.GetAsyncAction<ObservableCollection<PartSpec>>("openApi/wpf/bt/spec/list", new BusinessType()
|
{
|
id = BtCache[businessTypeName]
|
});
|
ObservableCollection<PartSpec> specs = result.HandleResult();
|
specTable.ItemsSource = specs;
|
}
|
catch (Exception e)
|
{
|
MessageBox.Show("查询规格失败!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
Logger.Error("查询规格失败!异常:{0}", e);
|
}
|
}
|
}
|
}
|