using DocumentFormat.OpenXml.EMMA; using DocumentFormat.OpenXml.Office2010.ExcelAc; using DocumentFormat.OpenXml.Office2021.DocumentTasks; using DocumentFormat.OpenXml.Spreadsheet; 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.Runtime.CompilerServices; 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; public double WeightParam; Records model = null; double LastSplitLength; public PartitionFrm(Records m, double dis, double wd) { InitializeComponent(); label2.Visible = false; //加载分卷信息 WeightParam = wd; LastSplitLength = dis; model = m; ShowDefectRecordInfo(true); } private void ShowDefectRecordInfo(bool isLoad) { if (model != null) { //第一卷可以设置批卷号和当前分卷号 if (model.ReelNo == 0) { textBox1.ReadOnly = false; textBox2.ReadOnly = false; } if (model.Len == 0 && (model.DefectInfoList == null || model.DefectInfoList.Count == 0)) { label2.Visible = true; label2.Text = $"小于1米不记录"; } //显示色差 if(!string.IsNullOrEmpty(model.PartReelNote)) txtR2.Text = model.PartReelNote2.Replace("色差:", ""); //model.PartReelNote2 = $"色差:{txtR2.Text}"; //分卷长度 double len = 0; len = model.Len - LastSplitLength - Config.CutDis + Config.JMOffset;//分卷,补差距 if (isLoad) { textBox1.Text = string.IsNullOrWhiteSpace(model.PartReelId) ? (model.ReelNo + 1).ToString() : model.PartReelId; textBox2.Text = $"{model.BatchId}@{model.ReelId}"; textBox5.Text = (model.ReelNo + 2).ToString(); textBox4.Text = $"{model.BatchId}@{model.ReelId}"; //卷长显示 numericUpDown1.Value = (decimal)len; //显示重量 if(WeightParam > 0) numericUpDown3.Value = (decimal)((double)numericUpDown1.Value * WeightParam); } //分卷数据分解卷 int cnt = 0; string str = ""; string strCut = ""; double rmCnt = 0; //让码计算 if (isLoad) { if (model.FMInformation != null && model.FMInformation.Count > 0) { //分卷长度 var rmList = model.FMInformation.Where(x => double.Parse(x[3]) < (model.Len - Config.CutDis)).ToList(); foreach (var dit in rmList) { rmCnt += double.Parse(dit[2].Split(',')[0]); } //总让码计数 RMCnt.Value = (decimal)rmCnt; } } //显示净长 double jLen = ((double)numericUpDown1.Value - (double)RMCnt.Value) > 0 ? ((double)numericUpDown1.Value - (double)RMCnt.Value) : 0; numericUpDown2.Value = (decimal)jLen; //总缺陷显示统计 List deflist = new List(); if (model.DefectInfoList != null && len > 0) { //显示缺陷信息 object[] obj1 = new object[1]; object[] obj2 = new object[1]; object[] obj3 = new object[1]; 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); } List 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[DefectTotal.Count + 1]; obj2 = new object[DefectTotal.Count + 1]; obj3 = new object[DefectTotal.Count + 1]; obj1[0] = "缺陷"; obj2[0] = "个数"; obj3[0] = "米数"; int index = 1; dataGridView1.Columns.Clear(); DataTable dt = new DataTable(); //建立个数据表 dt.Columns.Add(new DataColumn("让码序号", typeof(string)));//在表中添加string类型的列 foreach (var dit in DefectTotal) { obj1[index] = dit.Name; obj2[index] = dit.Count; obj3[index++] = Math.Round(deflist.Where(x => x.Name == dit.Name).ToList().Select(t => t.Height).Sum() / 100.0, 2); dt.Columns.Add(new DataColumn((index - 1).ToString(), typeof(string)));//在表中添加string类型的列 cnt += dit.Count; str += $"{dit.Name}{dit.Count}个,"; } dataGridView1.DataSource = dt; dt.Rows.Add(obj1); dt.Rows.Add(obj2); dt.Rows.Add(obj3); //隐藏列头 dataGridView1.ColumnHeadersVisible = false; } //总缺陷计数 defectCnt.Text = cnt.ToString(); } //厚度显示 if (model.ThicknessList != null && model.ThicknessList.Count > 0) { this.dataGridView2.Rows.Clear(); //分卷长度分开 var thList = model.ThicknessList.Where(x => (x.Y_Dis / 100) < (model.Len - Config.CutDis)).ToList(); for (int i = 0; i < thList.Count; i++) { double ave = Math.Round((thList[i].Value1 + thList[i].Value2 + thList[i].Value3)/3, 2); var rowItem = new object[]{ (thList[i].Y_Dis /100).ToString("0.00"), thList[i].Value1.ToString(),thList[i].Value2.ToString(),thList[i].Value3.ToString(), ave.ToString()}; this.dataGridView2.Rows.Insert(i, rowItem); } } //裁切记录 if (model.DowngradeInformation != null && model.DowngradeInformation.Count > 0) { foreach (var item in model.DowngradeInformation) { strCut += $"裁切{item[0]}米,原因{item[1]},等级{item[2]},"; } } //分段信息 string fdStr = ""; if (model.FDInfor != null && model.FDInfor.Count > 0) { //分卷长度分开 var fdList = model.FDInfor.Where(x => x[1] < (model.Len - Config.CutDis)).ToList(); double last = (len - fdList.Select(x => x[0]).Sum()) > 0 ? (len - fdList.Select(x => x[0]).Sum()) : 0; fdList.Add(new double[2] { Math.Round(last, 2), len }); fdStr += $"本卷分{fdList.Count()}段,分别"; for (int i = 0; i < fdList.Count; i++) { fdStr += $"{Math.Round(fdList[i][0], 2)}米,"; } } //总结 double tLen = Math.Round((double)numericUpDown1.Value,2); double kg = Math.Round((double)numericUpDown3.Value, 2); textBox3.Text = $"本卷共计{tLen}米,各类缺陷共计{cnt}个,让码{RMCnt.Value},重量{kg}kg"; if (!string.IsNullOrEmpty(str)) textBox3.Text += $",{str.Remove(str.Length - 1, 1)}"; if (!string.IsNullOrEmpty(fdStr)) textBox3.Text += $",{fdStr.Remove(fdStr.Length - 1, 1)}"; if (!string.IsNullOrEmpty(strCut)) textBox3.Text += $",{strCut.Remove(strCut.Length - 1, 1)}"; //else if (string.IsNullOrEmpty(fdStr)) // textBox3.Text = $"本卷共计{len}米,各类缺陷共计{cnt}个,让码{RMCnt.Value},{strCut.Remove(strCut.Length - 1, 1)}"; //else if (string.IsNullOrEmpty(strCut)) // textBox3.Text = $"本卷共计{len}米,各类缺陷共计{cnt}个,让码{RMCnt.Value},{str.Remove(str.Length - 1, 1)},{fdStr.Remove(str.Length - 1, 1)}"; //else // textBox3.Text = $"本卷共计{len}米,各类缺陷共计{cnt}个,让码{RMCnt.Value},{str.Remove(str.Length - 1, 1)},{fdStr.Remove(str.Length - 1, 1)},{strCut.Remove(strCut.Length - 1, 1)}"; } else { label2.Visible = true; label2.Text = $"无数据!"; } } /// /// 取消 /// /// /// 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 (Math.Round((double)numericUpDown1.Value, 2) > 0) WeightParam = Math.Round((double)numericUpDown3.Value, 2) / Math.Round((double)numericUpDown1.Value, 2); else WeightParam = 0; if (model != null) { model.PartReelNote = textBox3.Text; //model.PartReelNote2 = $"厚度:{txtR1.Text},色差:{txtR2.Text},花纹对比:{txtR3.Text}"; model.PartReelNote2 = $"色差:{txtR2.Text}"; //分段信息信息 0:卷长 1:让码 2:净长 3:重量 model.LengthWeightInfor = new double[4] {Math.Round((double)numericUpDown1.Value ,2), Math.Round((double)RMCnt.Value, 2), Math.Round((double)numericUpDown2.Value, 2), Math.Round((double)numericUpDown3.Value, 2) } ; } this.DialogResult = DialogResult.OK; this.Close(); } public class JDefectTotal { [Description("疵点名")] public string Name { get; set; } [Description("疵点数")] public int Count { get; set; } } private void RMCnt_ValueChanged(object sender, EventArgs e) { ShowDefectRecordInfo(false); this.Refresh(); } private void numericUpDown1_ValueChanged(object sender, EventArgs e) { ShowDefectRecordInfo(false); this.Refresh(); } private void numericUpDown3_ValueChanged(object sender, EventArgs e) { ShowDefectRecordInfo(false); this.Refresh(); } } }