添加项目文件。
This commit is contained in:
25
WinFormsApp1.sln
Normal file
25
WinFormsApp1.sln
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.14.36414.22 d17.14
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsApp1", "WinFormsApp1\WinFormsApp1.csproj", "{0381403B-467B-4EF5-88B1-C81DC8C5F72C}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{0381403B-467B-4EF5-88B1-C81DC8C5F72C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{0381403B-467B-4EF5-88B1-C81DC8C5F72C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{0381403B-467B-4EF5-88B1-C81DC8C5F72C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{0381403B-467B-4EF5-88B1-C81DC8C5F72C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {8AF56E48-64A8-47EF-8B64-B63116FF7585}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
18
WinFormsApp1/FastDataGridView.cs
Normal file
18
WinFormsApp1/FastDataGridView.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
public class FastDataGridView : DataGridView
|
||||||
|
{
|
||||||
|
public FastDataGridView()
|
||||||
|
{
|
||||||
|
// 通过反射开启 DataGridView 的 DoubleBuffered 属性
|
||||||
|
typeof(DataGridView)
|
||||||
|
.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic)
|
||||||
|
.SetValue(this, true, null);
|
||||||
|
|
||||||
|
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
|
||||||
|
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
||||||
|
this.SetStyle(ControlStyles.UserPaint, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
202
WinFormsApp1/Form1.Designer.cs
generated
Normal file
202
WinFormsApp1/Form1.Designer.cs
generated
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
namespace WinFormDataGridViewDemo
|
||||||
|
{
|
||||||
|
partial class Form1
|
||||||
|
{
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
private System.Windows.Forms.Button btnCoverRow;
|
||||||
|
private System.Windows.Forms.Button btnCoverAll;
|
||||||
|
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
btnCoverRow = new Button();
|
||||||
|
btnCoverAll = new Button();
|
||||||
|
saveBtn = new Button();
|
||||||
|
LayoutPath = new TextBox();
|
||||||
|
button1 = new Button();
|
||||||
|
AlarmPath = new TextBox();
|
||||||
|
openFileDialog1 = new OpenFileDialog();
|
||||||
|
label1 = new Label();
|
||||||
|
panel3 = new Panel();
|
||||||
|
progressBar1 = new ProgressBar();
|
||||||
|
DiffCountLab = new Label();
|
||||||
|
label2 = new Label();
|
||||||
|
tableLayoutPanel1 = new TableLayoutPanel();
|
||||||
|
dataGridView1 = new DataGridView();
|
||||||
|
panel3.SuspendLayout();
|
||||||
|
tableLayoutPanel1.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// btnCoverRow
|
||||||
|
//
|
||||||
|
btnCoverRow.Location = new Point(238, 78);
|
||||||
|
btnCoverRow.Name = "btnCoverRow";
|
||||||
|
btnCoverRow.Size = new Size(90, 30);
|
||||||
|
btnCoverRow.TabIndex = 1;
|
||||||
|
btnCoverRow.Text = "覆盖选中行";
|
||||||
|
btnCoverRow.UseVisualStyleBackColor = true;
|
||||||
|
btnCoverRow.Click += btnCoverRow_Click;
|
||||||
|
//
|
||||||
|
// btnCoverAll
|
||||||
|
//
|
||||||
|
btnCoverAll.Location = new Point(132, 78);
|
||||||
|
btnCoverAll.Name = "btnCoverAll";
|
||||||
|
btnCoverAll.Size = new Size(100, 30);
|
||||||
|
btnCoverAll.TabIndex = 2;
|
||||||
|
btnCoverAll.Text = "覆盖全部";
|
||||||
|
btnCoverAll.UseVisualStyleBackColor = true;
|
||||||
|
btnCoverAll.Click += btnCoverAll_Click;
|
||||||
|
//
|
||||||
|
// saveBtn
|
||||||
|
//
|
||||||
|
saveBtn.Location = new Point(329, 43);
|
||||||
|
saveBtn.Name = "saveBtn";
|
||||||
|
saveBtn.Size = new Size(102, 30);
|
||||||
|
saveBtn.TabIndex = 4;
|
||||||
|
saveBtn.Text = "保存";
|
||||||
|
saveBtn.UseVisualStyleBackColor = true;
|
||||||
|
saveBtn.Click += SaveAlarm;
|
||||||
|
//
|
||||||
|
// LayoutPath
|
||||||
|
//
|
||||||
|
LayoutPath.Location = new Point(125, 9);
|
||||||
|
LayoutPath.Name = "LayoutPath";
|
||||||
|
LayoutPath.Size = new Size(198, 27);
|
||||||
|
LayoutPath.TabIndex = 6;
|
||||||
|
LayoutPath.Click += OpenLayoutXml_Click;
|
||||||
|
//
|
||||||
|
// button1
|
||||||
|
//
|
||||||
|
button1.Location = new Point(329, 7);
|
||||||
|
button1.Name = "button1";
|
||||||
|
button1.Size = new Size(102, 30);
|
||||||
|
button1.TabIndex = 5;
|
||||||
|
button1.Text = "重新加载";
|
||||||
|
button1.UseVisualStyleBackColor = true;
|
||||||
|
button1.Click += reloadXml;
|
||||||
|
//
|
||||||
|
// AlarmPath
|
||||||
|
//
|
||||||
|
AlarmPath.Location = new Point(125, 42);
|
||||||
|
AlarmPath.Name = "AlarmPath";
|
||||||
|
AlarmPath.Size = new Size(198, 27);
|
||||||
|
AlarmPath.TabIndex = 8;
|
||||||
|
AlarmPath.Click += SecsAlarm_Click;
|
||||||
|
//
|
||||||
|
// openFileDialog1
|
||||||
|
//
|
||||||
|
openFileDialog1.FileName = "openFileDialog1";
|
||||||
|
//
|
||||||
|
// label1
|
||||||
|
//
|
||||||
|
label1.AutoSize = true;
|
||||||
|
label1.Location = new Point(16, 13);
|
||||||
|
label1.Name = "label1";
|
||||||
|
label1.Size = new Size(101, 20);
|
||||||
|
label1.TabIndex = 9;
|
||||||
|
label1.Text = "LayoutAlarm";
|
||||||
|
//
|
||||||
|
// panel3
|
||||||
|
//
|
||||||
|
panel3.Controls.Add(progressBar1);
|
||||||
|
panel3.Controls.Add(DiffCountLab);
|
||||||
|
panel3.Controls.Add(btnCoverAll);
|
||||||
|
panel3.Controls.Add(btnCoverRow);
|
||||||
|
panel3.Controls.Add(button1);
|
||||||
|
panel3.Controls.Add(saveBtn);
|
||||||
|
panel3.Controls.Add(label2);
|
||||||
|
panel3.Controls.Add(LayoutPath);
|
||||||
|
panel3.Controls.Add(label1);
|
||||||
|
panel3.Controls.Add(AlarmPath);
|
||||||
|
panel3.Location = new Point(3, 3);
|
||||||
|
panel3.Name = "panel3";
|
||||||
|
panel3.Size = new Size(760, 111);
|
||||||
|
panel3.TabIndex = 10;
|
||||||
|
//
|
||||||
|
// progressBar1
|
||||||
|
//
|
||||||
|
progressBar1.Location = new Point(16, 81);
|
||||||
|
progressBar1.Name = "progressBar1";
|
||||||
|
progressBar1.Size = new Size(110, 24);
|
||||||
|
progressBar1.TabIndex = 12;
|
||||||
|
//
|
||||||
|
// DiffCountLab
|
||||||
|
//
|
||||||
|
DiffCountLab.AutoSize = true;
|
||||||
|
DiffCountLab.Location = new Point(334, 83);
|
||||||
|
DiffCountLab.Name = "DiffCountLab";
|
||||||
|
DiffCountLab.Size = new Size(84, 20);
|
||||||
|
DiffCountLab.TabIndex = 11;
|
||||||
|
DiffCountLab.Text = "差异行数:";
|
||||||
|
//
|
||||||
|
// label2
|
||||||
|
//
|
||||||
|
label2.AutoSize = true;
|
||||||
|
label2.Location = new Point(3, 43);
|
||||||
|
label2.Name = "label2";
|
||||||
|
label2.Size = new Size(116, 20);
|
||||||
|
label2.TabIndex = 10;
|
||||||
|
label2.Text = "SECSAlarmXml";
|
||||||
|
//
|
||||||
|
// tableLayoutPanel1
|
||||||
|
//
|
||||||
|
tableLayoutPanel1.AutoSize = true;
|
||||||
|
tableLayoutPanel1.ColumnCount = 1;
|
||||||
|
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
|
||||||
|
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
|
||||||
|
tableLayoutPanel1.Controls.Add(panel3, 0, 0);
|
||||||
|
tableLayoutPanel1.Controls.Add(dataGridView1, 0, 1);
|
||||||
|
tableLayoutPanel1.Location = new Point(22, 12);
|
||||||
|
tableLayoutPanel1.Name = "tableLayoutPanel1";
|
||||||
|
tableLayoutPanel1.RowCount = 2;
|
||||||
|
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 19.0031147F));
|
||||||
|
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 80.99689F));
|
||||||
|
tableLayoutPanel1.Size = new Size(816, 617);
|
||||||
|
tableLayoutPanel1.TabIndex = 12;
|
||||||
|
//
|
||||||
|
// dataGridView1
|
||||||
|
//
|
||||||
|
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
dataGridView1.Location = new Point(3, 120);
|
||||||
|
dataGridView1.Name = "dataGridView1";
|
||||||
|
dataGridView1.RowHeadersWidth = 51;
|
||||||
|
dataGridView1.Size = new Size(810, 478);
|
||||||
|
dataGridView1.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// Form1
|
||||||
|
//
|
||||||
|
ClientSize = new Size(1454, 634);
|
||||||
|
Controls.Add(tableLayoutPanel1);
|
||||||
|
Name = "Form1";
|
||||||
|
Text = "AlarmDiff";
|
||||||
|
panel3.ResumeLayout(false);
|
||||||
|
panel3.PerformLayout();
|
||||||
|
tableLayoutPanel1.ResumeLayout(false);
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
private Button saveBtn;
|
||||||
|
private DataGridView dataGridView1;
|
||||||
|
private Button button1;
|
||||||
|
private OpenFileDialog openFileDialog1;
|
||||||
|
private TextBox LayoutPath;
|
||||||
|
private TextBox AlarmPath;
|
||||||
|
private Label label1;
|
||||||
|
private Panel panel3;
|
||||||
|
private Label label2;
|
||||||
|
private Panel panel1;
|
||||||
|
private TableLayoutPanel tableLayoutPanel1;
|
||||||
|
private Label DiffCountLab;
|
||||||
|
private ProgressBar progressBar1;
|
||||||
|
}
|
||||||
|
}
|
||||||
386
WinFormsApp1/Form1.cs
Normal file
386
WinFormsApp1/Form1.cs
Normal file
@@ -0,0 +1,386 @@
|
|||||||
|
using System;
|
||||||
|
using System.Data;
|
||||||
|
using System.Data.SqlTypes;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using System.Xml;
|
||||||
|
|
||||||
|
namespace WinFormDataGridViewDemo
|
||||||
|
{
|
||||||
|
public partial class Form1 : Form
|
||||||
|
{
|
||||||
|
private static Boolean SaveFlag = true;
|
||||||
|
private int diffcount = 0;
|
||||||
|
//<2F><>ʼ<EFBFBD><CABC>
|
||||||
|
public Form1()
|
||||||
|
{
|
||||||
|
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
// <20><>ʼ<EFBFBD><CABC> DataGridView
|
||||||
|
dataGridView1.ColumnCount = 4;
|
||||||
|
dataGridView1.Columns[0].Name = "LayoutKey";
|
||||||
|
dataGridView1.Columns[1].Name = "LayoutValue";
|
||||||
|
dataGridView1.Columns[2].Name = "SecsKey";
|
||||||
|
dataGridView1.Columns[3].Name = "SecsValue";
|
||||||
|
dataGridView1.Columns[0].ReadOnly = true;
|
||||||
|
dataGridView1.Columns[1].ReadOnly = true;
|
||||||
|
dataGridView1.Columns[2].ReadOnly = true;
|
||||||
|
dataGridView1.Columns[3].ReadOnly = false;
|
||||||
|
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
|
||||||
|
dataGridView1.AllowUserToAddRows = false;
|
||||||
|
LoadDataGrid();
|
||||||
|
dataGridView1.Dock = DockStyle.Fill;
|
||||||
|
tableLayoutPanel1.Dock = DockStyle.Fill;
|
||||||
|
dataGridView1.RowPostPaint += dataGridView1_RowPostPaint;
|
||||||
|
dataGridView1.CellFormatting += dataGridView1_CellFormatting;
|
||||||
|
dataGridView1.AllowUserToAddRows = false;
|
||||||
|
//dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = System.Drawing.Color.LightGray;
|
||||||
|
|
||||||
|
int w = 0;
|
||||||
|
foreach (DataGridViewColumn item in dataGridView1.Columns)
|
||||||
|
{
|
||||||
|
w += item.Width;
|
||||||
|
}
|
||||||
|
dataGridView1.Width = w;
|
||||||
|
|
||||||
|
int borderWidth = this.Width - this.ClientSize.Width;
|
||||||
|
this.Width = dataGridView1.Width + borderWidth + 200;
|
||||||
|
}
|
||||||
|
//<2F><><EFBFBD><EFBFBD>
|
||||||
|
private void LoadDataGrid()
|
||||||
|
{
|
||||||
|
SaveFlag = true;
|
||||||
|
var alramLayout = @"D:\iWISEETEC\ABN12\\AlarmLayout_Eng.xml";
|
||||||
|
var alramSecsXml = @"D:\iWISEETEC\WSecsAgent\\SecsPar\\config\\yui.xml";
|
||||||
|
if (!string.Empty.Equals(LayoutPath.Text))
|
||||||
|
{
|
||||||
|
alramLayout = LayoutPath.Text;
|
||||||
|
}
|
||||||
|
if (!string.Empty.Equals(AlarmPath.Text))
|
||||||
|
{
|
||||||
|
alramSecsXml = AlarmPath.Text;
|
||||||
|
}
|
||||||
|
var layoutResult = LoadAlarmLayoutXML(alramLayout);
|
||||||
|
var secsResult = LoadAlarmSecsXML(alramSecsXml, out XmlDocument doc);
|
||||||
|
|
||||||
|
dataGridView1.Rows.Clear();
|
||||||
|
|
||||||
|
var mergedList = layoutResult.Select(kv => new
|
||||||
|
{
|
||||||
|
LayoutKey = kv.Key,
|
||||||
|
LayoutValue = kv.Value,
|
||||||
|
SecsKey = kv.Key,
|
||||||
|
SecsValue = secsResult.ContainsKey(kv.Key) ? secsResult[kv.Key] : ""
|
||||||
|
}).ToList();
|
||||||
|
|
||||||
|
foreach (var item in mergedList)
|
||||||
|
{
|
||||||
|
dataGridView1.Rows.Add(item.LayoutKey, item.LayoutValue, item.SecsKey, item.SecsValue);
|
||||||
|
}
|
||||||
|
diffcount = 0;
|
||||||
|
UpdateDiffCount();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>
|
||||||
|
private void btnCoverRow_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
foreach (DataGridViewRow row in dataGridView1.SelectedRows)
|
||||||
|
{
|
||||||
|
if (row.IsNewRow) continue;
|
||||||
|
var name = row.Cells[1].Value?.ToString();
|
||||||
|
row.Cells[3].Value = name;
|
||||||
|
}
|
||||||
|
if (dataGridView1.CurrentRow != null)
|
||||||
|
{
|
||||||
|
var rowIndex = dataGridView1.CurrentRow.Index;
|
||||||
|
var code = dataGridView1.Rows[rowIndex].Cells[0].Value?.ToString();
|
||||||
|
var name = dataGridView1.Rows[rowIndex].Cells[1].Value?.ToString();
|
||||||
|
|
||||||
|
dataGridView1.Rows[rowIndex].Cells[3].Value = name;
|
||||||
|
SaveFlag = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateDiffCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
// <20><><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD>
|
||||||
|
private async void btnCoverAll_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var rowCount = dataGridView1.Rows.Count;
|
||||||
|
Cursor = Cursors.WaitCursor;
|
||||||
|
//progressBar1.Minimum = 0;
|
||||||
|
panel3.Enabled = false;
|
||||||
|
progressBar1.Value = 0;
|
||||||
|
progressBar1.Maximum = diffcount;
|
||||||
|
progressBar1.Visible = true;
|
||||||
|
var index = 0;
|
||||||
|
await Task.Run(() =>
|
||||||
|
{
|
||||||
|
foreach (DataGridViewRow row in dataGridView1.Rows)
|
||||||
|
{
|
||||||
|
var leftValue = row.Cells[1].Value.ToString();
|
||||||
|
if ("" == leftValue)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
var rightValue = row.Cells[3].Value.ToString();
|
||||||
|
if (leftValue == rightValue)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Invoke(() =>
|
||||||
|
{
|
||||||
|
index++;
|
||||||
|
return row.Cells[3].Value = leftValue;
|
||||||
|
});
|
||||||
|
|
||||||
|
SaveFlag = false;
|
||||||
|
|
||||||
|
Invoke(() => {
|
||||||
|
progressBar1.Value += 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
diffcount -= index;
|
||||||
|
Invoke(SetDiffCountText);
|
||||||
|
});
|
||||||
|
progressBar1.Value = 0;
|
||||||
|
panel3.Enabled = true;
|
||||||
|
this.Cursor = Cursors.Default;
|
||||||
|
MessageBox.Show($"<22>Ѹ<EFBFBD><D1B8><EFBFBD> {index} <20><>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>桿д<E6A1BF><D0B4>XML");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//<2F>к<EFBFBD>
|
||||||
|
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
|
||||||
|
{
|
||||||
|
string rowNumber = (e.RowIndex + 1).ToString();
|
||||||
|
|
||||||
|
var headerBounds = new Rectangle(
|
||||||
|
e.RowBounds.Left,
|
||||||
|
e.RowBounds.Top,
|
||||||
|
dataGridView1.RowHeadersWidth,
|
||||||
|
e.RowBounds.Height);
|
||||||
|
|
||||||
|
TextRenderer.DrawText(
|
||||||
|
e.Graphics,
|
||||||
|
rowNumber,
|
||||||
|
dataGridView1.Font,
|
||||||
|
headerBounds,
|
||||||
|
SystemColors.ControlText,
|
||||||
|
TextFormatFlags.VerticalCenter | TextFormatFlags.Right
|
||||||
|
);
|
||||||
|
}
|
||||||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.ColumnIndex == 3 && e.RowIndex >= 0)
|
||||||
|
{
|
||||||
|
if (dataGridView1.Rows[e.RowIndex].Cells[1].Value?.ToString() != dataGridView1.Rows[e.RowIndex].Cells[3].Value?.ToString())
|
||||||
|
{
|
||||||
|
//dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.FromArgb(255, 182, 193);
|
||||||
|
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.FromArgb(255, 200, 200);
|
||||||
|
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.White;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = dataGridView1.DefaultCellStyle.BackColor;
|
||||||
|
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.ForeColor = dataGridView1.DefaultCellStyle.ForeColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
//ͳ<>Ʋ<EFBFBD><C6B2><EFBFBD>
|
||||||
|
private void UpdateDiffCount()
|
||||||
|
{
|
||||||
|
if (diffcount != 0) diffcount = 0;
|
||||||
|
var map = new Dictionary<string, int>();
|
||||||
|
foreach (DataGridViewRow row in dataGridView1.Rows)
|
||||||
|
{
|
||||||
|
if (row.IsNewRow) continue;
|
||||||
|
|
||||||
|
if (!(row.Cells[1].Value.ToString() == row.Cells[3].Value?.ToString()))
|
||||||
|
{
|
||||||
|
diffcount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SetDiffCountText();
|
||||||
|
}
|
||||||
|
//<2F><><EFBFBD><EFBFBD>
|
||||||
|
private void SaveAlarm(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (SaveFlag)
|
||||||
|
{
|
||||||
|
MessageBox.Show("δ<><EFBFBD><DEB8><EFBFBD><EFBFBD>豣<EFBFBD><E8B1A3>!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string alramSecsXml = @"D:\iWISEETEC\WSecsAgent\SecsPar\config\yui.xml";
|
||||||
|
|
||||||
|
if (!File.Exists(alramSecsXml))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Secs XML <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
XmlDocument doc = new XmlDocument();
|
||||||
|
doc.Load(alramSecsXml);
|
||||||
|
|
||||||
|
XmlNode root = doc.DocumentElement;
|
||||||
|
if (root == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("XML <20><><EFBFBD>ڵ㲻<DAB5><E3B2BB><EFBFBD>ڣ<EFBFBD>");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
XmlNodeList nodes = doc.SelectNodes("//Item");
|
||||||
|
Dictionary<int, XmlNode> nodeDict = new Dictionary<int, XmlNode>();
|
||||||
|
|
||||||
|
if (nodes != null)
|
||||||
|
{
|
||||||
|
foreach (XmlNode node in nodes)
|
||||||
|
{
|
||||||
|
if (node.Attributes?["Code"] != null &&
|
||||||
|
int.TryParse(node.Attributes["Code"].Value, out int code))
|
||||||
|
{
|
||||||
|
nodeDict[code] = node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (DataGridViewRow row in dataGridView1.Rows)
|
||||||
|
{
|
||||||
|
if (row.IsNewRow) continue;
|
||||||
|
|
||||||
|
if (int.TryParse(row.Cells[2].Value?.ToString(), out int key))
|
||||||
|
{
|
||||||
|
string newValue = row.Cells[3].Value?.ToString() ?? "";
|
||||||
|
|
||||||
|
if (nodeDict.ContainsKey(key))
|
||||||
|
{
|
||||||
|
// <20><EFBFBD>
|
||||||
|
nodeDict[key].Attributes["Name"].Value = newValue;
|
||||||
|
//Description<6F><6E><EFBFBD>ܲ<EFBFBD><DCB2><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
if (nodeDict[key].Attributes["Description"] != null)
|
||||||
|
{
|
||||||
|
nodeDict[key].Attributes["Description"].Value = newValue;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// <20><><EFBFBD><EFBFBD>
|
||||||
|
XmlElement newNode = doc.CreateElement("Item");
|
||||||
|
XmlAttribute codeAttr = doc.CreateAttribute("Code");
|
||||||
|
XmlAttribute UnitAttr = doc.CreateAttribute("Unit");
|
||||||
|
XmlAttribute LevelAttr = doc.CreateAttribute("Level");
|
||||||
|
XmlAttribute nameAttr = doc.CreateAttribute("Name");
|
||||||
|
XmlAttribute descriptionAttr = doc.CreateAttribute("Description");
|
||||||
|
XmlAttribute HowToAttr = doc.CreateAttribute("HowTo");
|
||||||
|
|
||||||
|
codeAttr.Value = key.ToString();
|
||||||
|
UnitAttr.Value = "00";
|
||||||
|
LevelAttr.Value = "W";
|
||||||
|
nameAttr.Value = newValue;
|
||||||
|
descriptionAttr.Value = newValue;
|
||||||
|
HowToAttr.Value = "";
|
||||||
|
|
||||||
|
newNode.Attributes.Append(codeAttr);
|
||||||
|
newNode.Attributes.Append(UnitAttr);
|
||||||
|
newNode.Attributes.Append(LevelAttr);
|
||||||
|
newNode.Attributes.Append(nameAttr);
|
||||||
|
newNode.Attributes.Append(descriptionAttr);
|
||||||
|
newNode.Attributes.Append(HowToAttr);
|
||||||
|
|
||||||
|
root.AppendChild(newNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
doc.Save(alramSecsXml);
|
||||||
|
MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>");
|
||||||
|
LoadDataGrid();
|
||||||
|
}
|
||||||
|
//<2F><><EFBFBD><EFBFBD>xml
|
||||||
|
private Dictionary<int, string> LoadAlarmLayoutXML(string path)
|
||||||
|
{
|
||||||
|
Dictionary<int, string> result = new Dictionary<int, string>();
|
||||||
|
string xmlContent = File.ReadAllText(path);
|
||||||
|
XmlDocument doc = new XmlDocument();
|
||||||
|
doc.LoadXml(xmlContent);
|
||||||
|
|
||||||
|
XmlNodeList nodes = doc.SelectNodes("//wAlarmLayout");
|
||||||
|
foreach (XmlNode node in nodes)
|
||||||
|
{
|
||||||
|
int erCode = int.Parse(node["erCode"].InnerText);
|
||||||
|
string msg = node["Msg"]?.InnerText ?? "";
|
||||||
|
|
||||||
|
result[erCode] = msg;
|
||||||
|
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
//<2F><><EFBFBD><EFBFBD>xml
|
||||||
|
private Dictionary<int, string> LoadAlarmSecsXML(string path, out XmlDocument doc)
|
||||||
|
{
|
||||||
|
var result = new Dictionary<int, string>();
|
||||||
|
doc = new XmlDocument();
|
||||||
|
|
||||||
|
doc.Load(path);
|
||||||
|
|
||||||
|
XmlNodeList nodes = doc.SelectNodes("//Item");
|
||||||
|
if (nodes == null) return result;
|
||||||
|
|
||||||
|
foreach (XmlNode node in nodes)
|
||||||
|
{
|
||||||
|
if (node.Attributes == null) continue;
|
||||||
|
|
||||||
|
string codeStr = node.Attributes["Code"]?.Value;
|
||||||
|
string name = node.Attributes["Name"]?.Value ?? "";
|
||||||
|
|
||||||
|
if (int.TryParse(codeStr, out int code))
|
||||||
|
{
|
||||||
|
result[code] = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
//<2F><><EFBFBD><EFBFBD> reloadXml
|
||||||
|
private void reloadXml(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadDataGrid();
|
||||||
|
MessageBox.Show($"<22><><EFBFBD>¼<EFBFBD><C2BC>سɹ<D8B3><C9B9><EFBFBD>", "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||||
|
|
||||||
|
}
|
||||||
|
//<2F><><EFBFBD><EFBFBD>LayoutXml·<6C><C2B7>
|
||||||
|
private void OpenLayoutXml_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
this.LayoutPath.Text = this.openFileDialog1.FileName;
|
||||||
|
LoadDataGrid();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
//<2F><><EFBFBD><EFBFBD>SecsAlarm·<6D><C2B7>
|
||||||
|
private void SecsAlarm_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
this.AlarmPath.Text = this.openFileDialog1.FileName;
|
||||||
|
LoadDataGrid();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//<2F><><EFBFBD><EFBFBD>lab<61><62><EFBFBD><EFBFBD>
|
||||||
|
private void SetDiffCountText()
|
||||||
|
{
|
||||||
|
this.DiffCountLab.Text = $"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:{diffcount}";
|
||||||
|
}
|
||||||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
126
WinFormsApp1/Form1.resx
Normal file
126
WinFormsApp1/Form1.resx
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
<?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="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>17, 7</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>52</value>
|
||||||
|
</metadata>
|
||||||
|
</root>
|
||||||
19
WinFormsApp1/Program.cs
Normal file
19
WinFormsApp1/Program.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using WinFormDataGridViewDemo;
|
||||||
|
|
||||||
|
namespace WinFormsApp1
|
||||||
|
{
|
||||||
|
internal static class Program
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The main entry point for the application.
|
||||||
|
/// </summary>
|
||||||
|
[STAThread]
|
||||||
|
static void Main()
|
||||||
|
{
|
||||||
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
|
// see https://aka.ms/applicationconfiguration.
|
||||||
|
ApplicationConfiguration.Initialize();
|
||||||
|
Application.Run(new Form1());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
WinFormsApp1/WinFormsApp1.csproj
Normal file
11
WinFormsApp1/WinFormsApp1.csproj
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<TargetFramework>net8.0-windows</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
Reference in New Issue
Block a user