wanghan 6 месяцев назад
Родитель
Сommit
d17720f9c5

+ 102 - 18
TeamAAS-VM/Core/Management.cs

@@ -269,6 +269,13 @@ namespace TeamAAS_VP.Core
         }
 
         public FtpUploader ftpService { get; set; } = new FtpUploader();
+
+        private ObservableCollection<ProductModel> _ProductList;
+        public ObservableCollection<ProductModel> ProductList
+        {
+            get { return _ProductList; }
+            set { SetProperty(ref _ProductList, value); }
+        }
         #endregion
 
         #region 命令
@@ -1213,7 +1220,7 @@ namespace TeamAAS_VP.Core
             var systemconfig = _configService.GetSystemConfiguration();
             for (int i = 0; i < 10; i++)
             {
-                if (systemconfig.DoubleSoftMode && i==1)
+                if (systemconfig.DoubleSoftMode && i == 1)
                 {
                     continue;
                 }
@@ -1307,7 +1314,9 @@ namespace TeamAAS_VP.Core
         Int16 _LastPickINC = 0;
         DateTime[] _LastMesCheckTime = new DateTime[10];
         string[] ProductMainSN = new string[10];//产品主sn
-        string wo = "";
+        string[] model_num = new string[10];//产品model_num
+        string[] wo = new string[10];//产品wo
+        string[] color = new string[10];//产品color
         /// <summary>
         /// PLC命令触发时
         /// </summary>
@@ -1900,7 +1909,7 @@ namespace TeamAAS_VP.Core
                             await plc.WriteNodeAsync(addressConfig.In_WorkDone.Address, (Int16)0);
                             // 停止采集压力并保存
                             await StopAndSavePressureCollectionAsync(currentProduct.Name, _productService.CurrentProductCode, positionIndex);
-                                }
+                        }
                         else
                         {
                             SendTaskMessage(Lang.停止锁付信号已关闭, MessageLevel.Alarm);
@@ -2186,7 +2195,6 @@ namespace TeamAAS_VP.Core
                                 {
                                     if (_configService.GetDeviceInfo().EnableMES)
                                     {
-                                        //这里缺少从MES获取产品配方的内容,需要补充
                                         if (i == 0)
                                         {
                                             SendTaskMessage($"收到当前过站检查请求(当站是否生产)...", MessageLevel.Debug);
@@ -2227,23 +2235,62 @@ namespace TeamAAS_VP.Core
                                                     SendTaskMessage($"询问mes成功:{response2}", MessageLevel.Debug);
 
                                                     item = response2.Split('\n');
-                                                    if (item[3].Contains("sn="))
+
+                                                    if (item[1].Contains("color="))
+                                                    {
+                                                        color[i] = item[1].Replace("color=", "");
+                                                        SendTaskMessage($"产品color:{color[i]}", MessageLevel.Info);
+                                                    }
+                                                    if (item[3].Contains("model_num="))
                                                     {
-                                                        ProductMainSN[i] = item[3].Replace("sn=", "");
+                                                        model_num[i] = item[3].Replace("model_num=", "");
+                                                        SendTaskMessage($"产品model_num:{model_num[i]}", MessageLevel.Info);
+                                                    }
+                                                    if (item[4].Contains("sn="))
+                                                    {
+                                                        ProductMainSN[i] = item[4].Replace("sn=", "");
                                                         SendTaskMessage($"产品主sn:{ProductMainSN[i]}", MessageLevel.Info);
                                                     }
                                                     if (item[5].Contains("wo="))
                                                     {
-                                                        wo = item[5].Replace("wo=", "");
-                                                        SendTaskMessage($"产品主wo:{wo}", MessageLevel.Info);
+                                                        wo[i] = item[5].Replace("wo=", "");
+                                                        SendTaskMessage($"产品主wo:{wo[i]}", MessageLevel.Info);
                                                     }
 
                                                     LogHelper.WriteLogMes($"第二次询问mes成功");
                                                     SendTaskMessage($"第二次询问mes成功:{response2}", 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);
+
                                                 }
                                                 else
                                                 {
@@ -2275,15 +2322,53 @@ namespace TeamAAS_VP.Core
                                                 SendTaskMessage($"询问mes成功:{response}", MessageLevel.Debug);
 
                                                 var item = response.Split('\n');
-                                                if (item[3].Contains("sn="))
+
+                                                if (item[1].Contains("color="))
+                                                {
+                                                    color[i] = item[1].Replace("color=", "");
+                                                    SendTaskMessage($"产品color:{color[i]}", MessageLevel.Info);
+                                                }
+                                                if (item[3].Contains("model_num="))
+                                                {
+                                                    model_num[i] = item[3].Replace("model_num=", "");
+                                                    SendTaskMessage($"产品model_num:{model_num[i]}", MessageLevel.Info);
+                                                }
+                                                if (item[4].Contains("sn="))
                                                 {
-                                                    ProductMainSN[i] = item[3].Replace("sn=", "");
+                                                    ProductMainSN[i] = item[4].Replace("sn=", "");
                                                     SendTaskMessage($"产品主sn:{ProductMainSN[i]}", MessageLevel.Info);
                                                 }
                                                 if (item[5].Contains("wo="))
                                                 {
-                                                    wo = item[5].Replace("wo=", "");
-                                                    SendTaskMessage($"产品主wo:{wo}", MessageLevel.Info);
+                                                    wo[i] = item[5].Replace("wo=", "");
+                                                    SendTaskMessage($"产品主wo:{wo[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进行取料更改
@@ -2300,7 +2385,6 @@ namespace TeamAAS_VP.Core
                                                 await plc.WriteNodeAsync(string.Format(addressConfig.Out_MesStatus.Address, i), (Int16)2);
                                             }
                                         }
-
                                         LogHelper.WriteLogMes($"【mes结束QUERY】");
                                         SendTaskMessage($"mes结束QUERY", MessageLevel.Info);
                                     }
@@ -2410,7 +2494,7 @@ namespace TeamAAS_VP.Core
                                                             SUPPLIER_NAME = stationConfig.DataInfo.SUPPLIER_NAME,
                                                             COMMODITY_TYPE = stationConfig.DataInfo.COMMODITY_TYPE,
                                                             REVISION = stationConfig.DataInfo.REVISION,
-                                                            WO = wo,
+                                                            WO = wo[i],
                                                             MFG_LOT = stationConfig.DataInfo.MFG_LOT,
                                                             MFG_ASSY_LINE = stationConfig.DataInfo.MFG_ASSY_LINE,
                                                             PROCESS_OUTCOME = torqueRes ? "PASS" : "FAIL",
@@ -2431,7 +2515,7 @@ namespace TeamAAS_VP.Core
                                                             SUPPLIER_NAME = stationConfig.DataInfo.SUPPLIER_NAME,
                                                             COMMODITY_TYPE = stationConfig.DataInfo.COMMODITY_TYPE,
                                                             REVISION = stationConfig.DataInfo.REVISION,
-                                                            WO = wo,
+                                                            WO = wo[i],
                                                             MFG_LOT = stationConfig.DataInfo.MFG_LOT,
                                                             MFG_ASSY_LINE = stationConfig.DataInfo.MFG_ASSY_LINE,
                                                             PROCESS_OUTCOME = turnRes ? "PASS" : "FAIL",
@@ -2452,7 +2536,7 @@ namespace TeamAAS_VP.Core
                                                             SUPPLIER_NAME = stationConfig.DataInfo.SUPPLIER_NAME,
                                                             COMMODITY_TYPE = stationConfig.DataInfo.COMMODITY_TYPE,
                                                             REVISION = stationConfig.DataInfo.REVISION,
-                                                            WO = wo,
+                                                            WO = wo[i],
                                                             MFG_LOT = stationConfig.DataInfo.MFG_LOT,
                                                             MFG_ASSY_LINE = stationConfig.DataInfo.MFG_ASSY_LINE,
                                                             PROCESS_OUTCOME = pressureRes ? "PASS" : "FAIL",
@@ -2468,7 +2552,7 @@ namespace TeamAAS_VP.Core
                                                     SendTaskMessage($"{i}:{stationConfig.DeviceName}产品记录保存成功", MessageLevel.Debug);
 
                                                     ftpService.UploadToFtp(stationConfig.SaveCsvPath);
-                                                    if (i==0)
+                                                    if (i == 0)
                                                     {
                                                         string name = $"{ProductMainSN[i]}_{DateTime.Now.ToString("yyyyMMddHHmmss")}";
                                                         string zippath = ftpService.CompressionImage(name);
@@ -2512,7 +2596,7 @@ namespace TeamAAS_VP.Core
                                         await plc.WriteNodeAsync(addressConfig.Out_ScrewFeederIsChanged.Address, (Int16)1); //不发生改变
                                         await plc.WriteNodeAsync(string.Format(addressConfig.Out_MesStatus.Address, i), (Int16)3);
                                     }
-                                }                     
+                                }
                                 else
                                 {
                                     SendTaskMessage($"{i}过站检查信号:state={state},处理为默认状态", MessageLevel.Alarm);

+ 2 - 1
TeamAAS-VM/Data/DatabaseInitializer.cs

@@ -27,7 +27,8 @@ namespace TeamAAS_VP.Data
                 // 创建数据库(如果不存在)
                 _db.DbMaintenance.CreateDatabase();
                 // 创建表
-                _db.CodeFirst.InitTables(typeof(User), typeof(ProductionRecord), typeof(UserLoginRecord), typeof(AlarmRecord), typeof(LockResult), typeof(ScrewFeederBatchRecord), typeof(PhotoCaptureRecord), typeof(HeadChangeRecord),typeof(NozzleChangeRecord), typeof(ThrowRecord));
+                _db.CodeFirst.InitTables(typeof(User), typeof(ProductionRecord), typeof(UserLoginRecord), typeof(AlarmRecord), typeof(LockResult), 
+                    typeof(ScrewFeederBatchRecord), typeof(PhotoCaptureRecord), typeof(HeadChangeRecord),typeof(NozzleChangeRecord), typeof(ThrowRecord), typeof(ProductWithMes));
 
                 // 创建索引
                 CreateIndexes();

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

@@ -1,3 +1,4 @@
+using NPOI.SS.Formula.Functions;
 using NPOI.Util;
 using SqlSugar;
 using System;
@@ -6,6 +7,7 @@ using System.Linq;
 using System.Threading.Tasks;
 using TeamAAS_VP.Interfaces;
 using TeamAAS_VP.Models;
+using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
 
 namespace TeamAAS_VP.Data
 {
@@ -1178,5 +1180,84 @@ 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.ProductName==null)
+            {
+                v.ProductName = "";
+            }
+            return v.ProductName;
+        }
+        #endregion
     }
 }

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

@@ -511,5 +511,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
     }
 }

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

@@ -0,0 +1,52 @@
+using Prism.Mvvm;
+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 - 1
TeamAAS-VM/Services/CalibrationService.cs

@@ -344,7 +344,7 @@ namespace TeamAAS_VP.Services
             Matrix<double> matrix = Matrix<double>.Build.DenseOfArray(calib.AffineTransformationMaterial);
 
             // 某些安装方式需要取反角度以匹配机器人坐标系定义
-            if (calib.CameraMount == CameraMount.FixedDown || calib.CameraMount == CameraMount.MobileJ2 || calib.CameraMount == CameraMount.MobileJ4)
+            if (calib.CameraMount == CameraMount.FixedDown || calib.CameraMount == CameraMount.MobileJ2 || calib.CameraMount == CameraMount.MobileJ4|| calib.CameraMount == CameraMount.MobileDown_XYPlatform)
             {
                 angle *= -1;
             }

+ 6 - 16
TeamAAS-VM/Services/MesService.cs

@@ -105,11 +105,11 @@ namespace TeamAAS_VP.Services
             string url = "";
             if (device.F == "PTL")
             {
-                url = $"{device.MesUrl}?c=QUERY_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&comp={device.comp}:{comp}&p=unit_process_check,message,model,sn,wo";
+                url = $"{device.MesUrl}?c=QUERY_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&comp={device.comp}:{comp}&p=message,sn,wo,model_num,color";
             }
             else
             {
-                url = $"{device.MesUrl}?c=QUERY_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&p=unit_process_check,message,model,sn,wo";
+                url = $"{device.MesUrl}?c=QUERY_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&p=message,sn,wo,model_num,color";
             }
 
             LogHelper.WriteLogMes($"【询问URL】{url}");
@@ -199,14 +199,10 @@ namespace TeamAAS_VP.Services
             var device = _configService.GetDeviceInfo();
             if (device == null || !device.EnableMES)
             {
-                LogHelper.WriteLogMes($"MES功能未启用!");
-                SendTaskMessage($"MES功能未启用!", MessageLevel.Info);
-                return (false, "MES功能未启用!");
+                return (true, "MES功能未启用!");
             }
             if (string.IsNullOrWhiteSpace(device.MesUrl))
             {
-                LogHelper.WriteLogMes($"Missing MES station URL");
-                SendTaskMessage($"Missing MES station URL", MessageLevel.Info);
                 return (false, "Missing MES station URL");
             }
 
@@ -277,22 +273,16 @@ namespace TeamAAS_VP.Services
             var device = _configService.GetDeviceInfo();
             if (device == null || !device.EnableMES)
             {
-                LogHelper.WriteLogMes($"MES功能未启用!");
-                SendTaskMessage($"MES功能未启用!", MessageLevel.Info);
-                return (false, "MES功能未启用!");
+                return (true, "MES功能未启用!");
             }
             if (string.IsNullOrWhiteSpace(device.MesUrl))
             {
-                LogHelper.WriteLogMes($"Missing MES station URL");
-                SendTaskMessage($"Missing MES station URL", MessageLevel.Info);
                 return (false, "Missing MES station URL");
             }
             if (device.F == "PTL")
             {
                 if (string.IsNullOrEmpty(device.comp))
                 {
-                    LogHelper.WriteLogMes($"PTL模式下comp不能为空");
-                    SendTaskMessage($"PTL模式下comp不能为空", MessageLevel.Info);
                     return (false, "PTL模式下comp不能为空");
                 }
             }
@@ -300,11 +290,11 @@ namespace TeamAAS_VP.Services
             string url = "";
             if (device.F == "PTL")
             {
-                url = $"{device.MesUrl}?c=QUERY_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&comp={device.comp}:{comp}&p=unit_process_check,message,model,sn,wo";
+                url = $"{device.MesUrl}?c=QUERY_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&comp={device.comp}:{comp}&p=message,sn,wo,model_num,color";
             }
             else
             {
-                url = $"{device.MesUrl}?c=QUERY_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&p=unit_process_check,message,model,sn,wo";
+                url = $"{device.MesUrl}?c=QUERY_RECORD&line={device.Line}&station={device.Station}&fixtureid={device.FixtureId}&sn={sn}&p=message,sn,wo,model_num,color";
             }
 
             LogHelper.WriteLogMes($"【询问URL】{url}");

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

@@ -548,6 +548,7 @@
     <Compile Include="Models\ImageParameters.cs" />
     <Compile Include="Models\NozzleChangeRecord.cs" />
     <Compile Include="Models\NumberStatistics.cs" />
+    <Compile Include="Models\ProductWithMes.cs" />
     <Compile Include="Models\ThrowRecord.cs" />
     <Compile Include="Models\Torque\PickDynamicTestResult.cs" />
     <Compile Include="Models\Torque\PickScrewAccuracyAnalyzerrConfigModel.cs" />

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

@@ -241,6 +241,7 @@ namespace TeamAAS_VP.ViewModels.Product
                 {
                     _productService.DeleteProduct(((ProductModel)product).ID);
                     Products = new ObservableCollection<ProductModel>(_productService.GetAllProducts());
+                    _systemDatabaseService.DeleteProWithMesAsync(SelectProduct);
                     SelectProduct = null;
                 }
             }
@@ -260,6 +261,9 @@ namespace TeamAAS_VP.ViewModels.Product
             if (!(product is ProductModel))
                 return;
             NavigationParameters parameters = new NavigationParameters();
+            Products = new ObservableCollection<ProductModel>(_productService.GetAllProducts());
+            SelectProduct = Products.FirstOrDefault(p => p.ID == ((ProductModel)product).ID);
+            if (SelectProduct == null) return;
             parameters.Add("SelectProduct", SelectProduct);
             _regionManager.RequestNavigate("ProductRegionContext", "ProductDescription", parameters);
         }

+ 110 - 2
TeamAAS-VM/ViewModels/SettingViewModel.cs

@@ -9,6 +9,7 @@ using Prism.Ioc;
 using Prism.Mvvm;
 using Prism.Regions;
 using Prism.Services.Dialogs;
+using SqlSugar;
 using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
@@ -18,7 +19,9 @@ using System.Globalization;
 using System.Linq;
 using System.Reflection.Metadata;
 using System.Text;
+using System.Web;
 using System.Windows;
+using System.Windows.Controls;
 using Team.FFFeederService.Interfaces;
 using TeamAAS_VP.Controls;
 using TeamAAS_VP.Core;
@@ -349,8 +352,8 @@ namespace TeamAAS_VP.ViewModels
         public DeviceInfo DeviceInfo
         {
             get { return _SelectDeviceInfo ?? DeviceInfoList?.FirstOrDefault(); }
-            set 
-            { 
+            set
+            {
                 if (value != null && DeviceInfoList != null)
                 {
                     var existing = DeviceInfoList.FirstOrDefault(d => d.DeviceNo == value.DeviceNo);
@@ -395,6 +398,27 @@ namespace TeamAAS_VP.ViewModels
             set { SetProperty(ref _WorkShift, 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 命令
@@ -515,6 +539,18 @@ namespace TeamAAS_VP.ViewModels
         public DelegateCommand SelectSaveImagePathCommand =>
             _SelectSaveImagePathCommand ?? (_SelectSaveImagePathCommand = new DelegateCommand(ExecuteSelectSaveImagePathCommand));
 
+        private DelegateCommand _GetProWithMesCommand;
+        public DelegateCommand GetProWithMesCommand =>
+            _GetProWithMesCommand ?? (_GetProWithMesCommand = new DelegateCommand(ExecuteGetProWithMesCommand));
+
+        private DelegateCommand _DeleteProWithMesCommand;
+        public DelegateCommand DeleteProWithMesCommand =>
+            _DeleteProWithMesCommand ?? (_DeleteProWithMesCommand = new DelegateCommand(ExecuteDeleteProWithMesCommand));
+
+        private DelegateCommand _SaveProWithMesCommand;
+        public DelegateCommand SaveProWithMesCommand =>
+            _SaveProWithMesCommand ?? (_SaveProWithMesCommand = new DelegateCommand(ExecuteSaveProWithMesCommandAsync));
+
         #endregion
 
         #region 事件
@@ -1489,6 +1525,14 @@ namespace TeamAAS_VP.ViewModels
                 this.PropertyChanged += OnPropertyChanged;
                 isFirstLoad = false;
             }
+            try
+            {
+                ProductList = new ObservableCollection<ProductModel>(_productService.GetAllProducts());
+            }
+            catch (Exception ex)
+            {
+                LogHelper.WriteLogError("加载产品列表时出错", ex);
+            }
         }
 
         /// <summary>
@@ -1870,5 +1914,69 @@ namespace TeamAAS_VP.ViewModels
             }
         }
         #endregion
+
+        #region 产品与mes绑定
+
+        private async void ExecuteGetProWithMesCommand()
+        {
+            var v = await _systemDatabaseService.QueryProductWithMesAsync(SelectProduct);
+            if (v == null)
+            {
+                ProMesInfo.ProductCode = "";
+                ProMesInfo.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
+
+
+        private DelegateCommand _testCommand;
+        public DelegateCommand testCommand =>
+            _testCommand ?? (_testCommand = new DelegateCommand(Execute_testCommand));
+        public FtpUploader ftpService { get; set; } = new FtpUploader();
+
+        private void Execute_testCommand()
+        {
+            var stationConfig = _configService.GetDeviceInfo(0);
+
+            ftpService.UploadToFtp(stationConfig.SaveCsvPath);
+
+            string name = $"CN0D0NDYCKJ006260336X02_{DateTime.Now.ToString("yyyyMMddHHmmss")}";
+            string zippath = ftpService.CompressionImage(name);
+            ftpService.UploadToFtp(zippath);
+
+
+        }
     }
 }

+ 167 - 0
TeamAAS-VM/Views/SettingView.xaml

@@ -2866,6 +2866,165 @@
                 </StackPanel>
             </TabItem>
 
+            <!--产品信息-->
+            <TabItem>
+                <TabItem.Header>
+                    <StackPanel HorizontalAlignment="Stretch">
+                        <materialDesign:PackIcon Width="24"
+                                     Height="24"
+                                     HorizontalAlignment="Center"
+                                     Kind="LanConnect" />
+                        <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>
@@ -3008,6 +3167,14 @@
                                           Width="60" />
                         </Grid>
                     </GroupBox>
+                    <!--<Button Style="{StaticResource MaterialDesignRaisedButton}"
+                            materialDesign:ButtonAssist.CornerRadius="10"
+                            Width="60"
+                            Margin="10"
+                            Content="test"
+                            HorizontalAlignment="Left"
+                            Command="{Binding testCommand}">
+                    </Button>-->
                 </StackPanel>
             </TabItem>