using MaiMuAOI.SysCtrl; using MaiMuAOI.SysUI.ProcessStep; using MaiMuControl.Utils; using Models; using Newtonsoft.Json; using OpenCvSharp; using OpenCvSharp.Flann; using ProductionControl.UI; using ProductionControl.UIExtend; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Runtime.Remoting.Metadata.W3cXsd2001; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using ToolKits.EnumTool; using ToolKits.mAPI; namespace MaiMuAOI.SysUI.ProductAndStep { public partial class ProductInfoFrm : Form { Service.ClassesService svcClasses = new Service.ClassesService(); Service.ProductService service = new Service.ProductService(); Models.Product model = new Models.Product(); public ProductInfoFrm(Models.Product m = null) { InitializeComponent(); UIStyle.SetUIStyle(this); this.uiTitel1.FatherForm = this; this.dgvBatchList.AutoGenerateColumns = false; dataGridView1.DefaultCellStyle.ForeColor = Color.Black; dataGridView2.DefaultCellStyle.ForeColor = Color.Black; dataGridView3.DefaultCellStyle.ForeColor = Color.Black; this.Cursor = Cursors.WaitCursor; skinTabControl1.SelectedIndex = 0; //显示打印内容 DataGridViewComboBoxColumn cbxColumn = (DataGridViewComboBoxColumn)dataGridView1.Columns["DataType"]; DataGridViewComboBoxColumn cbxColumn2 = (DataGridViewComboBoxColumn)dataGridView2.Columns["DataType2"]; DataGridViewComboBoxColumn cbxColumn3 = (DataGridViewComboBoxColumn)dataGridView3.Columns["DataType3"]; foreach (var s in System.Enum.GetValues(typeof(PrintDataPdtEnum))) { PrintDataPdtEnum dataEnum = (PrintDataPdtEnum)s; cbxColumn.Items.Add(dataEnum.GetDescription()); cbxColumn2.Items.Add(dataEnum.GetDescription()); cbxColumn3.Items.Add(dataEnum.GetDescription()); } if (m != null) { model = m; this.Text += $" (ID:{m.Id})"; this.txtCode.Text = m.Code; this.txtName.Text = m.Name; this.txtSpec.Text = m.Spec; this.cmbHoleCount.Text = m.HoleCount.ToString(); this.txtBatchId.Text = m.BatchId; this.numTargetCount.Value = m.TargetCount; this.toolTip1.SetToolTip(this.numTargetCount, "已完成:" + m.CompleteCount); this.numTensionBaseValue.Value = (decimal)m.TensionBaseValue; this.numTensionUpFloatValue.Value = (decimal)m.TensionUpFloatValue; this.numTensionDownFloatValue.Value = (decimal)m.TensionDownFloatValue; this.numHeightBaseValue.Value = (decimal)m.HeightBaseValue; this.numHeightUpFloatValue.Value = (decimal)m.HeightUpFloatValue; this.numHeightDownFloatValue.Value = (decimal)m.HeightDownFloatValue; this.txtHeightBaseDec.Text = m.HeightBaseDec; this.numLineWidthBaseValue.Value = (decimal)m.LineWidthBaseValue; this.numLineWidthUpFloatValue.Value = (decimal)m.LineWidthUpFloatValue; this.numLineWidthDownFloatValue.Value = (decimal)m.LineWidthDownFloatValue; this.numPTBaseValue.Value = (decimal)m.PTBaseValue; this.numPTUpFloatValue.Value = (decimal)m.PTUpFloatValue; this.numPTDownFloatValue.Value = (decimal)m.PTDownFloatValue; this.numPTXBaseValue.Value = (decimal)m.PTXBaseValue; this.numPTXUpFloatValue.Value = (decimal)m.PTXUpFloatValue; this.numPTXDownFloatValue.Value = (decimal)m.PTXDownFloatValue; //if (m.Type > 0) //{ // this.txtCode.Enabled = false; // this.txtName.Width = this.txtCode.Width; // this.txtSpec.Enabled = false; //} this.tsbtnAddFile.Enabled = true; this.tsbtnNewBatchId.Enabled = true; this.dgvBatchList.DataSource = new BindingSource(m.BatchHistoryList, null); //2023-11-2 mark this.cbMarkType.SelectedIndex = m.MarkType; this.numMarkSize.Value = (decimal)m.MarkSize; //2023-12-18 主栅 this.cbMarkDisturb.Checked = (m.MarkDisturb == 1); this.cbMainGrid.Checked = (m.MainGrid == 1); //2024-1-24 pad this.cbHavePad.Checked = (m.HavePad == 1); //2024-5-10 网节 this.cbWangJie.Checked = (m.HaveWJ == 1); Models.Attachment attachmentFile = model.AttachmentList.FirstOrDefault(x => x.Type == 0); if (attachmentFile != null) { this.btnOpenFile.Text = attachmentFile.Name; this.btnOpenFile.Visible = true; if ((this.groupBox5.Width - this.btnOpenFile.Width) > 0) { this.btnOpenFile.Left = (this.groupBox5.Width - this.btnOpenFile.Width) / 2; } else this.btnOpenFile.Left = 20; this.textBoxPath.Text = ConfMgr.Instance.ProjectDir+ $"\\{model.Id}\\" + attachmentFile.Name; } //是否显示上传功能 if(ConfMgr.Instance.SysConfigParams.OpenPdtServer) tsbPdtPush.Visible = true; else tsbPdtPush.Visible = false; /////////////Print//////////////// this.cbOrderPrint.Checked = m.EnableOrderPrint; this.tbOrderTempPath.Text = m.OrderTempPath; this.cbOpenBarTenderPrint.Checked = m.EnableLabelPrint; this.tbBarTenderTempPath.Text = m.LabelTempPath; this.cbOpenExcelPrint.Checked = m.EnableExcelPrint; this.tbExcelTempPath.Text = m.ExcelTempPath; if (m.PrintInfoList != null) foreach (var item in m.PrintInfoList) { if (item.Type == 1 && !item.IsValue) { int index = this.dataGridView1.Rows.Add(); this.dataGridView1.Rows[index].Cells[0].Value = item.PrintKey; this.dataGridView1.Rows[index].Cells[1].Value = item.PrintCode; } else if (item.Type == 0 && !item.IsValue) { int index = this.dataGridView2.Rows.Add(); this.dataGridView2.Rows[index].Cells[0].Value = item.PrintKey; this.dataGridView2.Rows[index].Cells[1].Value = item.PrintCode; } else if (item.Type == 3 && !item.IsValue) { int index = this.dataGridView3.Rows.Add(); this.dataGridView3.Rows[index].Cells[0].Value = item.PrintKey; this.dataGridView3.Rows[index].Cells[1].Value = item.PrintCode; } } //////////////////////////////// this.cbOrderSave.Checked = m.EnableOrderSave; this.tbSavePath.Text = m.OrderSavePath; } else { cbMarkType.SelectedIndex = 2; numMarkSize.Value = (decimal)0.5; this.textBoxPath.Text = ""; } InitDataView(); this.Cursor = Cursors.Default; } ArrayList GetArrayList() { ArrayList list = new ArrayList(); Type type = typeof(T); //list.Add(new DictionaryEntry("start", "启动按钮")); foreach (int value in Enum.GetValues(type)) { string strName = Enum.GetName(type, value);//获取名称 list.Add(new DictionaryEntry(value, strName)); } return list; } private void InitDataView() { try { //显示的数据 this.cmbClasses.DisplayMember = "Name"; this.cmbClasses.ValueMember = "Id"; var list = svcClasses.GetListNav(0); this.cmbClasses.DataSource = list; if (model !=null && model.ClassesId > 0) this.cmbClasses.SelectedValue = model.ClassesId; //缺陷项 //ArrayList lstDefect = new ArrayList(); //List DefectNames = new List(); //foreach (var item in Enum.GetValues(typeof(DefectCodeEnum))) //{ // DefectCountOfSizeControl userCon = new DefectCountOfSizeControl(); // userCon.Code = item.ToString(); // userCon.Title = EnumExtension.GetEnumDescription((DefectCodeEnum)item); // if (model != null && model.QualifiedCriterionList != null) // { // var qalifiedItem = model.QualifiedCriterionList.FirstOrDefault(m => m.DefectCode == userCon.Code); // if (qalifiedItem != null) // { // userCon.Checked = true; // userCon.SizeValue = (decimal)qalifiedItem.Size; // userCon.MaxDefectCount = qalifiedItem.MaxDefectCount; // } // } // this.flpQualifiedPannel.Controls.Add(userCon); //} //获取所有缺陷项 //var lstDefect = GetArrayList(); //判断是rj还是pt if (model != null && model.ClassesId > 0) { Classes tClasses = svcClasses.GetById(model.ClassesId); //lstDefect.RemoveAt(10); //lstDefect.RemoveAt(11); //lstDefect.RemoveAt(11); //lstDefect.RemoveAt(11); //if (tClasses.Name == "乳剂") //{ // lstDefect.RemoveAt(11); // lstDefect.RemoveAt(11); // lstDefect.RemoveAt(11); //} //else // lstDefect.RemoveAt(14); } this.flpQualifiedPannel.Controls.Clear(); foreach (var item in ConfMgr.Instance.DefectItemParamsList) { string mdname = "rj.onnx"; if (model != null && !string.IsNullOrEmpty(model.DefectModelFile)) mdname = model.DefectModelFile; if ((item.Type.Split(',').Count(p => p == "-1") > 0 ) || (item.Type.Split(',').Count(p => p == mdname.Replace(".onnx", "")) > 0)) { DefectCountOfSizeControl userCon = new DefectCountOfSizeControl(); userCon.Code = item.Code; userCon.Title = item.Name; userCon.Threshold = (decimal)item.Threshold; //不显示,是有默认值 if (item.Show == 0) { userCon.Checked = true; userCon.Threshold = (decimal)item.Threshold; userCon.SizeValue = (decimal)item.Size; userCon.MaxDefectCount = item.MaxDefectCount; userCon.Visible = false; } else { if (model != null && model.QualifiedCriterionList != null) { var qalifiedItem = model.QualifiedCriterionList.FirstOrDefault(m => m.DefectCode == userCon.Code); if (qalifiedItem != null) { userCon.Checked = true; userCon.Threshold = qalifiedItem.Threshold != 0 ? (decimal)qalifiedItem.Threshold : (decimal)item.Threshold; userCon.SizeValue = (decimal)qalifiedItem.Size; userCon.MaxDefectCount = qalifiedItem.MaxDefectCount; } } } this.flpQualifiedPannel.Controls.Add(userCon); } } //模型文件 string strDefectModelFile = ConfMgr.Instance.SysConfigParams.AIModelPath; string[] onnxFiles = Directory.GetFiles(strDefectModelFile, "*.onnx"); string onlyName; foreach (string onnxFile in onnxFiles) { onlyName = Path.GetFileName(onnxFile); cmbDefectModelFile.Items.Add(onlyName); if (!string.IsNullOrWhiteSpace(model.DefectModelFile) && onlyName.ToLower() == model.DefectModelFile.ToLower()) this.cmbDefectModelFile.SelectedItem = model.DefectModelFile; } } catch(Exception e) { MessageBox.Show("数据&模型载入出错:"+ e.Message,"报警", MessageBoxButtons.OK,MessageBoxIcon.Error); } } private void ProductInfoFrm_Load(object sender, EventArgs e) { } /// /// 保存产品信息 /// private void savePdt() { string szCode = this.txtCode.Text.Trim(); string szName = this.txtName.Text.Trim(); string szSpec = this.txtSpec.Text.Trim(); string szHoleCount = this.cmbHoleCount.Text.Trim(); string szBatchId = this.txtBatchId.Text.Trim(); int liTargetCount = (int)this.numTargetCount.Value; string szHeightBaseDec = this.txtHeightBaseDec.Text.Trim().Trim(new char[] { ';', ',' }); if (szCode == "" || szName == "") throw new Exception("请填写料号和名称!"); if (this.cmbClasses.SelectedIndex < 0) throw new Exception("请选择产品类型!"); if (szHoleCount == "" || !Util.IsNumber(szHoleCount)) throw new Exception("请正确填写产品目数!"); if (this.cmbDefectModelFile.SelectedIndex < 0) throw new Exception("请选择检测模型文件!"); if (this.cbMarkType.SelectedIndex < 0) throw new Exception("请选择Mark!"); //if (szBatchId == "")// || liTargetCount < 1 // throw new Exception("请填写批次号");// 和批次目标数量!"); if (szHeightBaseDec != "") { double num; string[] szs = szHeightBaseDec.Split(new char[] { ';', ',' }); foreach (string s in szs) { if (!double.TryParse(s, out num)) throw new Exception(s + " 非数值!"); } } model.Code = szCode; model.Name = szName; model.Spec = szSpec; model.ClassesId = (int)this.cmbClasses.SelectedValue; model.HoleCount = Convert.ToInt32(szHoleCount); model.DefectModelFile = this.cmbDefectModelFile.Text.Trim(); model.TensionBaseValue = (double)this.numTensionBaseValue.Value; model.TensionUpFloatValue = (double)this.numTensionUpFloatValue.Value; model.TensionDownFloatValue = (double)this.numTensionDownFloatValue.Value; model.HeightBaseValue = (double)this.numHeightBaseValue.Value; model.HeightUpFloatValue = (double)this.numHeightUpFloatValue.Value; model.HeightDownFloatValue = (double)this.numHeightDownFloatValue.Value; model.HeightBaseDec = szHeightBaseDec; model.LineWidthBaseValue = (double)this.numLineWidthBaseValue.Value; model.LineWidthUpFloatValue = (double)this.numLineWidthUpFloatValue.Value; model.LineWidthDownFloatValue = (double)this.numLineWidthDownFloatValue.Value; model.PTBaseValue = (double)this.numPTBaseValue.Value; model.PTUpFloatValue = (double)this.numPTUpFloatValue.Value; model.PTDownFloatValue = (double)this.numPTDownFloatValue.Value; model.PTXBaseValue = (double)this.numPTXBaseValue.Value; model.PTXUpFloatValue = (double)this.numPTXUpFloatValue.Value; model.PTXDownFloatValue = (double)this.numPTXDownFloatValue.Value; if (model.QualifiedCriterionList == null) model.QualifiedCriterionList = new List(); else model.QualifiedCriterionList.Clear(); foreach (DefectCountOfSizeControl defectControl in this.flpQualifiedPannel.Controls) { if (defectControl.Checked) { model.QualifiedCriterionList.Add( new Models.QualifiedCriterion() { DefectCode = defectControl.Code, Size = (float)defectControl.SizeValue, MaxDefectCount = (int)defectControl.MaxDefectCount, Threshold = (double)defectControl.Threshold, ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code, CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code }); } } model.ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code; //2023-11-2 mark model.MarkType = this.cbMarkType.SelectedIndex; model.MarkSize = (double)this.numMarkSize.Value; //2023-12-18 主栅 model.MarkDisturb = this.cbMarkDisturb.Checked ? 1 : 0; model.MainGrid = this.cbMainGrid.Checked ? 1 : 0; //2024-1-24 是否存在pad model.HavePad = this.cbHavePad.Checked ? 1 : 0; //2024-5-10 是否存在网节 model.HaveWJ = this.cbWangJie.Checked ? 1 : 0; ////////////////////Print////////////////////////// model.EnableOrderPrint = this.cbOrderPrint.Checked; model.OrderTempPath = this.tbOrderTempPath.Text; model.EnableLabelPrint = this.cbOpenBarTenderPrint.Checked; model.LabelTempPath = this.tbBarTenderTempPath.Text; model.EnableExcelPrint = this.cbOpenExcelPrint.Checked; model.ExcelTempPath = this.tbExcelTempPath.Text; List labeldata = new List(); for (int i = 0; i < this.dataGridView1.RowCount; i++) { if (this.dataGridView1.Rows[i].Cells[0].Value != null) labeldata.Add(new PrintInfo() { Type = 1, IsValue = false, PrintKey = this.dataGridView1.Rows[i].Cells[0].Value.ToString(), PrintCode = this.dataGridView1.Rows[i].Cells[1].Value.ToString(), PrintName = "", CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code, ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code }); } for (int i = 0; i < this.dataGridView2.RowCount; i++) { if (this.dataGridView2.Rows[i].Cells[0].Value != null) labeldata.Add(new PrintInfo() { Type = 0, IsValue = false, PrintKey = this.dataGridView2.Rows[i].Cells[0].Value.ToString(), PrintCode = this.dataGridView2.Rows[i].Cells[1].Value.ToString(), PrintName = "", CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code, ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code }); } for (int i = 0; i < this.dataGridView3.RowCount; i++) { if (this.dataGridView3.Rows[i].Cells[0].Value != null) labeldata.Add(new PrintInfo() { Type = 3, IsValue = false, PrintKey = this.dataGridView3.Rows[i].Cells[0].Value.ToString(), PrintCode = this.dataGridView3.Rows[i].Cells[1].Value.ToString(), PrintName = "", CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code, ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code }); } model.PrintInfoList = labeldata; ///////////////////////////////////////////////// model.EnableOrderSave = cbOrderSave.Checked; model.OrderSavePath = tbSavePath.Text; /// bool result; if (model.Id == 0) { model.BatchId = szBatchId; model.TargetCount = liTargetCount; model.CompleteCount = 0; model.CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code; result = service.InsertNav(model); } else { if (model.BatchId != szBatchId && !string.IsNullOrWhiteSpace(model.BatchId)) { if (model.CompleteCount < model.TargetCount && MessageBox.Show($"本批次完成数量未达到目标数量,确定更换批次号?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) return; if (model.BatchHistoryList.FirstOrDefault(m => m.BatchId == szBatchId) != null) throw new Exception("当前批次号与历史中所用批次号重复,请重新填写!"); model.BatchHistoryList.Add(new Models.BatchHistory() { BatchId = model.BatchId, TargetCount = model.TargetCount, CompleteCount = model.CompleteCount, CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code, ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code }); model.CompleteCount = 0; } model.BatchId = szBatchId; model.TargetCount = liTargetCount; result = service.UpdateNav(model); } SysMgr.Instance.WriteSysEditLog("产品信息修改", JsonConvert.SerializeObject(model)); if (!result) throw new Exception("保存失败!"); } private void tsbtnSave_Click(object sender, EventArgs e) { try { tsbtnSave.Select(); savePdt(); this.tsbtnAddFile.Enabled = true; this.tsbtnNewBatchId.Enabled = true; MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.OK; this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void tsbtnExit_Click(object sender, EventArgs e) { this.Close(); } private void tsbtnNewBatchId_Click(object sender, EventArgs e) { } private void tsbtnAddFile_Click(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; System.Windows.Forms.Application.DoEvents(); try { if (this.cbMarkType.SelectedIndex < 0) throw new Exception("请选择Mark!"); //.dwg /.dxf /.dws /.dwt string filePath = ConfMgr.SelectFile("gbx,gbr文件|*.gb?"); if (string.IsNullOrWhiteSpace(filePath)) return; //后台线程转BMP与JPG string tempClass = this.cmbDefectModelFile.Text; int tempIndex = this.cbMarkType.SelectedIndex; double tempSize = (double)this.numMarkSize.Value; //2023-12-18 int tMarkDistrub = this.cbMarkDisturb.Checked ? 1 : 0; int tMainGrid = this.cbMainGrid.Checked ? 1 : 0; //2024-1-24 int tHavePad = this.cbHavePad.Checked ? 1 : 0; //2024-5-10 int tHaveWJ = this.cbWangJie.Checked ? 1 : 0; string fileName = Path.GetFileName(filePath); string fileExtend = Path.GetExtension(filePath); string fileOnlyName = fileName.Substring(0, fileName.Length - fileExtend.Length); //判断是否已经保存产品信息 if (string.IsNullOrEmpty(model.Name)) { //产品信息未保存,保存产品信息 savePdt(); } //显示等待弹窗 WaitFrm waitingBox = new WaitFrm((obj, args) => { try { string targFilePath = ConfMgr.Instance.ProjectDir + $"\\{model.Id}\\"; if (!Directory.Exists(targFilePath)) Directory.CreateDirectory(targFilePath); else//删除原文件 ConfMgr.DelFilesInFolder(targFilePath); targFilePath += fileName; //File.Copy(res.file_path, defectFileName + ".bmp", true); bool result = API.CopyFile(filePath, targFilePath, false);//更快 //false-覆盖 if (!result) throw new Exception("移动文件失败!"); Yolo5.Yolo_Class yolo = new Yolo5.Yolo_Class(); string bmpPath = targFilePath.Substring(0, targFilePath.Length - 4) + ".bmp"; //2023-11-3 mark //yolo.gerber2image(targFilePath, bmpPath); double[] markParam = new double[8]; if (tempClass.IndexOf("rj") >= 0) markParam[0] = 2; else if (tempClass.IndexOf("pi") >= 0) markParam[0] = 1; else if (tempClass.IndexOf("best") >= 0) markParam[0] = 1; else markParam[0] = 0; //if (tempClass.Contains("乳剂")) // markParam[0] = 2; //else if (tempClass.Contains("PI")) // markParam[0] = 1; //else // markParam[0] = 0; if (tempIndex == 0) { //默认情况 实心圆,0.5mm markParam[1] = 2; markParam[2] = 0.5; markParam[3] = 1; markParam[4] = 0; markParam[5] = 0; markParam[6] = 0; markParam[7] = 0; } else { markParam[1] = tempIndex - 1; markParam[2] = tempSize; markParam[3] = tempIndex == 1 ? 0 : 1; markParam[4] = tMarkDistrub; markParam[5] = tMainGrid; markParam[6] = tHavePad; markParam[7] = tHaveWJ; } yolo.gerber2image(targFilePath, bmpPath, markParam); //换背景JPG Mat mat = Cv2.ImRead(bmpPath); Cv2.CvtColor(mat, mat, ColorConversionCodes.RGB2GRAY);//转灰度图 for (int i = 0; i < mat.Height; i++) { for (int j = 0; j < mat.Width; j++) { if (mat.At(i, j) == 255)//白色 mat.Set(i, j, 0); else mat.Set(i, j, 255); } } model.MapPath = bmpPath; //灰转彩 //Cv2.CvtColor(mat, mat, ColorConversionCodes.GRAY2RGB); //for (int i = 0; i < mat.Height; i++) //{ // for (int j = 0; j < mat.Width; j++) // { // if (mat.At(i, j) == 255)//白色 // mat.Set(i, j, 0); //黄色 // } //} bmpPath = targFilePath.Substring(0, targFilePath.Length - 4) + ".jpg"; OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat).Save(bmpPath, ImageFormat.Jpeg); //});//不能加.Start(); if (model.AttachmentList == null) model.AttachmentList = new List(); Models.Attachment attachmentFile = model.AttachmentList.FirstOrDefault(m => m.Type == 0); if (attachmentFile != null) { attachmentFile.Type = 0;//图纸 attachmentFile.NameTimestamp = $"{model.Id}\\{fileOnlyName}"; attachmentFile.Name = fileName; attachmentFile.ExtendName = fileExtend; } else { model.AttachmentList.Add(new Models.Attachment() { TBName = "product", Type = 0, NameTimestamp = $"{model.Id}\\{fileOnlyName}", Name = fileName, ExtendName = fileExtend, CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code, ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code }); } if (!service.UpdateNav(model)) throw new Exception("保存文件失败!"); model = service.GetModelNav(model.Code); } catch (Exception ex) { MessageBox.Show($"图纸解析失败-请检查图纸:{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }, "图纸解析上传..."); waitingBox.ShowDialog(this); this.btnOpenFile.Text = fileName; this.textBoxPath.Text = ConfMgr.Instance.ProjectDir + $"\\{model.Id}\\" + fileName; this.btnOpenFile.Visible = true; } catch (Exception ex) { MessageBox.Show($"图纸上传失败-请检查图纸:{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { this.Cursor = Cursors.Default; } } private void btnOpenFile_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { if (model == null || model.AttachmentList == null) { MessageBox.Show("还未上传!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Models.Attachment attachmentFile = model.AttachmentList.FirstOrDefault(m => m.Type == 0); if (attachmentFile == null) { MessageBox.Show("还未上传!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string filePath = ConfMgr.Instance.ProjectDir + $"\\{model.Id}\\" + attachmentFile.Name; if (File.Exists(filePath)) Process.Start(filePath); } private void tbtnGetPos_Click(object sender, EventArgs e) { if ((model.MapPath == null) || (string.IsNullOrEmpty(model.MapPath))) { MessageBox.Show("还未上传图纸!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } List dList = new List(); if (model.GetPointList != null) { var list = model.GetPointList.Split(','); dList = new List(); if (list.Length < 28) { for (int i = 0; i < 28; i++) { dList.Add(0); } } else { for (int i = 0; i < list.Length; i++) { dList.Add(double.Parse(list[i])); } } } FrmGetPosByPic frm = new FrmGetPosByPic(model, model.MapPath, dList.ToArray()); frm.ShowDialog(); model.GetPointList = string.Join(",", frm.GetPoints()); ; model.MapPath = frm.GetMapPath(); if (!service.UpdateNav(model)) throw new Exception("保存文件失败!"); model = service.GetModelNav(model.Code); } private void textBoxPath_DoubleClick(object sender, EventArgs e) { if (File.Exists(this.textBoxPath.Text)) { Models.Attachment attachmentFile = model.AttachmentList.FirstOrDefault(x => x.Type == 0); if (attachmentFile != null) { System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("Explorer.exe"); psi.Arguments = "/e,/select," + ConfMgr.Instance.ProjectDir + $"\\{model.Id}\\"; System.Diagnostics.Process.Start(psi); } } } #region 发送产品数据 private void tsbPdtPush_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; System.Windows.Forms.Application.DoEvents(); SysMgr.Instance.SendPdtData(model); this.Cursor = Cursors.Default; } catch (Exception ex) { ; } } #endregion #region 打印设置 private void tbBarTenderTempPath_DoubleClick(object sender, EventArgs e) { TextBox bt = (TextBox)sender; OpenFileDialog openFileDialog1 = new OpenFileDialog(); DialogResult result = openFileDialog1.ShowDialog(); if (result == DialogResult.OK) { bt.Text = openFileDialog1.FileName; } } #endregion #region 流程管理 private void tsbStep_Click(object sender, EventArgs e) { try { if (model.StepId != null && model.StepInfo != null) { //存在流程,直接打开 //新老流程判断 if (model.StepInfo.ProcessType == "快速流程") { StepProcessFrm frm = new StepProcessFrm(model.StepInfo); frm.ShowDialog(this); } else { StepInfoFrm frm = new StepInfoFrm(model.StepInfo); frm.ShowDialog(this); } } else { //新建流程 StepSelectFrm stepSelectFrm = new StepSelectFrm(); stepSelectFrm.ShowDialog(); if (stepSelectFrm.ProcessSelect == 200) { //老流程 StepInfoFrm frm = new StepInfoFrm(); frm.ShowDialog(); model.StepId = frm.StepID; } else if (stepSelectFrm.ProcessSelect == 100) { //新流程 StepProcessFrm frm = new StepProcessFrm(); frm.ShowDialog(); model.StepId = frm.StepID; } model.ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code; bool result = service.UpdateNav(model); if (!result) throw new Exception("保存失败!"); model = service.GetModelNav(model.Id); } } catch (Exception ex) { MessageBox.Show($"{ex.Message}!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } #endregion #region 保存设置 private void tbSavePath_DoubleClick(object sender, EventArgs e) { TextBox bt = (TextBox)sender; string path = ConfMgr.SelectFolder(Application.StartupPath); if (!string.IsNullOrWhiteSpace(path)) { bt.Text = path; } } #endregion private void cmbClasses_SelectedIndexChanged(object sender, EventArgs e) { //int ClassesId = (int)this.cmbClasses.SelectedValue; //this.flpQualifiedPannel.Controls.Clear(); //foreach (var item in ConfMgr.Instance.DefectItemParamsList) //{ // if ((item.Type.Split(',').Count(p => p == "-1") > 0) || // (item.Type.Split(',').Count(p => p == ClassesId.ToString()) > 0)) // { // DefectCountOfSizeControl userCon = new DefectCountOfSizeControl(); // userCon.Code = item.Code; // userCon.Title = item.Name; // userCon.Threshold = (decimal)item.Threshold; // if (model != null && model.QualifiedCriterionList != null) // { // var qalifiedItem = model.QualifiedCriterionList.FirstOrDefault(m => m.DefectCode == userCon.Code); // if (qalifiedItem != null) // { // userCon.Checked = true; // userCon.Threshold = qalifiedItem.Threshold != 0 ? (decimal)qalifiedItem.Threshold : (decimal)item.Threshold; // userCon.SizeValue = (decimal)qalifiedItem.Size; // userCon.MaxDefectCount = qalifiedItem.MaxDefectCount; // } // } // this.flpQualifiedPannel.Controls.Add(userCon); // } //} } private void cmbDefectModelFile_SelectedIndexChanged(object sender, EventArgs e) { //int ClassesId = (int)this.cmbDefectModelFile.SelectedValue; this.flpQualifiedPannel.Controls.Clear(); foreach (var item in ConfMgr.Instance.DefectItemParamsList) { bool st = false; foreach (var name in item.Type.Split(',')) { st = cmbDefectModelFile.Text.Replace(".onnx", "").IndexOf(name) >=0; if (st) { break; } } if ((item.Type.Split(',').Count(p => p == "-1") > 0) || st) { DefectCountOfSizeControl userCon = new DefectCountOfSizeControl(); userCon.Code = item.Code; userCon.Title = item.Name; userCon.Threshold = (decimal)item.Threshold; if (model != null && model.QualifiedCriterionList != null) { //不显示,是有默认值 if (item.Show == 0) { userCon.Checked = true; userCon.Threshold = (decimal)item.Threshold; userCon.SizeValue = (decimal)item.Size; userCon.MaxDefectCount = item.MaxDefectCount; userCon.Visible = false; } else { if (model != null && model.QualifiedCriterionList != null) { var qalifiedItem = model.QualifiedCriterionList.FirstOrDefault(m => m.DefectCode == userCon.Code); if (qalifiedItem != null) { userCon.Checked = true; userCon.Threshold = qalifiedItem.Threshold != 0 ? (decimal)qalifiedItem.Threshold : (decimal)item.Threshold; userCon.SizeValue = (decimal)qalifiedItem.Size; userCon.MaxDefectCount = qalifiedItem.MaxDefectCount; } } } //var qalifiedItem = model.QualifiedCriterionList.FirstOrDefault(m => m.DefectCode == userCon.Code); //if (qalifiedItem != null) //{ // userCon.Checked = true; // userCon.Threshold = qalifiedItem.Threshold != 0 ? (decimal)qalifiedItem.Threshold : (decimal)item.Threshold; // userCon.SizeValue = (decimal)qalifiedItem.Size; // userCon.MaxDefectCount = qalifiedItem.MaxDefectCount; //} } this.flpQualifiedPannel.Controls.Add(userCon); } } } } }