Files
6098/Cowain.Bake.UI/UserManagerment/ViewModels/DeviceModeViewModel.cs

148 lines
5.4 KiB
C#
Raw Normal View History

using Cowain.Bake.BLL;
using Cowain.Bake.Common.Enums;
using Cowain.Bake.Communication.MOM;
using Cowain.Bake.Model;
using Newtonsoft.Json;
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using System.Windows.Input;
using Unity;
using static Cowain.Bake.Common.Models.MESModel;
namespace Cowain.Bake.UI.UserManagerment.ViewModels
{
public class DeviceModeViewModel : BindableBase
{
TDeviceConfig dev;
private string _userName;
public string UserName
{
get { return _userName; }
set
{
SetProperty(ref _userName, value);
}
}
private string _userPwa;
public string UserPwa
{
get { return _userPwa; }
set
{
SetProperty(ref _userPwa, value);
}
}
private string _url;
public string Url
{
get { return _url; }
set
{
SetProperty(ref _url, value);
}
}
private int _selectedRadioButtonIndex;
public int SelectedRadioButtonIndex
{
get { return _selectedRadioButtonIndex; }
set
{
SetProperty(ref _selectedRadioButtonIndex, value);
}
}
public class CloseWindowEvent : PubSubEvent
{
public CloseWindowEvent()
{
}
}
private IEventAggregator _eventAggregator;
private IUnityContainer _unityContainer;
public DeviceModeViewModel(IUnityContainer unityContainer, IEventAggregator eventAggregator)
{
//初始化数据库连接池
_unityContainer = unityContainer;
_eventAggregator = eventAggregator;
string v = _unityContainer.Resolve<BLL.SysSetupService>().GetValueByParaID(ESysSetup.MOMMode.ToString());
SelectedRadioButtonIndex = int.Parse(v);
dev = _unityContainer.Resolve<DeviceConfigService>().GetConfig(EDeviceType.MOM)[0];
dynamic d = JsonConvert.DeserializeObject<dynamic>(dev.Json);
_url = d.URL;
}
public ICommand ExitCommand
{
get => new DelegateCommand<object>(OnExit);
}
public ICommand SwitchCommand
{
get => new DelegateCommand<object>(OnSwitch);
}
//public ICommand MesIpUpdateCommand
//{
// get => new DelegateCommand<object>(OnMesUpdate);
//}
private void OnExit(object obj )
{
_eventAggregator.GetEvent<CloseWindowEvent>().Publish();
}
// _unityContainer.Resolve<SysSetupService>().GetValueByParaID(ESysSetup.MOMMode.ToString())
public void OnSwitch(object obj)
{
if (string.IsNullOrEmpty(UserName)|| string.IsNullOrEmpty(this.UserPwa))
{
HandyControl.Controls.MessageBox.Info("工号与密码不能为空!请输入后切换");
return;
}
int deviceMode = int.Parse(_unityContainer.Resolve<SysSetupService>().GetValueByParaID(ESysSetup.MOMMode.ToString()));
_unityContainer.Resolve<SysSetupService>().UpdateValue(ESysSetup.MOMMode.ToString(), SelectedRadioButtonIndex.ToString());
MESReturnCmdModel mesModel = _unityContainer.Resolve<MESProcess>().EqptRun(UserName, this.UserPwa,
SelectedRadioButtonIndex.ToString());
string MOMMessage = "";
if (null != mesModel)
{
MOMMessage = mesModel.Info.MOMMessage;
}
if (null == mesModel || mesModel.Info.ResultFlag == EResultFlag.NG.ToString())
{
_unityContainer.Resolve<SysSetupService>().UpdateValue(ESysSetup.MOMMode.ToString(), deviceMode.ToString());
HandyControl.Controls.MessageBox.Error($@"切换【{((EMOMMode)SelectedRadioButtonIndex).GetDescription()}】失败 {MOMMessage}", "切换提示");
return;
}
HandyControl.Controls.MessageBox.Show($@"切换【{((EMOMMode)SelectedRadioButtonIndex).GetDescription()}】成功!", "切换提示");
_unityContainer.Resolve<LogService>().AddLog($@"切换【{((EMOMMode)SelectedRadioButtonIndex).GetDescription()}】!", E_LogType.Operate.ToString());
}
//public void OnMesUpdate(object obj)
//{
// dynamic dc = JsonConvert.DeserializeObject<dynamic>(dev.Json);
// if (MessageBoxResult.OK == HandyControl.Controls.MessageBox.Ask("是否修改Mes地址该操作可能会导致Mes(MOM)无法使用,请仔细确认无误", "操作提示"))
// {
// dc.URL = _url;
// _unityContainer.Resolve<DeviceConfigService>().UpdateMesJosn(JsonConvert.SerializeObject(dc));
// //_unityContainer.Resolve<MESProcess>().GetJsonParam(JsonConvert.SerializeObject(dc));
// return;
// }
// Url = dc.URL;
//}
public void Refresh()
{
string v = _unityContainer.Resolve<BLL.SysSetupService>().GetValueByParaID(ESysSetup.MOMMode.ToString());
SelectedRadioButtonIndex = int.Parse(v);
dev = _unityContainer.Resolve<DeviceConfigService>().GetConfig(EDeviceType.MOM)[0];
dynamic d = JsonConvert.DeserializeObject<dynamic>(dev.Json);
Url = d.URL;
}
}
}