kingno
2025-04-03 a97ac998301461e6284595b1cf2c7b40ce5b2459
优化数据库字段的json传输
新增打印机
1个文件已添加
12个文件已修改
208 ■■■■ 已修改文件
libs.zip 补丁 | 查看 | 原始文档 | blame | 历史
libs/PFW/Bro.Common.Model.dll 补丁 | 查看 | 原始文档 | blame | 历史
libs/PFW/Bro.UI.Model.Winform.dll 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M135.Common/FrmProductList.cs 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M135.Common/MESHelper.cs 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M135.Common/ProductModel.cs 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M135.DBManager/Models/P_PRODUCT_DETAIL.cs 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M141.Process/Bro.M141.Process.csproj 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M141.Process/M141Process.cs 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M141.Process/M141Process_ImageCheck.cs 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M141.Process/M141Process_Mysql.cs 109 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M141.Process/UI/UIPrinter.cs 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/Bro.M141_AOI1.Process/AOI1Process.cs 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
libs.zip
Binary files differ
libs/PFW/Bro.Common.Model.dll
Binary files differ
libs/PFW/Bro.UI.Model.Winform.dll
Binary files differ
src/Bro.M135.Common/FrmProductList.cs
@@ -1,4 +1,5 @@
using Bro.Common.Helper;
using Bro.Common.Interface;
using Bro.Common.Model;
using Bro.UI.Model.Winform;
using Sunny.UI;
@@ -117,7 +118,7 @@
            {
                this.Invoke(() =>
                {
                    var specList = p.Details.SelectMany(u => u.SpecList ?? new List<Spec>()).ToList();
                    var specList = p.Details.SelectMany(u => u.SpecList ?? new List<ISpec>()).ToList();
                    specList.AddRange(p.Details.SelectMany(u => u.ResultList.SelectMany(s => s.Specs.Select(m => (Spec)m))));
                    specList.Sort((a, b) => string.Compare(a.Code, b.Code));
src/Bro.M135.Common/MESHelper.cs
@@ -1,4 +1,5 @@
using Bro.Common.Helper;
using Bro.Common.Interface;
using Bro.Common.Model;
using Newtonsoft.Json;
using System.ComponentModel;
@@ -50,7 +51,7 @@
            data.result = isOK ? MES_OK : MES_NG;
            var specList = p.Details.SelectMany(u => u.ResultList.SelectMany(u => u.Specs)).ToList();
            specList.AddRange(p.Details.SelectMany(u => u.SpecList ?? new List<Spec>()));
            specList.AddRange(p.Details.SelectMany(u => u.SpecList ?? new List<ISpec>()));
            specList.ForEach(s =>
            {
src/Bro.M135.Common/ProductModel.cs
@@ -1,4 +1,5 @@
using Bro.Common.Helper;
using Bro.Common.Interface;
using Bro.Common.Model;
using Bro.M135.DBManager;
using Newtonsoft.Json;
@@ -53,11 +54,11 @@
            {
                if (!string.IsNullOrWhiteSpace(d.FAIData))
                {
                    d.SpecList = JsonConvert.DeserializeObject<List<Spec>>(d.FAIData);
                    d.SpecList = JsonConvert.DeserializeObject<List<ISpec>>(d.FAIData);
                }
                else
                {
                    d.SpecList = new List<Spec>();
                    d.SpecList = new List<ISpec>();
                }
                if (!string.IsNullOrWhiteSpace(d.DefectDesc))
src/Bro.M135.DBManager/Models/P_PRODUCT_DETAIL.cs
@@ -1,4 +1,5 @@
using Bro.Common.Model;
using Bro.Common.Interface;
using Bro.Common.Model;
using Bro.DataBase.Model;
using System.ComponentModel.DataAnnotations.Schema;
@@ -13,11 +14,11 @@
        public string FAIData { get; set; } = "";
        public bool IsDone { get; set; } = false;
        [NotMapped]
        //[NotMapped]
        public List<DetectResult> ResultList { get; set; } = new List<DetectResult>();
        [NotMapped]
        public List<Spec> SpecList { get; set; } = new List<Spec>();
        [NotMapped]
        //[NotMapped]
        public List<ISpec> SpecList { get; set; } = new List<ISpec>();
        //[NotMapped]
        public List<string> DefectList { get; set; } = new List<string>();
    }
}
src/Bro.M141.Process/Bro.M141.Process.csproj
@@ -52,6 +52,7 @@
  </ItemGroup>-->
    <ItemGroup>
        <PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.6" />
        <PackageReference Include="NPOI" Version="2.7.1" />
        <PackageReference Include="ScottPlot.WinForms" Version="4.1.58" />
        <PackageReference Include="System.ServiceModel.Duplex" Version="4.8.1" />
src/Bro.M141.Process/M141Process.cs
@@ -72,11 +72,11 @@
        }
        public PLCBase Plc1;
        PLCBase Plc2;
        Thread ThHeartPlc;
        public override void Open()
        {
            base.Open();
            ML = DeviceCollection.FirstOrDefault(u => u is MachineLearningBase) as MachineLearningBase;
            if (ML == null)
            {
@@ -145,7 +145,6 @@
                Thread.Sleep(3000);
            }
        }
        /// <summary>
        /// 网络预热
@@ -271,6 +270,10 @@
                else
                {
                    p.BasketCode = mysqlhelper.Getbasketcode(p.SEQUENCE);
                    if ("NoRead".Equals(p.BasketCode))
                    {
                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"{p.PID}_{p.SEQUENCE}获取框具码失败 赋值Noread");
                    }
                }
                mysqlhelper.NewProduct(p);
@@ -370,22 +373,16 @@
                                    var errorSpec = _errorSpec.Copy();
                                    errorSpec.Code = "检测TBD";
                                    errorSpec.ActualValue = -999;
                                    DetectResult ngResult = new DetectResult() { Specs = new List<ISpec>() { errorSpec }, PID = u.Key };
                                    DetectResult ngResult = new DetectResult() { Specs = new List<ISpec>() { errorSpec }, PID = u.Key ,Id=Guid.NewGuid().ToString()};
                                    ngResults.Add(ngResult);
                                }
                            }
                        });
                        detectResults.AddRange(ngResults);
                        resultList.AddRange(detectResults);
                    }
                    RunCustomizedMethod(products, triggerText, triggerSource, imgSet, measureBind.CustomizedMonitorId, resultList);
                    RunCustomizedMethod(products, triggerText, triggerSource, imgSet, measureBind.CustomizedCombineMethodId, resultList);
                }
                catch (Exception ex)
                {
@@ -952,7 +949,7 @@
                        CSVRecordAsync($"{positionName}_Record_{DateTime.Now.ToString("yyyyMMdd")}.csv", data, head);
                        //UpdatePositionResultToDB(detail);
                        var seqData = p.SEQUENCE.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                        //var seqData = p.SEQUENCE.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                        mysqlhelper.UpdateProduct(p);
                        if (positionSet.IsLastPosition)
src/Bro.M141.Process/M141Process_ImageCheck.cs
@@ -3,10 +3,12 @@
using Bro.Common.Interface;
using Bro.Common.Model;
using Bro.M135.Common;
using Bro.M135.DBManager;
using HalconDotNet;
using Microsoft.VisualBasic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NPOI.Util;
using Sunny.UI;
using System.Data;
using System.Data.SqlTypes;
@@ -28,6 +30,9 @@
        Dictionary<string, List<double>> dicdate = new Dictionary<string, List<double>>();
        ManualResetEvent set1 = new ManualResetEvent(false);
        ManualResetEvent set2 = new ManualResetEvent(false);
        public event Action<string> StartPrinter;
        [ProcessMethod("ImageCheck", "ImageCheckOperation", "通用图片检测操作", InvokeType.TestInvoke)]
        public ResponseMessage ImageCheckOperation(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
@@ -499,6 +504,27 @@
        [ProcessMethod("printer", "printer", "打印机打印", InvokeType.TestInvoke)]
        public ResponseMessage Printer(IOperationConfig config, IDevice invokeDevice, IDevice sourceDevice)
        {
            ResponseMessage msg = new ResponseMessage();
            Plc2 = invokeDevice as PLCBase;
            string message = "";
            StartPrinter.Invoke(message);
            return msg;
        }
        public void PlcwritePrinter(int add,int value)
        {
            Plc2.WriteSingleAddress(add,value,out _);
        }
        protected List<ISpec> GetSpecListFromConfigSelection(List<SpecSelector> specSelectors)
        {
@@ -508,9 +534,10 @@
                var spec = M141Config.SpecCollection.FirstOrDefault(s => s.Code == u.SpecCode);
                if (spec != null)
                {
                    var temp = spec.Copy<Spec>();
                    var temp = spec.Copy();
                    temp.ActualValue = null;
                    temp.MeasureResult = null;
                    temp.Source = "";
                    specList.Add(temp);
                }
            });
@@ -585,7 +612,7 @@
            resultList.ForEach(u => u.SetResult());
            var defects = resultList.GetDefectDescList();
            var ngSpecCodes = p.Details.SelectMany(u => u.SpecList ?? new List<Spec>()).Where(u => u.MeasureResult != true).Select(u => u.Code);
            var ngSpecCodes = p.Details.SelectMany(u => u.SpecList ?? new List<ISpec>()).Where(u => u.MeasureResult != true).Select(u => u.Code);
            var ngDefectDescList = p.Details.SelectMany(u => u.DefectList ?? new List<string>()).ToList();
            defects.AddRange(ngSpecCodes);
src/Bro.M141.Process/M141Process_Mysql.cs
@@ -1,5 +1,6 @@
using Bro.Common.Helper;
using Bro.Common.Interface;
using Bro.Common.Model;
using Bro.M135.Common;
using MySql.Data.MySqlClient;
using Newtonsoft.Json;
@@ -11,6 +12,7 @@
using System.Text;
using System.Threading.Tasks;
using Windows.Globalization.PhoneNumberFormatting;
using static Org.BouncyCastle.Math.EC.ECCurve;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
namespace Bro.M141.Process
@@ -29,7 +31,7 @@
            connStrAll = $"server={IP};port=3306;user id=root;password=123456;database=BroDB;charset=utf8";
        }
        public void Operatoremysql(string sql, string connStr)//操作
        public bool Operatoremysql(string sql, string connStr)//操作
        {
            MySqlConnection con = new MySqlConnection(connStr);
            try
@@ -41,12 +43,16 @@
                con.Open();
                MySqlCommand coon = new MySqlCommand(sql, con);
                coon.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception e)
            {
                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"数据库操作异常 {sql} {e.ToString()}");
            }
            con.Close();
                return false;
                //CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"数据库操作异常 {sql} {e.ToString()}");
            }
            return true;
        }
        public DataTable selectdt(string str, string connStr)//查询表格
@@ -62,12 +68,14 @@
                con.Open();
                MySqlDataAdapter da = new MySqlDataAdapter(str, con);
                da.Fill(dt);
                con.Close();
            }
            catch (Exception e)
            {
                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"数据库查询异常 {str} {e.ToString()}");
            }
                //CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"数据库查询异常 {str} {e.ToString()}");
            con.Close();
                return null;
            }
            return dt;
        }
@@ -89,9 +97,8 @@
            }
            catch (Exception e)
            {
                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"数据库查询数据异常 {str}  {e.ToString()}");
                //CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"数据库查询数据异常 {str}  {e.ToString()}");
            }
            con.Close();
            return strr;
        }
@@ -111,13 +118,22 @@
                string str1 = "select id from forlocal  order by id desc limit 1";
                string index = selectmysql(str1, connStrLocal);
                if (!string.IsNullOrEmpty(index))
                {
                string str2 = $"delete from forlocal where id < ({index}-1000)";
                Operatoremysql(str2, connStrLocal);
                }
                string mysqlstr = $"insert into forlocal (basketcode,pid,plcnum,sn,data,time) values('{pro.BasketCode}','{pro.PID}','{pro.SEQUENCE}','{pro.SN}','{JsonConvert.SerializeObject(pro, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All })}','{DateTime.Now.ToString("yyyyMMddHHmmss")}')";
                string mysqlstr = $"insert into forlocal (basketcode,pid,plcnum,sn,data,time) values('{pro.BasketCode}','{pro.PID}','{pro.SEQUENCE}','{pro.SN}','{JsonConvert.SerializeObject(pro)}','{DateTime.Now.ToString("yyyyMMddHHmmss")}')";
                Operatoremysql(mysqlstr, connStrLocal);
                if (Operatoremysql(mysqlstr, connStrLocal))
                {
                    CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"数据库forlocal插入数据成功");
                }
                else
                {
                    CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"数据库forlocal插入数据异失败  {mysqlstr}");
                }
            }
            catch (Exception e)
            {
@@ -129,8 +145,54 @@
        {
            try
            {
                string mysqlstr = $"update forlocal set data='{JsonConvert.SerializeObject(pro)}' where plcnum='{pro.SEQUENCE}'";
                Operatoremysql(mysqlstr, connStrLocal);
                if (pro.Details!=null)
                {
                    foreach (var item in pro.Details)
                    {
                        if (item.ResultList!=null)
                        {
                            item.ResultList.ForEach(u =>
                            {
                                if (u.NetResults != null)
                                {
                                    u.NetResults.ForEach(x =>
                                    {
                                        if (x.DetectDetails != null)
                                        {
                                            var distinctItems = x.DetectDetails.GroupBy(i => new { i.ClassName, i.FinalResult }) // 根据Id和Name去重
                             .Select(g => g.First()) // 选择每个组的第一个元素
                             .ToList();
                                            x.DetectDetails = distinctItems;
                                        }
                                    });
                                }
                            });
                        }
                    }
                }
                JsonSerializerSettings settings = new JsonSerializerSettings
                {
                    TypeNameHandling = TypeNameHandling.All
                };
                string jsondata = JsonConvert.SerializeObject(pro, settings);
                //CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"{jsondata}");
                string mysqlstr = $"update forlocal set data='{jsondata}' where plcnum='{pro.SEQUENCE}'";
                if (Operatoremysql(mysqlstr, connStrLocal))
                {
                    CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"数据库forlocal更新数据成功");
                }
                else
                {
                    CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"数据库forlocal更新数据失败 {mysqlstr}");
                }
            }
            catch (Exception e)
            {
@@ -151,14 +213,24 @@
                    string str1 = "select id from forall  order by id desc limit 1";
                    string index = selectmysql(str1, connStrAll);
                    if (!string.IsNullOrEmpty(index))
                    {
                    string str2 = $"delete from forall where id < ({index}-1000)";
                    Operatoremysql(str2, connStrAll);
                    }
                    string mysqlstr = $"insert into forall (basketcode,device,plcnum,sn,data,time) values('{pro.BasketCode}','{devicestr}','{pro.SEQUENCE}','{pro.SN}','{JsonConvert.SerializeObject(pro)}','{DateTime.Now.ToString("yyyyMMddHHmmss")}')";
                    string mysqlstr = $"insert into forall (basketcode,device,plcnum,sn,data,time) values('{pro.BasketCode}','{devicestr}','{pro.SEQUENCE}','{pro.SN}','{JsonConvert.SerializeObject(pro, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All })}','{DateTime.Now.ToString("yyyyMMddHHmmss")}')";
                    Operatoremysql(mysqlstr, connStrAll);
                    if (Operatoremysql(mysqlstr, connStrAll))
                    {
                        CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"数据库forall插入数据成功");
                    }
                    else
                    {
                        CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Error, $"数据库forall插入数据异失败  {mysqlstr}");
                    }
                }
                catch (Exception e)
                {
@@ -179,13 +251,14 @@
                }
                else
                {
                    ProductModel p = JsonConvert.DeserializeObject<ProductModel>(str, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All });
                    ProductModel p = null;
                    p = JsonConvert.DeserializeObject<ProductModel>(str, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All });
                    return p;
                }
            }
            catch (Exception e)
            {
                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"数据库forlocal更新数据异常 {e.ToString()}");
                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"数据库forlocal获取对象异常 {e.ToString()}");
            }
            return null;
        }
@@ -203,7 +276,7 @@
            }
            catch (Exception e)
            {
                CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"数据库forlocal更新数据异常 {e.ToString()}");
                //CommonLogger.LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"数据库forlocal获取异常 {e.ToString()}");
            }
            return "NoRead";
        }
src/Bro.M141.Process/UI/UIPrinter.cs
@@ -38,7 +38,12 @@
        {
            base.OnProcessUpdated();
            printDocument1.PrintPage += new PrintPageEventHandler(printDocument_Print);
            Process141.StartPrinter += StartPrint;
            textBox1.Text = "Broconcentric";
        }
        PrintDocument printDocument1 = new PrintDocument();
        int ttwith = (int)(80 * 4);
@@ -47,9 +52,16 @@
        public void StartPrint(string str)
        {
            try
            {
            ttwith = 320;
            ttheigh = 160;
            message = str;
                if (string.IsNullOrEmpty(message))
                {
                    message = textBox1.Text;
                }
            this.printDocument1.DefaultPageSettings.PrinterSettings.PrinterName = "Honeywell PX240S (300 dpi)";
            this.printDocument1.DefaultPageSettings.PaperSize = new PaperSize("Custum", ttwith, ttheigh);
@@ -58,6 +70,21 @@
            this.printDocument1.Print();
        }
            catch
            {
            }
            int statuscode = GetPrinterStatusCodeInt();
            string status = GetPrinterStatusMessage(statuscode);
            //   Config141
            Process141.PlcwritePrinter(1520, 0);
            Process141.PlcwritePrinter(1510, 1);
        }
        private void printDocument_Print(object sender, PrintPageEventArgs e)
src/Bro.M141_AOI1.Process/AOI1Process.cs
@@ -34,7 +34,6 @@
        public override void Open()
        {
            base.Open();
        }
        [ProcessMethod("", "PositionCheck_P1", "工位1检测", InvokeType.TestInvoke)]