首次提交:添加src文件夹代码

This commit is contained in:
2026-02-27 14:02:43 +08:00
commit d330cfbca7
4184 changed files with 5546478 additions and 0 deletions

View File

@@ -0,0 +1,189 @@
using Cowain.Bake.Common;
using Cowain.Bake.Model;
using Prism.Regions;
using System.Collections.ObjectModel;
using Unity;
using Cowain.Bake.BLL;
using Prism.Commands;
using JSON = Newtonsoft.Json.JsonConvert;
using System;
using Cowain.Bake.Common.Core;
using HandyControl.Controls;
using System.Windows;
using System.Threading.Tasks;
namespace Cowain.Bake.UI.FactoryMaintenance.ViewModels
{
public class DeviceManagementViewModel : ViewModelBase, INavigationAware
{
private bool _autoRefresh;
public bool AutoRefresh
{
get { return _autoRefresh; }
set { SetProperty(ref _autoRefresh, value); }
}
private TDeviceConfig _editDevice;
public TDeviceConfig EditDevice
{
get => _editDevice ?? (_editDevice = new TDeviceConfig());
set
{
SetProperty(ref _editDevice, value);
}
}
private TDeviceConfig selectDevice;
public TDeviceConfig SelectDevice
{
get => selectDevice ?? (selectDevice = new TDeviceConfig());
set
{
SetProperty(ref selectDevice, value);
}
}
private ObservableCollection<TDeviceConfig> _deviceList;
public ObservableCollection<TDeviceConfig> DeviceList
{
//get { return _taskList; }
get => _deviceList ?? (_deviceList = new ObservableCollection<TDeviceConfig>());
set { SetProperty(ref _deviceList, value); }
}
public DeviceManagementViewModel(IUnityContainer unityContainer, IRegionManager regionManager) : base(unityContainer, regionManager)
{
AutoRefresh = true;
this.PageTitle = "设备管理";
_unityContainer = unityContainer;
Task.Run(() => AsyncRefreshTask());
}
public DelegateCommand SelectCommand => new DelegateCommand(() =>
{
if (SelectDevice != null && SelectDevice.Id > 0)
{
var json = PrettifyJson(SelectDevice.Json);
if (json.Item1)
{
SelectDevice.Json = json.Item2;
//深拷贝
EditDevice = JSON.DeserializeObject<TDeviceConfig>(JSON.SerializeObject(SelectDevice));
}
}
});
public DelegateCommand VerifyCommand => new DelegateCommand(() =>
{
IsVerify(true);
});
bool IsVerify(bool b = false)
{
if (PrettifyJson(EditDevice.Json).Item1)
{
if (b)
{
Growl.Success("有效的JSON格式");
}
return true;
}
Growl.Error("不是有效的JSON格式, 请重新输入!");
return false;
}
public DelegateCommand EditCommand => new DelegateCommand(() =>
{
if (!IsVerify())
{
return;
}
var result = HandyControl.Controls.MessageBox.Ask($@"是否确定要修改设备信息?", "操作提示");
if (result == System.Windows.MessageBoxResult.Cancel)
{
return;
}
var res = _unityContainer.Resolve<DeviceConfigService>().Update(EditDevice);
if (res > 0)
{
Growl.Success("设备信息修改完成!");
Refresh();
}
else
{
Growl.Error("设备信息修改失败!");
}
if (!EditDevice.Enable)
{
CommonCoreHelper.Instance.BlockStatusColor.Add(EditDevice); //刷新主界面的PLC状态
}
});
public async void AsyncRefreshTask()
{
while(true)
{
if (AutoRefresh)
{
Application.Current?.Dispatcher?.Invoke(new Action(() =>
{
Refresh();
}));
}
await Task.Delay(2000);
}
}
private (bool, string) PrettifyJson(string raw)
{
(bool, string) result = (true, "");
try
{
result.Item2 = Newtonsoft.Json.Linq.JToken.Parse(raw).ToString(Newtonsoft.Json.Formatting.Indented);
// 如果已经是 JSON 字符串,先解析再序列化即可
//var doc = System.Text.Json.JsonDocument.Parse(raw);
//return System.Text.Json.JsonSerializer.Serialize(doc.RootElement,
// new System.Text.Json.JsonSerializerOptions
// {
// WriteIndented = true
// });
}
catch(Exception ex)
{
// 万一不是合法 JSON直接原样返回
LogHelper.Instance.GetCurrentClassWarn($"{raw},{ex.Message}");
result.Item1 = false;
}
return result;
}
public override void Refresh()
{
DeviceList.Clear();
var models = _unityContainer.Resolve<DeviceConfigService>().GetAll();
models.ForEach(x => DeviceList.Add(x));
}
void INavigationAware.OnNavigatedTo(NavigationContext navigationContext)
{
}
bool INavigationAware.IsNavigationTarget(NavigationContext navigationContext)
{
return false;
}
void INavigationAware.OnNavigatedFrom(NavigationContext navigationContext)
{
}
}
}

View File

@@ -0,0 +1,84 @@
using Cowain.Bake.BLL;
using Cowain.Bake.Common;
using Cowain.Bake.Common.Core;
using Cowain.Bake.Model;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using Unity;
using JSON = Newtonsoft.Json.JsonConvert;
namespace Cowain.Bake.UI.FactoryMaintenance.ViewModels
{
public class MomOutboundViewModel : ViewModelBase
{
private string batteryCode;
public string BatteryCode
{
get => batteryCode;
set => SetProperty(ref batteryCode, value);
}
private string sendData;
public string SendData
{
get => sendData;
set => SetProperty(ref sendData, value);
}
private string recvData;
public string RecvData
{
get => recvData;
set => SetProperty(ref recvData, value);
}
public MomOutboundViewModel(IUnityContainer unityContainer, IRegionManager regionManager) : base(unityContainer, regionManager)
{
this.PageTitle = "电芯出站信息";
_unityContainer = unityContainer;
}
public DelegateCommand<object> SendToMomCommand => new DelegateCommand<object>((x) =>
{
List<int> batterys = new List<int>();
TBatteryInfo battery = _unityContainer.Resolve<BatteryInfoService>().GetBatteryInfos(BatteryCode);
if (null == battery)
{
HandyControl.Controls.MessageBox.Fatal("找不到此电芯,请重新输入电芯条码!");
return;
}
batterys.Add(battery.Id);
//此时托盘可能已经转历史盘托了
TPalletInfo palletInfo = _unityContainer.Resolve<BLL.PalletInfoService>().GetPalletInfoOrHistory(battery.Id);
if (null == palletInfo)
{
LogHelper.Instance.Error($"找不到此电芯所属托盘!", true);
return;
}
RecvData = _unityContainer.Resolve<Common.Interface.ICommonFun>().ManualMesOutUnBinding(palletInfo, battery);
});
//public DelegateCommand<object> SendToMomCommand => new DelegateCommand<object>((x) =>
//{
// if (string.IsNullOrEmpty(SendData))
// {
// HandyControl.Controls.MessageBox.Fatal("发送数据为空!");
// return;
// }
// //var result =_unityContainer.Resolve<Common.Interface.ICommonFun>().SendData(SendData); //发送
// //if (null == result)
// //{
// // RecvData = "接收数据超时!";
// //}
// //else
// //{
// // RecvData = JSON.SerializeObject(result);
// //}
//});
}
}

View File

@@ -0,0 +1,82 @@
using Cowain.Bake.Common;
using Cowain.Bake.Communication.Interface;
using Prism.Regions;
using Prism.Services.Dialogs;
using System.Collections.ObjectModel;
using Unity;
namespace Cowain.Bake.UI.FactoryMaintenance.ViewModels
{
public class PLCVarMonitorViewModel : ViewModelBase
{
IDialogService _dialogService;
public ObservableCollection<IPLCDevice> plcList;
public PLCVarMonitorViewModel(IUnityContainer unityContainer, IRegionManager regionManager, IDialogService dialogService)
: base(unityContainer, regionManager)
{
this.PageTitle = "标签监视";
_dialogService = dialogService;
}
public ObservableCollection<IPLCDevice> PlcList
{
get => plcList ?? (plcList = new ObservableCollection<IPLCDevice>());
}
public override void Refresh()
{
// 用户信息刷新
PlcList.Clear();
var pList = _unityContainer.ResolveAll<IPLCDevice>();
foreach (var item in pList)
{
PlcList.Add(item);
}
}
//public DelegateCommand<Variable> SelectScriptCommand => new DelegateCommand<Variable>((x) =>
//{
// DialogParameters param = new DialogParameters();
// param.Add("variable", x);
// _dialogService.ShowDialog(
// "ScriptSelectDialog",
// param,
// result =>
// {
// if (result.Result == ButtonResult.OK)
// {
// this.Refresh();
// }
// });
//});
//public DelegateCommand<Variable> DeleteScriptCommand => new DelegateCommand<Variable>((x) =>
//{
// var result = HandyControl.Controls.MessageBox.Ask($@"是否确定要删除脚本关联?", "操作提示");
// if (result == System.Windows.MessageBoxResult.Cancel)
// {
// return;
// }
// IPLCService service = _unityContainer.Resolve<IPLCService>();
// int res = service.DelectScript(x);
// if (res > 0)
// {
// Growl.Success("变量删除脚本关联成功!");
// x.ScriptName = "";
// x.ScriptId = 0;
// this.Refresh();
// }
// else
// {
// Growl.Success("变量删除脚本关联失败,Id不存在");
// }
//});
}
}

View File

@@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity;
using Cowain.Bake.Model;
using System.Collections.ObjectModel;
using Cowain.Bake.BLL;
using System.Text.RegularExpressions;
using Prism.Mvvm;
using Prism.Commands;
using Cowain.Bake.Common.Core;
using Cowain.Bake.Common.Enums;
using Prism.Regions;
using Cowain.Bake.Common.Interface;
namespace Cowain.Bake.UI.FactoryMaintenance.ViewModels
{
public class SysSetupViewModel : BindableBase, INavigationAware
{
private readonly IUnityContainer _unityContainer;
private bool isAllowed;
public bool IsAllowed
{
get => isAllowed;
set => SetProperty(ref isAllowed, value);
}
private TSysSetup selectedItem;
public TSysSetup SelectedItem
{
get => selectedItem;
set => SetProperty(ref selectedItem, value);
}
public SysSetupViewModel(IUnityContainer unityContainer)
{
_unityContainer = unityContainer;
ShowInfo();
isAllowed = unityContainer.Resolve<UserService>().CheckPermission(ERole.Mantainer);
}
public DelegateCommand<object> CellEditEndingCommand => new DelegateCommand<object>((x) =>
{
Regex regex = new Regex(selectedItem.CheckRegular);
if (!regex.IsMatch(selectedItem.ParamValue))
{
string oldValue = _unityContainer.Resolve<SysSetupService>().GetValueByID(selectedItem.Id);
LogHelper.Instance.Error(selectedItem.ParamName + "的值:" + selectedItem.ParamValue + ",不正确,已回滚!", true);
var findSelect = ParamList.Where(item => item.Id == selectedItem.Id).FirstOrDefault();
findSelect.ParamValue = oldValue;
}
});
public ObservableCollection<TSysSetup> paraList = new ObservableCollection<TSysSetup>();
public ObservableCollection<TSysSetup> ParamList
{
get => paraList;
set => SetProperty(ref paraList, value);
}
public DelegateCommand<object> SaveCommand => new DelegateCommand<object>((x) =>
{
var sysSetupService = _unityContainer.Resolve<SysSetupService>();
foreach (var item in ParamList)
{
Regex reg = new Regex(item.CheckRegular);
if (reg.IsMatch(item.ParamValue))
{
sysSetupService.UpdateValue(item.Id , item.ParamValue);
}
else
{
LogHelper.Instance.Error(item.ParamName + "格式不正确,不保存。", true);
}
}
ShowInfo();
HandyControl.Controls.Growl.Success("保存成功");
_unityContainer.Resolve<ICommonFun>().SetBatteryCodeLen();
_unityContainer.Resolve<LogService>().AddLog($@"修改参数", E_LogType.Operate.ToString());
});
private void ShowInfo()
{
ParamList.Clear();
var sysSetupService = _unityContainer.Resolve<SysSetupService>();
sysSetupService.GetShowParam().ForEach(item => ParamList.Add(item));
}
void INavigationAware.OnNavigatedTo(NavigationContext navigationContext)
{
}
bool INavigationAware.IsNavigationTarget(NavigationContext navigationContext)
{
return false;
}
void INavigationAware.OnNavigatedFrom(NavigationContext navigationContext)
{
}
}
}