283 lines
10 KiB
C#
283 lines
10 KiB
C#
using Automation.BDaq;
|
|
using DocumentFormat.OpenXml.Bibliography;
|
|
using DocumentFormat.OpenXml.Office2021.DocumentTasks;
|
|
using DocumentFormat.OpenXml.Wordprocessing;
|
|
using Irony.Parsing;
|
|
using LeatherApp.UIExtend;
|
|
using Models;
|
|
using OpenCvSharp;
|
|
using OpenCvSharp.Extensions;
|
|
using Sunny.UI;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
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;
|
|
/// <summary>
|
|
/// 忽略信息
|
|
/// </summary>
|
|
public List<DefectInfo> lstDel = new List<DefectInfo>();
|
|
/// <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];
|
|
private Mat Image;
|
|
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)
|
|
{
|
|
InitializeComponent();
|
|
SectioningLen = fdLen;
|
|
list = lst;
|
|
Image = img;
|
|
_records = model;
|
|
lstPreWait = Waitlst;
|
|
if(Image != null)
|
|
pictureBox1.Image = Image.ToBitmap();
|
|
init(modelName);
|
|
|
|
if (Config.CustomerName != "XCL")
|
|
{
|
|
uiLabel1.Visible = false;
|
|
numFMLen.Visible = false;
|
|
btnFM.Visible = false;
|
|
btnCut.Visible = false;
|
|
btnAllWait.Visible = false;
|
|
}
|
|
}
|
|
|
|
private void init(string modelName)
|
|
{
|
|
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)
|
|
{
|
|
Code = item.Code,
|
|
Tag = item,
|
|
DefecLocation=$"[{item.CentreX}cm,{Math.Round(item.CentreY/ 100.0f,2)}米]",
|
|
Image = img.ToBitmap()
|
|
};
|
|
//userCon.CodeChangeEvent = (code, name) =>
|
|
//{
|
|
// item.Code = code;
|
|
// item.Name = name;
|
|
// API.OutputDebugString("BBBBBBBBBBB-" + item.Code+" "+ item.Name);
|
|
//};
|
|
this.flowLayoutPanel1.Controls.Add(userCon);
|
|
});
|
|
//模拟计算让码数
|
|
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");
|
|
}
|
|
private void FHome_Defect_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
public class JDefectTotal
|
|
{
|
|
[Description("疵点名")]
|
|
public string Name { get; set; }
|
|
|
|
[Description("疵点数")]
|
|
public int Count { get; set; }
|
|
}
|
|
private void btnOK_Click(object sender, EventArgs e)
|
|
{
|
|
List<DefectInfo> Fmlst = new List<DefectInfo>();
|
|
for (int i = 0; i < this.flowLayoutPanel1.Controls.Count; i++)
|
|
{
|
|
UIDefectImage userCon= this.flowLayoutPanel1.Controls[i] as UIDefectImage;
|
|
if (userCon.CheckedSts == 1)
|
|
{
|
|
var item=(DefectInfo)userCon.Tag;
|
|
lstDel.Add(item);
|
|
list.Remove(item);
|
|
}
|
|
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");
|
|
}
|
|
}
|
|
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();
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|