Explorar o código

添加切换产品功能

wanghan hai 6 meses
pai
achega
d86a793e4a

+ 85 - 2
TeamAAS-VM/Core/Management.cs

@@ -233,6 +233,13 @@ namespace TeamAAS_VP.Core
             get { return _Yield; }
             set { SetProperty(ref _Yield, value); }
         }
+
+        private ObservableCollection<ProductModel> _ProductList;
+        public ObservableCollection<ProductModel> ProductList
+        {
+            get { return _ProductList; }
+            set { SetProperty(ref _ProductList, value); }
+        }
         #endregion
 
         #region 命令
@@ -1266,6 +1273,8 @@ namespace TeamAAS_VP.Core
         /// </summary>
         string[] wo = new string[10];
 
+        string[] model_num = new string[10];//产品model_num
+        string[] color = new string[10];//产品color
         /// <summary>
         /// 二次定位相机的工具坐标
         /// </summary>
@@ -2342,7 +2351,44 @@ namespace TeamAAS_VP.Core
                                                     wo[i] = woItem.Replace("wo=", "").Trim();
                                                     SendTaskMessage($"工单信息:{wo[i]}", MessageLevel.Info);
                                                 }
-
+                                                string modelItem = item.FirstOrDefault(f => f.Contains("model_num="));
+                                                if (modelItem != null)
+                                                {
+                                                    model_num[i] = modelItem.Replace("model_num=", "").Trim();
+                                                    SendTaskMessage($"model_num:{model_num[i]}", MessageLevel.Info);
+                                                }
+                                                string colorItem = item.FirstOrDefault(f => f.Contains("color="));
+                                                if (colorItem != null)
+                                                {
+                                                    color[i] = colorItem.Replace("color=", "").Trim();
+                                                    SendTaskMessage($"color:{color[i]}", MessageLevel.Info);
+                                                }
+                                                //切换产品
+                                                if (i == 0)//i=0时才会切换产品
+                                                {
+                                                    var q = await _systemDatabaseService.QueryProductFromMesAsync(model_num[i], color[i]);
+                                                    if (!string.IsNullOrEmpty(q))
+                                                    {
+                                                        ProductList = new ObservableCollection<ProductModel>(_productService.GetAllProducts());
+                                                        Guid productId = Guid.Empty;
+                                                        foreach (var itt in ProductList)
+                                                        {
+                                                            if (itt.Name == q)
+                                                            {
+                                                                productId = itt.ID;
+                                                                break;
+                                                            }
+                                                        }
+                                                        if (currentProduct.ID != productId)
+                                                        {
+                                                            //切换产品
+                                                            _productService.LoadProduct(productId);
+                                                            _productService.SetCurrentProduct(productId);
+                                                            await WritePositionToPlcAsync();
+                                                            SendTaskMessage($"切换产品成功", MessageLevel.Debug);
+                                                        }
+                                                    }
+                                                }
                                                 //产品发生改变并且供料器发生了变化时,需要通知PLC进行取料更改
                                                 await plc.WriteNodeAsync(addressConfig.Out_ScrewFeederIsChanged.Address, (Int16)1); //不发生改变
                                                 await plc.WriteNodeAsync(string.Format(addressConfig.Out_MesStatus.Address, i), (Int16)1);
@@ -2397,9 +2443,46 @@ namespace TeamAAS_VP.Core
                                                 wo[i] = woItem.Replace("wo=", "").Trim();
                                                 SendTaskMessage($"工单信息:{wo[i]}", MessageLevel.Info);
                                             }
-
+                                            string modelItem = item.FirstOrDefault(f => f.Contains("model_num="));
+                                            if (modelItem != null)
+                                            {
+                                                model_num[i] = modelItem.Replace("model_num=", "").Trim();
+                                                SendTaskMessage($"model_num:{model_num[i]}", MessageLevel.Info);
+                                            }
+                                            string colorItem = item.FirstOrDefault(f => f.Contains("color="));
+                                            if (colorItem != null)
+                                            {
+                                                color[i] = colorItem.Replace("color=", "").Trim();
+                                                SendTaskMessage($"color:{color[i]}", MessageLevel.Info);
+                                            }
                                             LogHelper.WriteLogMes($"询问mes成功");
                                             SendTaskMessage($"询问mes成功:{response}", MessageLevel.Debug);
+                                            //切换产品
+                                            if (i == 0)//i=0时才会切换产品
+                                            {
+                                                var q = await _systemDatabaseService.QueryProductFromMesAsync(model_num[i], color[i]);
+                                                if (!string.IsNullOrEmpty(q))
+                                                {
+                                                    ProductList = new ObservableCollection<ProductModel>(_productService.GetAllProducts());
+                                                    Guid productId = Guid.Empty;
+                                                    foreach (var itt in ProductList)
+                                                    {
+                                                        if (itt.Name == q)
+                                                        {
+                                                            productId = itt.ID;
+                                                            break;
+                                                        }
+                                                    }
+                                                    if (currentProduct.ID != productId)
+                                                    {
+                                                        //切换产品
+                                                        _productService.LoadProduct(productId);
+                                                        _productService.SetCurrentProduct(productId);
+                                                        await WritePositionToPlcAsync();
+                                                        SendTaskMessage($"切换产品成功", MessageLevel.Debug);
+                                                    }
+                                                }
+                                            }
                                             //产品发生改变并且供料器发生了变化时,需要通知PLC进行取料更改
                                             await plc.WriteNodeAsync(addressConfig.Out_ScrewFeederIsChanged.Address, (Int16)1); //不发生改变
                                             await plc.WriteNodeAsync(string.Format(addressConfig.Out_MesStatus.Address, i), (Int16)1);

+ 80 - 0
TeamAAS-VM/Data/SystemDatabaseService.cs

@@ -864,5 +864,85 @@ namespace TeamAAS_VP.Data
             await _db.Deleteable<ThrowRecord>().Where(r => r.DayTime >= todayStart && r.DayTime < todayEnd).ExecuteCommandAsync();
         }
         #endregion
+
+
+        #region 产品和mes的绑定,自动切换产品
+        /// <summary>
+        /// 添加绑定信息
+        /// </summary>
+        /// <param name="record"></param>
+        /// <param name="product"></param>
+        /// <returns></returns>
+        /// <exception cref="ArgumentNullException"></exception>
+        public async Task InsertProWithMesAsync(ProductWithMes record, ProductModel product)
+        {
+            //record.Id = product.ID;
+            record.ProductName = product.Name;
+            await _db.Insertable(record).ExecuteCommandAsync();
+        }
+
+        /// <summary>
+        /// 删除绑定信息
+        /// </summary>
+        /// <param name="record"></param>
+        /// <param name="product"></param>
+        /// <returns></returns>
+        public async Task<int> DeleteProWithMesAsync(ProductModel product)
+        {
+            var v = await _db.Deleteable<ProductWithMes>().Where(r => r.ProductName == product.Name).ExecuteCommandAsync();
+            return v;
+        }
+
+        /// <summary>
+        /// 更新绑定信息
+        /// </summary>
+        /// <param name="record"></param>
+        /// <param name="product"></param>
+        /// <returns></returns>
+        /// <exception cref="ArgumentNullException"></exception>
+        public async Task<int> UpdateProductWithMesAsync(ProductWithMes record, ProductModel product)
+        {
+            if (record == null) throw new ArgumentNullException(nameof(record));
+            var v = await _db.Updateable(record).Where(r => r.ProductName == product.Name).ExecuteCommandAsync();
+            return v;
+        }
+
+        /// <summary>
+        /// 查询绑定信息
+        /// </summary>
+        /// <param name="product"></param>
+        /// <returns></returns>
+        public async Task<ProductWithMes> QueryProductWithMesAsync(ProductModel product)
+        {
+            var total = await _db.Queryable<ProductWithMes>().Where(r => r.ProductName == product.Name).FirstAsync();
+            return total;
+        }
+
+        /// <summary>
+        /// 查询所有绑定信息
+        /// </summary>
+        /// <param name="product"></param>
+        /// <returns></returns>
+        public async Task<List<ProductWithMes>> QueryProductWithMesALLAsync()
+        {
+            var total = await _db.Queryable<ProductWithMes>().ToListAsync();
+            return total;
+        }
+
+        /// <summary>
+        /// 通过产品的编码和颜色查询产品的名称
+        /// </summary>
+        /// <param name="code"></param>
+        /// <returns></returns>
+        public async Task<string> QueryProductFromMesAsync(string code, string color)
+        {
+            var v = await _db.Queryable<ProductWithMes>().Where(r => r.ProductCode == code && r.ProductColor == color).FirstAsync();
+            if (v == null || v.ProductName == null)
+            {
+                return "";
+            }
+            return v.ProductName;
+        }
+        #endregion
     }
 }

+ 49 - 0
TeamAAS-VM/Interfaces/ISystemDatabaseService.cs

@@ -430,5 +430,54 @@ namespace TeamAAS_VP.Interfaces
         /// </summary>
         /// <returns></returns>
         Task ResetThrowNumberAsync();
+
+        #region 产品和mes的绑定,自动切换产品
+        /// <summary>
+        /// 添加绑定信息
+        /// </summary>
+        /// <param name="record"></param>
+        /// <param name="product"></param>
+        /// <returns></returns>
+        /// <exception cref="ArgumentNullException"></exception>
+        Task InsertProWithMesAsync(ProductWithMes record, ProductModel product);
+
+        /// <summary>
+        /// 删除绑定信息
+        /// </summary>
+        /// <param name="record"></param>
+        /// <param name="product"></param>
+        /// <returns></returns>
+        Task<int> DeleteProWithMesAsync(ProductModel product);
+
+        /// <summary>
+        /// 更新绑定信息
+        /// </summary>
+        /// <param name="record"></param>
+        /// <param name="product"></param>
+        /// <returns></returns>
+        /// <exception cref="ArgumentNullException"></exception>
+        Task<int> UpdateProductWithMesAsync(ProductWithMes record, ProductModel product);
+
+        /// <summary>
+        /// 查询绑定信息
+        /// </summary>
+        /// <param name="product"></param>
+        /// <returns></returns>
+        Task<ProductWithMes> QueryProductWithMesAsync(ProductModel product);
+
+        /// <summary>
+        /// 查询所有绑定信息
+        /// </summary>
+        /// <param name="product"></param>
+        /// <returns></returns>
+        Task<List<ProductWithMes>> QueryProductWithMesALLAsync();
+
+        /// <summary>
+        /// 通过产品的编码和颜色查询产品的id
+        /// </summary>
+        /// <param name="code"></param>
+        /// <returns></returns>
+        Task<string> QueryProductFromMesAsync(string code, string color);
+        #endregion
     }
 }

+ 3 - 1
TeamAAS-VM/Models/Product/ProductModel.cs

@@ -492,7 +492,9 @@ namespace TeamAAS_VP.Models
                 RemovePoints = this.RemovePoints,
                 PressurePlacePoints = this.PressurePlacePoints,
                 IsLoad = this.IsLoad,
-                IsCreate = this.IsCreate
+                IsCreate = this.IsCreate,
+                 ScrewCameraLocalPos1 = this.ScrewCameraLocalPos1,
+                ScrewCameraLocalPos2 = this.ScrewCameraLocalPos2
             };
         }
     }

+ 50 - 0
TeamAAS-VM/Models/ProductWithMes.cs

@@ -0,0 +1,50 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TeamAAS_VP.Models
+{
+    [SugarTable("ProductWithMes")]
+    public class ProductWithMes : BindableBase
+    {
+        //[SugarColumn(IsPrimaryKey = true)]
+        //public Guid Id { get; set; } = Guid.NewGuid();
+
+
+        private string _ProductName;
+        [SugarColumn(IsPrimaryKey = true)]
+        /// <summary>
+        /// 产品名称
+        /// </summary>
+        public string ProductName
+        {
+            get { return _ProductName; }
+            set { SetProperty(ref _ProductName, value); }
+        }
+
+
+        private string _ProductCode;
+        /// <summary>
+        /// 产品编码
+        /// </summary>
+        public string ProductCode
+        {
+            get { return _ProductCode; }
+            set { SetProperty(ref _ProductCode, value); }
+        }
+
+
+        private string _ProductColor = "";
+        /// <summary>
+        /// 产品颜色
+        /// </summary>
+        public string ProductColor
+        {
+            get { return _ProductColor; }
+            set { SetProperty(ref _ProductColor, value); }
+        }
+    }
+}

+ 1 - 0
TeamAAS-VM/TeamAAS-VP.csproj

@@ -546,6 +546,7 @@
     <Compile Include="Models\DeviceInfo.cs" />
     <Compile Include="Models\Feeder\ScrewFeederInfo.cs" />
     <Compile Include="Models\PhotoCaptureRecord.cs" />
+    <Compile Include="Models\ProductWithMes.cs" />
     <Compile Include="Models\ScanRs232ConfigModel.cs" />
     <Compile Include="Models\PressureModel.cs" />
     <Compile Include="Models\ScrewFeederBatchRecord.cs" />

+ 1 - 0
TeamAAS-VM/ViewModels/Product/ProductHomeViewModel.cs

@@ -242,6 +242,7 @@ namespace TeamAAS_VP.ViewModels.Product
                 {
                     _productService.DeleteProduct(((ProductModel)product).ID);
                     Products = new ObservableCollection<ProductModel>(_productService.GetAllProducts());
+                    _systemDatabaseService.DeleteProWithMesAsync(SelectProduct);
                     SelectProduct = null;
                 }
             }

+ 79 - 0
TeamAAS-VM/ViewModels/SettingViewModel.cs

@@ -386,6 +386,27 @@ namespace TeamAAS_VP.ViewModels
             set { SetProperty(ref _ScanConfig, value); }
         }
 
+        private ObservableCollection<ProductModel> _ProductList;
+        public ObservableCollection<ProductModel> ProductList
+        {
+            get { return _ProductList; }
+            set { SetProperty(ref _ProductList, value); }
+        }
+
+        private ProductWithMes _ProMesInfo = new ProductWithMes();
+        public ProductWithMes ProMesInfo
+        {
+            get { return _ProMesInfo; }
+            set { SetProperty(ref _ProMesInfo, value); }
+        }
+
+        private ProductModel _SelectProduct;
+
+        public ProductModel SelectProduct
+        {
+            get { return _SelectProduct; }
+            set { SetProperty(ref _SelectProduct, value); }
+        }
         #endregion
 
         #region 命令
@@ -1454,6 +1475,14 @@ namespace TeamAAS_VP.ViewModels
                 this.PropertyChanged += OnPropertyChanged;
                 isFirstLoad = false;
             }
+            try
+            {
+                ProductList = new ObservableCollection<ProductModel>(_productService.GetAllProducts());
+            }
+            catch (Exception ex)
+            {
+                LogHelper.WriteLogError("加载产品列表时出错", ex);
+            }
         }
 
         /// <summary>
@@ -1774,5 +1803,55 @@ namespace TeamAAS_VP.ViewModels
             }
         }
         #endregion
+
+        #region 产品与mes绑定
+
+        private async void ExecuteGetProWithMesCommand()
+        {
+            var v = await _systemDatabaseService.QueryProductWithMesAsync(SelectProduct);
+            if (v == null)
+            {
+                ProMesInfo.ProductCode = "";
+                ProMesInfo.ProductColor = "";
+            }
+            else
+            {
+                ProMesInfo.ProductCode = v.ProductCode;
+                ProMesInfo.ProductColor = v.ProductColor;
+            }
+        }
+
+        private async void ExecuteDeleteProWithMesCommand()
+        {
+            var v = await _systemDatabaseService.DeleteProWithMesAsync(SelectProduct);
+            if (v > 0)
+            {
+                _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "删除成功", Duration = 1 });
+                var F = await _systemDatabaseService.QueryProductWithMesAsync(SelectProduct);
+                if (F == null)
+                {
+                    ProMesInfo.ProductCode = "";
+                    ProMesInfo.ProductColor = "";
+                }
+            }
+        }
+        private async void ExecuteSaveProWithMesCommandAsync()
+        {
+            var v = await _systemDatabaseService.QueryProductWithMesAsync(SelectProduct);
+            if (v == null)
+            {
+                await _systemDatabaseService.InsertProWithMesAsync(ProMesInfo, SelectProduct);
+                _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "添加成功", Duration = 1 });
+            }
+            else
+            {
+                var n = await _systemDatabaseService.UpdateProductWithMesAsync(ProMesInfo, SelectProduct);
+                if (n > 0)
+                {
+                    _eventAggregator.GetEvent<SnackbarMessageNotification>().Publish(new MessageParameter() { Msg = "更新成功", Duration = 1 });
+                }
+            }
+        }
+        #endregion
     }
 }

+ 159 - 1
TeamAAS-VM/Views/SettingView.xaml

@@ -2177,7 +2177,6 @@
                 </Grid>
             </TabItem>
 
-
             <!--通讯-->
             <TabItem>
                 <TabItem.Header>
@@ -3002,6 +3001,165 @@
                 </ScrollViewer>
             </TabItem>
 
+            <!--产品信息-->
+            <TabItem>
+                <TabItem.Header>
+                    <StackPanel HorizontalAlignment="Stretch">
+                        <materialDesign:PackIcon Width="24"
+                                                 Height="24"
+                                                 HorizontalAlignment="Center"
+                                                 Kind="BallotOutline" />
+                        <TextBlock Style="{StaticResource TabHeaderTextBlockStyle}"
+                                   FontSize="{DynamicResource Font.Size.Body2}"
+                                   Text="产品信息"
+                                   HorizontalAlignment="Stretch" />
+                    </StackPanel>
+                </TabItem.Header>
+
+                <StackPanel Margin="16">
+
+                    <GroupBox HorizontalAlignment="Left"
+                              Margin="10,5"
+                              Header="产品与mes参数绑定设置"
+                              Width="400"
+                              FontSize="{DynamicResource Font.Size.Title4}">
+                        <Grid Margin="20">
+                            <Grid.ColumnDefinitions>
+                                <ColumnDefinition Width="auto" />
+                                <ColumnDefinition Width="auto" />
+                            </Grid.ColumnDefinitions>
+                            <Grid.RowDefinitions>
+                                <RowDefinition Height="auto" />
+                                <RowDefinition Height=" auto" />
+                                <RowDefinition Height=" auto" />
+                                <RowDefinition Height=" auto" />
+                            </Grid.RowDefinitions>
+
+                            <TextBlock Margin="0,0,0,8"
+                                       Text="产品名称:"
+                                       VerticalAlignment="Center"
+                                       FontSize="{DynamicResource Font.Size.Body3}"
+                                       HorizontalAlignment="Right" />
+                            <ComboBox x:Name="selectProduct"
+                                      Grid.Column="1"
+                                      Width="100"
+                                      Margin="10,4"
+                                      FontSize="14"
+                                      materialDesign:HintAssist.Hint="{lex:Loc 选择产品}"
+                                      SelectedItem="{Binding SelectProduct,Mode=TwoWay}"
+                                      ItemsSource="{Binding ProductList,Mode=TwoWay}"
+                                      HorizontalAlignment="Left">
+                                <ComboBox.ItemTemplate>
+                                    <DataTemplate>
+                                        <StackPanel Orientation="Vertical">
+                                            <StackPanel Orientation="Horizontal">
+                                                <materialDesign:PackIcon Kind="CubeOutline" />
+                                                <TextBlock Text="{Binding Name}" />
+                                            </StackPanel>
+                                            <TextBlock Text="{Binding Description}"
+                                                       MinHeight="0"
+                                                       MaxWidth="300"
+                                                       Foreground="Gray"
+                                                       TextTrimming="CharacterEllipsis"
+                                                       FontSize="{DynamicResource Font.Size.Captions4}"
+                                                       TextWrapping="Wrap" />
+                                        </StackPanel>
+                                    </DataTemplate>
+                                </ComboBox.ItemTemplate>
+                            </ComboBox>
+                            <TextBlock Margin="0,0,0,8"
+                                       Grid.Row="1"
+                                       Text="产品编码(model):"
+                                       VerticalAlignment="Center"
+                                       FontSize="{DynamicResource Font.Size.Body3}"
+                                       HorizontalAlignment="Right" />
+                            <TextBox Grid.Row="1"
+                                     Grid.Column="1"
+                                     Margin="10,4"
+                                     MinWidth="100"
+                                     FontSize="{DynamicResource Font.Size.Body3}"
+                                     TextAlignment="Center"
+                                     HorizontalAlignment="Left"
+                                     VerticalAlignment="Center">
+                                <TextBox.Text>
+                                    <Binding Path="ProMesInfo.ProductCode"
+                                             Mode="TwoWay">
+                                    </Binding>
+                                </TextBox.Text>
+                            </TextBox>
+
+                            <TextBlock Margin="0,0,0,8"
+                                       Grid.Row="2"
+                                       VerticalAlignment="Center"
+                                       Text="产品颜色:"
+                                       FontSize="{DynamicResource Font.Size.Body3}"
+                                       HorizontalAlignment="Right" />
+                            <TextBox Grid.Row="2"
+                                     Grid.Column="1"
+                                     Margin="10,4"
+                                     MinWidth="100"
+                                     FontSize="{DynamicResource Font.Size.Body3}"
+                                     TextAlignment="Center"
+                                     HorizontalAlignment="Left"
+                                     VerticalAlignment="Center">
+                                <TextBox.Text>
+                                    <Binding Path="ProMesInfo.ProductColor"
+                                             Mode="TwoWay">
+                                    </Binding>
+                                </TextBox.Text>
+                            </TextBox>
+
+                            <StackPanel Grid.Row="5"
+                                        Grid.ColumnSpan="2"
+                                        Margin="0,6"
+                                        Orientation="Horizontal"
+                                        HorizontalAlignment="Center">
+                                <Button Margin="5"
+                                        Style="{StaticResource MaterialDesignRaisedButton}"
+                                        materialDesign:ButtonAssist.CornerRadius="10"
+                                        MinWidth="100"
+                                        Command="{Binding GetProWithMesCommand}">
+                                    <StackPanel Orientation="Horizontal"
+                                                HorizontalAlignment="Center">
+                                        <materialDesign:PackIcon Kind="PuzzleEditOutline"
+                                                                 Margin="0,0,6,0" />
+                                        <TextBlock VerticalAlignment="Center"
+                                                   Text="获取" />
+                                    </StackPanel>
+                                </Button>
+                                <Button Margin="5"
+                                        Style="{StaticResource MaterialDesignRaisedButton}"
+                                        materialDesign:ButtonAssist.CornerRadius="10"
+                                        MinWidth="100"
+                                        Command="{Binding DeleteProWithMesCommand}">
+                                    <StackPanel Orientation="Horizontal"
+                                                HorizontalAlignment="Center">
+                                        <materialDesign:PackIcon Kind="DeleteForeverOutline"
+                                                                 Margin="0,0,6,0" />
+                                        <TextBlock VerticalAlignment="Center"
+                                                   Text="删除" />
+                                    </StackPanel>
+                                </Button>
+                                <Button Margin="5"
+                                        Style="{StaticResource MaterialDesignRaisedButton}"
+                                        materialDesign:ButtonAssist.CornerRadius="10"
+                                        MinWidth="100"
+                                        Command="{Binding SaveProWithMesCommand}">
+                                    <StackPanel Orientation="Horizontal"
+                                                HorizontalAlignment="Center">
+                                        <materialDesign:PackIcon Kind="ContentSaveCheck"
+                                                                 Margin="0,0,6,0" />
+                                        <TextBlock VerticalAlignment="Center"
+                                                   Text="保存" />
+                                    </StackPanel>
+                                </Button>
+                            </StackPanel>
+
+                        </Grid>
+                    </GroupBox>
+                </StackPanel>
+            </TabItem>
+            
             <!--生产排班-->
             <TabItem>
                 <TabItem.Header>