This commit is contained in:
GukSang.Jin
2026-02-05 15:19:07 +08:00
parent b648d0b83c
commit 09568c2c18
9 changed files with 614 additions and 217 deletions

View File

@@ -25,7 +25,8 @@ namespace 全自动水压检测仪
private DataGridView dataGridView;
private Button btnExport;
private Button btnReturn;
private Button btnDelete;
private ConductivityRepository _repository;
public Report()
{
InitializeComponent();
@@ -38,6 +39,7 @@ namespace 全自动水压检测仪
this.Text = "测试数据报表";
this.StartPosition = FormStartPosition.CenterScreen;
this.ResumeLayout(false);
}
public Report(List<ConductivityTestData> CurrentReport)
@@ -53,6 +55,7 @@ namespace 全自动水压检测仪
this.StartPosition = FormStartPosition.CenterScreen;
this.ResumeLayout(false);
this.CurrentReport = CurrentReport;
_repository = new ConductivityRepository();
}
/// <summary>
@@ -115,12 +118,12 @@ namespace 全自动水压检测仪
private void CreateGridColumns()
{
dataGridView.Columns.Clear();
dataGridView.ScrollBars = ScrollBars.Both;
dataGridView.Columns.Add(new DataGridViewTextBoxColumn
{
Name = "Id",
HeaderText = "编号",
Width = 70,
Width = 50,
DataPropertyName = "Id", // 绑定到ConductivityTestData的Id属性
SortMode = DataGridViewColumnSortMode.NotSortable,
DefaultCellStyle = { Alignment = DataGridViewContentAlignment.MiddleCenter }
@@ -128,20 +131,20 @@ namespace 全自动水压检测仪
dataGridView.Columns.Add(new DataGridViewTextBoxColumn
{
Name = "ContactNumber",
Name = "lldh",
HeaderText = "联络单号",
Width = 150,
DataPropertyName = "ContactNumber",
Width = 140,
DataPropertyName = "lldh",
SortMode = DataGridViewColumnSortMode.NotSortable,
DefaultCellStyle = { Alignment = DataGridViewContentAlignment.MiddleCenter }
});
dataGridView.Columns.Add(new DataGridViewTextBoxColumn
{
Name = "ItemNumber",
Name = "jh",
HeaderText = "件号",
Width = 130,
DataPropertyName = "ItemNumber",
Width = 120,
DataPropertyName = "jh",
SortMode = DataGridViewColumnSortMode.NotSortable,
DefaultCellStyle = { Alignment = DataGridViewContentAlignment.MiddleCenter }
});
@@ -165,7 +168,7 @@ namespace 全自动水压检测仪
{
Name = "quantity",
HeaderText = "数量",
Width = 80,
Width = 50,
DataPropertyName = "quantity",
SortMode = DataGridViewColumnSortMode.NotSortable,
DefaultCellStyle = {
@@ -274,7 +277,7 @@ namespace 全自动水压检测仪
{
Name = "standarderror",
HeaderText = "标准差值(PSI)",
Width = 75,
Width = 95,
DataPropertyName = "standarderror",
SortMode = DataGridViewColumnSortMode.NotSortable,
DefaultCellStyle = {
@@ -369,6 +372,28 @@ namespace 全自动水压检测仪
btnReturn.Cursor = Cursors.Hand;
// 导出报表按钮
btnDelete = new Button
{
Text = "一键清除",
Width = 100,
Height = 35,
Font = new Font(this.Font, FontStyle.Regular),
BackColor = Color.LightSteelBlue,
FlatStyle = FlatStyle.Flat,
FlatAppearance = { BorderSize = 1, BorderColor = Color.SteelBlue },
Left = 260,
Top = 10,
};
btnDelete.Click += BtnDelete_Click;
btnDelete.Cursor = Cursors.Hand;
btnPanel.Controls.Add(btnDelete);
btnPanel.Controls.Add(btnExport);
btnPanel.Controls.Add(btnReturn);
@@ -447,16 +472,30 @@ namespace 全自动水压检测仪
private void Report_Load(object sender, EventArgs e)
{
// 检查数据源
if (CurrentReport == null || CurrentReport.Count == 0)
{
MessageBox.Show("没有测试数据可显示", "提示",
MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
//if (CurrentReport == null || CurrentReport.Count == 0)
//{
// MessageBox.Show("没有测试数据可显示", "提示",
// MessageBoxButtons.OK, MessageBoxIcon.Information);
// return;
//}
try
{
dataGridView.CellFormatting += DataGridView_CellFormatting;
var result = _repository.GetTestData();
if (result != null && result.Count > 0)
{
CurrentReport = result;
}
int i = 0;
CurrentReport.ForEach(x =>
{
i++;
x.Id = i;
});
dataGridView.DataSource = CurrentReport;
// 刷新显示
@@ -489,6 +528,28 @@ namespace 全自动水压检测仪
ReturnToMain();
}
/// <summary>
/// 返回按钮点击事件
/// </summary>
private void BtnDelete_Click(object sender, EventArgs e)
{
DialogResult ask = MessageBox.Show("此操作会清空所有历史数据,请先导出?",
"确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (ask == DialogResult.Yes)
{
CurrentReport.Clear();
dataGridView.DataSource = new List<ConductivityTestData>();
_repository.DeleteTestAllItems();
// 刷新显示
dataGridView.Refresh();
}
}
/// <summary>
/// 导出报表功能
/// </summary>