Feiyu/Model/StandModel.cs
2025-12-10 17:55:48 +08:00

584 lines
15 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Community;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace Model
{
/// <summary>
/// 站别模型
/// </summary>
public class StandModel : NotificationObject
{
/// <summary>
/// 刷新图表的委托
/// </summary>
/// <param name="hv"></param>
public delegate void delegeateRefreshChart(int InOnOut, int number);
/// <summary>
/// 刷新图表的委托事件
/// </summary>
public event delegeateRefreshChart eventRefreshChart;
#region 基本信息
public int ID { get; set; }
/// <summary>
/// 上级ID
/// </summary>
public int ParentID { get; set; }
#region 站别名称
private string standName;
/// <summary>
/// 站别名称
/// </summary>
public string StandName
{
get { return standName; }
set
{
standName = value;
RaisePropertyChanged("StandName");
}
}
#endregion
#region 简码
private string shortCode;
/// <summary>
/// 简码
/// </summary>
public string ShortCode
{
get { return shortCode; }
set
{
shortCode = value;
RaisePropertyChanged("ShortCode");
}
}
#endregion
#region 工位
private string stationNo;
/// <summary>
/// 工位
/// </summary>
public string StationNo
{
get { return stationNo; }
set
{
stationNo = value;
RaisePropertyChanged("StationNo");
}
}
#endregion
#region 机台编号
private string machineNumber;
/// <summary>
/// 机台编号
/// </summary>
public string MachineNumber
{
get { return machineNumber; }
set
{
machineNumber = value;
RaisePropertyChanged("MachineNumber");
}
}
#endregion
#region 站别类型 预留
private int standType;
/// <summary>
/// 站别类型 预留
/// </summary>
public int StandType
{
get { return standType; }
set
{
standType = value;
RaisePropertyChanged("StandType");
}
}
#endregion
#region PLCID
private int plcID;
/// <summary>
/// PLCID
/// </summary>
public int PlcID
{
get { return plcID; }
set
{
plcID = value;
RaisePropertyChanged("PlcID");
}
}
#endregion
#region 设备1 ID
private int deviceID1;
/// <summary>
/// 设备1 ID
/// </summary>
public int DeviceID1
{
get { return deviceID1; }
set
{
deviceID1 = value;
RaisePropertyChanged("DeviceID1");
}
}
#endregion
#region 设备2 ID
private int deviceID2;
/// <summary>
/// 设备2 ID
/// </summary>
public int DeviceID2
{
get { return deviceID2; }
set
{
deviceID2 = value;
RaisePropertyChanged("DeviceID2");
}
}
#endregion
#region 设备3 ID
private int deviceID3;
/// <summary>
/// 设备3 ID
/// </summary>
public int DeviceID3
{
get { return deviceID3; }
set
{
deviceID3 = value;
RaisePropertyChanged("DeviceID3");
}
}
#endregion
#region 设备4 ID
private int deviceID4;
/// <summary>
/// 设备4 ID
/// </summary>
public int DeviceID4
{
get { return deviceID4; }
set
{
deviceID4 = value;
RaisePropertyChanged("DeviceID4");
}
}
#endregion
#region 设备5 ID
private int deviceID5;
/// <summary>
/// 设备5 ID
/// </summary>
public int DeviceID5
{
get { return deviceID5; }
set
{
deviceID5 = value;
RaisePropertyChanged("DeviceID5");
}
}
#endregion
#region 连续NG次数
private int ngCount;
/// <summary>
/// 连续NG次数
/// </summary>
public int NgCount
{
get { return ngCount; }
set { ngCount = value; RaisePropertyChanged("NgCount"); }
}
#endregion
#region 站别状态
private ShowInfo standState;
/// <summary>
/// 站别状态
/// </summary>
public ShowInfo StandState
{
get { return standState; }
set
{
standState = value == null ? StandState = new ShowInfo() { StatusBackground = ColorStr.Gray, StatuInfo = "等待运行" } : value;
RaisePropertyChanged("StandState");
}
}
private ShowInfo product;
/// <summary>
/// 站别状态
/// </summary>
public ShowInfo Product
{
get { return product; }
set
{
product = value == null ? new ShowInfo() : value;
RaisePropertyChanged("Product");
}
}
private ShowInfo testRes;
/// <summary>
/// 测试结果
/// </summary>
public ShowInfo TestRes
{
get { return testRes; }
set { testRes = value; RaisePropertyChanged("TestRes"); }
}
#endregion
#region 启用
private bool enableing;
/// <summary>
/// 启用
/// </summary>
public bool Enableing
{
get { return enableing; }
set
{
enableing = value;
if (!value)
{
VisibilitySoft = Visibility.Collapsed;
}
else
{
VisibilitySoft = Visibility.Visible;
}
RaisePropertyChanged("Enableing");
}
}
#endregion
#region 机台数据
private string runTime;
/// <summary>
/// 测试时间
/// </summary>
public string RunTime
{
get { return runTime; }
set
{
runTime = value;
RaisePropertyChanged("RunTime");
}
}
private int inputQuantity;
/// <summary>
/// 投入数量
/// </summary>
public int InputQuantity
{
get { return inputQuantity; }
set
{
inputQuantity = value;
try
{
if (OutputQuantity != 0)
{
Yield = Math.Round(((decimal)OutputQuantity / value), 4);
}
}
catch
{
}
RaisePropertyChanged("InputQuantity");
}
}
private int outputQuantity;
/// <summary>
/// 产出数量
/// </summary>
public int OutputQuantity
{
get { return outputQuantity; }
set
{
outputQuantity = value;
try
{
if (value != 0 && value <= InputQuantity)
{
Yield = Math.Round(((decimal)value / InputQuantity), 4);
}
BadQuantity = InputQuantity - value;
}
catch
{
}
RaisePropertyChanged("OutputQuantity");
}
}
private int badQuantity;
/// <summary>
/// 不良数量
/// </summary>
public int BadQuantity
{
get { return badQuantity; }
set
{
badQuantity = value;
RaisePropertyChanged("BadQuantity");
}
}
private double cTime;
/// <summary>
/// C/T时间
/// </summary>
public double CTime
{
get { return cTime; }
set
{
cTime = value;
RaisePropertyChanged("CTime");
}
}
private decimal yield;
/// <summary>
/// 良率
/// </summary>
public decimal Yield
{
get { return yield; }
set
{
yield = value;
RaisePropertyChanged("Yield");
}
}
private int capacity;
/// <summary>
/// 产能
/// </summary>
public int Capacity
{
get { return capacity; }
set
{
capacity = value;
RaisePropertyChanged("Capacity");
}
}
#endregion
#endregion
#region 站别是否可见
private Visibility visibilitySoft;
/// <summary>
/// 站别是否可见
/// </summary>
public Visibility VisibilitySoft
{
get { return visibilitySoft; }
set
{
visibilitySoft = value;
RaisePropertyChanged("VisibilitySoft");
}
}
#endregion
#region 构造函数
/// <summary>
/// 构造函数
/// </summary>
public StandModel()
{
StandState = new ShowInfo() { StatusBackground = ColorStr.Gray, StatuInfo = "等待运行" };
TestRes = new ShowInfo() { StatusBackground = ColorStr.Gray, StatuInfo = "unknown" };
Product = new ShowInfo();
}
#endregion
#region 记录日志信息
byte[] data { get; set; }
/// <summary>
/// 文件夹路径
/// </summary>
string path { get; set; }
/// <summary>
/// 文件路径
/// </summary>
string paths { get; set; }
/// <summary>
/// 记录信息对象
/// </summary>
RecordInfo info { get; set; }
/// <summary>
/// 打开的文件流对象
/// </summary>
FileStream FS { get; set; }
/// <summary>
/// 记录日志信息到文件
/// </summary>
/// <param name="info"></param>
private void RecordLog(string showMag)
{
lock (this)
{
path = @"D:\\LAGLog\ATSLog"; //文件夹路径
paths = @"D:\\LAGLog\ATSLog\" + DateTime.Now.ToString("yyyyMMdd") + ".txt"; //文件路径 以年月日为名称
//创建文件夹
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
//打开或创建文件
FS = File.Open(paths, FileMode.Append);
//获得字节数组
data = System.Text.Encoding.Default.GetBytes(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff") + showMag + "\r\n");
//开始写入
FS.Write(data, 0, data.Length);
//清空缓冲区、关闭流
FS.Flush();
FS.Close();
}
}
/// <summary>
/// 记录测试结果
/// </summary>
/// <param name="CM"></param>
private void TestResultLog(CylinderMeasurementModel CM)
{
lock (this)
{
path = @"D:\\TestResultLog\";
paths = @"D:\\TestResultLog\" + DateTime.Now.ToString("D") + ".CSV";
//实例化字符串流
StringBuilder sb = new StringBuilder();
//创建文件夹
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
//创建文件
if (!File.Exists(paths))
{
sb.Append("测量项目").Append(",").Append("最大外径").Append(",").Append("最小外径").Append(",").Append("平均外径").Append(",").Append("跳动率").Append(",").Append("结果(NG/OK)").Append(",").Append("检查时间").Append(",\r\n");
}
using (FileStream fs = new FileStream(paths, FileMode.Append))
{
using (StreamWriter sw = new StreamWriter(fs, UnicodeEncoding.GetEncoding("GB2312"))) //UnicodeEncoding.GetEncoding("GB2312")
{
sb.Append(CM.CmName).Append(",").Append(CM.MaxDiam).Append(",").Append(CM.MinDiam).Append(",").Append(CM.AverageDiam).Append(",").Append(CM.BeatRate).Append(",").Append(CM.Result).Append(",").Append(DateTime.Now.ToLongTimeString().ToString());
//将字符串流数据写入文件
sw.WriteLine(sb);
//刷新文件流
sw.Flush();
}
}
}
}
#endregion
#region 记录远程交互信息
/// <summary>
/// 记录远程交互信息
/// </summary>
/// <param name="str"></param>
private void RecordRemoteSensingLog(string str)
{
try
{
path = @"D:\\MesUploadLog\" + DateTime.Now.ToString("D") + "\\";
paths = path + this.StandName + ".txt";
//创建文件夹
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
//打开或创建文件
FS = File.Open(paths, FileMode.Append);
//获得字节数组
data = System.Text.Encoding.Default.GetBytes(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff") + "---" + str + "\r\n");
//开始写入
FS.Write(data, 0, data.Length);
//清空缓冲区、关闭流
FS.Flush();
FS.Close();
}
catch (Exception)
{
}
}
#endregion
}
}