using Aucma.Scada.Business; using Aucma.Scada.Model.domain; using Aucma.Scada.UI.Page.InventoryInfo; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using HighWayIot.Config; using HighWayIot.Plc; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows; namespace Aucma.Scada.UI.viewModel.InventoryInfo { public class BoxFoamRearInventoryViewModel : ViewModelBase { [DllImport("user32.dll")] public static extern int MessageBoxTimeoutA(IntPtr hWnd, string msg, string Caps, int type, int Id, int time); private ObservableCollection spaceItems = new ObservableCollection(); private InventoryInfoBusiness inventoryInfoBusiness = InventoryInfoBusiness.Instance; private OutStoreBusiness outStoreBusiness = OutStoreBusiness.Instance; private InStoreBusiness inStoreBusiness = InStoreBusiness.Instance; private AppConfig appConfig = AppConfig.Instance; private AssemblyPlanBusiness assemblyPlanBusiness = AssemblyPlanBusiness.Instance; public BoxFoamRearInventoryViewModel() { #region 事件绑定 // 设置型号 SubmitCommand = new RelayCommand(obj => SubmitCommandExecute(obj)); SubmitCommand2 = new RelayCommand(obj => SubmitCommandExecute2(obj)); SubmitCommand3 = new RelayCommand(obj => SubmitCommandExecute3(obj)); UpdateInStoreFlagCommand = new RelayCommand(obj => UpdateInStoreFlag(obj)); UpdateOutStoreFlagCommand = new RelayCommand(obj => UpdateOutStoreFlag(obj)); UpdateUnusualFlagCommand = new RelayCommand(obj => UpdateUnusualFlag(obj)); UpdateSpaceStatusCommand = new RelayCommand(obj => UpdateSpaceStatus(obj)); SpaceDetailCommand = new RelayCommand(obj => SpaceDetail(obj)); OutOnlyOneCommand = new RelayCommand(obj => OutOnlyOne(obj)); OutAllCommand = new RelayCommand(obj => OutAll(obj)); #endregion outStoreBusiness.RefreshStoreStockEvent += Query; inStoreBusiness.RefreshInStoreTaskEvent += RefreshSpaceInfo; SelectTypeViewModel.RefreshPageEvent += Query; Query(); } #region 参数定义 public RelayCommand SubmitCommand { get; set; } private void SubmitCommandExecute(string spaceCode) { SelectType type = new SelectType(1,spaceCode); type.ShowDialog(); } public RelayCommand SubmitCommand2 { get; set; } private void SubmitCommandExecute2(string spaceCode) { SelectType type = new SelectType(2,spaceCode); type.ShowDialog(); } public RelayCommand SubmitCommand3 { get; set; } private void SubmitCommandExecute3(string spaceCode) { SelectType type = new SelectType(3,spaceCode); type.ShowDialog(); } public ObservableCollection _shapes; public ObservableCollection Shapes { get { return _shapes; } set { _shapes = value; RaisePropertyChanged(nameof(Shapes)); } } private ObservableCollection spaceDetailDataGrid; public ObservableCollection SpaceDetailDataGrid { get { return spaceDetailDataGrid; } set { spaceDetailDataGrid = value; RaisePropertyChanged(() => SpaceDetailDataGrid); } } #endregion #region 事件定义 /// /// 修改入库状态标识 /// public RelayCommand UpdateInStoreFlagCommand { get; set; } /// /// 修改出库状态标识 /// public RelayCommand UpdateOutStoreFlagCommand { get; set; } /// /// 修改异常状态标识 /// public RelayCommand UpdateUnusualFlagCommand { get; set; } /// /// 修改货道状态 /// public RelayCommand UpdateSpaceStatusCommand { get; set; } /// /// 货道明细 /// public RelayCommand SpaceDetailCommand { get; set; } /// /// 出一个 /// public RelayCommand OutOnlyOneCommand { get; set; } /// /// 整条道出 /// public RelayCommand OutAllCommand { get; set; } #endregion /// /// 刷新货道信息,入库完成委托事件 /// /// /// private void RefreshSpaceInfo(object obj = null, bool isFinish = true) { Query(); } private void Query() { App.Current.Dispatcher.Invoke((Action)(() => { var info = inventoryInfoBusiness.GetSpaceInfos(appConfig.foamStoreCode).OrderBy(x=>x.objId); if (info != null) { if (spaceItems.Count > 0) { spaceItems.Clear(); } foreach (var item in info) { spaceItems.Add(item); } Shapes = spaceItems; } })); } /// /// 货道入库标识设置 /// /// private void UpdateInStoreFlag(object obj) { string info = obj as string; bool result = inventoryInfoBusiness.UpdateInStoreFlag(appConfig.foamStoreCode, info); if (result) { Query(); MessageBoxTimeoutA((IntPtr)0, $"货道入库状态修改成功,3秒后关闭提示", "提示", 0, 0, 3000); } else { MessageBox.Show("货道入库状态修改失败"); } } /// /// 货道出库标识设置 /// /// private void UpdateOutStoreFlag(object obj) { string info = obj as string; bool result = inventoryInfoBusiness.UpdateOutStoreFlag(appConfig.foamStoreCode, info); if (result) { Query(); MessageBoxTimeoutA((IntPtr)0, $"货道出库状态修改成功,3秒后关闭提示", "提示", 0, 0, 3000); } else { MessageBox.Show("货道出库状态修改失败"); } } /// /// 货道异常标识设置 /// /// private void UpdateUnusualFlag(object obj) { string info = obj as string; bool result = inventoryInfoBusiness.UpdateUnusualFlag(appConfig.foamStoreCode, info); if (result) { Query(); MessageBoxTimeoutA((IntPtr)0, $"货道异常标识修改成功,3秒后关闭提示", "提示", 0, 0, 3000); } else { MessageBox.Show("货道异常标识修改失败"); } } /// /// 修改货道状态 /// /// private void UpdateSpaceStatus(object obj) { string info = obj as string; bool result = inventoryInfoBusiness.UpdateSpaceStatus(appConfig.foamStoreCode, info); if (result) { Query(); MessageBoxTimeoutA((IntPtr)0, $"货道状态修改成功,3秒后关闭提示", "提示", 0, 0, 3000); } else { MessageBox.Show("货道状态修改失败"); } } /// /// 货道明细 /// /// private void SpaceDetail(object obj) { string info = obj as string; //SpaceDetailWindow spaceDetailWindow = new SpaceDetailWindow(appConfig.shellStoreCode, info); //spaceDetailWindow.Show(); //inventoryInfoBusiness.RefreshBaseSpaceDetails(appConfig.shellStoreCode, info); var list = inventoryInfoBusiness.GetBaseSpaceDetails(appConfig.foamStoreCode, info); RefreshSpaceDetails(list); } /// /// 刷新货道明细列表 /// /// private void RefreshSpaceDetails(List spaceDetails) { SpaceDetailDataGrid = new ObservableCollection(); if (spaceDetails != null) { spaceDetails.ForEach( arg => { SpaceDetailDataGrid.Add(arg); }); } } /// /// 手动出一个 /// /// private void OutOnlyOne(object obj) { string info = obj as string; bool result = outStoreBusiness.OutOnlyOneBySpaceCode(appConfig.foamStoreCode, info); if (result) { Query(); MessageBoxTimeoutA((IntPtr)0, $"出库任务创建成功,3秒后关闭提示", "提示", 0, 0, 3000); } else { MessageBox.Show("出库任务创建失败"); } } /// /// 整条道出 /// /// private void OutAll(object obj) { string info = obj as string; bool result = outStoreBusiness.OutAllBySpaceCode(appConfig.foamStoreCode, info); if (result) { Query(); MessageBoxTimeoutA((IntPtr)0, $"出库任务创建成功,3秒后关闭提示", "提示", 0, 0, 3000); } else { MessageBox.Show("出库任务创建失败"); } } ///// ///// 手动出一个 ///// ///// //private void OutOnlyOne(object obj) //{ // string info = obj as string; // bool result = outStoreBusiness.OutOnlyOneBySpaceCode(appConfig.foamStoreCode, info); // if (result) // { // Query(); // MessageBoxTimeoutA((IntPtr)0, $"出库任务创建成功,3秒后关闭提示", "提示", 0, 0, 3000); // } // else // { // MessageBox.Show("出库任务创建失败"); // } //} ///// ///// 整条道出 ///// ///// //private void OutAll(object obj) //{ //} } }