@ -1,7 +1,9 @@
using Admin.Core.IService ;
using Admin.Core.Model ;
using Admin.Core.Service ;
using Aucma.Core.HwPLc ;
using Aucma.Core.ProductOffLineCX1.Business ;
using Aucma.Core.ProductOffLineCX1.Config ;
using Aucma.Core.ProductOffLineCX1.Models ;
using Aucma.Core.ProductOffLineCX1.Views ;
using CommunityToolkit.Mvvm.ComponentModel ;
@ -32,11 +34,14 @@ namespace Aucma.Core.ProductOffLineCX1.ViewModels
OffLineBusiness offLineBusiness = OffLineBusiness . Instance ;
private IndexPageView firstPage = new IndexPageView ( ) ; //首页
private DirectionEditView directionEditView = new DirectionEditView ( ) ;
private SelectQualityView selectQualityView = new SelectQualityView ( ) ;
private SelectQualityView selectQualityView = new SelectQualityView ( ) ;
private AppConfig appConfig = AppConfig . Instance ;
public QualityPageViewModel ( )
{
UserContent1 = directionEditView ;
UserContent2 = selectQualityView ;
DirectionInit ( ) ;
// 传入库方向
offLineBusiness . getDirectioneEvent + = getInstoreDirection ;
QualityPageView . getAllQualityEvent + = test ;
@ -47,32 +52,76 @@ namespace Aucma.Core.ProductOffLineCX1.ViewModels
}
// 初始化界面分垛模式及分垛方向
private void DirectionInit ( )
{
#region 分垛模式
if ( appConfig . SelectedMaterialType = = "1" )
{
SelectedMaterialType = "手动模式" ;
}
else if ( appConfig . SelectedMaterialType = = "2" )
{
SelectedMaterialType = "自动模式" ;
}
else
{
SelectedMaterialType = "手动模式" ;
appConfig . SelectedMaterialType = "1" ;
}
# endregion
#region 默认方向
if ( appConfig . PalletizDirection = = "1" )
{
_isSelectedOptionA = true ;
_isSelectedOptionB = false ;
}
else if ( appConfig . PalletizDirection = = "2" )
{
_isSelectedOptionA = false ;
_isSelectedOptionB = true ;
}
else
{
_isSelectedOptionA = true ;
_isSelectedOptionB = true ;
appConfig . PalletizDirection = "1" ;
}
# endregion
}
/// <summary>
/// 根据自动/手动模式获取入库方向
/// </summary>
/// <param name="materialType"></param>
public String getInstoreDirection ( string materialType )
{
// 二线默认A库, 一线默认B库
string direction = "B" ;
string direction = string . Empty ;
Application . Current . Dispatcher . Invoke ( ( ) = >
// 自动模式模式
if ( appConfig . SelectedMaterialType = = "2" )
{
// 设置了入库自动模式模式
if ( SelectedMaterialType ! = null & & SelectedMaterialType . Content . ToString ( ) = = "自动模式" )
BaseMaterialInfo info = _baseMaterialInfoServices . Query ( x = > x . MaterialCode = = materialType ) . FirstOrDefault ( ) ;
if ( info ! = null & & ! string . IsNullOrEmpty ( info . InboundDirection ) ) // 设置过了方向
{
BaseMaterialInfo info = _baseMaterialInfoServices . Query ( x = > x . MaterialCode = = materialType ) . FirstOrDefault ( ) ;
if ( info ! = null & & ! string . IsNullOrEmpty ( info . InboundDirection ) ) // 设置过了方向
{
direction = info . InboundDirection ;
}
direction = info . InboundDirection ;
}
else // 设置手动模式
else // 自动模式未设置方向,按照手动模式走
{
if ( IsSelectedOptionA = = true ) direction = "A" ;
if ( IsSelectedOptionB = = true ) direction = "B" ;
direction = appConfig . PalletizDirection = = "1" ? "A" : "B" ;
}
} ) ;
}
else // 设置手动模式
{
direction = appConfig . PalletizDirection = = "1" ? "A" : "B" ;
}
return direction ;
}
@ -123,19 +172,33 @@ namespace Aucma.Core.ProductOffLineCX1.ViewModels
/// 分垛模式(自动模式,手动模式)SelectedMaterialType.content.tostring()
/// </summary>
/// private string _selectedMaterialType;
private ComboBoxItem _selectedMaterialType ;
public ComboBoxItem SelectedMaterialType
private string _selectedMaterialType ;
public string SelectedMaterialType
{
get { return _selectedMaterialType ; }
set
{
if ( _selectedMaterialType ! = value )
{
if ( value = = "手动模式" )
{
appConfig . SelectedMaterialType = "1" ;
}
else if ( value = = "自动模式" )
{
appConfig . SelectedMaterialType = "2" ;
}
else
{
appConfig . SelectedMaterialType = "1" ;
}
_selectedMaterialType = value ;
OnPropertyChanged ( nameof ( SelectedMaterialType ) ) ;
}
}
}
#region 单选框
private bool _isSelectedOptionA ;
public bool IsSelectedOptionA
@ -143,17 +206,47 @@ namespace Aucma.Core.ProductOffLineCX1.ViewModels
get { return _isSelectedOptionA ; }
set
{
if ( _isSelectedOptionA ! = value )
{
_isSelectedOptionA = value ;
OnPropertyChanged ( nameof ( IsSelectedOptionA ) ) ;
// 如果选择了A选项, 将B选项设为false
if ( _isSelectedOptionA )
if ( value )
{
var result = MessageBox . Show ( "确认切换A库方向吗?" , "确认" , MessageBoxButton . YesNo , MessageBoxImage . Question ) ;
if ( result = = MessageBoxResult . Yes )
{
IsSelectedOptionB = false ;
var obj = PlcHelper . melsecList . FirstOrDefault ( d = > d . EquipName . Equals ( "成品下线Plc" ) ) ;
// obj = null;
if ( obj ! = null )
{
bool flag = obj . plc . ReadBool ( "B100A" ) ;
if ( flag )
{
_isSelectedOptionA = value ;
OnPropertyChanged ( nameof ( IsSelectedOptionA ) ) ;
appConfig . PalletizDirection = "1" ;
// 如果选择了A选项, 将B选项设为false
if ( _isSelectedOptionA )
{
IsSelectedOptionB = false ;
}
}
else
{
MessageBox . Show ( "切换失败,请检查提升机及二楼平台是否残留箱体或数据!" ) ;
}
}
else
{
MessageBox . Show ( "Plc连接失败, 请检查连接!" ) ;
}
}
}
else
{
_isSelectedOptionA = value ;
OnPropertyChanged ( nameof ( IsSelectedOptionA ) ) ;
}
}
}
@ -163,22 +256,54 @@ namespace Aucma.Core.ProductOffLineCX1.ViewModels
get { return _isSelectedOptionB ; }
set
{
if ( _isSelectedOptionB ! = value )
if ( value )
{
_isSelectedOptionB = value ;
OnPropertyChanged ( nameof ( IsSelectedOptionB ) ) ;
var result = MessageBox . Show ( "确认切换B方向吗?" , "确认" , MessageBoxButton . YesNo , MessageBoxImage . Question ) ;
// 如果选择了B选项, 将A选项设为false
if ( _isSelectedOptionB )
if ( result = = MessageBoxResult . Yes )
{
IsSelectedOptionA = false ;
var obj = PlcHelper . melsecList . FirstOrDefault ( d = > d . EquipName . Equals ( "成品下线Plc" ) ) ;
// obj = null;
if ( obj ! = null )
{
bool flag = obj . plc . ReadBool ( "B100A" ) ;
if ( flag )
{
_isSelectedOptionB = value ;
OnPropertyChanged ( nameof ( IsSelectedOptionB ) ) ;
appConfig . PalletizDirection = "2" ;
// 如果选择了B选项, 将A选项设为false
if ( _isSelectedOptionB )
{
IsSelectedOptionA = false ;
}
}
else
{
MessageBox . Show ( "切换失败,请检查提升机及二楼平台是否残留箱体或数据!" ) ;
}
}
else
{
MessageBox . Show ( "Plc连接失败, 请检查连接!" ) ;
}
}
}
else
{
_isSelectedOptionB = value ;
OnPropertyChanged ( nameof ( IsSelectedOptionB ) ) ;
}
}
}
# endregion
# endregion