添加项目文件。
This commit is contained in:
94
CowainHmi/Alarm/AddRowCount.Designer.cs
generated
Normal file
94
CowainHmi/Alarm/AddRowCount.Designer.cs
generated
Normal file
@@ -0,0 +1,94 @@
|
||||
namespace CowainHmi.Alarm
|
||||
{
|
||||
partial class AddRowCount
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.rowCountInput = new System.Windows.Forms.NumericUpDown();
|
||||
((System.ComponentModel.ISupportInitialize)(this.rowCountInput)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(48, 64);
|
||||
this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(87, 16);
|
||||
this.label1.TabIndex = 0;
|
||||
this.label1.Text = "增加的行数";
|
||||
//
|
||||
// button1
|
||||
//
|
||||
this.button1.Location = new System.Drawing.Point(144, 121);
|
||||
this.button1.Name = "button1";
|
||||
this.button1.Size = new System.Drawing.Size(100, 30);
|
||||
this.button1.TabIndex = 2;
|
||||
this.button1.Text = "确定";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
this.button1.Click += new System.EventHandler(this.button1_Click);
|
||||
//
|
||||
// rowCountInput
|
||||
//
|
||||
this.rowCountInput.Location = new System.Drawing.Point(144, 60);
|
||||
this.rowCountInput.Name = "rowCountInput";
|
||||
this.rowCountInput.Size = new System.Drawing.Size(120, 26);
|
||||
this.rowCountInput.TabIndex = 3;
|
||||
this.rowCountInput.Value = new decimal(new int[] {
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
//
|
||||
// AddRowCount
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(345, 195);
|
||||
this.Controls.Add(this.rowCountInput);
|
||||
this.Controls.Add(this.button1);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Font = new System.Drawing.Font("宋体", 12F);
|
||||
this.Margin = new System.Windows.Forms.Padding(4);
|
||||
this.Name = "AddRowCount";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "增加的行数";
|
||||
((System.ComponentModel.ISupportInitialize)(this.rowCountInput)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.Button button1;
|
||||
private System.Windows.Forms.NumericUpDown rowCountInput;
|
||||
}
|
||||
}
|
||||
26
CowainHmi/Alarm/AddRowCount.cs
Normal file
26
CowainHmi/Alarm/AddRowCount.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
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 CowainHmi.Alarm
|
||||
{
|
||||
public partial class AddRowCount : Form
|
||||
{
|
||||
public AddRowCount()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
FrmEditAlarmTable.rowCount = (int)rowCountInput.Value;
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
120
CowainHmi/Alarm/AddRowCount.resx
Normal file
120
CowainHmi/Alarm/AddRowCount.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
441
CowainHmi/Alarm/AlarmExcelHelper.cs
Normal file
441
CowainHmi/Alarm/AlarmExcelHelper.cs
Normal file
@@ -0,0 +1,441 @@
|
||||
using PCHMI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Data.OleDb;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
|
||||
namespace CowainHmi.Alarm
|
||||
{
|
||||
public class AlarmExcelHelper
|
||||
{
|
||||
public static DataTable ReadReleaseExcel<T>(string fileName, BindingList<T> bindingList)
|
||||
{
|
||||
OleDbConnection oleDbConnection = null;
|
||||
try
|
||||
{
|
||||
string text = new FILE().GET_RELEASE_DIR() + $"\\DATA\\{fileName}.xls";
|
||||
//string text = Environment.CurrentDirectory + $"\\DATA\\{fileName}.xls";
|
||||
if (!File.Exists(text))
|
||||
{
|
||||
SaveBindingListToExcel(bindingList, fileName);
|
||||
}
|
||||
if (File.Exists(text))
|
||||
{
|
||||
OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
|
||||
oleDbConnection = new OleDbConnection(CONFIG.Is64Str() + "Data Source=" + text + ";Extended Properties=Excel 8.0;");
|
||||
try
|
||||
{
|
||||
oleDbConnection.Open();
|
||||
OleDbCommand selectCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", oleDbConnection);
|
||||
dataAdapter.SelectCommand = selectCommand;
|
||||
DataTable dt = new DataTable();
|
||||
dataAdapter.Fill(dt);
|
||||
return dt;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
new PClass().WErrTxt("读取报警表格异常:" + ex.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
oleDbConnection.Close();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
oleDbConnection?.Close();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static DataTable ReadErrExcel(string fileName)
|
||||
{
|
||||
OleDbConnection oleDbConnection = null;
|
||||
try
|
||||
{
|
||||
string text = System.Windows.Forms.Application.StartupPath + $"\\DATA\\{fileName}.xls";
|
||||
if (File.Exists(text))
|
||||
{
|
||||
OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
|
||||
oleDbConnection = new OleDbConnection(CONFIG.Is64Str() + "Data Source=" + text + ";Extended Properties=Excel 8.0;");
|
||||
try
|
||||
{
|
||||
oleDbConnection.Open();
|
||||
OleDbCommand selectCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", oleDbConnection);
|
||||
dataAdapter.SelectCommand = selectCommand;
|
||||
DataTable dt = new DataTable();
|
||||
dataAdapter.Fill(dt);
|
||||
return dt;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
new PClass().WErrTxt("读取报警表格异常:" + ex.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
oleDbConnection.Close();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
oleDbConnection?.Close();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 更新实时报警表格
|
||||
/// </summary>
|
||||
public static void UpdateAlarmRT(string pid, string type, string group, string id, string error, bool rw, string fileName)
|
||||
{
|
||||
OleDbConnection oleDbConnection = null;
|
||||
try
|
||||
{
|
||||
if (PClass.SystemRun)
|
||||
{
|
||||
string text = System.Windows.Forms.Application.StartupPath + $"\\UDTA\\{fileName}.xls";
|
||||
if (!File.Exists(text))
|
||||
{
|
||||
new JUDGE_DIR().CreateExcelFile(text, "AlarmLog", new string[]
|
||||
{
|
||||
"PLC",
|
||||
"DTIM",
|
||||
"报警类别",
|
||||
"报警组",
|
||||
"ID",
|
||||
"ErrText",
|
||||
"TP",
|
||||
});
|
||||
}
|
||||
oleDbConnection = new OleDbConnection(CONFIG.Is64Str() + "Data Source=" + text + ";Extended Properties=Excel 8.0;");
|
||||
oleDbConnection.Open();
|
||||
DataTable dt = GetAlarmRT(fileName);
|
||||
var dr = dt.Select($"报警类别='{type}' and 报警组='{group}' and ID='{id}'").FirstOrDefault();
|
||||
string sql = String.Empty;
|
||||
if (dr == null)
|
||||
{
|
||||
if (rw)
|
||||
{
|
||||
sql =
|
||||
$"insert into [AlarmLog$] (PLC,报警类别,报警组,ID,DTIM,TP,ErrText) values('{pid}','{type}','{group}','{id}','{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fffff")}','1','{error}')";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (rw)
|
||||
{
|
||||
//更新记录
|
||||
sql =
|
||||
$"UPDATE [AlarmLog$] SET DTIM='{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fffff")}',TP='1' WHERE 报警类别='{type}' and 报警组='{group}' and ID='{id}' ";
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//删除记录
|
||||
sql =
|
||||
$"UPDATE [AlarmLog$] SET DTIM='{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fffff")}',TP='0' WHERE 报警类别='{type}' and 报警组='{group}' and ID='{id}' ";
|
||||
}
|
||||
|
||||
}
|
||||
if (!string.IsNullOrEmpty(sql))
|
||||
{
|
||||
new OleDbCommand(sql, oleDbConnection).ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
oleDbConnection?.Close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static DataTable GetAlarmRT(string fileName)
|
||||
{
|
||||
OleDbConnection oleDbConnection = null;
|
||||
try
|
||||
{
|
||||
string text = System.Windows.Forms.Application.StartupPath + $"\\UDTA\\{fileName}.xls";
|
||||
if (File.Exists(text))
|
||||
{
|
||||
|
||||
OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
|
||||
oleDbConnection = new OleDbConnection(CONFIG.Is64Str() + "Data Source=" + text + ";Extended Properties=Excel 8.0;");
|
||||
try
|
||||
{
|
||||
oleDbConnection.Open();
|
||||
OleDbCommand selectCommand = new OleDbCommand("SELECT * FROM [AlarmLog$]", oleDbConnection);
|
||||
dataAdapter.SelectCommand = selectCommand;
|
||||
DataTable dt = new DataTable();
|
||||
dataAdapter.Fill(dt);
|
||||
return dt;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
new PClass().WErrTxt("读取实时报警记录错误:" + ex.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
oleDbConnection.Close();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
oleDbConnection?.Close();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static void SaveAlarmLog(string pid, string type, string group, string id, string tp, string error)
|
||||
{
|
||||
OleDbConnection oleDbConnection = null;
|
||||
try
|
||||
{
|
||||
if (PClass.SystemRun)
|
||||
{
|
||||
string text = System.Windows.Forms.Application.StartupPath + "\\UDTA\\AlarmDirectory";
|
||||
text = text + "\\" + DateTime.Now.ToLocalTime().ToString("yyMMdd") + ".xls";
|
||||
if (!File.Exists(text))
|
||||
{
|
||||
new JUDGE_DIR().CreateExcelFile(text, "AlarmLog", new string[]
|
||||
{
|
||||
"PLC",
|
||||
"报警类别",
|
||||
"报警组",
|
||||
"ID",
|
||||
"DTIM",
|
||||
"TP",
|
||||
"ErrText"
|
||||
});
|
||||
}
|
||||
oleDbConnection = new OleDbConnection(CONFIG.Is64Str() + "Data Source=" + text + ";Extended Properties=Excel 8.0;");
|
||||
oleDbConnection.Open();
|
||||
string sql =
|
||||
$"insert into [AlarmLog$] (PLC,报警类别,报警组,ID,DTIM,TP,ErrText) values('{pid}','{type}','{group}','{id}','{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fffff")}','{tp}','{error}')";
|
||||
new OleDbCommand(sql, oleDbConnection).ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
oleDbConnection?.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public static DataTable GetAlarmLog(string fileName)
|
||||
{
|
||||
OleDbConnection oleDbConnection = null;
|
||||
|
||||
string text = System.Windows.Forms.Application.StartupPath + "\\UDTA\\AlarmDirectory";//Application.StartupPath为文件执行路径
|
||||
text = text + "\\" + fileName + ".xls";
|
||||
if (File.Exists(text))//判断文件是否存在
|
||||
{
|
||||
OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
|
||||
oleDbConnection = new OleDbConnection(CONFIG.Is64Str() + "Data Source=" + text + ";Extended Properties=Excel 8.0;");
|
||||
try
|
||||
{
|
||||
oleDbConnection.Open();
|
||||
OleDbCommand selectCommand = new OleDbCommand("SELECT * FROM [AlarmLog$]", oleDbConnection);
|
||||
dataAdapter.SelectCommand = selectCommand;
|
||||
DataTable dt = new DataTable();
|
||||
dataAdapter.Fill(dt);
|
||||
return dt;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
new PClass().WErrTxt("读取历史报警记录错误:" + ex.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
oleDbConnection.Close();
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static BindingList<T> GetDataList<T>(DataTable dt)
|
||||
{
|
||||
if (dt == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var list = new BindingList<T>();
|
||||
var plist = new List<PropertyInfo>(typeof(T).GetProperties());
|
||||
foreach (DataRow item in dt.Rows)
|
||||
{
|
||||
T s = Activator.CreateInstance<T>();
|
||||
for (int i = 0; i < dt.Columns.Count; i++)
|
||||
{
|
||||
PropertyInfo info = plist.Find(p => p.Name == dt.Columns[i].ColumnName);
|
||||
if (info != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!Convert.IsDBNull(item[i]))
|
||||
{
|
||||
object v = null;
|
||||
if (info.PropertyType.ToString().Contains("System.Nullable"))
|
||||
{
|
||||
v = Convert.ChangeType(item[i], Nullable.GetUnderlyingType(info.PropertyType));
|
||||
}
|
||||
else
|
||||
{
|
||||
v = Convert.ChangeType(item[i], info.PropertyType);
|
||||
}
|
||||
info.SetValue(s, v, null);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
list.Add(s);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public class EnumItemModel<T>
|
||||
{
|
||||
public string EnumName { get; set; }
|
||||
public int EnumValue { get; set; }
|
||||
public string Description { get; set; }
|
||||
public T EnumItem { get; set; }
|
||||
}
|
||||
|
||||
public static List<EnumItemModel<T>> GetEnumItems<T>() where T : Enum
|
||||
{
|
||||
// 获取枚举的类型信息
|
||||
Type enumType = typeof(T);
|
||||
|
||||
// 获取枚举的名称数组和值数组
|
||||
string[] enumNames = Enum.GetNames(enumType);
|
||||
Array enumValues = Enum.GetValues(enumType);
|
||||
|
||||
// 创建一个列表来存储枚举项模型对象
|
||||
List<EnumItemModel<T>> enumItems = new List<EnumItemModel<T>>();
|
||||
|
||||
// 遍历枚举的名称和值数组
|
||||
for (int i = 0; i < enumNames.Length; i++)
|
||||
{
|
||||
string name = enumNames[i];
|
||||
//int value = 0;
|
||||
int value = Convert.ToInt32(enumValues.GetValue(i));
|
||||
string description = GetEnumDescription(enumType, name);
|
||||
|
||||
// 创建一个枚举项模型对象,并将其添加到列表中
|
||||
EnumItemModel<T> enumItem = new EnumItemModel<T>
|
||||
{
|
||||
EnumName = name,
|
||||
EnumValue = value,
|
||||
Description = description,
|
||||
EnumItem = (T)Enum.Parse(typeof(T), name)
|
||||
};
|
||||
enumItems.Add(enumItem);
|
||||
}
|
||||
|
||||
// 返回枚举项列表
|
||||
return enumItems;
|
||||
}
|
||||
public static string GetEnumDescription(Type enumType, string enumName)
|
||||
{
|
||||
// 使用反射获取枚举项的描述属性
|
||||
FieldInfo fieldInfo = enumType.GetField(enumName);
|
||||
DescriptionAttribute[] attributes = (DescriptionAttribute[])fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
|
||||
|
||||
// 如果存在描述属性,则返回描述值,否则返回空字符串
|
||||
return (attributes.Length > 0) ? attributes[0].Description : string.Empty;
|
||||
}
|
||||
|
||||
public static BindingList<T> DeepCopyList<T>(BindingList<T> other)
|
||||
{
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
BinaryFormatter formatter = new BinaryFormatter();
|
||||
formatter.Serialize(ms, other);
|
||||
ms.Position = 0;
|
||||
return (BindingList<T>)formatter.Deserialize(ms);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SaveBindingListToExcel<T>(BindingList<T> bindingList, string fileName)
|
||||
{
|
||||
string filePath = new FILE().GET_RELEASE_DIR() + $"\\DATA\\{fileName}.xls";
|
||||
//string filePath = Environment.CurrentDirectory + $"\\DATA\\{fileName}.xls";
|
||||
File.Delete(filePath);
|
||||
// 创建数据表
|
||||
DataTable dataTable = new DataTable(typeof(T).Name);
|
||||
|
||||
// 添加列
|
||||
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(T));
|
||||
foreach (PropertyDescriptor prop in properties)
|
||||
{
|
||||
dataTable.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
|
||||
}
|
||||
|
||||
// 添加行
|
||||
foreach (T item in bindingList)
|
||||
{
|
||||
DataRow row = dataTable.NewRow();
|
||||
foreach (PropertyDescriptor prop in properties)
|
||||
{
|
||||
row[prop.Name] = prop.GetValue(item) ?? DBNull.Value;
|
||||
}
|
||||
dataTable.Rows.Add(row);
|
||||
}
|
||||
// 使用OleDb写入Excel
|
||||
using (OleDbConnection conn = new OleDbConnection(CONFIG.Is64Str() + "Data Source=" + filePath + ";Extended Properties=Excel 8.0;"))
|
||||
{
|
||||
conn.Open();
|
||||
string sheetName = "Sheet1";
|
||||
using (OleDbCommand cmd = new OleDbCommand($"CREATE TABLE [{sheetName}] ({string.Join(",", dataTable.Columns.Cast<DataColumn>().Select(c => $"[{c.ColumnName}] {GetOleDbType(c.DataType)}"))})", conn))
|
||||
{
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
using (OleDbDataAdapter adapter = new OleDbDataAdapter($"SELECT * FROM [{sheetName}]", conn))
|
||||
{
|
||||
using (OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter))
|
||||
{
|
||||
adapter.Update(dataTable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetOleDbType(Type dataType)
|
||||
{
|
||||
if (dataType == typeof(string))
|
||||
return "Text";
|
||||
else if (dataType == typeof(int))
|
||||
return "Integer";
|
||||
else if (dataType == typeof(double))
|
||||
return "Double";
|
||||
else if (dataType == typeof(DateTime))
|
||||
return "DateTime";
|
||||
else
|
||||
return "Variant";
|
||||
}
|
||||
}
|
||||
}
|
||||
62
CowainHmi/Alarm/AlarmHistory.cs
Normal file
62
CowainHmi/Alarm/AlarmHistory.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using CowainHmi.Alarm;
|
||||
using PCHMI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Data.OleDb;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace CowainHmi
|
||||
{
|
||||
[DefaultEvent(""), ToolboxBitmap(typeof(AlarmHistory), "alarm.png")]
|
||||
public partial class AlarmHistory : UserControl
|
||||
{
|
||||
public AlarmHistory()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.dgvErr.AutoGenerateColumns = false;
|
||||
this.dtDate.Value = DateTime.Now;
|
||||
}
|
||||
private void btnUpdate_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (PClass.SystemRun)
|
||||
{
|
||||
string name = this.dtDate.Value.ToString("yyMMdd");
|
||||
this.dgvErr.DataSource = null;
|
||||
this.dgvErr.DataSource = AlarmExcelHelper.GetAlarmLog(name);
|
||||
}
|
||||
}
|
||||
|
||||
private void dgvErr_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
|
||||
{
|
||||
DgvRowPostPaint2(this.dgvErr, e);
|
||||
}
|
||||
public void DgvRowPostPaint2(DataGridView dgv, DataGridViewRowPostPaintEventArgs e)
|
||||
{
|
||||
Color color = Color.Black;
|
||||
string val = dgv.Rows[e.RowIndex].Cells[5].Value.ToString();
|
||||
if (val == "1")
|
||||
{
|
||||
color = Color.Red;
|
||||
}
|
||||
if (val == "0")
|
||||
{
|
||||
color = Color.Green;
|
||||
}
|
||||
dgv.Rows[e.RowIndex].DefaultCellStyle.ForeColor = color;
|
||||
new DataGridViewStyle().DgvRowPostPaint(dgv, e);
|
||||
}
|
||||
|
||||
private void dgvErr_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
|
||||
{
|
||||
e.CellStyle.SelectionForeColor = e.CellStyle.ForeColor;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
214
CowainHmi/Alarm/AlarmHistory.designer.cs
generated
Normal file
214
CowainHmi/Alarm/AlarmHistory.designer.cs
generated
Normal file
@@ -0,0 +1,214 @@
|
||||
|
||||
namespace CowainHmi
|
||||
{
|
||||
partial class AlarmHistory
|
||||
{
|
||||
/// <summary>
|
||||
/// 必需的设计器变量。
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// 清理所有正在使用的资源。
|
||||
/// </summary>
|
||||
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region 组件设计器生成的代码
|
||||
|
||||
/// <summary>
|
||||
/// 设计器支持所需的方法 - 不要修改
|
||||
/// 使用代码编辑器修改此方法的内容。
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
|
||||
this.dtDate = new System.Windows.Forms.DateTimePicker();
|
||||
this.panel1 = new System.Windows.Forms.Panel();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.btnUpdate = new System.Windows.Forms.Button();
|
||||
this.dgvErr = new System.Windows.Forms.DataGridView();
|
||||
this.DTIM = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.报警类别 = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.报警组 = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.ErrText = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.TP = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.panel1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dgvErr)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// dtDate
|
||||
//
|
||||
this.dtDate.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.dtDate.CalendarFont = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.dtDate.CustomFormat = "yyyy-MM-dd HH:mm";
|
||||
this.dtDate.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.dtDate.Format = System.Windows.Forms.DateTimePickerFormat.Short;
|
||||
this.dtDate.Location = new System.Drawing.Point(137, 8);
|
||||
this.dtDate.Name = "dtDate";
|
||||
this.dtDate.Size = new System.Drawing.Size(125, 26);
|
||||
this.dtDate.TabIndex = 8;
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
this.panel1.Controls.Add(this.label2);
|
||||
this.panel1.Controls.Add(this.label1);
|
||||
this.panel1.Controls.Add(this.btnUpdate);
|
||||
this.panel1.Controls.Add(this.dtDate);
|
||||
this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
|
||||
this.panel1.Location = new System.Drawing.Point(0, 0);
|
||||
this.panel1.Name = "panel1";
|
||||
this.panel1.Size = new System.Drawing.Size(766, 42);
|
||||
this.panel1.TabIndex = 0;
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.label2.Location = new System.Drawing.Point(387, 11);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(260, 19);
|
||||
this.label2.TabIndex = 11;
|
||||
this.label2.Text = "故障发生红色/故障离开绿色";
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.label1.Location = new System.Drawing.Point(3, 12);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(129, 19);
|
||||
this.label1.TabIndex = 10;
|
||||
this.label1.Text = "根据日期查询";
|
||||
//
|
||||
// btnUpdate
|
||||
//
|
||||
this.btnUpdate.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.btnUpdate.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.btnUpdate.Location = new System.Drawing.Point(661, 3);
|
||||
this.btnUpdate.Name = "btnUpdate";
|
||||
this.btnUpdate.Size = new System.Drawing.Size(97, 36);
|
||||
this.btnUpdate.TabIndex = 9;
|
||||
this.btnUpdate.Text = "查询";
|
||||
this.btnUpdate.UseVisualStyleBackColor = true;
|
||||
this.btnUpdate.Click += new System.EventHandler(this.btnUpdate_Click);
|
||||
//
|
||||
// dgvErr
|
||||
//
|
||||
this.dgvErr.AllowUserToAddRows = false;
|
||||
this.dgvErr.AllowUserToResizeRows = false;
|
||||
this.dgvErr.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dgvErr.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||
this.DTIM,
|
||||
this.报警类别,
|
||||
this.ID,
|
||||
this.报警组,
|
||||
this.ErrText,
|
||||
this.TP});
|
||||
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
|
||||
dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Window;
|
||||
dataGridViewCellStyle1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.ControlText;
|
||||
dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.GradientActiveCaption;
|
||||
dataGridViewCellStyle1.SelectionForeColor = System.Drawing.Color.Yellow;
|
||||
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
|
||||
this.dgvErr.DefaultCellStyle = dataGridViewCellStyle1;
|
||||
this.dgvErr.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.dgvErr.Location = new System.Drawing.Point(0, 42);
|
||||
this.dgvErr.Name = "dgvErr";
|
||||
this.dgvErr.ReadOnly = true;
|
||||
this.dgvErr.RowTemplate.Height = 23;
|
||||
this.dgvErr.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
|
||||
this.dgvErr.Size = new System.Drawing.Size(766, 571);
|
||||
this.dgvErr.TabIndex = 1;
|
||||
this.dgvErr.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.dgvErr_CellFormatting);
|
||||
this.dgvErr.RowPostPaint += new System.Windows.Forms.DataGridViewRowPostPaintEventHandler(this.dgvErr_RowPostPaint);
|
||||
//
|
||||
// DTIM
|
||||
//
|
||||
this.DTIM.DataPropertyName = "DTIM";
|
||||
this.DTIM.HeaderText = "报警时间";
|
||||
this.DTIM.Name = "DTIM";
|
||||
this.DTIM.ReadOnly = true;
|
||||
this.DTIM.Width = 200;
|
||||
//
|
||||
// 报警类别
|
||||
//
|
||||
this.报警类别.DataPropertyName = "报警类别";
|
||||
this.报警类别.HeaderText = "报警类别";
|
||||
this.报警类别.Name = "报警类别";
|
||||
this.报警类别.ReadOnly = true;
|
||||
//
|
||||
// ID
|
||||
//
|
||||
this.ID.DataPropertyName = "ID";
|
||||
this.ID.HeaderText = "报警编号";
|
||||
this.ID.Name = "ID";
|
||||
this.ID.ReadOnly = true;
|
||||
//
|
||||
// 报警组
|
||||
//
|
||||
this.报警组.DataPropertyName = "报警组";
|
||||
this.报警组.HeaderText = "报警组";
|
||||
this.报警组.Name = "报警组";
|
||||
this.报警组.ReadOnly = true;
|
||||
//
|
||||
// ErrText
|
||||
//
|
||||
this.ErrText.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
|
||||
this.ErrText.DataPropertyName = "ErrText";
|
||||
this.ErrText.HeaderText = "报警内容";
|
||||
this.ErrText.Name = "ErrText";
|
||||
this.ErrText.ReadOnly = true;
|
||||
//
|
||||
// TP
|
||||
//
|
||||
this.TP.DataPropertyName = "TP";
|
||||
this.TP.HeaderText = "类型";
|
||||
this.TP.Name = "TP";
|
||||
this.TP.ReadOnly = true;
|
||||
this.TP.Visible = false;
|
||||
//
|
||||
// AlarmHistory
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.Controls.Add(this.dgvErr);
|
||||
this.Controls.Add(this.panel1);
|
||||
this.Name = "AlarmHistory";
|
||||
this.Size = new System.Drawing.Size(766, 613);
|
||||
this.panel1.ResumeLayout(false);
|
||||
this.panel1.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dgvErr)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.DateTimePicker dtDate;
|
||||
private System.Windows.Forms.Panel panel1;
|
||||
private System.Windows.Forms.Button btnUpdate;
|
||||
private System.Windows.Forms.DataGridView dgvErr;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.Label label2;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn DTIM;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn 报警类别;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn ID;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn 报警组;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn ErrText;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn TP;
|
||||
}
|
||||
}
|
||||
138
CowainHmi/Alarm/AlarmHistory.resx
Normal file
138
CowainHmi/Alarm/AlarmHistory.resx
Normal file
@@ -0,0 +1,138 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="DTIM.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="报警类别.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ID.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="报警组.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ErrText.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="TP.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
</root>
|
||||
22
CowainHmi/Alarm/AlarmModel.cs
Normal file
22
CowainHmi/Alarm/AlarmModel.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CowainHmi.Alarm
|
||||
{
|
||||
public class AlarmModel
|
||||
{
|
||||
public int PLC { get; set; }
|
||||
public string Address { get; set; }
|
||||
public string VarType { get; set; }
|
||||
public int TP { get; set; }
|
||||
public int Group { get; set; }
|
||||
public string ErrCode { get; set; }
|
||||
public string Level { get; set; }
|
||||
public string[] Language { get; set; }
|
||||
public int CurValue { get; set; }
|
||||
public int LastValue { get; set; }
|
||||
}
|
||||
}
|
||||
61
CowainHmi/Alarm/AlarmNow.Designer.cs
generated
Normal file
61
CowainHmi/Alarm/AlarmNow.Designer.cs
generated
Normal file
@@ -0,0 +1,61 @@
|
||||
namespace CowainHmi.Alarm
|
||||
{
|
||||
partial class AlarmNow
|
||||
{
|
||||
/// <summary>
|
||||
/// 必需的设计器变量。
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// 清理所有正在使用的资源。
|
||||
/// </summary>
|
||||
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region 组件设计器生成的代码
|
||||
|
||||
/// <summary>
|
||||
/// 设计器支持所需的方法 - 不要修改
|
||||
/// 使用代码编辑器修改此方法的内容。
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.timer1 = new System.Windows.Forms.Timer(this.components);
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// timer1
|
||||
//
|
||||
this.timer1.Enabled = true;
|
||||
this.timer1.Interval = 200;
|
||||
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
|
||||
//
|
||||
// AlarmNow
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.BackColor = System.Drawing.SystemColors.Control;
|
||||
this.BackgroundImage = global::CowainHmi.Properties.Resources.alarm1;
|
||||
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.DoubleBuffered = true;
|
||||
this.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.Name = "AlarmNow";
|
||||
this.Size = new System.Drawing.Size(91, 75);
|
||||
this.Load += new System.EventHandler(this.AlarmNow_Load);
|
||||
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.AlarmNow_MouseDown);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
private System.Windows.Forms.Timer timer1;
|
||||
}
|
||||
}
|
||||
581
CowainHmi/Alarm/AlarmNow.cs
Normal file
581
CowainHmi/Alarm/AlarmNow.cs
Normal file
@@ -0,0 +1,581 @@
|
||||
using CowainHmi.UIEditor;
|
||||
using PCHMI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Design;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using System.Windows.Forms;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
|
||||
namespace CowainHmi.Alarm
|
||||
{
|
||||
public partial class AlarmNow : UserControl
|
||||
{
|
||||
private string fileName = "";
|
||||
[Browsable(true)]
|
||||
[Category("PCHMI"), Description("设置报警文件名称")]
|
||||
[Editor(typeof(AlarmUIEditor), typeof(UITypeEditor))]
|
||||
public string FileName
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.fileName;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.fileName = value;
|
||||
}
|
||||
}
|
||||
|
||||
private bool autoShow = true;
|
||||
|
||||
[Category("PCHMI"), Description("是否自动弹出报警窗口")]
|
||||
public bool AutoShow
|
||||
{
|
||||
get
|
||||
{
|
||||
return autoShow;
|
||||
}
|
||||
set
|
||||
{
|
||||
autoShow = value;
|
||||
}
|
||||
}
|
||||
|
||||
private bool linkErrEnable;
|
||||
|
||||
[Category("PCHMI"), Description("通讯报警是否捕获")]
|
||||
public bool LinkErrEnable
|
||||
{
|
||||
get
|
||||
{
|
||||
return linkErrEnable;
|
||||
}
|
||||
set
|
||||
{
|
||||
linkErrEnable = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private string upLoadAddr = "";
|
||||
[Category("PCHMI"), Description("数据上传命令地址")]
|
||||
[Editor(typeof(StringText), typeof(UITypeEditor))]
|
||||
public string UpLoadAddr
|
||||
{
|
||||
get
|
||||
{
|
||||
return upLoadAddr;
|
||||
}
|
||||
set
|
||||
{
|
||||
upLoadAddr = value;
|
||||
}
|
||||
}
|
||||
private string upCountAddr = "";
|
||||
[Category("PCHMI"), Description("数据上传计数地址")]
|
||||
[Editor(typeof(StringText), typeof(UITypeEditor))]
|
||||
public string UpCountAddr
|
||||
{
|
||||
get
|
||||
{
|
||||
return upCountAddr;
|
||||
}
|
||||
set
|
||||
{
|
||||
upCountAddr = value;
|
||||
}
|
||||
}
|
||||
private string levelAddr = "";
|
||||
[Category("PCHMI"), Description("报警等级地址")]
|
||||
[Editor(typeof(StringText), typeof(UITypeEditor))]
|
||||
public string LevelAddr
|
||||
{
|
||||
get
|
||||
{
|
||||
return levelAddr;
|
||||
}
|
||||
set
|
||||
{
|
||||
levelAddr = value;
|
||||
}
|
||||
}
|
||||
private string groupAddr = "";
|
||||
[Category("PCHMI"), Description("报警组地址")]
|
||||
[Editor(typeof(StringText), typeof(UITypeEditor))]
|
||||
public string GroupAddr
|
||||
{
|
||||
get
|
||||
{
|
||||
return groupAddr;
|
||||
}
|
||||
set
|
||||
{
|
||||
groupAddr = value;
|
||||
}
|
||||
}
|
||||
private string idAddr = "";
|
||||
[Category("PCHMI"), Description("报警ID地址")]
|
||||
[Editor(typeof(StringText), typeof(UITypeEditor))]
|
||||
public string IdAddr
|
||||
{
|
||||
get
|
||||
{
|
||||
return idAddr;
|
||||
}
|
||||
set
|
||||
{
|
||||
idAddr = value;
|
||||
}
|
||||
}
|
||||
private string sd1Addr = "";
|
||||
[Category("PCHMI"), Description("报警SD1地址")]
|
||||
[Editor(typeof(StringText), typeof(UITypeEditor))]
|
||||
public string Sd1Addr
|
||||
{
|
||||
get
|
||||
{
|
||||
return sd1Addr;
|
||||
}
|
||||
set
|
||||
{
|
||||
sd1Addr = value;
|
||||
}
|
||||
}
|
||||
private string sd2Addr = "";
|
||||
[Category("PCHMI"), Description("报警SD2地址")]
|
||||
[Editor(typeof(StringText), typeof(UITypeEditor))]
|
||||
public string Sd2Addr
|
||||
{
|
||||
get
|
||||
{
|
||||
return sd2Addr;
|
||||
}
|
||||
set
|
||||
{
|
||||
sd2Addr = value;
|
||||
}
|
||||
}
|
||||
private string sd3Addr = "";
|
||||
[Category("PCHMI"), Description("报警SD3地址")]
|
||||
[Editor(typeof(StringText), typeof(UITypeEditor))]
|
||||
public string Sd3Addr
|
||||
{
|
||||
get
|
||||
{
|
||||
return sd3Addr;
|
||||
}
|
||||
set
|
||||
{
|
||||
sd3Addr = value;
|
||||
}
|
||||
}
|
||||
private string errTextAddr = "";
|
||||
[Category("PCHMI"), Description("报警文本地址")]
|
||||
[Editor(typeof(StringText), typeof(UITypeEditor))]
|
||||
public string ErrTextAddr
|
||||
{
|
||||
get
|
||||
{
|
||||
return errTextAddr;
|
||||
}
|
||||
set
|
||||
{
|
||||
errTextAddr = value;
|
||||
}
|
||||
}
|
||||
|
||||
private string retAddr = "";
|
||||
[Category("PCHMI"), Description("报警反馈命令地址")]
|
||||
[Editor(typeof(StringText), typeof(UITypeEditor))]
|
||||
public string RetAddr
|
||||
{
|
||||
get
|
||||
{
|
||||
return retAddr;
|
||||
}
|
||||
set
|
||||
{
|
||||
retAddr = value;
|
||||
}
|
||||
}
|
||||
private string retCountAddr = "";
|
||||
[Category("PCHMI"), Description("报警反馈计数地址")]
|
||||
[Editor(typeof(StringText), typeof(UITypeEditor))]
|
||||
public string RetCountAddr
|
||||
{
|
||||
get
|
||||
{
|
||||
return retCountAddr;
|
||||
}
|
||||
set
|
||||
{
|
||||
retCountAddr = value;
|
||||
}
|
||||
}
|
||||
|
||||
private int plcId = 0;
|
||||
[Category("PCHMI"), Description("PLC编号")]
|
||||
public int PLCId
|
||||
{
|
||||
get
|
||||
{
|
||||
return plcId;
|
||||
}
|
||||
set
|
||||
{
|
||||
plcId = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int ErrorCount { get; private set; }
|
||||
public bool Error { get; private set; }
|
||||
private int retCountSave;
|
||||
private bool newError;
|
||||
private bool chgError;
|
||||
private DataTable _errTable = new DataTable();
|
||||
private List<AlarmModel> _errList = new List<AlarmModel>();
|
||||
public AlarmNow()
|
||||
{
|
||||
InitializeComponent();
|
||||
_errTable.Columns.Add("PLC", typeof(string));
|
||||
_errTable.Columns.Add("DTIM", typeof(string));
|
||||
_errTable.Columns.Add("报警类别", typeof(string));
|
||||
_errTable.Columns.Add("报警组", typeof(string));
|
||||
_errTable.Columns.Add("ID", typeof(string));
|
||||
_errTable.Columns.Add("ErrText", typeof(string));
|
||||
_errTable.Columns.Add("TP", typeof(string));
|
||||
// 确保控件重绘时调用OnPaint
|
||||
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
|
||||
}
|
||||
|
||||
private void AlarmNow_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(FileName))
|
||||
{
|
||||
FileName = this.Name;
|
||||
}
|
||||
InitErrExcel();
|
||||
//刚打开时加载实时报警表格
|
||||
var rt = AlarmExcelHelper.GetAlarmRT(FileName);
|
||||
if (rt != null)
|
||||
{
|
||||
var list = rt.Select("TP='1'");
|
||||
foreach (var item in list)
|
||||
{
|
||||
_errTable.Rows.Add(item.ItemArray);
|
||||
}
|
||||
}
|
||||
//初始读一次,相当于注册变量
|
||||
ushort level = PCHMI.RT.GET_UINT16(PLCId, LevelAddr);
|
||||
ushort group = PCHMI.RT.GET_UINT16(PLCId, GroupAddr);
|
||||
int id = PCHMI.RT.GET_UINT16(PLCId, IdAddr) + 10000;
|
||||
short sd1 = PCHMI.RT.GET_INT16(PLCId, Sd1Addr);
|
||||
int sd2 = PCHMI.RT.GET_INT32(PLCId, Sd2Addr);
|
||||
float sd3 = PCHMI.RT.GET_F32(PLCId, Sd3Addr);
|
||||
string errText = PCHMI.RT.GET_SIEMENS_STRING(PLCId, ErrTextAddr, 100);
|
||||
ushort count = PCHMI.RT.GET_UINT16(PLCId, UpCountAddr);
|
||||
short upLoad = PCHMI.RT.GET_INT16(PLCId, UpLoadAddr);
|
||||
timer1.Enabled = true;
|
||||
}
|
||||
|
||||
private void InitErrExcel()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(FileName))
|
||||
{
|
||||
//读取报警表格文件
|
||||
DataTable _errExcel = AlarmExcelHelper.ReadErrExcel(FileName);
|
||||
if (_errExcel != null && _errExcel.Rows.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < _errExcel.Rows.Count; i++)
|
||||
{
|
||||
DataRow row = _errExcel.Rows[i];
|
||||
AlarmModel model = new AlarmModel();
|
||||
model.PLC = Convert.ToInt32(row["PLC"]);
|
||||
model.VarType = row["类型"].ToString();
|
||||
model.Address = row["地址"].ToString();
|
||||
model.ErrCode = row["代码"].ToString();
|
||||
model.Level = row["等级"].ToString();
|
||||
model.Language = new string[] {
|
||||
row["语言1"].ToString(),
|
||||
row["语言2"].ToString(),
|
||||
row["语言3"].ToString(),
|
||||
row["语言4"].ToString(),
|
||||
row["语言5"].ToString(),
|
||||
row["语言6"].ToString(),
|
||||
row["语言7"].ToString(),
|
||||
row["语言8"].ToString()
|
||||
};
|
||||
if (!int.TryParse(row["触发条件"].ToString(), out int tp))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
model.TP = tp;
|
||||
if (!int.TryParse(row["报警组"].ToString(), out int group))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
model.Group = group;
|
||||
_errList.Add(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool isFlg = false;
|
||||
private void timer1_Tick(object sender, EventArgs e)
|
||||
{
|
||||
if (isFlg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
isFlg = true;
|
||||
if (this.DesignMode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!PClass.SystemRun)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//通讯报警
|
||||
if (LinkErrEnable)
|
||||
{
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
if (!PClass.IsPlcLink(i))
|
||||
{
|
||||
//报警发生,查询表格中是否存在此报警
|
||||
var dr = _errTable.Select($"报警类别='{AlarmType.错误.ToString()}' and 报警组='S' and ID='0'").FirstOrDefault();
|
||||
if (dr == null)
|
||||
{
|
||||
//添加报警到table中
|
||||
_errTable.Rows.Add(new object[]
|
||||
{
|
||||
PLCId.ToString(),
|
||||
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fffff"),
|
||||
AlarmType.错误.ToString(),//错误类型
|
||||
"S",//组
|
||||
"0",//ID
|
||||
$"PLC{PLCId},连接异常", //错误信息
|
||||
"1"
|
||||
});
|
||||
newError = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//通讯报警离开
|
||||
var dr = _errTable.Select($"报警类别='{AlarmType.错误.ToString()}' and 报警组='S' and ID='0'").FirstOrDefault();
|
||||
if (dr != null)
|
||||
{
|
||||
//删除报警
|
||||
_errTable.Rows.Remove(dr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (PClass.IsPlcLink(PLCId) && !string.IsNullOrEmpty(UpLoadAddr))
|
||||
{
|
||||
//循环读数据,PLC主动上传报警
|
||||
ushort level = PCHMI.RT.GET_UINT16(PLCId, LevelAddr);
|
||||
ushort group = PCHMI.RT.GET_UINT16(PLCId, GroupAddr);
|
||||
int id = PCHMI.RT.GET_UINT16(PLCId, IdAddr) + 10000;
|
||||
short sd1 = PCHMI.RT.GET_INT16(PLCId, Sd1Addr);
|
||||
int sd2 = PCHMI.RT.GET_INT32(PLCId, Sd2Addr);
|
||||
float sd3 = PCHMI.RT.GET_F32(PLCId, Sd3Addr);
|
||||
string errText = PCHMI.RT.GET_SIEMENS_STRING(PLCId, ErrTextAddr, 100);
|
||||
ushort count = PCHMI.RT.GET_UINT16(PLCId, UpCountAddr);
|
||||
short upLoad = PCHMI.RT.GET_INT16(PLCId, UpLoadAddr);
|
||||
if (retCountSave != count && upLoad > 0)
|
||||
{
|
||||
//计数改变,需要上传数据
|
||||
|
||||
string errMsg = errText.Replace("{1}", sd1.ToString()).Replace("{2}", sd2.ToString()).Replace("{3}", sd3.ToString());
|
||||
string alarmType = ((AlarmType)level).ToString();
|
||||
if (upLoad == 1)
|
||||
{
|
||||
//报警发生,添加报警,还需要写到实时数据库中
|
||||
var dr = _errTable.Select($"报警类别='{alarmType}' and 报警组='{group}' and ID='{id}'").FirstOrDefault();
|
||||
if (dr == null)
|
||||
{
|
||||
_errTable.Rows.Add(new object[]
|
||||
{
|
||||
PLCId.ToString(),
|
||||
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fffff"),
|
||||
alarmType,//错误类型
|
||||
group.ToString(),//组
|
||||
id.ToString(),//ID
|
||||
errMsg, //错误信息
|
||||
"1"
|
||||
});
|
||||
AlarmExcelHelper.UpdateAlarmRT(PLCId.ToString(), alarmType, group.ToString(), id.ToString(), errMsg, true, FileName);
|
||||
AlarmExcelHelper.SaveAlarmLog(PLCId.ToString(), alarmType, group.ToString(), id.ToString(), "1", errMsg);
|
||||
}
|
||||
PCHMI.RT.SEND_UINT16(PLCId, RetAddr, 1);
|
||||
PCHMI.RT.SEND_UINT16(PLCId, RetCountAddr, count);
|
||||
retCountSave = count;
|
||||
newError = true;
|
||||
}
|
||||
else if (upLoad == 2)
|
||||
{
|
||||
//报警离开
|
||||
var dr = _errTable.Select($"报警类别='{alarmType}' and 报警组='{group}' and ID='{id}'").FirstOrDefault();
|
||||
if (dr != null)
|
||||
{
|
||||
_errTable.Rows.Remove(dr);
|
||||
AlarmExcelHelper.UpdateAlarmRT(PLCId.ToString(), alarmType, group.ToString(), id.ToString(), errMsg, false, FileName);
|
||||
AlarmExcelHelper.SaveAlarmLog(PLCId.ToString(), alarmType, group.ToString(), id.ToString(), "0", errMsg);
|
||||
}
|
||||
PCHMI.RT.SEND_UINT16(PLCId, RetAddr, 1);
|
||||
PCHMI.RT.SEND_UINT16(PLCId, RetCountAddr, count);
|
||||
retCountSave = count;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_errList.Count > 0)
|
||||
{
|
||||
//判断报警表格中是否有报警发生
|
||||
foreach (var alarmModel in _errList)
|
||||
{
|
||||
if (CONFIG.PLC_OFF[alarmModel.PLC])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
switch (alarmModel.VarType)
|
||||
{
|
||||
case "BIT":
|
||||
alarmModel.CurValue = (int)PCHMI.RT.GET_BIT(alarmModel.PLC, alarmModel.Address);
|
||||
break;
|
||||
case "INT16":
|
||||
alarmModel.CurValue = (int)PCHMI.RT.GET_INT16(alarmModel.PLC, alarmModel.Address);
|
||||
break;
|
||||
case "UINT16":
|
||||
alarmModel.CurValue = (int)PCHMI.RT.GET_UINT16(alarmModel.PLC, alarmModel.Address);
|
||||
break;
|
||||
case "INT32":
|
||||
alarmModel.CurValue = PCHMI.RT.GET_INT32(alarmModel.PLC, alarmModel.Address);
|
||||
break;
|
||||
case "UINT32":
|
||||
alarmModel.CurValue = (int)PCHMI.RT.GET_UINT32(alarmModel.PLC, alarmModel.Address);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (alarmModel.CurValue != alarmModel.LastValue)
|
||||
{
|
||||
//值改变
|
||||
if (alarmModel.CurValue == alarmModel.TP)
|
||||
{
|
||||
//报警发生
|
||||
var dr = _errTable.Select($"报警类别='{alarmModel.Level}' and 报警组='{alarmModel.Group}' and ID='{alarmModel.ErrCode}'").FirstOrDefault();
|
||||
if (dr == null)
|
||||
{
|
||||
_errTable.Rows.Add(new object[]
|
||||
{
|
||||
PLCId.ToString(),
|
||||
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fffff"),
|
||||
alarmModel.Level,//错误类型
|
||||
alarmModel.Group.ToString(),//组
|
||||
alarmModel.ErrCode.ToString(),//ID
|
||||
alarmModel.Language[GLOBAL.Language], //错误信息
|
||||
"1"
|
||||
});
|
||||
//AlarmExcelHelper.UpdateAlarmRT(PLCId.ToString(), alarmModel.Level, alarmModel.Group.ToString(), alarmModel.ErrCode.ToString(), alarmModel.Language[GLOBAL.Language], true, FileName);
|
||||
AlarmExcelHelper.SaveAlarmLog(PLCId.ToString(), alarmModel.Level, alarmModel.Group.ToString(), alarmModel.ErrCode.ToString(), "1", alarmModel.Language[GLOBAL.Language]);
|
||||
newError = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//报警离开
|
||||
var dr = _errTable.Select($"报警类别='{alarmModel.Level}' and 报警组='{alarmModel.Group.ToString()}' and ID='{alarmModel.ErrCode.ToString()}'").FirstOrDefault();
|
||||
if (dr != null)
|
||||
{
|
||||
_errTable.Rows.Remove(dr);
|
||||
//AlarmExcelHelper.UpdateAlarmRT(PLCId.ToString(), alarmModel.Level, alarmModel.Group.ToString(), alarmModel.ErrCode.ToString(), alarmModel.Language[GLOBAL.Language], false, FileName);
|
||||
AlarmExcelHelper.SaveAlarmLog(PLCId.ToString(), alarmModel.Level, alarmModel.Group.ToString(), alarmModel.ErrCode.ToString(), "0", alarmModel.Language[GLOBAL.Language]);
|
||||
}
|
||||
}
|
||||
}
|
||||
alarmModel.LastValue = alarmModel.CurValue;
|
||||
}
|
||||
}
|
||||
|
||||
ErrorCount = _errTable.Rows.Count;
|
||||
Error = ErrorCount > 0 ? true : false;
|
||||
if (Error)
|
||||
{
|
||||
//有报警
|
||||
chgError = !chgError;
|
||||
//控制报警图标闪烁
|
||||
this.BackgroundImage = chgError ? global::CowainHmi.Properties.Resources.alarm1 : global::CowainHmi.Properties.Resources.Alarm;
|
||||
if (newError & this.AutoShow)
|
||||
{
|
||||
//有新报警出现,自动弹窗
|
||||
ShowErrDlg();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//无报警
|
||||
this.BackgroundImage = global::CowainHmi.Properties.Resources.alarm1;
|
||||
}
|
||||
isFlg = false;
|
||||
}
|
||||
|
||||
DlgAlarmNow dlgAlarm;
|
||||
private void ShowErrDlg()
|
||||
{
|
||||
//弹出报警窗口
|
||||
if (dlgAlarm == null)
|
||||
{
|
||||
dlgAlarm = new DlgAlarmNow(_errTable);
|
||||
}
|
||||
dlgAlarm.Show(); //显示窗体
|
||||
dlgAlarm.WindowState = FormWindowState.Normal;
|
||||
dlgAlarm.Activate();
|
||||
newError = false;
|
||||
}
|
||||
private void AlarmNow_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
ShowErrDlg();
|
||||
}
|
||||
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaint(e);
|
||||
if (ErrorCount == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
using (Brush brush = new SolidBrush(ForeColor))
|
||||
{
|
||||
// 获取Graphics对象
|
||||
Graphics g = e.Graphics;
|
||||
// 获取控件的绘制区域
|
||||
// 计算字符串绘制的起始位置(控件的右上角,留出一些内边距)
|
||||
//PointF textPosition = new PointF(this.Width - g.MeasureString(ErrorCount.ToString(), this.Font).Width - padding, padding);
|
||||
PointF textPosition = new PointF(1, 7);
|
||||
// 设置字符串格式,这里我们使用StringFormat来居中字符串
|
||||
StringFormat sf = new StringFormat();
|
||||
sf.Alignment = StringAlignment.Near;
|
||||
sf.LineAlignment = StringAlignment.Center;
|
||||
g.DrawString(ErrorCount.ToString(), this.Font, brush, textPosition, sf);
|
||||
sf.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
123
CowainHmi/Alarm/AlarmNow.resx
Normal file
123
CowainHmi/Alarm/AlarmNow.resx
Normal file
@@ -0,0 +1,123 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
||||
27
CowainHmi/Alarm/AlarmType.cs
Normal file
27
CowainHmi/Alarm/AlarmType.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CowainHmi.Alarm
|
||||
{
|
||||
public enum AlarmType
|
||||
{
|
||||
Null = 0,
|
||||
错误 = 1,
|
||||
警告 = 2,
|
||||
信息 = 3,
|
||||
安全 = 4,
|
||||
未定义1 = 5,
|
||||
未定义2 = 6
|
||||
}
|
||||
public enum DataType
|
||||
{
|
||||
BIT,
|
||||
INT16,
|
||||
INT32,
|
||||
UINT16,
|
||||
UINT32
|
||||
}
|
||||
}
|
||||
32
CowainHmi/Alarm/AlarmUIEditor.cs
Normal file
32
CowainHmi/Alarm/AlarmUIEditor.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using PCHMI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing.Design;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms.Design;
|
||||
|
||||
namespace CowainHmi.Alarm
|
||||
{
|
||||
public class AlarmUIEditor : UITypeEditor
|
||||
{
|
||||
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
|
||||
{
|
||||
return UITypeEditorEditStyle.Modal;
|
||||
}
|
||||
|
||||
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
|
||||
{
|
||||
IWindowsFormsEditorService windowsFormsEditorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
|
||||
if (windowsFormsEditorService != null)
|
||||
{
|
||||
FrmEditAlarmTable form = new FrmEditAlarmTable((string)value);
|
||||
windowsFormsEditorService.ShowDialog(form);
|
||||
context.OnComponentChanged();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
142
CowainHmi/Alarm/DlgAlarmNow.Designer.cs
generated
Normal file
142
CowainHmi/Alarm/DlgAlarmNow.Designer.cs
generated
Normal file
@@ -0,0 +1,142 @@
|
||||
namespace CowainHmi.Alarm
|
||||
{
|
||||
partial class DlgAlarmNow
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
|
||||
this.dgvErr = new System.Windows.Forms.DataGridView();
|
||||
this.DTIM = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.报警类别 = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.报警组 = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.ErrText = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dgvErr)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// dgvErr
|
||||
//
|
||||
this.dgvErr.AllowUserToAddRows = false;
|
||||
this.dgvErr.AllowUserToResizeRows = false;
|
||||
this.dgvErr.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dgvErr.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||
this.DTIM,
|
||||
this.报警类别,
|
||||
this.报警组,
|
||||
this.ID,
|
||||
this.ErrText});
|
||||
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
|
||||
dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Window;
|
||||
dataGridViewCellStyle1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.ControlText;
|
||||
dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.GradientInactiveCaption;
|
||||
dataGridViewCellStyle1.SelectionForeColor = System.Drawing.Color.Yellow;
|
||||
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
|
||||
this.dgvErr.DefaultCellStyle = dataGridViewCellStyle1;
|
||||
this.dgvErr.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.dgvErr.Location = new System.Drawing.Point(0, 0);
|
||||
this.dgvErr.Name = "dgvErr";
|
||||
this.dgvErr.ReadOnly = true;
|
||||
this.dgvErr.RowHeadersWidth = 51;
|
||||
this.dgvErr.RowTemplate.Height = 23;
|
||||
this.dgvErr.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
|
||||
this.dgvErr.Size = new System.Drawing.Size(884, 489);
|
||||
this.dgvErr.TabIndex = 1;
|
||||
this.dgvErr.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.dgvErr_CellFormatting);
|
||||
this.dgvErr.RowPostPaint += new System.Windows.Forms.DataGridViewRowPostPaintEventHandler(this.dgvErr_RowPostPaint);
|
||||
//
|
||||
// DTIM
|
||||
//
|
||||
this.DTIM.DataPropertyName = "DTIM";
|
||||
this.DTIM.HeaderText = "报警时间";
|
||||
this.DTIM.MinimumWidth = 6;
|
||||
this.DTIM.Name = "DTIM";
|
||||
this.DTIM.ReadOnly = true;
|
||||
this.DTIM.Width = 190;
|
||||
//
|
||||
// 报警类别
|
||||
//
|
||||
this.报警类别.DataPropertyName = "报警类别";
|
||||
this.报警类别.HeaderText = "报警类别";
|
||||
this.报警类别.MinimumWidth = 6;
|
||||
this.报警类别.Name = "报警类别";
|
||||
this.报警类别.ReadOnly = true;
|
||||
this.报警类别.Width = 80;
|
||||
//
|
||||
// 报警组
|
||||
//
|
||||
this.报警组.DataPropertyName = "报警组";
|
||||
this.报警组.HeaderText = "报警组";
|
||||
this.报警组.MinimumWidth = 6;
|
||||
this.报警组.Name = "报警组";
|
||||
this.报警组.ReadOnly = true;
|
||||
this.报警组.Width = 80;
|
||||
//
|
||||
// ID
|
||||
//
|
||||
this.ID.DataPropertyName = "ID";
|
||||
this.ID.HeaderText = "报警编号";
|
||||
this.ID.MinimumWidth = 6;
|
||||
this.ID.Name = "ID";
|
||||
this.ID.ReadOnly = true;
|
||||
this.ID.Width = 80;
|
||||
//
|
||||
// ErrText
|
||||
//
|
||||
this.ErrText.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
|
||||
this.ErrText.DataPropertyName = "ErrText";
|
||||
this.ErrText.HeaderText = "报警内容";
|
||||
this.ErrText.MinimumWidth = 6;
|
||||
this.ErrText.Name = "ErrText";
|
||||
this.ErrText.ReadOnly = true;
|
||||
//
|
||||
// DlgAlarmNow
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(884, 489);
|
||||
this.Controls.Add(this.dgvErr);
|
||||
this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||
this.Name = "DlgAlarmNow";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "实时报警";
|
||||
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.DlgAlarmNow_FormClosing);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dgvErr)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.DataGridView dgvErr;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn DTIM;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn 报警类别;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn 报警组;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn ID;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn ErrText;
|
||||
}
|
||||
}
|
||||
66
CowainHmi/Alarm/DlgAlarmNow.cs
Normal file
66
CowainHmi/Alarm/DlgAlarmNow.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using PCHMI;
|
||||
using System;
|
||||
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 CowainHmi.Alarm
|
||||
{
|
||||
public partial class DlgAlarmNow : Form
|
||||
{
|
||||
public DlgAlarmNow(DataTable dt)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.dgvErr.AutoGenerateColumns = false;
|
||||
this.dgvErr.DataSource = dt;
|
||||
}
|
||||
|
||||
private void dgvErr_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
|
||||
{
|
||||
Color color = Color.Black;
|
||||
string type = dgvErr.Rows[e.RowIndex].Cells[1].Value.ToString();
|
||||
AlarmType alarmType = (AlarmType)Enum.Parse(typeof(AlarmType), type);
|
||||
switch (alarmType)
|
||||
{
|
||||
case AlarmType.错误: //错误
|
||||
color = Color.Red;
|
||||
break;
|
||||
case AlarmType.警告: //警告
|
||||
//color = Color.DarkOrange;
|
||||
//color = Color.OrangeRed;
|
||||
color = Color.Black;
|
||||
|
||||
break;
|
||||
case AlarmType.信息: //提示
|
||||
color = Color.Black;
|
||||
break;
|
||||
default:
|
||||
color = Color.Black;
|
||||
break;
|
||||
}
|
||||
dgvErr.Rows[e.RowIndex].DefaultCellStyle.ForeColor = color;
|
||||
new DataGridViewStyle().DgvRowPostPaint(dgvErr, e);
|
||||
}
|
||||
|
||||
private void dgvErr_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
|
||||
{
|
||||
e.CellStyle.SelectionForeColor = e.CellStyle.ForeColor;
|
||||
}
|
||||
|
||||
private void DlgAlarmNow_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
e.Cancel = true;
|
||||
this.Hide();
|
||||
}
|
||||
|
||||
private void DlgAlarmNow_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
135
CowainHmi/Alarm/DlgAlarmNow.resx
Normal file
135
CowainHmi/Alarm/DlgAlarmNow.resx
Normal file
@@ -0,0 +1,135 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="DTIM.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="报警类别.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="报警组.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ID.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ErrText.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
</root>
|
||||
396
CowainHmi/Alarm/FrmEditAlarmRecord.Designer.cs
generated
Normal file
396
CowainHmi/Alarm/FrmEditAlarmRecord.Designer.cs
generated
Normal file
@@ -0,0 +1,396 @@
|
||||
namespace CowainHmi.Alarm
|
||||
{
|
||||
partial class FrmEditAlarmRecord
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.地址 = new System.Windows.Forms.TextBox();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.类型 = new System.Windows.Forms.ComboBox();
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.等级 = new System.Windows.Forms.ComboBox();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.label4 = new System.Windows.Forms.Label();
|
||||
this.PLC = new System.Windows.Forms.TextBox();
|
||||
this.触发条件 = new System.Windows.Forms.TextBox();
|
||||
this.label5 = new System.Windows.Forms.Label();
|
||||
this.代码 = new System.Windows.Forms.TextBox();
|
||||
this.label6 = new System.Windows.Forms.Label();
|
||||
this.报警组 = new System.Windows.Forms.TextBox();
|
||||
this.label7 = new System.Windows.Forms.Label();
|
||||
this.语言1 = new System.Windows.Forms.TextBox();
|
||||
this.label8 = new System.Windows.Forms.Label();
|
||||
this.语言2 = new System.Windows.Forms.TextBox();
|
||||
this.label9 = new System.Windows.Forms.Label();
|
||||
this.语言3 = new System.Windows.Forms.TextBox();
|
||||
this.label10 = new System.Windows.Forms.Label();
|
||||
this.语言4 = new System.Windows.Forms.TextBox();
|
||||
this.label11 = new System.Windows.Forms.Label();
|
||||
this.语言5 = new System.Windows.Forms.TextBox();
|
||||
this.label12 = new System.Windows.Forms.Label();
|
||||
this.语言6 = new System.Windows.Forms.TextBox();
|
||||
this.label13 = new System.Windows.Forms.Label();
|
||||
this.语言7 = new System.Windows.Forms.TextBox();
|
||||
this.label14 = new System.Windows.Forms.Label();
|
||||
this.语言8 = new System.Windows.Forms.TextBox();
|
||||
this.label15 = new System.Windows.Forms.Label();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(46, 50);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(35, 12);
|
||||
this.label1.TabIndex = 0;
|
||||
this.label1.Text = "地址:";
|
||||
//
|
||||
// 地址
|
||||
//
|
||||
this.地址.Location = new System.Drawing.Point(93, 47);
|
||||
this.地址.Name = "地址";
|
||||
this.地址.Size = new System.Drawing.Size(213, 21);
|
||||
this.地址.TabIndex = 1;
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(46, 79);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(35, 12);
|
||||
this.label2.TabIndex = 2;
|
||||
this.label2.Text = "类型:";
|
||||
//
|
||||
// 类型
|
||||
//
|
||||
this.类型.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.类型.FormattingEnabled = true;
|
||||
this.类型.Location = new System.Drawing.Point(93, 76);
|
||||
this.类型.Name = "类型";
|
||||
this.类型.Size = new System.Drawing.Size(213, 20);
|
||||
this.类型.TabIndex = 3;
|
||||
//
|
||||
// button1
|
||||
//
|
||||
this.button1.Location = new System.Drawing.Point(93, 456);
|
||||
this.button1.Name = "button1";
|
||||
this.button1.Size = new System.Drawing.Size(213, 30);
|
||||
this.button1.TabIndex = 4;
|
||||
this.button1.Text = "保存";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
this.button1.Click += new System.EventHandler(this.button1_Click);
|
||||
//
|
||||
// 等级
|
||||
//
|
||||
this.等级.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.等级.FormattingEnabled = true;
|
||||
this.等级.Location = new System.Drawing.Point(93, 191);
|
||||
this.等级.Name = "等级";
|
||||
this.等级.Size = new System.Drawing.Size(213, 20);
|
||||
this.等级.TabIndex = 5;
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Location = new System.Drawing.Point(46, 195);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(35, 12);
|
||||
this.label3.TabIndex = 6;
|
||||
this.label3.Text = "等级:";
|
||||
//
|
||||
// label4
|
||||
//
|
||||
this.label4.AutoSize = true;
|
||||
this.label4.Location = new System.Drawing.Point(52, 21);
|
||||
this.label4.Name = "label4";
|
||||
this.label4.Size = new System.Drawing.Size(29, 12);
|
||||
this.label4.TabIndex = 7;
|
||||
this.label4.Text = "PLC:";
|
||||
//
|
||||
// PLC
|
||||
//
|
||||
this.PLC.Location = new System.Drawing.Point(93, 18);
|
||||
this.PLC.Name = "PLC";
|
||||
this.PLC.Size = new System.Drawing.Size(213, 21);
|
||||
this.PLC.TabIndex = 8;
|
||||
//
|
||||
// 触发条件
|
||||
//
|
||||
this.触发条件.Location = new System.Drawing.Point(93, 104);
|
||||
this.触发条件.Name = "触发条件";
|
||||
this.触发条件.Size = new System.Drawing.Size(213, 21);
|
||||
this.触发条件.TabIndex = 10;
|
||||
//
|
||||
// label5
|
||||
//
|
||||
this.label5.AutoSize = true;
|
||||
this.label5.Location = new System.Drawing.Point(22, 108);
|
||||
this.label5.Name = "label5";
|
||||
this.label5.Size = new System.Drawing.Size(59, 12);
|
||||
this.label5.TabIndex = 9;
|
||||
this.label5.Text = "触发条件:";
|
||||
//
|
||||
// 代码
|
||||
//
|
||||
this.代码.Location = new System.Drawing.Point(93, 133);
|
||||
this.代码.Name = "代码";
|
||||
this.代码.Size = new System.Drawing.Size(213, 21);
|
||||
this.代码.TabIndex = 12;
|
||||
//
|
||||
// label6
|
||||
//
|
||||
this.label6.AutoSize = true;
|
||||
this.label6.Location = new System.Drawing.Point(46, 137);
|
||||
this.label6.Name = "label6";
|
||||
this.label6.Size = new System.Drawing.Size(35, 12);
|
||||
this.label6.TabIndex = 11;
|
||||
this.label6.Text = "代码:";
|
||||
//
|
||||
// 报警组
|
||||
//
|
||||
this.报警组.Location = new System.Drawing.Point(93, 162);
|
||||
this.报警组.Name = "报警组";
|
||||
this.报警组.Size = new System.Drawing.Size(213, 21);
|
||||
this.报警组.TabIndex = 14;
|
||||
//
|
||||
// label7
|
||||
//
|
||||
this.label7.AutoSize = true;
|
||||
this.label7.Location = new System.Drawing.Point(34, 166);
|
||||
this.label7.Name = "label7";
|
||||
this.label7.Size = new System.Drawing.Size(47, 12);
|
||||
this.label7.TabIndex = 13;
|
||||
this.label7.Text = "报警组:";
|
||||
//
|
||||
// 语言1
|
||||
//
|
||||
this.语言1.Location = new System.Drawing.Point(93, 219);
|
||||
this.语言1.Name = "语言1";
|
||||
this.语言1.Size = new System.Drawing.Size(213, 21);
|
||||
this.语言1.TabIndex = 16;
|
||||
//
|
||||
// label8
|
||||
//
|
||||
this.label8.AutoSize = true;
|
||||
this.label8.Location = new System.Drawing.Point(40, 224);
|
||||
this.label8.Name = "label8";
|
||||
this.label8.Size = new System.Drawing.Size(41, 12);
|
||||
this.label8.TabIndex = 15;
|
||||
this.label8.Text = "语言1:";
|
||||
//
|
||||
// 语言2
|
||||
//
|
||||
this.语言2.Location = new System.Drawing.Point(93, 248);
|
||||
this.语言2.Name = "语言2";
|
||||
this.语言2.Size = new System.Drawing.Size(213, 21);
|
||||
this.语言2.TabIndex = 18;
|
||||
//
|
||||
// label9
|
||||
//
|
||||
this.label9.AutoSize = true;
|
||||
this.label9.Location = new System.Drawing.Point(40, 253);
|
||||
this.label9.Name = "label9";
|
||||
this.label9.Size = new System.Drawing.Size(41, 12);
|
||||
this.label9.TabIndex = 17;
|
||||
this.label9.Text = "语言2:";
|
||||
//
|
||||
// 语言3
|
||||
//
|
||||
this.语言3.Location = new System.Drawing.Point(93, 277);
|
||||
this.语言3.Name = "语言3";
|
||||
this.语言3.Size = new System.Drawing.Size(213, 21);
|
||||
this.语言3.TabIndex = 20;
|
||||
//
|
||||
// label10
|
||||
//
|
||||
this.label10.AutoSize = true;
|
||||
this.label10.Location = new System.Drawing.Point(40, 282);
|
||||
this.label10.Name = "label10";
|
||||
this.label10.Size = new System.Drawing.Size(41, 12);
|
||||
this.label10.TabIndex = 19;
|
||||
this.label10.Text = "语言3:";
|
||||
//
|
||||
// 语言4
|
||||
//
|
||||
this.语言4.Location = new System.Drawing.Point(93, 306);
|
||||
this.语言4.Name = "语言4";
|
||||
this.语言4.Size = new System.Drawing.Size(213, 21);
|
||||
this.语言4.TabIndex = 22;
|
||||
//
|
||||
// label11
|
||||
//
|
||||
this.label11.AutoSize = true;
|
||||
this.label11.Location = new System.Drawing.Point(40, 311);
|
||||
this.label11.Name = "label11";
|
||||
this.label11.Size = new System.Drawing.Size(41, 12);
|
||||
this.label11.TabIndex = 21;
|
||||
this.label11.Text = "语言4:";
|
||||
//
|
||||
// 语言5
|
||||
//
|
||||
this.语言5.Location = new System.Drawing.Point(93, 335);
|
||||
this.语言5.Name = "语言5";
|
||||
this.语言5.Size = new System.Drawing.Size(213, 21);
|
||||
this.语言5.TabIndex = 24;
|
||||
//
|
||||
// label12
|
||||
//
|
||||
this.label12.AutoSize = true;
|
||||
this.label12.Location = new System.Drawing.Point(40, 340);
|
||||
this.label12.Name = "label12";
|
||||
this.label12.Size = new System.Drawing.Size(41, 12);
|
||||
this.label12.TabIndex = 23;
|
||||
this.label12.Text = "语言5:";
|
||||
//
|
||||
// 语言6
|
||||
//
|
||||
this.语言6.Location = new System.Drawing.Point(93, 364);
|
||||
this.语言6.Name = "语言6";
|
||||
this.语言6.Size = new System.Drawing.Size(213, 21);
|
||||
this.语言6.TabIndex = 26;
|
||||
//
|
||||
// label13
|
||||
//
|
||||
this.label13.AutoSize = true;
|
||||
this.label13.Location = new System.Drawing.Point(40, 369);
|
||||
this.label13.Name = "label13";
|
||||
this.label13.Size = new System.Drawing.Size(41, 12);
|
||||
this.label13.TabIndex = 25;
|
||||
this.label13.Text = "语言6:";
|
||||
//
|
||||
// 语言7
|
||||
//
|
||||
this.语言7.Location = new System.Drawing.Point(93, 393);
|
||||
this.语言7.Name = "语言7";
|
||||
this.语言7.Size = new System.Drawing.Size(213, 21);
|
||||
this.语言7.TabIndex = 28;
|
||||
//
|
||||
// label14
|
||||
//
|
||||
this.label14.AutoSize = true;
|
||||
this.label14.Location = new System.Drawing.Point(40, 398);
|
||||
this.label14.Name = "label14";
|
||||
this.label14.Size = new System.Drawing.Size(41, 12);
|
||||
this.label14.TabIndex = 27;
|
||||
this.label14.Text = "语言7:";
|
||||
//
|
||||
// 语言8
|
||||
//
|
||||
this.语言8.Location = new System.Drawing.Point(93, 422);
|
||||
this.语言8.Name = "语言8";
|
||||
this.语言8.Size = new System.Drawing.Size(213, 21);
|
||||
this.语言8.TabIndex = 30;
|
||||
//
|
||||
// label15
|
||||
//
|
||||
this.label15.AutoSize = true;
|
||||
this.label15.Location = new System.Drawing.Point(40, 427);
|
||||
this.label15.Name = "label15";
|
||||
this.label15.Size = new System.Drawing.Size(41, 12);
|
||||
this.label15.TabIndex = 29;
|
||||
this.label15.Text = "语言8:";
|
||||
//
|
||||
// FrmEditAlarmRecord
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(422, 513);
|
||||
this.Controls.Add(this.语言8);
|
||||
this.Controls.Add(this.label15);
|
||||
this.Controls.Add(this.语言7);
|
||||
this.Controls.Add(this.label14);
|
||||
this.Controls.Add(this.语言6);
|
||||
this.Controls.Add(this.label13);
|
||||
this.Controls.Add(this.语言5);
|
||||
this.Controls.Add(this.label12);
|
||||
this.Controls.Add(this.语言4);
|
||||
this.Controls.Add(this.label11);
|
||||
this.Controls.Add(this.语言3);
|
||||
this.Controls.Add(this.label10);
|
||||
this.Controls.Add(this.语言2);
|
||||
this.Controls.Add(this.label9);
|
||||
this.Controls.Add(this.语言1);
|
||||
this.Controls.Add(this.label8);
|
||||
this.Controls.Add(this.报警组);
|
||||
this.Controls.Add(this.label7);
|
||||
this.Controls.Add(this.代码);
|
||||
this.Controls.Add(this.label6);
|
||||
this.Controls.Add(this.触发条件);
|
||||
this.Controls.Add(this.label5);
|
||||
this.Controls.Add(this.PLC);
|
||||
this.Controls.Add(this.label4);
|
||||
this.Controls.Add(this.label3);
|
||||
this.Controls.Add(this.等级);
|
||||
this.Controls.Add(this.button1);
|
||||
this.Controls.Add(this.类型);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.地址);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Name = "FrmEditAlarmRecord";
|
||||
this.Text = "报警编辑";
|
||||
this.Load += new System.EventHandler(this.FrmEditAlarmRecord_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.TextBox 地址;
|
||||
private System.Windows.Forms.Label label2;
|
||||
private System.Windows.Forms.ComboBox 类型;
|
||||
private System.Windows.Forms.Button button1;
|
||||
private System.Windows.Forms.ComboBox 等级;
|
||||
private System.Windows.Forms.Label label3;
|
||||
private System.Windows.Forms.Label label4;
|
||||
private System.Windows.Forms.TextBox PLC;
|
||||
private System.Windows.Forms.TextBox 触发条件;
|
||||
private System.Windows.Forms.Label label5;
|
||||
private System.Windows.Forms.TextBox 代码;
|
||||
private System.Windows.Forms.Label label6;
|
||||
private System.Windows.Forms.TextBox 报警组;
|
||||
private System.Windows.Forms.Label label7;
|
||||
private System.Windows.Forms.TextBox 语言1;
|
||||
private System.Windows.Forms.Label label8;
|
||||
private System.Windows.Forms.TextBox 语言2;
|
||||
private System.Windows.Forms.Label label9;
|
||||
private System.Windows.Forms.TextBox 语言3;
|
||||
private System.Windows.Forms.Label label10;
|
||||
private System.Windows.Forms.TextBox 语言4;
|
||||
private System.Windows.Forms.Label label11;
|
||||
private System.Windows.Forms.TextBox 语言5;
|
||||
private System.Windows.Forms.Label label12;
|
||||
private System.Windows.Forms.TextBox 语言6;
|
||||
private System.Windows.Forms.Label label13;
|
||||
private System.Windows.Forms.TextBox 语言7;
|
||||
private System.Windows.Forms.Label label14;
|
||||
private System.Windows.Forms.TextBox 语言8;
|
||||
private System.Windows.Forms.Label label15;
|
||||
}
|
||||
}
|
||||
86
CowainHmi/Alarm/FrmEditAlarmRecord.cs
Normal file
86
CowainHmi/Alarm/FrmEditAlarmRecord.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using PCHMI;
|
||||
using System;
|
||||
using System.CodeDom;
|
||||
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;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
|
||||
namespace CowainHmi.Alarm
|
||||
{
|
||||
public partial class FrmEditAlarmRecord : Form
|
||||
{
|
||||
PLCInfoModel.PLCAlarmInfo dataRow;
|
||||
List<AlarmExcelHelper.EnumItemModel<AlarmType>> alarmType;
|
||||
public FrmEditAlarmRecord(PLCInfoModel.PLCAlarmInfo _dataRow)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.MaximizeBox = false;
|
||||
this.StartPosition = FormStartPosition.CenterScreen;
|
||||
this.FormBorderStyle = FormBorderStyle.FixedSingle;
|
||||
this.StartPosition = FormStartPosition.CenterScreen;
|
||||
this.dataRow = _dataRow;
|
||||
}
|
||||
|
||||
private void FrmEditAlarmRecord_Load(object sender, EventArgs e)
|
||||
{
|
||||
alarmType = AlarmExcelHelper.GetEnumItems<AlarmType>();
|
||||
SetComboBox();
|
||||
SetValue();
|
||||
}
|
||||
private void SetValue()
|
||||
{
|
||||
PLC.Text= dataRow.PLC;
|
||||
地址.Text = dataRow.地址;
|
||||
类型.Text = dataRow.类型;
|
||||
触发条件.Text = dataRow.触发条件;
|
||||
代码.Text = dataRow.代码;
|
||||
报警组.Text = dataRow.报警组;
|
||||
//等级.Text = alarmType.Where(item => item.EnumValue == dataRow.等级).FirstOrDefault().EnumName;
|
||||
等级.Text= dataRow.等级;
|
||||
语言1.Text = dataRow.语言1;
|
||||
语言2.Text = dataRow.语言2;
|
||||
语言3.Text = dataRow.语言3;
|
||||
语言4.Text = dataRow.语言4;
|
||||
语言5.Text = dataRow.语言5;
|
||||
语言6.Text = dataRow.语言6;
|
||||
语言7.Text = dataRow.语言7;
|
||||
语言8.Text = dataRow.语言8;
|
||||
}
|
||||
private void SetComboBox()
|
||||
{
|
||||
var dataType = AlarmExcelHelper.GetEnumItems<DataType>();
|
||||
类型.DataSource = new BindingSource(dataType.Select(item => item.EnumName), null);
|
||||
类型.DisplayMember = "Value";
|
||||
|
||||
等级.DataSource = new BindingSource(alarmType.Select(item => item.EnumName), null);
|
||||
等级.DisplayMember = "Value";
|
||||
}
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
dataRow.PLC = PLC.Text;
|
||||
dataRow.地址 = 地址.Text;
|
||||
dataRow.类型 = 类型.Text;
|
||||
dataRow.触发条件 = 触发条件.Text;
|
||||
dataRow.代码 = 代码.Text;
|
||||
dataRow.报警组 = 报警组.Text;
|
||||
//dataRow.等级 = alarmType.Where(item => item.EnumName == 等级.Text).FirstOrDefault().EnumValue;
|
||||
dataRow.等级 = 等级.Text;
|
||||
dataRow.语言1 = 语言1.Text;
|
||||
dataRow.语言2 = 语言2.Text;
|
||||
dataRow.语言3 = 语言3.Text;
|
||||
dataRow.语言4 = 语言4.Text;
|
||||
dataRow.语言5 = 语言5.Text;
|
||||
dataRow.语言6 = 语言6.Text;
|
||||
dataRow.语言7 = 语言7.Text;
|
||||
dataRow.语言8 = 语言8.Text;
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
120
CowainHmi/Alarm/FrmEditAlarmRecord.resx
Normal file
120
CowainHmi/Alarm/FrmEditAlarmRecord.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
155
CowainHmi/Alarm/FrmEditAlarmTable.Designer.cs
generated
Normal file
155
CowainHmi/Alarm/FrmEditAlarmTable.Designer.cs
generated
Normal file
@@ -0,0 +1,155 @@
|
||||
namespace CowainHmi.Alarm
|
||||
{
|
||||
partial class FrmEditAlarmTable
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.panel1 = new System.Windows.Forms.Panel();
|
||||
this.button4 = new System.Windows.Forms.Button();
|
||||
this.button3 = new System.Windows.Forms.Button();
|
||||
this.button2 = new System.Windows.Forms.Button();
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.btnSave = new System.Windows.Forms.Button();
|
||||
this.dataGridView1 = new System.Windows.Forms.DataGridView();
|
||||
this.panel1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
this.panel1.Controls.Add(this.button4);
|
||||
this.panel1.Controls.Add(this.button3);
|
||||
this.panel1.Controls.Add(this.button2);
|
||||
this.panel1.Controls.Add(this.button1);
|
||||
this.panel1.Controls.Add(this.btnSave);
|
||||
this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
|
||||
this.panel1.Location = new System.Drawing.Point(0, 0);
|
||||
this.panel1.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.panel1.Name = "panel1";
|
||||
this.panel1.Size = new System.Drawing.Size(758, 55);
|
||||
this.panel1.TabIndex = 1;
|
||||
//
|
||||
// button4
|
||||
//
|
||||
this.button4.Location = new System.Drawing.Point(660, 11);
|
||||
this.button4.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.button4.Name = "button4";
|
||||
this.button4.Size = new System.Drawing.Size(87, 35);
|
||||
this.button4.TabIndex = 4;
|
||||
this.button4.Text = "删除选中行";
|
||||
this.button4.UseVisualStyleBackColor = true;
|
||||
this.button4.Click += new System.EventHandler(this.button4_Click);
|
||||
//
|
||||
// button3
|
||||
//
|
||||
this.button3.Location = new System.Drawing.Point(295, 10);
|
||||
this.button3.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.button3.Name = "button3";
|
||||
this.button3.Size = new System.Drawing.Size(70, 35);
|
||||
this.button3.TabIndex = 3;
|
||||
this.button3.Text = "增加";
|
||||
this.button3.UseVisualStyleBackColor = true;
|
||||
this.button3.Click += new System.EventHandler(this.button3_Click);
|
||||
//
|
||||
// button2
|
||||
//
|
||||
this.button2.Location = new System.Drawing.Point(9, 10);
|
||||
this.button2.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.button2.Name = "button2";
|
||||
this.button2.Size = new System.Drawing.Size(152, 35);
|
||||
this.button2.TabIndex = 2;
|
||||
this.button2.Text = "自动生成报警代码";
|
||||
this.button2.UseVisualStyleBackColor = true;
|
||||
this.button2.Click += new System.EventHandler(this.button2_Click);
|
||||
//
|
||||
// button1
|
||||
//
|
||||
this.button1.Location = new System.Drawing.Point(382, 10);
|
||||
this.button1.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.button1.Name = "button1";
|
||||
this.button1.Size = new System.Drawing.Size(70, 35);
|
||||
this.button1.TabIndex = 1;
|
||||
this.button1.Text = "导出";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
this.button1.Click += new System.EventHandler(this.button1_Click);
|
||||
//
|
||||
// btnSave
|
||||
//
|
||||
this.btnSave.Location = new System.Drawing.Point(471, 10);
|
||||
this.btnSave.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.btnSave.Name = "btnSave";
|
||||
this.btnSave.Size = new System.Drawing.Size(70, 35);
|
||||
this.btnSave.TabIndex = 0;
|
||||
this.btnSave.Text = "保存";
|
||||
this.btnSave.UseVisualStyleBackColor = true;
|
||||
this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
|
||||
//
|
||||
// dataGridView1
|
||||
//
|
||||
this.dataGridView1.AllowUserToAddRows = false;
|
||||
this.dataGridView1.AllowUserToDeleteRows = false;
|
||||
this.dataGridView1.BackgroundColor = System.Drawing.Color.White;
|
||||
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.dataGridView1.Location = new System.Drawing.Point(0, 55);
|
||||
this.dataGridView1.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.dataGridView1.Name = "dataGridView1";
|
||||
this.dataGridView1.ReadOnly = true;
|
||||
this.dataGridView1.RowTemplate.Height = 27;
|
||||
this.dataGridView1.Size = new System.Drawing.Size(758, 453);
|
||||
this.dataGridView1.TabIndex = 2;
|
||||
this.dataGridView1.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellClick);
|
||||
this.dataGridView1.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellDoubleClick);
|
||||
//
|
||||
// FrmEditAlarmTable
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(758, 508);
|
||||
this.Controls.Add(this.dataGridView1);
|
||||
this.Controls.Add(this.panel1);
|
||||
this.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.Name = "FrmEditAlarmTable";
|
||||
this.Text = "编辑报警列表";
|
||||
this.Load += new System.EventHandler(this.FrmEditAlarmTable_Load);
|
||||
this.panel1.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Panel panel1;
|
||||
private System.Windows.Forms.DataGridView dataGridView1;
|
||||
private System.Windows.Forms.Button button1;
|
||||
private System.Windows.Forms.Button btnSave;
|
||||
private System.Windows.Forms.Button button2;
|
||||
private System.Windows.Forms.Button button3;
|
||||
private System.Windows.Forms.Button button4;
|
||||
}
|
||||
}
|
||||
180
CowainHmi/Alarm/FrmEditAlarmTable.cs
Normal file
180
CowainHmi/Alarm/FrmEditAlarmTable.cs
Normal file
@@ -0,0 +1,180 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace CowainHmi.Alarm
|
||||
{
|
||||
public partial class FrmEditAlarmTable : Form
|
||||
{
|
||||
private string excelFileName;
|
||||
public FrmEditAlarmTable(string _excelFileName)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.excelFileName = _excelFileName;
|
||||
}
|
||||
private BindingList<PLCInfoModel.PLCAlarmInfo> alarmModels=new BindingList<PLCInfoModel.PLCAlarmInfo>();
|
||||
private void FrmEditAlarmTable_Load(object sender, EventArgs e)
|
||||
{
|
||||
var excelDataTable = AlarmExcelHelper.ReadReleaseExcel(excelFileName,alarmModels);
|
||||
alarmModels= AlarmExcelHelper.GetDataList<PLCInfoModel.PLCAlarmInfo>(excelDataTable);
|
||||
dataGridView1.DataSource = alarmModels;
|
||||
}
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
string selectAddress = "";
|
||||
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
if (e.RowIndex < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//selectAddress = GetCellValueByRowColumnIndex(dataGridView1, e.RowIndex, "地址");
|
||||
}
|
||||
|
||||
public string GetCellValueByRowColumnIndex(DataGridView dataGridView, int rowIndex, string columnName)
|
||||
{
|
||||
// 确保行号和DataGridView的行数在有效范围内
|
||||
if (rowIndex < 0 || rowIndex >= dataGridView.Rows.Count)
|
||||
{
|
||||
throw new IndexOutOfRangeException("rowIndex is out of range.");
|
||||
}
|
||||
|
||||
// 查找具有指定列名的列
|
||||
DataGridViewColumn column = dataGridView.Columns.Cast<DataGridViewColumn>().FirstOrDefault(c => c.Name == columnName);
|
||||
|
||||
// 确保找到了列
|
||||
if (column == null)
|
||||
{
|
||||
throw new ArgumentException("Column with specified name not found.", nameof(columnName));
|
||||
}
|
||||
|
||||
// 获取单元格的值
|
||||
// 注意:这里使用rowIndex作为行索引,column.Index作为列索引
|
||||
// 因为DataGridViewCellCollection是基于列的索引来访问单元格的,而不是直接使用列名
|
||||
return dataGridView.Rows[rowIndex].Cells[column.Index].Value?.ToString() ?? string.Empty;
|
||||
}
|
||||
|
||||
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (e.RowIndex < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var address = GetCellValueByRowColumnIndex(dataGridView1, e.RowIndex, "地址");
|
||||
var rowInfo = alarmModels.Where(item => item.地址 == address).FirstOrDefault();
|
||||
if (rowInfo != null)
|
||||
{
|
||||
var previousList = AlarmExcelHelper.DeepCopyList<PLCInfoModel.PLCAlarmInfo>(alarmModels);
|
||||
string previousAddress = rowInfo.地址;
|
||||
FrmEditAlarmRecord frmEditAlarmRecord = new FrmEditAlarmRecord(rowInfo);
|
||||
frmEditAlarmRecord.ShowDialog();
|
||||
int count = previousList.Where(item => item.地址 != previousAddress && item.地址 == rowInfo.地址).Count();
|
||||
if (count > 0)
|
||||
{
|
||||
rowInfo.地址 = previousAddress;
|
||||
MessageBox.Show("PLC地址冲突,已回滚为以前的地址!");
|
||||
}
|
||||
dataGridView1.Refresh();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void btnSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
AlarmExcelHelper.SaveBindingListToExcel<PLCInfoModel.PLCAlarmInfo>(alarmModels, excelFileName);
|
||||
MessageBox.Show("保存成功");
|
||||
}
|
||||
public static int rowCount;
|
||||
private void button3_Click(object sender, EventArgs e)
|
||||
{
|
||||
//int rowCount = 1;
|
||||
AddRowCount addRowCount = new AddRowCount();
|
||||
addRowCount.ShowDialog();
|
||||
for (int i = 0; i < rowCount; i++)
|
||||
{
|
||||
PLCInfoModel.PLCAlarmInfo rowInfo = new PLCInfoModel.PLCAlarmInfo();
|
||||
rowInfo.地址=Guid.NewGuid().ToString().Substring(0,8);
|
||||
alarmModels.Add(rowInfo);
|
||||
}
|
||||
dataGridView1.Refresh();
|
||||
//PLCInfoModel.PLCAlarmInfo rowInfo = new PLCInfoModel.PLCAlarmInfo();
|
||||
//int count=alarmModels.Where(item => item.地址==rowInfo.地址).Count();
|
||||
//if (count>0)
|
||||
//{
|
||||
// MessageBox.Show("有新增加的行没有更改,请先修改!");
|
||||
// return;
|
||||
//}
|
||||
//alarmModels.Add(rowInfo);
|
||||
//var previousList = AlarmExcelHelper.DeepCopyList<PLCInfoModel.PLCAlarmInfo>(alarmModels);
|
||||
//string previousAddress = rowInfo.地址;
|
||||
//FrmEditAlarmRecord frmEditAlarmRecord = new FrmEditAlarmRecord(rowInfo);
|
||||
//frmEditAlarmRecord.ShowDialog();
|
||||
//count = previousList.Where(item => item.地址 != previousAddress && item.地址 == rowInfo.地址).Count();
|
||||
//if (count > 0)
|
||||
//{
|
||||
// rowInfo.地址 = previousAddress;
|
||||
// MessageBox.Show("PLC地址冲突,已回滚为以前的地址!");
|
||||
//}
|
||||
//dataGridView1.Refresh();
|
||||
}
|
||||
|
||||
private void button4_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView1.SelectedRows.Count > 0)
|
||||
{
|
||||
// 显示确认对话框
|
||||
var result = MessageBox.Show("确定要删除选中的行吗?", "确认删除", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
|
||||
|
||||
if (result != DialogResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// 遍历所有选中行并删除
|
||||
foreach (DataGridViewRow row in dataGridView1.SelectedRows)
|
||||
{
|
||||
// 如果行不是新行(未保存的行),则删除
|
||||
if (!row.IsNewRow && row.Index>=0)
|
||||
{
|
||||
//dataGridView1.Rows.Remove(row);
|
||||
selectAddress = GetCellValueByRowColumnIndex(dataGridView1, row.Index, "地址");
|
||||
var deleteItem = alarmModels.Where(item => item.地址 == selectAddress).FirstOrDefault();
|
||||
alarmModels.Remove(deleteItem);
|
||||
}
|
||||
}
|
||||
dataGridView1.Refresh();
|
||||
MessageBox.Show("删除成功!");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("请选择要删除的行。");
|
||||
}
|
||||
}
|
||||
|
||||
private void button2_Click(object sender, EventArgs e)
|
||||
{
|
||||
for (int i = 0; i < alarmModels.Count; i++)
|
||||
{
|
||||
alarmModels[i].代码 = (i + 1).ToString();
|
||||
}
|
||||
dataGridView1.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
120
CowainHmi/Alarm/FrmEditAlarmTable.resx
Normal file
120
CowainHmi/Alarm/FrmEditAlarmTable.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
31
CowainHmi/Alarm/PLCInfoModel.cs
Normal file
31
CowainHmi/Alarm/PLCInfoModel.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CowainHmi.Alarm
|
||||
{
|
||||
public class PLCInfoModel
|
||||
{
|
||||
[Serializable]
|
||||
public class PLCAlarmInfo
|
||||
{
|
||||
public string PLC { get; set; } = "0";
|
||||
public string 地址 { get; set; } = "DB9999.0.0";
|
||||
public string 类型 { get; set; } = DataType.BIT.ToString();
|
||||
public string 触发条件 { get; set; } = "1";
|
||||
public string 代码 { get; set; } = "1";
|
||||
public string 报警组 { get; set; } = "1";
|
||||
public string 等级 { get; set; } = AlarmType.Null.ToString();
|
||||
public string 语言1 { get; set; } = "报警";
|
||||
public string 语言2 { get; set; }
|
||||
public string 语言3 { get; set; }
|
||||
public string 语言4 { get; set; }
|
||||
public string 语言5 { get; set; }
|
||||
public string 语言6 { get; set; }
|
||||
public string 语言7 { get; set; }
|
||||
public string 语言8 { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user