Browse Source

BIserver

样式分支
NXX 2 years ago
parent
commit
3f1327562b
11 changed files with 732 additions and 106 deletions
  1. +178
    -96
      BPASmartClient.MorkF/Control_MorkF.cs
  2. +14
    -0
      BPASmartClient.MorkF/Model/LocalPotStep.cs
  3. +7
    -3
      BPASmartClient.MorkF/View/DebugView.xaml
  4. +11
    -3
      BPASmartClient.MorkF/View/DebugView.xaml.cs
  5. +80
    -0
      BPASmartClient.MorkF/View/LocalMenu.xaml
  6. +333
    -0
      BPASmartClient.MorkF/View/LocalMenu.xaml.cs
  7. +7
    -1
      BPASmartClient.MorkF/ViewModel/DebugViewModel.cs
  8. +99
    -0
      BPASmartClient.MorkF/ViewModel/LocalMenuViewModel.cs
  9. +1
    -1
      BPASmartClient.MorkS/BPASmartClient.MorkS.csproj
  10. +1
    -1
      BPASmartClient.MorkT_HQ/BPASmartClient.MorkTHQ.csproj
  11. +1
    -1
      DosingSystem/BPASmartClient.DosingSystem.csproj

+ 178
- 96
BPASmartClient.MorkF/Control_MorkF.cs View File

@@ -10,6 +10,7 @@ using BPA.Models;
using static BPASmartClient.EventBus.EventBus;
using BPASmartClient.Model.小炒机;
using BPASmartClient.MorkF.Model;
using System.Text;

namespace BPASmartClient.MorkF
{
@@ -37,7 +38,8 @@ namespace BPASmartClient.MorkF
ActionManage.GetInstance.Register(PLCInite, "InitCommand");
ActionManage.GetInstance.Register(FoodPlcInite, "FoodPlcInite");
ActionManage.GetInstance.Register(InitialData, "SimultaorOrder");

ActionManage.GetInstance.Register(StartOrder, "StartOrder");
ActionManage.GetInstance.Register(StartLocalOrder, "StartLocalOrder");
#endregion

#region 菜品库
@@ -72,14 +74,14 @@ namespace BPASmartClient.MorkF
ActionManage.GetInstance.Register(SetStir, "SetStir");
#endregion

}

#region 菜品库

public void FoodLibInit()
{
WriteControl("",true);
WriteControl("", true);
}
public void Electromagnetism(object o)
{
@@ -108,7 +110,7 @@ namespace BPASmartClient.MorkF
public void PawTurnBack()
{
WriteControl("", true);
}
}
/// <summary>
/// 设定机械臂的位置
/// </summary>
@@ -140,7 +142,7 @@ namespace BPASmartClient.MorkF
/// </summary>
public void OutSeasonings(List<SeasoningList> seasoningLists)
{
foreach(SeasoningList seasoning in seasoningLists)
foreach (SeasoningList seasoning in seasoningLists)
{
WriteControl(morkF.PassWayValue[seasoning.Loc], (ushort)seasoning.Qty);
Thread.Sleep(300);
@@ -150,7 +152,7 @@ namespace BPASmartClient.MorkF
WriteControl(morkF.StartPassWay[seasoning.Loc], true);
Thread.Sleep(300);
}
}

#region 炒锅1
@@ -174,7 +176,7 @@ namespace BPASmartClient.MorkF
WriteControl("LB4", false);
Thread.Sleep(200);
WriteControl("LB53", false);
foreach(var item in morkF.StartPassWay.Values)
foreach (var item in morkF.StartPassWay.Values)
{
Thread.Sleep(200);
WriteControl(item, false);
@@ -240,16 +242,20 @@ namespace BPASmartClient.MorkF
//搅拌臂去炒制位
public void StirArmGoWork()
{
WriteControl("LB6", true);
MessageLog.GetInstance.Show("搅拌臂去工作位");
while (!morkF.ArmOnWorking)
if (!morkF.ArmOnWorking)
{
WriteControl("LB6", true);
MessageLog.GetInstance.Show("搅拌臂去工作位");
while (!morkF.ArmOnWorking)
{
Thread.Sleep(200);
}

WriteControl("LB6", false);
Thread.Sleep(200);
MessageLog.GetInstance.Show("搅拌臂到达工作位");
}
WriteControl("LB6", false);
Thread.Sleep(200);
MessageLog.GetInstance.Show("搅拌臂到达工作位");

}
//HBOT放盒子到位
public void HBOTGoWork()
@@ -268,16 +274,16 @@ namespace BPASmartClient.MorkF
//加热挡位设定
public void SetFire(object o)
{
if(o == null) return;
if(o is List<int> ints&&ints.Count == 1)
if (o == null) return;
if (o is List<int> ints && ints.Count == 1)
{
WriteControl("LW14", (ushort)ints[0]);
Thread.Sleep(200);

}
}
/// <summary>
/// 搅拌挡位设定
/// </summary>
@@ -319,8 +325,47 @@ namespace BPASmartClient.MorkF
// //resultorder.AddRange(new int[] { 1, 2, 3 });
//}



}

/// <summary>
/// 本地菜单下单
/// </summary>
private void StartOrder(object o)
{
if(o==null) return;
if(o is int goodId)
{
var res = morkF.LocalstirFryGoods?.FirstOrDefault(p => p.GoodsKey == goodId);//匹配订单对应制作流程
if (res != null)
{
/* morkF.listStirBom.Add(res.StirFryBomInfo);*///添加订单制作流程
if (morkF.StirFryGoodsQuenes.Count > 0) return;
morkF.StirFryGoodsQuenes.Enqueue(new OrderLocInfo()
{
SuborderId = Guid.NewGuid().ToString(),
StirPotActions = res.StirPotActions,
GoodName = "本地菜品"
});
MessageLog.GetInstance.Show($"添加本地订单{res.GoodsKey}");
}
}
}

private void StartLocalOrder()
{
if (morkF.StirFryGoodsQuenes.Count > 0) return;//只能一个一个做
if (Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions.Count>0)
{
morkF.StirFryGoodsQuenes.Enqueue(new OrderLocInfo()
{
SuborderId = Guid.NewGuid().ToString(),
StirPotActions = Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions,
GoodName = "本地菜品"
});
MessageLog.GetInstance.Show($"添加本地模拟的订单{Json<LocalPotStep>.Data.LocalstirFryGoods.GoodsKey}");
}
}
#endregion

@@ -397,88 +442,103 @@ namespace BPASmartClient.MorkF
if (@event == null) return;
if (@event is StirFryGoodsEvent stirFry)
{
morkF.LocalstirFryGoods = stirFry.stirFrymessage.stirFryGoods;
if (stirFry.stirFrymessage.stirFryGoods.Count > 0)
{
foreach (var item in stirFry.stirFrymessage.stirFryGoods)
{
morkF.LocalstirFryGoods.Add(new StirFryGoods
{
GoodsKey = item.GoodsKey,
StirPotActions = OrderSort(item.StirPotActions),
});
}
}

MessageLog.GetInstance.Show("接收到小炒流程信息");
//流程解析
foreach (var item in morkF.LocalstirFryGoods)
{
MessageLog.GetInstance.Show($"添加菜谱{item.GoodsKey}");
// morkF.listStirBom.Add(item.StirFryBomInfo);//添加订单制作流程
string MenuStep = "菜单步骤:";
foreach (var items in item.StirPotActions)
{
switch (items.Actions)
{
case "加热开启":
MessageLog.GetInstance.Show(items.Actions);
case nameof(StirFryPotActionEnum.加热开启):
MenuStep += items.Actions + ",";
break;
case "设置加热挡位1":
MessageLog.GetInstance.Show(items.Actions);
case nameof(StirFryPotActionEnum.设置加热挡位1):
MenuStep += items.Actions + ",";
break;
case "设置加热挡位2":
MessageLog.GetInstance.Show(items.Actions);
case nameof(StirFryPotActionEnum.设置加热挡位2):
MenuStep += items.Actions + ",";
break;
case "设置加热挡位3":
MessageLog.GetInstance.Show(items.Actions);
case nameof(StirFryPotActionEnum.设置加热挡位3):
MenuStep += items.Actions + ",";
break;
case "设置加热挡位4":
MessageLog.GetInstance.Show(items.Actions);
case nameof(StirFryPotActionEnum.设置加热挡位4):
MenuStep += items.Actions + ",";
break;
case "设置加热挡位5":
MessageLog.GetInstance.Show(items.Actions);
case nameof(StirFryPotActionEnum.设置加热挡位5):
MenuStep += items.Actions + ",";
break;
case "设置加热挡位6":
MessageLog.GetInstance.Show(items.Actions);
case nameof(StirFryPotActionEnum.设置加热挡位6):
MenuStep += items.Actions + ",";
break;
case "设置加热挡位7":
MessageLog.GetInstance.Show(items.Actions);
case nameof(StirFryPotActionEnum.设置加热挡位7):
MenuStep += items.Actions + ",";
break;
case "设置加热挡位8":
MessageLog.GetInstance.Show(items.Actions);
case nameof(StirFryPotActionEnum.设置加热挡位8):
MenuStep += items.Actions + ",";
break;
case "设置加热挡位9":
MessageLog.GetInstance.Show(items.Actions);
case nameof(StirFryPotActionEnum.设置加热挡位9):
MenuStep += items.Actions + ",";
break;
case "设置加热挡位10":
MessageLog.GetInstance.Show(items.Actions);
case nameof(StirFryPotActionEnum.设置加热挡位10):
MenuStep += items.Actions + ",";
break;
case "停止加热":
MessageLog.GetInstance.Show(items.Actions);
case nameof(StirFryPotActionEnum.停止加热):
MenuStep += items.Actions + ",";
break;
case "加调料":
MessageLog.GetInstance.Show(items.Actions);
case nameof(StirFryPotActionEnum.加调料):
MenuStep += items.Actions + ",";
break;
case "取原料":
MessageLog.GetInstance.Show(items.Actions);
case nameof(StirFryPotActionEnum.取原料):
MenuStep += items.Actions + ",";
break;
case "开启搅拌":
MessageLog.GetInstance.Show(items.Actions);
case nameof(StirFryPotActionEnum.开启搅拌):
MenuStep += items.Actions + ",";
break;
case "设置搅拌挡位1":
MessageLog.GetInstance.Show(items.Actions);
case nameof(StirFryPotActionEnum.设置搅拌挡位1):
MenuStep += items.Actions + ",";
break;
case "设置搅拌挡位2":
MessageLog.GetInstance.Show(items.Actions);
case nameof(StirFryPotActionEnum.设置搅拌挡位2):
MenuStep += items.Actions + ",";
break;
case "设置搅拌挡位3":
MessageLog.GetInstance.Show(items.Actions);
case nameof(StirFryPotActionEnum.设置搅拌挡位3):
MenuStep += items.Actions + ",";
break;
case "关闭搅拌":
MessageLog.GetInstance.Show(items.Actions);
case nameof(StirFryPotActionEnum.关闭搅拌):
MenuStep += items.Actions + ",";
break;
case "出餐启动":
MessageLog.GetInstance.Show(items.Actions);
case nameof(StirFryPotActionEnum.出餐启动):
MenuStep += items.Actions + ",";
break;
case "倒菜品":
MessageLog.GetInstance.Show(items.Actions);
case nameof(StirFryPotActionEnum.道菜启动):
MenuStep += items.Actions + ",";
break;
case "搅拌臂原点位":
MessageLog.GetInstance.Show(items.Actions);
case nameof(StirFryPotActionEnum.炒制菜品):
MenuStep += items.Actions + ",";
break;
case "搅拌臂炒制位":
MessageLog.GetInstance.Show(items.Actions);
case nameof(StirFryPotActionEnum.搅拌臂原点位):
MenuStep += items.Actions + ",";
break;
case "洗锅":
MessageLog.GetInstance.Show(items.Actions);
case nameof(StirFryPotActionEnum.搅拌臂炒制位):
MenuStep += items.Actions + ",";
break;
case nameof(StirFryPotActionEnum.洗锅):
MenuStep += items.Actions + ",";
break;
default:
break;
@@ -487,12 +547,33 @@ namespace BPASmartClient.MorkF


}
MessageLog.GetInstance.Show(MenuStep);



}
}
});
}


private List<PotActions> OrderSort(List<PotActions> potActions)
{
if (potActions.Count > 1)
{
potActions.Sort(
delegate (PotActions st1, PotActions st2)
{
//降序排列
//return st2.FryTime.CompareTo(st1.FryTime);

//升序版(颠倒 st1 和 st2 即可)
return st1.FryTime.CompareTo(st2.FryTime);

});
}
return potActions;
}
/// <summary>
/// 订单状态发布
/// </summary>
@@ -518,6 +599,7 @@ namespace BPASmartClient.MorkF
if (order.MorkOrder.GoodBatchings == null) return;
OrderCount++;
DeviceProcessLogShow($"接收到{OrderCount}次订单");
Enum.GetNames(typeof(StirFryPotActionEnum));

var res = morkF.LocalstirFryGoods?.FirstOrDefault(p => p.GoodsKey == order.MorkOrder.RecipeId);//匹配订单对应制作流程
if (res != null)
@@ -561,99 +643,99 @@ namespace BPASmartClient.MorkF
{
switch (item.Actions)
{
case "加热开启":
case nameof(StirFryPotActionEnum.加热开启):
StartFire();
MessageLog.GetInstance.Show(item.Actions);
break;
case "设置加热挡位1":
case nameof(StirFryPotActionEnum.设置加热挡位1):
SetFire(new List<int> { 1 });
MessageLog.GetInstance.Show(item.Actions);
break;
case "设置加热挡位2":
case nameof(StirFryPotActionEnum.设置加热挡位2):
SetFire(new List<int> { 2 });
MessageLog.GetInstance.Show(item.Actions);
break;
case "设置加热挡位3":
case nameof(StirFryPotActionEnum.设置加热挡位3):
SetFire(new List<int> { 3 });
MessageLog.GetInstance.Show(item.Actions);
break;
case "设置加热挡位4":
case nameof(StirFryPotActionEnum.设置加热挡位4):
SetFire(new List<int> { 4 });
MessageLog.GetInstance.Show(item.Actions);
break;
case "设置加热挡位5":
case nameof(StirFryPotActionEnum.设置加热挡位5):
SetFire(new List<int> { 5 });
MessageLog.GetInstance.Show(item.Actions);
break;
case "设置加热挡位6":
case nameof(StirFryPotActionEnum.设置加热挡位6):
SetFire(new List<int> { 6 });
MessageLog.GetInstance.Show(item.Actions);
break;
case "设置加热挡位7":
case nameof(StirFryPotActionEnum.设置加热挡位7):
SetFire(new List<int> { 7 });
MessageLog.GetInstance.Show(item.Actions);
break;
case "设置加热挡位8":
case nameof(StirFryPotActionEnum.设置加热挡位8):
SetFire(new List<int> { 8 });
MessageLog.GetInstance.Show(item.Actions);
break;
case "设置加热挡位9":
case nameof(StirFryPotActionEnum.设置加热挡位9):
SetFire(new List<int> { 9 });
MessageLog.GetInstance.Show(item.Actions);
break;
case "设置加热挡位10":
case nameof(StirFryPotActionEnum.设置加热挡位10):
SetFire(new List<int> { 10 });
MessageLog.GetInstance.Show(item.Actions);
break;
case "停止加热":
case nameof(StirFryPotActionEnum.停止加热):
StopFire();
MessageLog.GetInstance.Show(item.Actions);
break;
case "加调料":
case nameof(StirFryPotActionEnum.加调料):
OutSeasonings(item.SeasoningLists);
MessageLog.GetInstance.Show(item.Actions);
break;
case "取原料":
case nameof(StirFryPotActionEnum.取原料):
MessageLog.GetInstance.Show(item.Actions);
break;
case "开启搅拌":
case nameof(StirFryPotActionEnum.开启搅拌):
StartStir();
MessageLog.GetInstance.Show(item.Actions);
break;
case "设置搅拌挡位1":
case nameof(StirFryPotActionEnum.设置搅拌挡位1):
SetStir(new List<int> { 1 });
MessageLog.GetInstance.Show(item.Actions);
break;
case "设置搅拌挡位2":
case nameof(StirFryPotActionEnum.设置搅拌挡位2):
SetStir(new List<int> { 2 });
MessageLog.GetInstance.Show(item.Actions);
break;
case "设置搅拌挡位3":
case nameof(StirFryPotActionEnum.设置搅拌挡位3):
SetStir(new List<int> { 3 });
MessageLog.GetInstance.Show(item.Actions);
break;
case "关闭搅拌":
case nameof(StirFryPotActionEnum.关闭搅拌):
StopStir();
MessageLog.GetInstance.Show(item.Actions);
break;
case "出餐启动":
case nameof(StirFryPotActionEnum.出餐启动):
MessageLog.GetInstance.Show(item.Actions);
break;
case "倒菜品":
case nameof(StirFryPotActionEnum.道菜启动):
OutFood();
break;
case "炒制菜品":
Thread.Sleep(item.FryTime * 1000);
case nameof(StirFryPotActionEnum.炒制菜品):
Thread.Sleep(item.During * 1000);
break;
case "搅拌臂原点位":
case nameof(StirFryPotActionEnum.搅拌臂原点位):
StirArmGoOrigin();
MessageLog.GetInstance.Show(item.Actions);
break;
case "搅拌臂炒制位":
case nameof(StirFryPotActionEnum.搅拌臂炒制位):
StirArmGoWork();
MessageLog.GetInstance.Show(item.Actions);
break;
case "洗锅":
case nameof(StirFryPotActionEnum.洗锅):
MessageLog.GetInstance.Show(item.Actions);
break;
default:


+ 14
- 0
BPASmartClient.MorkF/Model/LocalPotStep.cs View File

@@ -0,0 +1,14 @@
using BPA.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.MorkF.Model
{
public class LocalPotStep
{
public StirFryGoods LocalstirFryGoods { get; set; } = new StirFryGoods();
}
}

+ 7
- 3
BPASmartClient.MorkF/View/DebugView.xaml View File

@@ -33,9 +33,13 @@

</Grid.RowDefinitions>
<WrapPanel Orientation="Horizontal">
<Button Content="炒锅初始化" Command="{Binding PlcInite}" Cursor="Hand"/>
<Button Content="炒锅1复位" Command="{Binding Plc1Reset}" Cursor="Hand"/>

<Button Content="炒锅初始化" Command="{Binding PlcInite}" Cursor="Hand" Margin="10,0"/>
<Button Content="炒锅1复位" Command="{Binding Plc1Reset}" Cursor="Hand" Margin="10,0"/>
<TextBlock Text="菜单编号;" Margin="10,0"/>
<TextBox Text="{Binding FoodMenuID}" Width="100"/>
<Button Content="下单" Margin="10,0" Command="{Binding StartOrder}" Cursor="Hand"/>
<Button Content="本地模拟流程配置" Click="Button_Click"/>
<Button Content="本地模拟流程下单" Margin="10,0" Command="{Binding StartLocalOrder}"/>
</WrapPanel>
<WrapPanel Grid.Row="1" Orientation="Horizontal" Margin="0,0,0,-37" RenderTransformOrigin="0.503,0.715">
<Button x:Name="checkValue" Content="炒锅1模拟" Command="{Binding Pot1SimOrder}" Margin="10,0"/>


+ 11
- 3
BPASmartClient.MorkF/View/DebugView.xaml.cs View File

@@ -1,4 +1,6 @@
using BPASmartClient.MorkF.ViewModel;
using BPASmartClient.Helper;
using BPASmartClient.MorkF.Model;
using BPASmartClient.MorkF.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -24,8 +26,14 @@ namespace BPASmartClient.MorkF.View
public DebugView()
{
InitializeComponent();
Json<LocalPotStep>.Read();

}

private void Button_Click(object sender, RoutedEventArgs e)
{
LocalMenu localMenu = new LocalMenu();
localMenu.ShowDialog();
}
}
}

+ 80
- 0
BPASmartClient.MorkF/View/LocalMenu.xaml View File

@@ -0,0 +1,80 @@
<Window x:Class="BPASmartClient.MorkF.View.LocalMenu"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:BPASmartClient.MorkF.View"
xmlns:vm="clr-namespace:BPASmartClient.MorkF.ViewModel"
mc:Ignorable="d"
Title="LocalMenu" Height="800" Width="800" WindowStartupLocation="CenterScreen" WindowStyle="None" AllowsTransparency="True" MouseLeftButtonDown="Window_MouseLeftButtonDown">
<Window.DataContext>
<vm:LocalMenuViewModel/>
</Window.DataContext>
<Window.Resources>
<Style TargetType="ListBoxItem" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border BorderBrush="Black" BorderThickness="0" Background="White">
<Grid Width="600" HorizontalAlignment="Center" VerticalAlignment="Center" >
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" Text="{Binding FryTime,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Center" VerticalAlignment="Center" />
<TextBox Grid.Column="1" Text="{Binding During}" Margin="10,0"/>
<ComboBox Grid.Column="2" Width="120" ItemsSource="{Binding DataContext.strPotActions , RelativeSource={RelativeSource AncestorType=Window,Mode=FindAncestor}}"
SelectedValue="{Binding Actions}" Margin="10,0"/>
<TextBox Grid.Column="3" Text="{Binding SeasoningLists[0].Loc}" Margin="10,0"/>
<TextBox Grid.Column="4" Text="{Binding SeasoningLists[0].Qty}" Margin="10,0"/>
<Button Grid.Column="5" Content="删除" Margin="10,0" HorizontalAlignment="Center"
Command="{Binding DataContext.Delete, RelativeSource={RelativeSource AncestorType=Window,Mode=FindAncestor}}"
CommandParameter="{Binding DataContext, RelativeSource={RelativeSource AncestorType=ListBoxItem,Mode=FindAncestor}}"/>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button Content="增加步骤" Command="{Binding AddFryTime}" Width="120" Height="40" Margin="10,0"/>
<Button Content="保存" Command="{Binding Save}" Width="120" Height="40" Margin="10,0"/>
<Button Content="退出" Click="Button_Click" Width="120" Height="40" Margin="10,0"/>
</StackPanel>
<Grid Grid.Row="1" Width="600" HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="步骤" HorizontalAlignment="Center"/>
<TextBlock Grid.Column="1" Text="时间" HorizontalAlignment="Center"/>
<TextBlock Grid.Column="2" Text="动作" HorizontalAlignment="Center"/>
<TextBlock Grid.Column="3" Text="调料位置" HorizontalAlignment="Center"/>
<TextBlock Grid.Column="4" Text="调料重量" HorizontalAlignment="Center"/>
<TextBlock Grid.Column="5" Text="删除" HorizontalAlignment="Center"/>
</Grid>
<ListBox x:Name="listview1" Grid.Row="2" BorderBrush="Black" BorderThickness="0" HorizontalAlignment="Center" AllowDrop="True"
ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemsSource="{Binding PotActionStep}" Margin=" 10" Background="Transparent"
PreviewMouseMove="listview1_MouseMove" Drop="listview1_Drop" PreviewMouseUp="listview1_MouseLeftButtonUp"
>
</ListBox>
</Grid>
</Window>

+ 333
- 0
BPASmartClient.MorkF/View/LocalMenu.xaml.cs View File

@@ -0,0 +1,333 @@
using BPA.Models;
using BPASmartClient.Helper;
using BPASmartClient.MorkF.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace BPASmartClient.MorkF.View
{
/// <summary>
/// LocalMenu.xaml 的交互逻辑
/// </summary>
public partial class LocalMenu : Window
{

double X, Y;
Border ultUE;
Popup mypopup;
ListBoxItem OldItem;
ListBoxItem new_Item;
bool isDown = false;

int lao_index;
int new_index;


/// <summary>
/// 当前拖拽子控件Item
/// </summary>
private ListBoxItem ChildListBoxItem;

public LocalMenu()
{
InitializeComponent();
}

private void Button_Click(object sender, RoutedEventArgs e)
{
this.Close();
}

private int GetCurrentIndex(GetPositionDelegate getPosition)
{
int index = -1;
for (int i = 0; i < listview1.Items.Count; ++i)
{
ListBoxItem item = GetListViewItem(i);
if (item != null && this.IsMouseOverTarget(item, getPosition))
{
index = i;
break;
}
}
return index;
}

private bool IsMouseOverTarget(Visual target, GetPositionDelegate getPosition)
{
Rect bounds = VisualTreeHelper.GetDescendantBounds(target);
Point mousePos = getPosition((IInputElement)target);
return bounds.Contains(mousePos);
}


delegate Point GetPositionDelegate(IInputElement element);

ListBoxItem GetListViewItem(int index)
{
if (listview1.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated)
return null;
return listview1.ItemContainerGenerator.ContainerFromIndex(index) as ListBoxItem;
}

private void CloneVisual(Border border, MouseButtonEventArgs e)
{
ListBoxItem listBoxItem = new ListBoxItem();
Point ptLeftUp = new Point(0, 0);
ptLeftUp = listview1.PointToScreen(ptLeftUp);
mypopup = new Popup();
double y = e.GetPosition(listview1).Y;
double x = e.GetPosition(listview1).X;

VisualBrush brush = new VisualBrush(border);
Rectangle rect = new Rectangle();
rect.Width = border.ActualWidth;
rect.Height = border.ActualHeight;
rect.Fill = brush;
rect.Opacity = border.Opacity;
border.Opacity = 0.8;
mypopup.Child = rect;
mypopup.AllowsTransparency = true;
mypopup.HorizontalOffset = ptLeftUp.X + x - ((FrameworkElement)ultUE).ActualWidth / 2;
mypopup.VerticalOffset = ptLeftUp.Y + y - ((FrameworkElement)ultUE).ActualHeight / 2;
mypopup.IsOpen = true;
}

private void listview1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
try
{
if (isDown)
{
isDown = false;
return;
}
var pos = e.GetPosition(listview1);
HitTestResult result = VisualTreeHelper.HitTest(listview1, pos);
if (result == null) return;
OldItem = Utils.FindVisualParent<ListBoxItem>(result.VisualHit);
if (OldItem != null)
{
if (e.Source is Border)
{
ultUE = (Border)e.Source;
ultUE.CaptureMouse();
ChildListBoxItem = Utils.FindVisualParent<ListBoxItem>(VisualTreeHelper.HitTest(ultUE, e.GetPosition(ultUE)).VisualHit);
CloneVisual(ultUE, e);
isDown = true;
}
}
}
catch (Exception)
{

throw;
}
}



private void listview1_MouseMove(object sender, MouseEventArgs e)
{
if (sender is ListBox listview&& e.LeftButton == MouseButtonState.Pressed&& listview.SelectedItem != null)
{
var pos = e.GetPosition(listview1);
HitTestResult result = VisualTreeHelper.HitTest(listview1, pos);
if (result == null)
{
return;
}
var listBoxItem = Utils.FindVisualParent<ListBoxItem>(result.VisualHit);
if (listBoxItem == null || listBoxItem.Content != listview1.SelectedItem)
{
return;
}
DataObject dataObj = new DataObject(listBoxItem.Content as PotActions);
DragDrop.DoDragDrop(listview1, dataObj, DragDropEffects.Move);
ActionManage.GetInstance.Send("SortFryTime");
}


}

private void listview1_Drop(object sender, DragEventArgs e)
{
var pos = e.GetPosition(listview1);
var result = VisualTreeHelper.HitTest(listview1, pos);
if (result == null)
{
return;
}
//查找元数据
var sourcePerson = e.Data.GetData(typeof(PotActions)) as PotActions;
if (sourcePerson == null)
{
return;
}
//查找目标数据
var listBoxItem = Utils.FindVisualParent<ListBoxItem>(result.VisualHit);
if (listBoxItem == null)
{
return;
}
var targetPerson = listBoxItem.Content as PotActions;
if (ReferenceEquals(targetPerson, sourcePerson))
{
return;
}
int i = listview1.Items.IndexOf(sourcePerson);
int j = listview1.Items.IndexOf(targetPerson);
ActionManage.GetInstance.Send("PotActionStep", new int[] { i, j });
//LocalMenuViewModel.PotActionStep.RemoveAt(listview1.Items.IndexOf(sourcePerson));
//LocalMenuViewModel.PotActionStep.Insert(listview1.Items.IndexOf(targetPerson)+1, sourcePerson);
//targetPerson.FryTime = listview1.Items.IndexOf(targetPerson) -1;
//LocalMenuViewModel.PotActionStep.Move(listview1.Items.IndexOf(sourcePerson), listview1.Items.IndexOf(targetPerson));


}

private void listview1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
////鼠标未按下返回
//if (!isDown) return;

//isDown = false;

//var pos = e.GetPosition(listview1);
//HitTestResult result = VisualTreeHelper.HitTest(listview1, pos);
//if (result == null) return;
//new_Item = Utils.FindVisualParent<ListBoxItem>(result.VisualHit);
//if (mypopup != null)
//{
// mypopup.IsOpen = false;
// mypopup = null;
//}

//MoveListBoxStyle(e, false);


}

private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}


/// <summary>
/// 移动效果
/// </summary>
/// <param name="boxItem"></param>
private void MoveListBoxStyle(MouseEventArgs e, bool isBool)
{
try
{
if (isBool)//为真,根据鼠标位置设置行透明度和显示状态
{
//移动到某行减轻某行 暗黑
//foreach (ListBoxItem item in Utils.FindVisualChildren<ListBoxItem>(listview1))
//{
// if (item != ChildListBoxItem)//这就是其他控件
// {
// double item_width = item.ActualWidth; //当前行宽
// double item_height = item.ActualHeight; //当前行高
// double item_x = e.GetPosition(item).X; //鼠标相对当前行X位移
// double item_y = e.GetPosition(item).Y; //鼠标相对当前行Y位移

// if (item_y <= item_height && item_y > 0 && item_x > 0 && item_x <= item_width)//鼠标进入哪一行,则将那一行变灰
// {
// item.Opacity = 0.5;
// item.Background = Brushes.AliceBlue;
// lao_index = LocalMenuViewModel.PotActionStep.IndexOf(item.Content as PotActions);
// new_index = LocalMenuViewModel.PotActionStep.IndexOf(ChildListBoxItem.Content as PotActions);
// //LocalMenuViewModel.PotActionStep.Move(lao_index, new_index);
// }
// else //鼠标没在哪一行,则保持原状
// {
// item.Opacity = 1;
// }
// }
// else
// {
// item.Visibility = Visibility.Hidden;
// }
//}
}
else//为假 恢复所有行透明度和显示状态
{
//LocalMenuViewModel.PotActionStep.Move(lao_index, new_index);
//移动到某行减轻某行 暗黑
foreach (ListBoxItem item in Utils.FindVisualChildren<ListBoxItem>(listview1))
{
item.Background = Brushes.Transparent;
item.Opacity = 1;
item.Visibility = Visibility.Visible;
}
}
}
catch (Exception ex)
{
}
}
}


internal static class Utils
{
//根据子元素查找父元素
public static T FindVisualParent<T>(DependencyObject obj) where T : class
{
while (obj != null)
{
if (obj is T)
return obj as T;

obj = VisualTreeHelper.GetParent(obj);
}
return null;
}

/// <summary>
/// 查询子控件
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="obj"></param>
/// <returns></returns>
public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
{
if (depObj != null)
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
if (child != null && child is T)
{
yield return (T)child;
}

foreach (T childOfChild in FindVisualChildren<T>(child))
{
yield return childOfChild;
}
}
}
}
}
}

+ 7
- 1
BPASmartClient.MorkF/ViewModel/DebugViewModel.cs View File

@@ -27,13 +27,17 @@ namespace BPASmartClient.MorkF.ViewModel
public int DeviceId { get; set; }

#region 设备控制
public int FoodMenuID { get { return _foodMenuID; } set { _foodMenuID = value; OnPropertyChanged(); } }
private int _foodMenuID;
public RelayCommand PlcInite { get; set; }
public RelayCommand FoodPlcInite { get; set; }
public RelayCommand Plc1Reset { get; set; }
public RelayCommand StartOrder { get; set; }
public RelayCommand StartLocalOrder { get; set; }



#endregion
#endregion

#region 菜品控制
public string RealX { get { return _realX; } set { _realX = value; OnPropertyChanged(); } }
@@ -168,6 +172,8 @@ namespace BPASmartClient.MorkF.ViewModel
PlcInite = new RelayCommand(() => { ActionManage.GetInstance.Send("InitCommand"); });
FoodPlcInite = new RelayCommand(() => { ActionManage.GetInstance.Send("FoodPlcInite"); });
Plc1Reset = new RelayCommand(() => { ActionManage.GetInstance.Send("Plc1Reset"); });
StartOrder = new RelayCommand(() => { ActionManage.GetInstance.Send("StartOrder", FoodMenuID); });
StartLocalOrder = new RelayCommand(() => { ActionManage.GetInstance.Send("StartLocalOrder"); });
#endregion

#region 菜品控制


+ 99
- 0
BPASmartClient.MorkF/ViewModel/LocalMenuViewModel.cs View File

@@ -0,0 +1,99 @@
using BPA.Models;
using BPASmartClient.Helper;
using BPASmartClient.MorkF.Model;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.MorkF.ViewModel
{
partial class LocalMenuViewModel:ObservableObject
{
public ObservableCollection<PotActions> PotActionStep { get; set; } = new ObservableCollection<PotActions>();

public ObservableCollection<string> strPotActions { get; set; } = new ObservableCollection<string>();


public RelayCommand<object> Delete { get; set; }
public RelayCommand AddFryTime { get; set; }
public RelayCommand Save { get; set; }

private void Deleted(object o)
{
if (o == null) return;
if(o is PotActions p)
{
PotActionStep.Remove(p);
}
}


public LocalMenuViewModel()
{
if(Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions.Count > 0)
{
PotActionStep.Clear();
PotActionStep = new ObservableCollection<PotActions>(Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions);
}
Delete = new RelayCommand<object>(Deleted);
AddFryTime = new RelayCommand(() =>
{
List<SeasoningList> seasoningLists = new List<SeasoningList>();
seasoningLists.Add(new SeasoningList { Loc = 0,Qty = 0});
PotActionStep.Add(new BPA.Models.PotActions
{
FryTime = PotActionStep.Count +1,
During =0,
SeasoningLists = seasoningLists,
});
});

Save = new RelayCommand(new Action(() =>
{
Json<LocalPotStep>.Data.LocalstirFryGoods.GoodsKey = 11;
Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions = new List<PotActions>(PotActionStep);
Json<LocalPotStep>.Save();
}));

foreach(var pot in Enum.GetNames(typeof(StirFryPotActionEnum)))
{
strPotActions.Add(pot);
}

ActionManage.GetInstance.Register(new Action(()=>
{
for (int i = 0; i < Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions.Count; i++)
{
Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions[i].FryTime = i + 1;
}
}), "SortFryTime");
ActionManage.GetInstance.Register(new Action<object>((o) =>
{
if (o == null) return ;
if(o is int[] ints)
{
Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions[ints[0]].FryTime = ints[1]+1;
Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions[ints[1]].FryTime = ints[0]+1;
var res = Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions[ints[0]];

Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions.Remove(res);
Json<LocalPotStep>.Data.LocalstirFryGoods.StirPotActions.Insert(ints[1],res);

}

}), "PotActionStep");


}
}
}

+ 1
- 1
BPASmartClient.MorkS/BPASmartClient.MorkS.csproj View File

@@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BPA.Models" Version="1.0.31" />
<PackageReference Include="BPA.Models" Version="1.0.34" />
<PackageReference Include="Microsoft.Toolkit.Mvvm" Version="7.1.2" />
<PackageReference Include="System.Speech" Version="6.0.0" />
</ItemGroup>


+ 1
- 1
BPASmartClient.MorkT_HQ/BPASmartClient.MorkTHQ.csproj View File

@@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BPA.Models" Version="1.0.31" />
<PackageReference Include="BPA.Models" Version="1.0.34" />
<PackageReference Include="Microsoft.Toolkit.Mvvm" Version="7.1.2" />
</ItemGroup>



+ 1
- 1
DosingSystem/BPASmartClient.DosingSystem.csproj View File

@@ -17,7 +17,7 @@

<ItemGroup>
<PackageReference Include="BPA.Helper" Version="1.0.19" />
<PackageReference Include="BPA.Message" Version="1.0.46" />
<PackageReference Include="BPA.Message" Version="1.0.66" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>



Loading…
Cancel
Save