132 lines
4.0 KiB
C#
132 lines
4.0 KiB
C#
using HandyControl.Controls;
|
|
using LiveCharts;
|
|
using Ping9719.WpfEx;
|
|
using Ping9719.WpfEx.Mvvm;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
using HandyControl.Tools.Extension;
|
|
using 货架标准上位机.Views.Controls;
|
|
using 货架标准上位机.Api;
|
|
using WCS.Model;
|
|
using System.Diagnostics;
|
|
using System.Security.Cryptography;
|
|
|
|
namespace 货架标准上位机.ViewModel
|
|
{
|
|
public class HomeViewModel : BindableBase
|
|
{
|
|
WarnInfoContainer WarnInfo = new WarnInfoContainer();//警告、错误等信息
|
|
|
|
public bool IsThisPageVisible = true;
|
|
|
|
public HomeViewModel()
|
|
{
|
|
Task.Run(() =>
|
|
{
|
|
while (true)
|
|
{
|
|
if (IsThisPageVisible)
|
|
{
|
|
RefreshUserControl();
|
|
}
|
|
Thread.Sleep(2000);
|
|
}
|
|
});
|
|
}
|
|
|
|
#region 绑定
|
|
private string textErr;
|
|
/// <summary>
|
|
/// 错误文本
|
|
/// </summary>
|
|
public string TextErr { get => textErr; set { SetProperty(ref textErr, value); } }
|
|
public ICommand ClearTextInfoCommand { get => new DelegateCommand(ClearTextInfo); }
|
|
/// <summary>
|
|
/// 清除信息文本
|
|
/// </summary>
|
|
public void ClearTextInfo()
|
|
{
|
|
TextBoxLog.ClearLog();
|
|
}
|
|
public ICommand ClearTextErrCommand { get => new DelegateCommand(ClearTextErr); }
|
|
/// <summary>
|
|
/// 清除全部错误文本
|
|
/// </summary>
|
|
public void ClearTextErr()
|
|
{
|
|
WarnInfo.RemoveAll(WarnInfoType.AlwayWarn);
|
|
}
|
|
|
|
public ICommand AddUserControlCommand { get => new DelegateCommand(RefreshUserControl); }
|
|
public WrapPanel wrapPanel;
|
|
public async void RefreshUserControl()
|
|
{
|
|
//var dia = Dialog.Show(new TextDialog());
|
|
try
|
|
{
|
|
var body = new GetShelfStatusRequest()
|
|
{
|
|
UserName = "xxx",
|
|
DeviceType = "WCS前端",
|
|
GroupNames = LocalFile.Config.GroupName,
|
|
};
|
|
var Result = await ApiHelp.Post<GetShelfStatusResponse>([LocalFile.Config.ApiIpHost, "home/getShelfStatus"], body);
|
|
if (Result != null && Result.Data?.Count > 0)
|
|
{
|
|
App.Current.Dispatcher.Invoke(() =>
|
|
{
|
|
wrapPanel.Children.Clear();
|
|
Result.Data
|
|
.ForEach(t =>
|
|
{
|
|
var shelf = new ShelfStatusControl(t.ShelfCode, t.CurentMode, "");
|
|
wrapPanel.Children.Add(shelf);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
finally
|
|
{
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 页面加载时任务
|
|
/// <summary>
|
|
/// 页面第一次加载时执行的任务
|
|
/// </summary>
|
|
public void LoadTask()
|
|
{
|
|
//注册警告事件
|
|
WarnInfo.WarnInfoChanged += (all, add, rem) =>
|
|
{
|
|
TextErr = string.Join(Environment.NewLine, all.OrderBy(o => (o.WarnType, o.Source, o.Text)));
|
|
|
|
if (add.Any())
|
|
Logs.Write(add.Select(o => o.ToString()), LogsType.Warning);
|
|
if (rem.Any())
|
|
Logs.Write(rem.Select(o => o.ToString()), LogsType.Warning);
|
|
|
|
//警告信息保存到数据库
|
|
if (WarnInfoDb.IsEnabled)
|
|
{
|
|
WarnInfoDb.db.Insertable(WarnInfoItemDb.GetList(add)).ExecuteCommand();
|
|
WarnInfoDb.db.Updateable(WarnInfoItemDb.GetList(rem)).ExecuteCommand();
|
|
}
|
|
};
|
|
}
|
|
#endregion
|
|
}
|
|
}
|