geboshi_V1/LeatherProject/LeatherApp/Page/FHome_Defect.cs

283 lines
10 KiB
C#
Raw Normal View History

2024-12-18 10:44:17 +08:00
using Automation.BDaq;
using DocumentFormat.OpenXml.Bibliography;
using DocumentFormat.OpenXml.Office2021.DocumentTasks;
using DocumentFormat.OpenXml.Wordprocessing;
using Irony.Parsing;
using LeatherApp.UIExtend;
2024-03-07 14:03:22 +08:00
using Models;
2024-08-05 09:39:58 +08:00
using OpenCvSharp;
using OpenCvSharp.Extensions;
2024-03-07 14:03:22 +08:00
using Sunny.UI;
using System;
2024-12-18 10:44:17 +08:00
using System.Collections;
2024-03-07 14:03:22 +08:00
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
2024-03-07 14:03:22 +08:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LeatherApp.Page
{
public partial class FHome_Defect : UIForm
{
private List<DefectInfo> list;
2024-12-18 10:44:17 +08:00
/// <summary>
/// 忽略信息
/// </summary>
2024-03-07 14:03:22 +08:00
public List<DefectInfo> lstDel = new List<DefectInfo>();
2024-12-18 10:44:17 +08:00
/// <summary>
/// 当前待定信息
/// </summary>
public List<DefectInfo> lstWait = new List<DefectInfo>();
/// <summary>
/// 之前待定信息
/// </summary>
private List<DefectInfo> lstPreWait = new List<DefectInfo>();
/// <summary>
/// 放码信息
/// </summary>
public string[] FMInfo = new string[4];
2024-08-05 09:39:58 +08:00
private Mat Image;
2024-12-18 10:44:17 +08:00
private Records _records;
/// <summary>
/// 分段信息
/// </summary>
public double SectioningLen;
public FHome_Defect(string modelName, List<DefectInfo> lst, Mat img, Records model, List<DefectInfo> Waitlst, double fdLen)
2024-03-07 14:03:22 +08:00
{
InitializeComponent();
2024-12-18 10:44:17 +08:00
SectioningLen = fdLen;
2024-03-07 14:03:22 +08:00
list = lst;
2024-08-05 09:39:58 +08:00
Image = img;
2024-12-18 10:44:17 +08:00
_records = model;
lstPreWait = Waitlst;
if(Image != null)
pictureBox1.Image = Image.ToBitmap();
init(modelName);
2024-12-18 10:44:17 +08:00
if (Config.CustomerName != "XCL")
{
uiLabel1.Visible = false;
numFMLen.Visible = false;
btnFM.Visible = false;
btnCut.Visible = false;
btnAllWait.Visible = false;
}
2024-03-07 14:03:22 +08:00
}
private void init(string modelName)
2024-03-07 14:03:22 +08:00
{
this.Text += $" 原图索引({list[0].PhotoIndex})";
list.ForEach(item => {
string filename = Path.Combine(Config.appBasePath + "\\TempPic\\", $"{item.imageID}.jpg");
OpenCvSharp.Mat img = new OpenCvSharp.Mat(filename);
UIDefectImage userCon = new UIDefectImage(modelName)
2024-03-07 14:03:22 +08:00
{
Code = item.Code,
Tag = item,
DefecLocation=$"[{item.CentreX}cm,{Math.Round(item.CentreY/ 100.0f,2)}米]",
Image = img.ToBitmap()
2024-03-07 14:03:22 +08:00
};
//userCon.CodeChangeEvent = (code, name) =>
//{
// item.Code = code;
// item.Name = name;
// API.OutputDebugString("BBBBBBBBBBB-" + item.Code+" "+ item.Name);
//};
this.flowLayoutPanel1.Controls.Add(userCon);
});
2024-12-18 10:44:17 +08:00
//模拟计算让码数
double ydis = Math.Round((list[list.Count - 1].CentreY - list[0].CentreY) / 100.0f, 2);
int bs = (int)(ydis / 0.2) + 1;
numFMLen.Text = (0.2 * bs).ToString("0.00");
2024-03-07 14:03:22 +08:00
}
private void FHome_Defect_Load(object sender, EventArgs e)
{
}
2024-12-18 10:44:17 +08:00
public class JDefectTotal
{
[Description("疵点名")]
public string Name { get; set; }
2024-03-07 14:03:22 +08:00
2024-12-18 10:44:17 +08:00
[Description("疵点数")]
public int Count { get; set; }
}
2024-03-07 14:03:22 +08:00
private void btnOK_Click(object sender, EventArgs e)
{
2024-12-18 10:44:17 +08:00
List<DefectInfo> Fmlst = new List<DefectInfo>();
for (int i = 0; i < this.flowLayoutPanel1.Controls.Count; i++)
2024-03-07 14:03:22 +08:00
{
UIDefectImage userCon= this.flowLayoutPanel1.Controls[i] as UIDefectImage;
2024-12-18 10:44:17 +08:00
if (userCon.CheckedSts == 1)
2024-03-07 14:03:22 +08:00
{
var item=(DefectInfo)userCon.Tag;
lstDel.Add(item);
list.Remove(item);
}
2024-12-18 10:44:17 +08:00
else if (userCon.CheckedSts == 2)
{
var item = (DefectInfo)userCon.Tag;
lstWait.Add(item);
}
else if (userCon.CheckedSts == 0)
{
var item = (DefectInfo)userCon.Tag;
Fmlst.Add(item);
}
}
if (Fmlst.Count > 0)
{
//生成放码信息
string str1 = "";
string str2 = "";
string str3 = "";
List<JDefectTotal> DefectTotal = Fmlst.GroupBy(x => x.Name).Select(g => new JDefectTotal { Name = g.Key, Count = g.Count() }).ToList();
if (DefectTotal != null && DefectTotal.Count > 0)
{
foreach (var dit in DefectTotal)
{
//str += $"{dit.Name}{dit.Count}个,";
str1 += $"{dit.Name},";
str2 += $"{dit.Count},";
str3 += $"{numFMLen.Text},";
}
//str.Remove(str.Length - 1, 1)
FMInfo[0] = str1.Remove(str1.Length - 1, 1);
FMInfo[1] = str2.Remove(str2.Length - 1, 1);
FMInfo[2] = str3.Remove(str3.Length - 1, 1);
FMInfo[3] = (Fmlst[0].CentreY / 100).ToString("0.00");
}
2024-03-07 14:03:22 +08:00
}
this.DialogResult = DialogResult.OK;
this.Close();
}
private void btnCancel_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.flowLayoutPanel1.Controls.Count; i++)
{
UIDefectImage userCon = this.flowLayoutPanel1.Controls[i] as UIDefectImage;
var item = (DefectInfo)userCon.Tag;
lstDel.Add(item);
list.Remove(item);
}
this.DialogResult = DialogResult.OK;
this.Close();
}
2024-12-18 10:44:17 +08:00
private void btnCut_Click(object sender, EventArgs e)
{
CuttingFrm frm = new CuttingFrm(list);
frm.ShowDialog(this);
if (frm.DialogResult == DialogResult.Cancel)
return;
else
{
//AddTextEvent(DateTime.Now, "降级裁切", $"裁切信息:米数({frm.Cut_info[0]}),原因({frm.Cut_info[1]}),降级({frm.Cut_info[2]})");
if (SaveCutingInfo(frm.Cut_info))
{
bool haveJT = false;
foreach (var item in list)
{
if (item.Name == "接头" || item.Name == "纸接")
haveJT = true;
}
if (!haveJT)
{
//不存在接头时进行裁切 记录裁切数据
//记录分段信息
double fdLen = Math.Round(list[0].CentreY / 100.0 - SectioningLen, 2);
if (fdLen > 0)
{
SectioningLen = list[0].CentreY / 100.0;
//添加分段信息
_records.FDInfor.Add(new double[2] { fdLen, Math.Round(list[0].CentreY / 100.0, 2) });
}
}
}
else
{
UIMessageTip.ShowWarning("无记录数据!", 2000);
}
}
}
#region
public bool SaveCutingInfo(string[] info)
{
if (_records != null)
{
Records model = _records;
if (model.DowngradeInformation == null)
model.DowngradeInformation = new List<string[]>();
model.DowngradeInformation.Add(info);
}
else
{
return false;
}
return true;
}
#endregion
/// <summary>
/// 待定
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnAllWait_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.flowLayoutPanel1.Controls.Count; i++)
{
UIDefectImage userCon = this.flowLayoutPanel1.Controls[i] as UIDefectImage;
var item = (DefectInfo)userCon.Tag;
lstWait.Add(item);
//list.Remove(item);
}
this.DialogResult = DialogResult.OK;
this.Close();
}
/// <summary>
/// 待定放码,之前待定和当前缺陷一起放码
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnFM_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.flowLayoutPanel1.Controls.Count; i++)
{
UIDefectImage userCon = this.flowLayoutPanel1.Controls[i] as UIDefectImage;
if (userCon.CheckedSts == 2 || userCon.CheckedSts == 0) //当前确认和待定都加入
{
var item = (DefectInfo)userCon.Tag;
lstPreWait.Add(item);
}
}
WaitFMFrm frm = new WaitFMFrm(lstPreWait);
frm.Render();
frm.ShowDialog();
if (frm.IsOK)
{
//放码待定信息
lstWait = frm.lastWaitlst;
FMInfo = frm.FMInfo;
this.DialogResult = DialogResult.Yes;
this.Close();
}
else
{
return;
}
frm.Dispose();
}
2024-03-07 14:03:22 +08:00
}
}