197 lines
9.2 KiB
C#

using Aurora.View;
using AuroraUIComponent.Util;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VisionCommon;
namespace WeldingCommon.Data
{
public enum ExportFormat
{
CSV,
XSXL,
TEXT,
JSON,
}
public class ActualProcessData : ObservableCollection<ActualProcessUnit>
{
private DataTable table = new DataTable("ActualProcessData");
public ActualProcessData()
{
table.Columns.Add("Date", typeof(string));
table.Columns.Add("Time", typeof(string));
table.Columns.Add(nameof(ActualProcessUnit.LotID), typeof(string));
table.Columns.Add(nameof(ActualProcessUnit.CellID), typeof(string));
table.Columns.Add(nameof(ActualProcessUnit.HeadNo), typeof(string));
table.Columns.Add(nameof(ActualProcessUnit.EncoderCheck), typeof(bool));
//table.Columns.Add(nameof(ActualProcessUnit.WeldType), typeof(string));
for (int i = 0; i < 16; i++)
TableColumnsAdd("_" + (i + 1).ToString());
}
public void TableClear()
{
table.Clear();
}
public void TableColumnsAdd(string objectNo)
{
table.Columns.Add(nameof(ActualProcessParameter.WeldType) + objectNo, typeof(string));
table.Columns.Add(nameof(ActualProcessParameter.StartPointX) + objectNo, typeof(double));
table.Columns.Add(nameof(ActualProcessParameter.StartPointY) + objectNo, typeof(double));
table.Columns.Add(nameof(ActualProcessParameter.EndPointX) + objectNo, typeof(double));
table.Columns.Add(nameof(ActualProcessParameter.EndPointY) + objectNo, typeof(double));
table.Columns.Add(nameof(ActualProcessParameter.WeldCondition) + objectNo, typeof(double));
table.Columns.Add(nameof(ActualProcessParameter.LaserOnDelay) + objectNo, typeof(double));
table.Columns.Add(nameof(ActualProcessParameter.LaserOffDelay) + objectNo, typeof(double));
table.Columns.Add(nameof(ActualProcessParameter.JumpDelay) + objectNo, typeof(double));
table.Columns.Add(nameof(ActualProcessParameter.MarkDelay) + objectNo, typeof(double));
table.Columns.Add(nameof(ActualProcessParameter.PolygonDelay) + objectNo, typeof(double));
table.Columns.Add(nameof(ActualProcessParameter.PowerCore) + objectNo, typeof(double));
table.Columns.Add(nameof(ActualProcessParameter.PowerRing) + objectNo, typeof(double));
table.Columns.Add(nameof(ActualProcessParameter.JumpSpeed) + objectNo, typeof(double));
table.Columns.Add(nameof(ActualProcessParameter.MarkSpeed) + objectNo, typeof(double));
table.Columns.Add(nameof(ActualProcessParameter.JumpX) + objectNo, typeof(double));
table.Columns.Add(nameof(ActualProcessParameter.JumpY) + objectNo, typeof(double));
}
public void CreateFiles(string fullPathNoExt, ExportFormat format = ExportFormat.CSV)
{
if (fullPathNoExt == null)
return;
if (format == ExportFormat.CSV)
CSV_Manager.GetInstance().Save_DataTableToCsv(fullPathNoExt, table);
Clear();
}
protected override void InsertItem(int index, ActualProcessUnit item)
{
base.InsertItem(index, item);
var values = new List<object>();
// 공통값 1회만 추가
values.Add(item.Date.ToString("yyyy-MM-dd"));
values.Add(item.Date.ToString("HH:mm:ss.fff"));
values.Add(item.LotID);
values.Add(item.CellID);
values.Add(item.HeadNo);
values.Add(item.EncoderCheck);
// ParamAPD[0] ~ [15] 반복 추가
for (int i = 0; i < item.ParamAPD.Count; i++)
{
var apd = item.ParamAPD[i];
values.Add(apd.WeldType);
values.Add(apd.StartPointX);
values.Add(apd.StartPointY);
values.Add(apd.EndPointX);
values.Add(apd.EndPointY);
values.Add(apd.WeldCondition);
values.Add(apd.LaserOnDelay);
values.Add(apd.LaserOffDelay);
values.Add(apd.JumpDelay);
values.Add(apd.MarkDelay);
values.Add(apd.PolygonDelay);
values.Add(apd.PowerCore);
values.Add(apd.PowerRing);
values.Add(apd.JumpSpeed);
values.Add(apd.MarkSpeed);
values.Add(apd.JumpX);
values.Add(apd.JumpY);
}
table.Rows.Add(values.ToArray());
}
//DataRow row = table.NewRow();
// for (int i = 0; i < item.ParamAPD.Count; i++)
// {
// table.Rows.Add(item.Date.ToString("yyyy-MM-dd"), item.Date.ToString("HH:mm:ss.fff"), item.LotID, item.CellID, item.HeadNo, item.WeldType, item.EncoderCheck,
// item.ParamAPD[0].StartPointX, item.ParamAPD[0].StartPointY, item.ParamAPD[0].EndPointX, item.ParamAPD[0].EndPointY,
// item.ParamAPD[0].WeldCondition, item.ParamAPD[0].LaserOnDelay, item.ParamAPD[0].LaserOffDelay, item.ParamAPD[0].JumpDelay, item.ParamAPD[0].MarkDelay,
// item.ParamAPD[0].PolygonDelay, item.ParamAPD[0].PowerCore, item.ParamAPD[0].PowerRing, item.ParamAPD[0].JumpSpeed, item.ParamAPD[0].MarkSpeed, item.ParamAPD[0].JumpX,
// item.ParamAPD[0].JumpY);
// }
//}
public void UpdateHeadNo(string headNo)
{
foreach (var item in this)
item.HeadNo = headNo;
foreach (DataRow row in table.Rows)
row["HeadNo"] = headNo;
}
protected override void ClearItems()
{
base.ClearItems();
table.Clear();
}
}
public class ActualProcessUnit : NotifyPropertyChangedBase
{
public DateTime Date { get => _Date; set => SetProperty(ref _Date, value); }
private DateTime _Date;
public string LotID { get => _LodID; set => SetProperty(ref _LodID, value); }
private string _LodID;
public string CellID { get => _CellID; set => SetProperty(ref _CellID, value); }
private string _CellID;
public string HeadNo { get => _HeadNo; set => SetProperty(ref _HeadNo, value); }
private string _HeadNo;
public bool EncoderCheck { get => _EncoderCheck; set => SetProperty(ref _EncoderCheck, value); }
private bool _EncoderCheck;
public List<ActualProcessParameter> ParamAPD { get => _ParamAPD; set => SetProperty(ref _ParamAPD, value); }
private List<ActualProcessParameter> _ParamAPD = new List<ActualProcessParameter>();
}
public class ActualProcessParameter : NotifyPropertyChangedBase
{
public string WeldType { get => _WeldType; set => SetProperty(ref _WeldType, value); }
private string _WeldType;
public double StartPointX { get => _StartPointX; set => SetProperty(ref _StartPointX, value); }
private double _StartPointX;
public double StartPointY { get => _StartPointY; set => SetProperty(ref _StartPointY, value); }
private double _StartPointY;
public double EndPointX { get => _EndtPointX; set => SetProperty(ref _EndtPointX, value); }
private double _EndtPointX;
public double EndPointY { get => _EndtPointY; set => SetProperty(ref _EndtPointY, value); }
private double _EndtPointY;
public double WeldCondition { get => _WeldCondition; set => SetProperty(ref _WeldCondition, value); }
private double _WeldCondition;
public double LaserOnDelay { get => _LaserOnDelay; set => SetProperty(ref _LaserOnDelay, value); }
private double _LaserOnDelay;
public double LaserOffDelay { get => _LaserOffDelay; set => SetProperty(ref _LaserOffDelay, value); }
private double _LaserOffDelay;
public double JumpDelay { get => _JumpDelay; set => SetProperty(ref _JumpDelay, value); }
private double _JumpDelay;
public double MarkDelay { get => _MarkDelay; set => SetProperty(ref _MarkDelay, value); }
private double _MarkDelay;
public double PolygonDelay { get => _PolygonDelay; set => SetProperty(ref _PolygonDelay, value); }
private double _PolygonDelay;
public double PowerCore { get => _PowerCore; set => SetProperty(ref _PowerCore, value); }
private double _PowerCore;
public double PowerRing { get => _PowerRing; set => SetProperty(ref _PowerRing, value); }
private double _PowerRing;
public double JumpSpeed { get => _JumpSpeed; set => SetProperty(ref _JumpSpeed, value); }
private double _JumpSpeed;
public double MarkSpeed { get => _MarkSpeed; set => SetProperty(ref _MarkSpeed, value); }
private double _MarkSpeed;
public double JumpX { get => _JumpX; set => SetProperty(ref _JumpX, value); }
private double _JumpX;
public double JumpY { get => _JumpY; set => SetProperty(ref _JumpY, value); }
private double _JumpY;
}
}