init: 导入项目到 meswork Gitea
This commit is contained in:
308
DataMirrorTools_Simulator/Foundation/Base.Class/BasicData.cs
Normal file
308
DataMirrorTools_Simulator/Foundation/Base.Class/BasicData.cs
Normal file
@@ -0,0 +1,308 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace BasicData
|
||||
{
|
||||
/// <summary>
|
||||
/// 变量类型代码
|
||||
/// 101 合格数据变量
|
||||
/// 102 不合格数据变量
|
||||
/// 103 机床报警变量
|
||||
/// 1 MES通讯状态PLC
|
||||
///2 MES激发变量开始扫描
|
||||
///3 MES激发变量返修标志
|
||||
///4 MES通讯状态MES
|
||||
///5 MES激发变量扫描完成
|
||||
///6 MES激发变量允许工作
|
||||
///7 MES激发变量物料验证完毕
|
||||
///8 MES激发变量返修放行
|
||||
///9 MES发动机机型标志
|
||||
///10 MES发动机号
|
||||
///11 MES发动机机型
|
||||
///25 MES发动机追踪代码
|
||||
///12 机床状态变量
|
||||
///13 MES激发变量托盘到位离开
|
||||
///14 监控系统通讯状态PLC
|
||||
///15 监控系统通讯状态MIS
|
||||
///16 加工时间变量激发
|
||||
///17 加工时间变量目标时间
|
||||
///18 加工时间变量实际时间
|
||||
///19 质量数据可以读数据
|
||||
///21 质量数据总成合格标志
|
||||
///20 MES保存完数据
|
||||
///26 加工时间保存完数据
|
||||
///22 质量数据发动机机型标志
|
||||
///23 质量数据发动机号
|
||||
///24 质量数据发动机机型
|
||||
///27 操作者工号
|
||||
///28 订单号
|
||||
///29 工位具体零件合格标志
|
||||
/// </summary>
|
||||
public struct QualityDataType
|
||||
{
|
||||
/// <summary>
|
||||
/// 变量类型代码
|
||||
/// 101 合格数据变量
|
||||
/// 102 不合格数据变量
|
||||
/// 103 机床报警变量
|
||||
/// 1 MES通讯状态PLC
|
||||
///2 MES激发变量开始扫描
|
||||
///3 MES激发变量返修标志
|
||||
///4 MES通讯状态MES
|
||||
///5 MES激发变量扫描完成
|
||||
///6 MES激发变量允许工作
|
||||
///7 MES激发变量物料验证完毕
|
||||
///8 MES激发变量返修放行
|
||||
///9 MES发动机机型标志
|
||||
///10 MES发动机号
|
||||
///11 MES发动机机型
|
||||
///25 MES发动机追踪代码
|
||||
///12 机床状态变量
|
||||
///13 MES激发变量托盘到位离开
|
||||
///14 监控系统通讯状态PLC
|
||||
///15 监控系统通讯状态MIS
|
||||
///16 加工时间变量激发
|
||||
///17 加工时间变量目标时间
|
||||
///18 加工时间变量实际时间
|
||||
///19 质量数据可以读数据
|
||||
///21 质量数据总成合格标志
|
||||
///20 MES保存完数据
|
||||
///26 加工时间保存完数据
|
||||
///22 质量数据发动机机型标志
|
||||
///23 质量数据发动机号
|
||||
///24 质量数据发动机机型
|
||||
///27 操作者工号
|
||||
///28 订单号
|
||||
/// 10 前提条件不满足
|
||||
///20 不合格
|
||||
///251 合格
|
||||
///254 直通
|
||||
///255 不要求工作
|
||||
///253 备用工位完成
|
||||
///254 返修工位完成
|
||||
///0 未定义
|
||||
///29 工位具体零件合格标志
|
||||
/// </summary>
|
||||
public int tagValueType;
|
||||
/// <summary>
|
||||
/// 变量类型
|
||||
/// </summary>
|
||||
public int tagTypeID;
|
||||
/// <summary>
|
||||
/// 工位号
|
||||
/// </summary>
|
||||
public string opName;
|
||||
/// <summary>
|
||||
/// 变量代码
|
||||
/// </summary>
|
||||
public int tagID;
|
||||
/// <summary>
|
||||
/// 变量值
|
||||
/// </summary>
|
||||
public object tagValue;
|
||||
/// <summary>
|
||||
/// 数据质量代码
|
||||
/// 192 数据正常
|
||||
/// </summary>
|
||||
public int tagQuality;
|
||||
/// <summary>
|
||||
/// 列位置(1,2,3,4)
|
||||
/// </summary>
|
||||
public int tagOrderBy;
|
||||
/// <summary>
|
||||
/// 变量排序(1:拧矩,2:转角)
|
||||
/// </summary>
|
||||
public int tagItemOrderBy;
|
||||
/// <summary>
|
||||
/// 变量代码与变量特点
|
||||
/// 0:没定义1:工位合格标志2:需要合格标志的测量数据3:每个工位的合格标志4:物料5:IQA码6:压装数据
|
||||
/// 7:压装合格标志8:(自动拧紧)工位合格标志
|
||||
/// </summary>
|
||||
public int tagProperty;
|
||||
/// <summary>
|
||||
/// 合格标志(0,1)
|
||||
/// </summary>
|
||||
public int isGoodBad;
|
||||
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class jsonobj
|
||||
{
|
||||
public string Type;
|
||||
public string Name;
|
||||
public string Param;
|
||||
public string Pagination;
|
||||
public bool HasReturn;
|
||||
}
|
||||
|
||||
|
||||
[Serializable]
|
||||
public class jsonobjV2
|
||||
{
|
||||
public string Type;
|
||||
public string Name;
|
||||
public object Param;
|
||||
public string Pagination;
|
||||
public bool HasReturn;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class MesBasicData
|
||||
{
|
||||
/// <summary>
|
||||
/// 通过指定路径将 文本文件 转换成 DataTable
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
public static DataTable GetBasicData(string fileName)
|
||||
{
|
||||
string[] strFileLines = File.ReadAllLines(fileName, Encoding.Default);
|
||||
if (strFileLines.Length < 2) return null;
|
||||
string[] strFieldName = strFileLines[0].Split('\t');
|
||||
DataTable dtBasicData;
|
||||
dtBasicData = new DataTable();
|
||||
for (int i = 0; i < strFieldName.Length; i++)
|
||||
{
|
||||
dtBasicData.Columns.Add(strFieldName[i]);
|
||||
}
|
||||
DataRow dr = dtBasicData.NewRow();
|
||||
|
||||
|
||||
for (int i = 1; i < strFileLines.Length; i++)
|
||||
{
|
||||
string[] strColumns = strFileLines[i].Split('\t');
|
||||
for (int j = 0; j < strColumns.Length; j++)
|
||||
{
|
||||
strColumns[j] = strColumns[j].Trim('"').TrimEnd('"');
|
||||
dr[j] = strColumns[j];
|
||||
}
|
||||
if (dr["是否启用"].ToString() == "1")
|
||||
{
|
||||
dtBasicData.Rows.Add(strColumns);
|
||||
|
||||
}
|
||||
}
|
||||
return dtBasicData;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class DataTableSelect
|
||||
{
|
||||
static public DataTable SelectTable(DataTable SourceTable, string filterString)
|
||||
{
|
||||
DataTable dt = SourceTable.Clone();
|
||||
var rows = SourceTable.Select(filterString);
|
||||
|
||||
if (rows != null && rows.Length > 0)
|
||||
{
|
||||
foreach (DataRow row in rows)
|
||||
{
|
||||
dt.ImportRow(row);
|
||||
}
|
||||
}
|
||||
|
||||
return dt;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回执行Select distinct后的DataTable
|
||||
/// </summary>
|
||||
/// <param name="SourceTable">源数据表</param>
|
||||
/// <param name="filterString">字段集</param>
|
||||
/// <param name="FieldNames">字段集</param>
|
||||
/// <returns></returns>
|
||||
static public DataTable SelectDistinctGroup(DataTable SourceTable, string filterString, params string[] FieldNames)
|
||||
{
|
||||
DataTable dtFilter;
|
||||
DataTable newTable;
|
||||
|
||||
dtFilter = SelectTable(SourceTable, filterString);
|
||||
|
||||
newTable = SelectDistinct(dtFilter, FieldNames);
|
||||
return newTable;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回执行Select distinct后的DataTable
|
||||
/// </summary>
|
||||
/// <param name="SourceTable">源数据表</param>
|
||||
/// <param name="FieldNames">字段集</param>
|
||||
/// <returns></returns>
|
||||
static public DataTable SelectDistinct(DataTable SourceTable, params string[] FieldNames)
|
||||
{
|
||||
object[] lastValues;
|
||||
DataTable newTable;
|
||||
DataRow[] orderedRows;
|
||||
|
||||
if (FieldNames == null || FieldNames.Length == 0)
|
||||
throw new ArgumentNullException("FieldNames");
|
||||
|
||||
lastValues = new object[FieldNames.Length];
|
||||
newTable = new DataTable();
|
||||
|
||||
foreach (string fieldName in FieldNames)
|
||||
newTable.Columns.Add(fieldName, SourceTable.Columns[fieldName].DataType);
|
||||
|
||||
orderedRows = SourceTable.Select("", string.Join(",", FieldNames));
|
||||
|
||||
foreach (DataRow row in orderedRows)
|
||||
{
|
||||
if (!fieldValuesAreEqual(lastValues, row, FieldNames))
|
||||
{
|
||||
newTable.Rows.Add(createRowClone(row, newTable.NewRow(), FieldNames));
|
||||
|
||||
setLastValues(lastValues, row, FieldNames);
|
||||
}
|
||||
}
|
||||
|
||||
return newTable;
|
||||
}
|
||||
|
||||
static private bool fieldValuesAreEqual(object[] lastValues, DataRow currentRow, string[] fieldNames)
|
||||
{
|
||||
bool areEqual = true;
|
||||
|
||||
for (int i = 0; i < fieldNames.Length; i++)
|
||||
{
|
||||
if (lastValues[i] == null || !lastValues[i].Equals(currentRow[fieldNames[i]]))
|
||||
{
|
||||
areEqual = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return areEqual;
|
||||
}
|
||||
|
||||
static private DataRow createRowClone(DataRow sourceRow, DataRow newRow, string[] fieldNames)
|
||||
{
|
||||
foreach (string field in fieldNames)
|
||||
newRow[field] = sourceRow[field];
|
||||
|
||||
return newRow;
|
||||
}
|
||||
|
||||
static private void setLastValues(object[] lastValues, DataRow sourceRow, string[] fieldNames)
|
||||
{
|
||||
for (int i = 0; i < fieldNames.Length; i++)
|
||||
lastValues[i] = sourceRow[fieldNames[i]];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user