优化
This commit is contained in:
23
db/rollback_normaltemperature_split_columns.sql
Normal file
23
db/rollback_normaltemperature_split_columns.sql
Normal file
@@ -0,0 +1,23 @@
|
||||
-- =====================================================
|
||||
-- 数据库回滚脚本:normaltemperature表移除联络单号和件号字段
|
||||
-- 创建时间:2026-02-04
|
||||
-- 说明:如果升级出现问题,使用此脚本回滚
|
||||
-- =====================================================
|
||||
|
||||
USE fullautowaterpressure;
|
||||
|
||||
-- 1. 删除索引
|
||||
DROP INDEX IF EXISTS `idx_contact_number` ON `normaltemperature`;
|
||||
DROP INDEX IF EXISTS `idx_item_number` ON `normaltemperature`;
|
||||
|
||||
-- 2. 删除新增字段
|
||||
ALTER TABLE `normaltemperature`
|
||||
DROP COLUMN IF EXISTS `ContactNumber`,
|
||||
DROP COLUMN IF EXISTS `ItemNumber`;
|
||||
|
||||
-- 3. 验证回滚
|
||||
DESCRIBE normaltemperature;
|
||||
|
||||
-- =====================================================
|
||||
-- 回滚完成
|
||||
-- =====================================================
|
||||
50
db/upgrade_normaltemperature_split_columns.sql
Normal file
50
db/upgrade_normaltemperature_split_columns.sql
Normal file
@@ -0,0 +1,50 @@
|
||||
-- =====================================================
|
||||
-- 数据库升级脚本:normaltemperature表添加联络单号和件号字段
|
||||
-- 创建时间:2026-02-04
|
||||
-- 说明:将barcode字段拆分为ContactNumber和ItemNumber两个独立字段
|
||||
-- =====================================================
|
||||
|
||||
USE fullautowaterpressure;
|
||||
|
||||
-- 1. 添加新字段
|
||||
ALTER TABLE `normaltemperature`
|
||||
ADD COLUMN `ContactNumber` VARCHAR(100) NULL COMMENT '联络单号' AFTER `barcode`,
|
||||
ADD COLUMN `ItemNumber` VARCHAR(100) NULL COMMENT '件号' AFTER `ContactNumber`;
|
||||
|
||||
-- 2. 迁移现有数据(假设barcode格式为"联络单号-件号")
|
||||
-- 如果barcode包含"-",则拆分
|
||||
UPDATE `normaltemperature`
|
||||
SET
|
||||
`ContactNumber` = SUBSTRING_INDEX(`barcode`, '-', 1),
|
||||
`ItemNumber` = SUBSTRING_INDEX(`barcode`, '-', -1)
|
||||
WHERE `barcode` IS NOT NULL AND `barcode` LIKE '%-%';
|
||||
|
||||
-- 如果barcode不包含"-",则全部作为联络单号
|
||||
UPDATE `normaltemperature`
|
||||
SET
|
||||
`ContactNumber` = `barcode`,
|
||||
`ItemNumber` = ''
|
||||
WHERE `barcode` IS NOT NULL AND `barcode` NOT LIKE '%-%';
|
||||
|
||||
-- 3. 创建索引以提高查询性能
|
||||
CREATE INDEX `idx_contact_number` ON `normaltemperature`(`ContactNumber`);
|
||||
CREATE INDEX `idx_item_number` ON `normaltemperature`(`ItemNumber`);
|
||||
|
||||
-- 4. 验证数据迁移
|
||||
SELECT
|
||||
COUNT(*) as total_records,
|
||||
COUNT(ContactNumber) as has_contact_number,
|
||||
COUNT(ItemNumber) as has_item_number,
|
||||
COUNT(CASE WHEN ContactNumber IS NOT NULL AND ItemNumber IS NOT NULL THEN 1 END) as both_fields
|
||||
FROM normaltemperature;
|
||||
|
||||
-- 5. 显示示例数据
|
||||
SELECT
|
||||
Id, barcode, ContactNumber, ItemNumber, CreateTime
|
||||
FROM normaltemperature
|
||||
ORDER BY Id DESC
|
||||
LIMIT 10;
|
||||
|
||||
-- =====================================================
|
||||
-- 升级完成
|
||||
-- =====================================================
|
||||
88
db/verify_split_columns.sql
Normal file
88
db/verify_split_columns.sql
Normal file
@@ -0,0 +1,88 @@
|
||||
-- =====================================================
|
||||
-- 验证脚本:检查联络单号和件号字段是否正确
|
||||
-- 创建时间:2026-02-04
|
||||
-- =====================================================
|
||||
|
||||
USE fullautowaterpressure;
|
||||
|
||||
-- 1. 检查normaltemperature表结构
|
||||
SHOW COLUMNS FROM normaltemperature LIKE '%Contact%';
|
||||
SHOW COLUMNS FROM normaltemperature LIKE '%Item%';
|
||||
|
||||
-- 2. 检查scandata表结构
|
||||
SHOW COLUMNS FROM scandata LIKE '%Contact%';
|
||||
SHOW COLUMNS FROM scandata LIKE '%Item%';
|
||||
|
||||
-- 3. 检查索引
|
||||
SHOW INDEX FROM normaltemperature WHERE Key_name LIKE 'idx_%';
|
||||
SHOW INDEX FROM scandata WHERE Key_name LIKE 'idx_%';
|
||||
|
||||
-- 4. 统计normaltemperature表数据
|
||||
SELECT
|
||||
'报表数据统计' as 表名,
|
||||
COUNT(*) as 总记录数,
|
||||
COUNT(ContactNumber) as 有联络单号,
|
||||
COUNT(ItemNumber) as 有件号,
|
||||
COUNT(CASE WHEN ContactNumber IS NOT NULL AND ItemNumber IS NOT NULL THEN 1 END) as 两者都有,
|
||||
COUNT(CASE WHEN ContactNumber IS NULL OR ItemNumber IS NULL THEN 1 END) as 缺失数据
|
||||
FROM normaltemperature;
|
||||
|
||||
-- 5. 统计scandata表数据
|
||||
SELECT
|
||||
'扫码数据统计' as 表名,
|
||||
COUNT(*) as 总记录数,
|
||||
COUNT(ContactNumber) as 有联络单号,
|
||||
COUNT(ItemNumber) as 有件号,
|
||||
COUNT(CASE WHEN ContactNumber IS NOT NULL AND ItemNumber IS NOT NULL THEN 1 END) as 两者都有,
|
||||
COUNT(CASE WHEN ContactNumber IS NULL OR ItemNumber IS NULL THEN 1 END) as 缺失数据
|
||||
FROM scandata;
|
||||
|
||||
-- 6. 查看normaltemperature最新10条记录
|
||||
SELECT
|
||||
Id,
|
||||
barcode as 原条码,
|
||||
ContactNumber as 联络单号,
|
||||
ItemNumber as 件号,
|
||||
CreateTime as 创建时间
|
||||
FROM normaltemperature
|
||||
ORDER BY Id DESC
|
||||
LIMIT 10;
|
||||
|
||||
-- 7. 查看scandata最新10条记录
|
||||
SELECT
|
||||
Id,
|
||||
barcode as 原条码,
|
||||
ContactNumber as 联络单号,
|
||||
ItemNumber as 件号,
|
||||
CreateTime as 创建时间
|
||||
FROM scandata
|
||||
ORDER BY Id DESC
|
||||
LIMIT 10;
|
||||
|
||||
-- 8. 检查数据一致性(barcode应该等于ContactNumber-ItemNumber)
|
||||
SELECT
|
||||
'数据一致性检查' as 检查项,
|
||||
COUNT(*) as 不一致记录数
|
||||
FROM normaltemperature
|
||||
WHERE barcode IS NOT NULL
|
||||
AND ContactNumber IS NOT NULL
|
||||
AND ItemNumber IS NOT NULL
|
||||
AND barcode != CONCAT(ContactNumber, '-', ItemNumber);
|
||||
|
||||
-- 9. 查找可能有问题的数据
|
||||
SELECT
|
||||
Id,
|
||||
barcode,
|
||||
ContactNumber,
|
||||
ItemNumber,
|
||||
CONCAT(ContactNumber, '-', ItemNumber) as 应该的barcode
|
||||
FROM normaltemperature
|
||||
WHERE barcode IS NOT NULL
|
||||
AND ContactNumber IS NOT NULL
|
||||
AND ItemNumber IS NOT NULL
|
||||
AND barcode != CONCAT(ContactNumber, '-', ItemNumber)
|
||||
LIMIT 10;
|
||||
|
||||
-- =====================================================
|
||||
-- 验证完成
|
||||
-- =====================================================
|
||||
@@ -15,12 +15,22 @@ namespace 材料热传导系数
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 条码
|
||||
/// 条码(保留用于兼容性)
|
||||
/// </summary>
|
||||
public string barcode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 条码
|
||||
/// 联络单号
|
||||
/// </summary>
|
||||
public string ContactNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 件号
|
||||
/// </summary>
|
||||
public string ItemNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 温度
|
||||
/// </summary>
|
||||
public double temperature { get; set; }
|
||||
|
||||
@@ -125,10 +135,10 @@ namespace 材料热传导系数
|
||||
{
|
||||
connection.Open();
|
||||
var sql = @"INSERT INTO normaltemperature
|
||||
(barcode, temperature, startpressure, dwelltime,
|
||||
(barcode, ContactNumber, ItemNumber, temperature, startpressure, dwelltime,
|
||||
diffpressure, endpressure, CreateTime, type)
|
||||
VALUES
|
||||
(@barcode, @temperature, @startpressure, @dwelltime, @diffpressure,@endpressure,CURRENT_TIMESTAMP,@type)";
|
||||
(@barcode, @ContactNumber, @ItemNumber, @temperature, @startpressure, @dwelltime, @diffpressure, @endpressure, CURRENT_TIMESTAMP, @type)";
|
||||
connection.Execute(sql, data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -992,12 +992,17 @@ namespace 全自动水压检测仪
|
||||
uiTextBox6.Text = uiLabel22.Text;//压差
|
||||
uiTextBox7.Text = uiLabel19.Text;//结束压力
|
||||
|
||||
// 组合联络单号和件号
|
||||
string barcode = $"{uiTextBox2.Text.Trim()}-{uiTextBox10.Text.Trim()}";
|
||||
// 获取联络单号和件号
|
||||
string contactNumber = uiTextBox2.Text.Trim();
|
||||
string itemNumber = uiTextBox10.Text.Trim();
|
||||
// 组合条码用于兼容性
|
||||
string barcode = $"{contactNumber}-{itemNumber}";
|
||||
|
||||
CurrentReport.Add(new ConductivityTestData
|
||||
{
|
||||
barcode = barcode,
|
||||
ContactNumber = contactNumber,
|
||||
ItemNumber = itemNumber,
|
||||
CreateTime = DateTime.Now,
|
||||
diffpressure = uiTextBox6.Text.ToDouble(),
|
||||
dwelltime = uiTextBox8.Text.ToDouble(),
|
||||
@@ -1010,6 +1015,8 @@ namespace 全自动水压检测仪
|
||||
_repository.InsertReportItems(new ConductivityTestData
|
||||
{
|
||||
barcode = barcode,
|
||||
ContactNumber = contactNumber,
|
||||
ItemNumber = itemNumber,
|
||||
CreateTime = DateTime.Now,
|
||||
diffpressure = uiTextBox6.Text.ToDouble(),
|
||||
dwelltime = uiTextBox8.Text.ToDouble(),
|
||||
|
||||
@@ -128,10 +128,20 @@ namespace 全自动水压检测仪
|
||||
|
||||
dataGridView.Columns.Add(new DataGridViewTextBoxColumn
|
||||
{
|
||||
Name = "barcode",
|
||||
HeaderText = "联络单号和件号",
|
||||
Width = 280,
|
||||
DataPropertyName = "Barcode", // 注意属性名大小写
|
||||
Name = "ContactNumber",
|
||||
HeaderText = "联络单号",
|
||||
Width = 150,
|
||||
DataPropertyName = "ContactNumber",
|
||||
SortMode = DataGridViewColumnSortMode.NotSortable,
|
||||
DefaultCellStyle = { Alignment = DataGridViewContentAlignment.MiddleCenter }
|
||||
});
|
||||
|
||||
dataGridView.Columns.Add(new DataGridViewTextBoxColumn
|
||||
{
|
||||
Name = "ItemNumber",
|
||||
HeaderText = "件号",
|
||||
Width = 130,
|
||||
DataPropertyName = "ItemNumber",
|
||||
SortMode = DataGridViewColumnSortMode.NotSortable,
|
||||
DefaultCellStyle = { Alignment = DataGridViewContentAlignment.MiddleCenter }
|
||||
});
|
||||
@@ -430,24 +440,16 @@ namespace 全自动水压检测仪
|
||||
using (StreamWriter writer = new StreamWriter(filePath, false, System.Text.Encoding.UTF8))
|
||||
{
|
||||
// 写入表头
|
||||
writer.WriteLine("编号,联络单号和件号,时间日期,初始压力(PSI),结束压力(PSI),压差(PSI),保压时间(h),温度模式");
|
||||
writer.WriteLine("编号,联络单号,件号,时间日期,初始压力(PSI),结束压力(PSI),压差(PSI),保压时间(h),温度模式");
|
||||
|
||||
// 写入数据
|
||||
foreach (var data in CurrentReport)
|
||||
{
|
||||
string tempMode = GetTemperatureModeDisplay(data.Type);
|
||||
|
||||
//writer.WriteLine($"{data.Id}," +
|
||||
// $"{data.barcode}," +
|
||||
// $"{data.CreateTime:yyyy-MM-dd HH:mm:ss}," +
|
||||
// $"{data.startpressure:F2}," +
|
||||
// $"{data.dwelltime:F1}," +
|
||||
// $"{data.diffpressure:F2}," +
|
||||
// $"{data.endpressure:F2}," +
|
||||
// $"{tempMode}");
|
||||
|
||||
writer.WriteLine($"{data.Id}," +
|
||||
$"{data.barcode}," +
|
||||
$"{data.ContactNumber ?? ""}," +
|
||||
$"{data.ItemNumber ?? ""}," +
|
||||
$"{data.CreateTime:yyyy-MM-dd HH:mm:ss}," +
|
||||
$"{data.startpressure:F2}," +
|
||||
$"{data.endpressure:F2}," +
|
||||
@@ -472,23 +474,24 @@ namespace 全自动水压检测仪
|
||||
writer.WriteLine("=======================================================\n");
|
||||
|
||||
// 写入表头
|
||||
writer.WriteLine(string.Format("{0,-8}{1,-20}{2,-20}{3,-12}{4,-12}{5,-12}{6,-12}{7,-10}",
|
||||
"编号", "联络单号和件号", "时间日期", "初始压力", "保压时间", "压差", "结束压力", "温度模式"));
|
||||
writer.WriteLine(new string('-', 120));
|
||||
writer.WriteLine(string.Format("{0,-8}{1,-15}{2,-15}{3,-20}{4,-12}{5,-12}{6,-12}{7,-12}{8,-10}",
|
||||
"编号", "联络单号", "件号", "时间日期", "初始压力", "结束压力", "压差", "保压时间", "温度模式"));
|
||||
writer.WriteLine(new string('-', 130));
|
||||
|
||||
// 写入数据
|
||||
foreach (var data in CurrentReport)
|
||||
{
|
||||
string tempMode = GetTemperatureModeDisplay(data.Type);
|
||||
|
||||
writer.WriteLine(string.Format("{0,-8}{1,-20}{2,-20}{3,-12:F2}{4,-12:F1}{5,-12:F2}{6,-12:F2}{7,-10}",
|
||||
writer.WriteLine(string.Format("{0,-8}{1,-15}{2,-15}{3,-20}{4,-12:F2}{5,-12:F2}{6,-12:F2}{7,-12:F1}{8,-10}",
|
||||
data.Id,
|
||||
data.barcode,
|
||||
data.ContactNumber ?? "",
|
||||
data.ItemNumber ?? "",
|
||||
data.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
data.startpressure,
|
||||
data.dwelltime,
|
||||
data.diffpressure,
|
||||
data.endpressure,
|
||||
data.diffpressure,
|
||||
data.dwelltime,
|
||||
tempMode));
|
||||
}
|
||||
}
|
||||
@@ -498,14 +501,6 @@ namespace 全自动水压检测仪
|
||||
/// </summary>
|
||||
private void ExportToExcel(string filePath)
|
||||
{
|
||||
//string csvPath = Path.ChangeExtension(filePath, ".csv");
|
||||
//ExportToCsv(csvPath);
|
||||
|
||||
//MessageBox.Show($"由于未安装Excel库,已导出为CSV文件:\n{csvPath}\n\n" +
|
||||
// "您可以将CSV文件导入Excel使用。", "导出提示",
|
||||
// MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
//ExcelPackage.LicenseContext = LicenseContext.NonCommercial; // 非商业用途
|
||||
|
||||
using (var package = new ExcelPackage())
|
||||
{
|
||||
var worksheet = package.Workbook.Worksheets.Add("测试数据报表");
|
||||
@@ -517,7 +512,7 @@ namespace 全自动水压检测仪
|
||||
int currentRow = 1;
|
||||
|
||||
// 主标题
|
||||
worksheet.Cells[currentRow, 1, currentRow, 8].Merge = true;
|
||||
worksheet.Cells[currentRow, 1, currentRow, 9].Merge = true;
|
||||
var titleCell = worksheet.Cells[currentRow, 1];
|
||||
titleCell.Value = "测试数据报表";
|
||||
titleCell.Style.Font.Size = 16;
|
||||
@@ -528,7 +523,7 @@ namespace 全自动水压检测仪
|
||||
currentRow++;
|
||||
|
||||
// 副标题
|
||||
worksheet.Cells[currentRow, 1, currentRow, 8].Merge = true;
|
||||
worksheet.Cells[currentRow, 1, currentRow, 9].Merge = true;
|
||||
var subTitleCell = worksheet.Cells[currentRow, 1];
|
||||
subTitleCell.Value = $"生成时间:{DateTime.Now:yyyy-MM-dd HH:mm:ss} | 记录数量:{CurrentReport.Count}条";
|
||||
subTitleCell.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
|
||||
@@ -537,7 +532,7 @@ namespace 全自动水压检测仪
|
||||
currentRow += 2;
|
||||
|
||||
// 表头
|
||||
string[] headers = { "编号", "联络单号和件号", "时间日期", "初始压力(PSI)", "结束压力(PSI)", "压差(PSI)", "保压时间(h)", "温度模式" };
|
||||
string[] headers = { "编号", "联络单号", "件号", "时间日期", "初始压力(PSI)", "结束压力(PSI)", "压差(PSI)", "保压时间(h)", "温度模式" };
|
||||
|
||||
for (int i = 0; i < headers.Length; i++)
|
||||
{
|
||||
@@ -565,16 +560,17 @@ namespace 全自动水压检测仪
|
||||
string tempMode = GetTemperatureModeDisplay(data.Type);
|
||||
|
||||
worksheet.Cells[currentRow, 1].Value = data.Id;
|
||||
worksheet.Cells[currentRow, 2].Value = data.barcode;
|
||||
worksheet.Cells[currentRow, 3].Value = data.CreateTime;
|
||||
worksheet.Cells[currentRow, 4].Value = data.startpressure;
|
||||
worksheet.Cells[currentRow, 5].Value = data.endpressure;
|
||||
worksheet.Cells[currentRow, 6].Value = data.diffpressure;
|
||||
worksheet.Cells[currentRow, 7].Value = data.dwelltime;
|
||||
worksheet.Cells[currentRow, 8].Value = tempMode;
|
||||
worksheet.Cells[currentRow, 2].Value = data.ContactNumber ?? "";
|
||||
worksheet.Cells[currentRow, 3].Value = data.ItemNumber ?? "";
|
||||
worksheet.Cells[currentRow, 4].Value = data.CreateTime;
|
||||
worksheet.Cells[currentRow, 5].Value = data.startpressure;
|
||||
worksheet.Cells[currentRow, 6].Value = data.endpressure;
|
||||
worksheet.Cells[currentRow, 7].Value = data.diffpressure;
|
||||
worksheet.Cells[currentRow, 8].Value = data.dwelltime;
|
||||
worksheet.Cells[currentRow, 9].Value = tempMode;
|
||||
|
||||
// 设置数据行样式
|
||||
for (int col = 1; col <= 8; col++)
|
||||
for (int col = 1; col <= 9; col++)
|
||||
{
|
||||
var cell = worksheet.Cells[currentRow, col];
|
||||
cell.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
|
||||
@@ -590,11 +586,11 @@ namespace 全自动水压检测仪
|
||||
}
|
||||
|
||||
// 设置格式
|
||||
worksheet.Cells[currentRow, 3].Style.Numberformat.Format = "yyyy-mm-dd hh:mm:ss";
|
||||
worksheet.Cells[currentRow, 4].Style.Numberformat.Format = "0.00";
|
||||
worksheet.Cells[currentRow, 4].Style.Numberformat.Format = "yyyy-mm-dd hh:mm:ss";
|
||||
worksheet.Cells[currentRow, 5].Style.Numberformat.Format = "0.00";
|
||||
worksheet.Cells[currentRow, 6].Style.Numberformat.Format = "0.00";
|
||||
worksheet.Cells[currentRow, 7].Style.Numberformat.Format = "0.0";
|
||||
worksheet.Cells[currentRow, 7].Style.Numberformat.Format = "0.00";
|
||||
worksheet.Cells[currentRow, 8].Style.Numberformat.Format = "0.0";
|
||||
|
||||
// 设置行高
|
||||
worksheet.Row(currentRow).Height = 25;
|
||||
|
||||
Reference in New Issue
Block a user