geboshi_V1/LeatherProject/LeatherApp/Page/PartitionFrm.cs

183 lines
7.3 KiB
C#
Raw Normal View History

using DocumentFormat.OpenXml.Office2010.ExcelAc;
using DocumentFormat.OpenXml.Office2021.DocumentTasks;
using Models;
using OpenCvSharp;
using S7.Net.Types;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LeatherApp.Page
{
public partial class PartitionFrm : Form
{
public string BathReelID;
public string PartReelID;
public string NextPartReelID;
Records model = null;
double LastSplitLength;
public PartitionFrm(Records m, double dis)
{
InitializeComponent();
label2.Visible = false;
//加载分卷信息
LastSplitLength = dis;
model = m;
if (model != null )
{
//第一卷可以设置批卷号和当前分卷号
if(model.ReelNo == 0)
{
textBox1.ReadOnly = false;
textBox2.ReadOnly = false;
}
textBox1.Text = string.IsNullOrWhiteSpace(model.PartReelId)? (model.ReelNo+1).ToString(): model.PartReelId;
textBox2.Text = model.ReelId;
textBox5.Text = (model.ReelNo + 2).ToString();
textBox4.Text = model.ReelId;
if (model.Len == 0 && (model.DefectInfoList == null || model.DefectInfoList.Count == 0))
{
label2.Visible = true;
label2.Text = $"小于1米不记录";
}
//分卷长度
double len = 0;
len = model.Len - LastSplitLength - Config.CutDis;//分卷,补差距
//分卷数据分解卷
int cnt = 0;
string str = "";
string strCut = "";
List<DefectInfo> deflist = new List<DefectInfo>();
if (model.DefectInfoList != null && len > 0)
{
deflist = model.DefectInfoList.FindAll(x => x.Y < ((model.Len - Config.CutDis) * 100));
foreach (var item in deflist)
{
item.Name = Config.getDefectName(model.ProductInfo.ModelName, item.Code);
}
//显示缺陷信息
object[] obj1 = new object[1];
object[] obj2 = new object[1];
List<JDefectTotal> DefectTotal = deflist.GroupBy(x => x.Name).Select(g => new JDefectTotal { Name = g.Key, Count = g.Count() }).ToList();
if(DefectTotal != null && DefectTotal.Count >0)
{
obj1 = new object[deflist.Count + 1];
obj2 = new object[deflist.Count + 1];
obj1[0] = "缺陷";
obj2[0] = "米数";
int index = 1;
dataGridView1.Columns.Clear();
DataTable dt = new DataTable(); //建立个数据表
dt.Columns.Add(new DataColumn("序号", typeof(string)));//在表中添加string类型的列
foreach (var dit in DefectTotal)
{
cnt += dit.Count;
//obj1[index] = dit.Count.ToString();
//obj2[index++] = (dit.Count * 0.2).ToString();
//dt.Columns.Add(new DataColumn(dit.Name, typeof(string)));//在表中添加string类型的列
str += $"{dit.Name}{dit.Count}个,";
}
foreach (var dit in deflist)
{
obj1[index] = dit.Name;
obj2[index++] = (dit.Y/100.0 - LastSplitLength).ToString();
dt.Columns.Add(new DataColumn((index -1).ToString(), typeof(string)));//在表中添加string类型的列
//str += $"{dit.Name}{dit.Count}个,";
}
dataGridView1.DataSource = dt;
dt.Rows.Add(obj1);
dt.Rows.Add(obj2);
//dataGridView1.Rows.Add(obj1);
//dataGridView1.Rows.Add(obj2);
defectCnt.Text = cnt.ToString();
RMCnt.Value = (decimal)(cnt * 0.2);
}
}
if(model.DowngradeInformation != null && model.DowngradeInformation.Count > 0)
{
foreach (var item in model.DowngradeInformation)
{
strCut += $"裁切{item[0]}米,原因{item[1]},降级{item[2]},";
}
}
//总结
if (string.IsNullOrEmpty(str))
textBox3.Text = $"本卷共计{len}米,各类缺陷共计{cnt}个,让码{RMCnt.Value}";
else if (string.IsNullOrEmpty(strCut))
textBox3.Text = $"本卷共计{len}米,各类缺陷共计{cnt}个,让码{RMCnt.Value},{str.Remove(str.Length - 1, 1)}";
else
textBox3.Text = $"本卷共计{len}米,各类缺陷共计{cnt}个,让码{RMCnt.Value},{str.Remove(str.Length - 1, 1)},{strCut.Remove(strCut.Length - 1, 1)}";
}
else
{
label2.Visible = true;
label2.Text = $"无数据!";
}
}
/// <summary>
/// 取消
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void skinButton2_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
private void skinButton1_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox5.Text) || string.IsNullOrEmpty(textBox2.Text))
{
label2.Text = "请输入[卷号]或者[分卷号]!";
label2.Visible = true;
return;
}
if(textBox1.Text == textBox5.Text)
{
label2.Text = "[分卷号]与下一卷相同!";
label2.Visible = true;
return;
}
label2.Visible = false;
PartReelID = textBox1.Text;
BathReelID = textBox2.Text;
NextPartReelID = textBox5.Text;
if (model != null)
{
model.PartReelNote = textBox3.Text;
model.PartReelNote2 = $"厚度:{txtR1.Text},色差:{txtR2.Text},花纹对比:{txtR3.Text}";
}
this.DialogResult = DialogResult.OK;
this.Close();
}
public class JDefectTotal
{
[Description("疵点名")]
public string Name { get; set; }
[Description("疵点数")]
public int Count { get; set; }
}
}
}