优化桌面端无用菜单和地磅数据可手动功能。

This commit is contained in:
geht
2026-05-18 15:55:11 +08:00
parent 5800b6b61c
commit c11f3104cb
18 changed files with 628 additions and 118 deletions

View File

@@ -168,9 +168,12 @@ public class WeightRecordEditDialogViewModel : BaseViewModel, IDialogResultable<
return;
}
// 净重自动计算
if (Record.GrossWeight.HasValue && Record.TareWeight.HasValue)
// 净重自动计算0 视为未称,不计算净重)
if (Record.GrossWeight.HasValue && Record.GrossWeight.Value > 0
&& Record.TareWeight.HasValue && Record.TareWeight.Value > 0)
Record.NetWeight = Math.Round(Record.GrossWeight.Value - Record.TareWeight.Value, 2);
else
Record.NetWeight = null;
// 写入密炼物料
Record.MixerMaterialIds = _mixerMaterialIds;

View File

@@ -98,6 +98,21 @@ public class WeightRecordOperationViewModel : BaseViewModel
private bool _tareWeightCaptured;
public bool TareWeightCaptured { get => _tareWeightCaptured; set => SetProperty(ref _tareWeightCaptured, value); }
/// <summary>
/// 手动输入毛重/皮重(仅用于测试联调,正式过磅请关闭)。
/// </summary>
private bool _isManualWeightEntry;
public bool IsManualWeightEntry
{
get => _isManualWeightEntry;
set
{
if (!SetProperty(ref _isManualWeightEntry, value)) return;
CaptureGrossWeightCommand.RaiseCanExecuteChanged();
CaptureTareWeightCommand.RaiseCanExecuteChanged();
}
}
// ─── 表单绑定属性 ───
private DateTime _weighDate = DateTime.Today;
@@ -234,14 +249,27 @@ public class WeightRecordOperationViewModel : BaseViewModel
public double? GrossWeight
{
get => _grossWeight;
set { SetProperty(ref _grossWeight, value); RecalcNetWeight(); }
set
{
if (!SetProperty(ref _grossWeight, value)) return;
// 测试用手动录入:有有效数值即视为已填写(用于「已采集」提示与保存)
if (IsManualWeightEntry)
GrossWeightCaptured = value.HasValue && value.Value > 0;
RecalcNetWeight();
}
}
private double? _tareWeight;
public double? TareWeight
{
get => _tareWeight;
set { SetProperty(ref _tareWeight, value); RecalcNetWeight(); }
set
{
if (!SetProperty(ref _tareWeight, value)) return;
if (IsManualWeightEntry)
TareWeightCaptured = value.HasValue && value.Value > 0;
RecalcNetWeight();
}
}
private double? _netWeight;
@@ -312,10 +340,12 @@ public class WeightRecordOperationViewModel : BaseViewModel
CaptureGrossWeightCommand = new DelegateCommand(CaptureGrossWeight, CanCaptureGrossWeight)
.ObservesProperty(() => IsWeightStable)
.ObservesProperty(() => IsManualWeightEntry)
.ObservesProperty(() => GrossWeightCaptured)
.ObservesProperty(() => TareWeightCaptured);
CaptureTareWeightCommand = new DelegateCommand(CaptureTareWeight, CanCaptureTareWeight)
.ObservesProperty(() => IsWeightStable)
.ObservesProperty(() => IsManualWeightEntry)
.ObservesProperty(() => GrossWeightCaptured)
.ObservesProperty(() => TareWeightCaptured);
SaveCommand = new DelegateCommand(async () => await SaveAsync());
@@ -386,7 +416,8 @@ public class WeightRecordOperationViewModel : BaseViewModel
{
_vehiclePresent = true;
_stableCountdown = 0;
_baseWeight = _rnd.Next(18000, 65000); // 18~65吨随机
// 同一张单第二次上磅:模拟重量与已采值协调(先毛后皮 → 皮重小于毛重;先皮后毛 → 毛重大于皮重)
PickBaseWeightForCurrentWeighingScenario();
AddLog("检测到车辆入场");
// 模拟摄像头识别车牌2秒后回传
@@ -411,6 +442,40 @@ public class WeightRecordOperationViewModel : BaseViewModel
leaveTimer.Start();
}
/// <summary>
/// 按当前单据已填毛重/皮重生成模拟磅台基准重量,保证净重合理。
/// </summary>
private void PickBaseWeightForCurrentWeighingScenario()
{
if (HasEffectiveWeighValue(GrossWeight) && !HasEffectiveWeighValue(TareWeight))
{
var g = GrossWeight!.Value;
// 皮重需明显小于毛重,留出净重空间
var maxTare = Math.Max(0, g - 30);
var minTare = Math.Min(maxTare * 0.22, maxTare - 80);
minTare = Math.Max(0, minTare);
if (maxTare - minTare < 25)
minTare = Math.Max(0, maxTare * 0.45);
if (maxTare - minTare < 1)
maxTare = Math.Max(minTare + 1, g - 5);
_baseWeight = minTare + _rnd.NextDouble() * Math.Max(1e-6, maxTare - minTare);
}
else if (HasEffectiveWeighValue(TareWeight) && !HasEffectiveWeighValue(GrossWeight))
{
var t = TareWeight!.Value;
var lower = t + Math.Max(100, t * 0.05);
var span = 8000 + _rnd.NextDouble() * 12000;
var upper = Math.Min(65000, lower + span);
if (upper - lower < 500)
upper = lower + 500;
_baseWeight = lower + _rnd.NextDouble() * (upper - lower);
}
else
{
_baseWeight = _rnd.Next(18000, 65000); // 18~65 吨随机(首次过磅或两称已齐)
}
}
private void SimulateVehicleLeave()
{
_vehiclePresent = false;
@@ -446,19 +511,25 @@ public class WeightRecordOperationViewModel : BaseViewModel
private bool CanCaptureGrossWeight()
{
return IsWeightStable && !GrossWeightCaptured;
if (GrossWeightCaptured) return false;
// 手动测试模式:无需等稳定即可点采集
if (IsManualWeightEntry) return true;
return IsWeightStable;
}
private bool CanCaptureTareWeight()
{
return IsWeightStable && !TareWeightCaptured;
if (TareWeightCaptured) return false;
if (IsManualWeightEntry) return true;
return IsWeightStable;
}
private void RecalcNetWeight()
{
if (GrossWeight.HasValue && TareWeight.HasValue)
// 与后端一致0 或占位视为“未称”,避免仅毛重时 net=tare(0) 即毛重、单据误判完成
if (HasEffectiveWeighValue(GrossWeight) && HasEffectiveWeighValue(TareWeight))
{
NetWeight = Math.Round(GrossWeight.Value - TareWeight.Value, 2);
NetWeight = Math.Round(GrossWeight!.Value - TareWeight!.Value, 2);
RaisePropertyChanged(nameof(NetWeightDisplay));
}
else
@@ -468,6 +539,8 @@ public class WeightRecordOperationViewModel : BaseViewModel
}
}
private static bool HasEffectiveWeighValue(double? kg) => kg.HasValue && kg.Value > 0;
private async Task SaveAsync()
{
if (string.IsNullOrWhiteSpace(PlateNumber))
@@ -481,12 +554,12 @@ public class WeightRecordOperationViewModel : BaseViewModel
var isOutbound = string.Equals(InoutDirection, "2", StringComparison.Ordinal);
if (!isCompleteSelectedRecord)
{
if (isOutbound && !TareWeight.HasValue)
if (isOutbound && !HasEffectiveWeighValue(TareWeight))
{
HandyControl.Controls.MessageBox.Warning("出厂流程请先采集皮重!");
return;
}
if (!isOutbound && !GrossWeight.HasValue)
if (!isOutbound && !HasEffectiveWeighValue(GrossWeight))
{
HandyControl.Controls.MessageBox.Warning("进厂流程请先采集毛重!");
return;
@@ -494,7 +567,7 @@ public class WeightRecordOperationViewModel : BaseViewModel
}
else
{
var needSecondWeightCaptured = isOutbound ? GrossWeight.HasValue : TareWeight.HasValue;
var needSecondWeightCaptured = isOutbound ? HasEffectiveWeighValue(GrossWeight) : HasEffectiveWeighValue(TareWeight);
if (!needSecondWeightCaptured)
{
HandyControl.Controls.MessageBox.Warning(isOutbound
@@ -558,6 +631,7 @@ public class WeightRecordOperationViewModel : BaseViewModel
ClearCustomerSelection();
ClearMixerMaterialSelection();
ClearVehicleMatch();
IsManualWeightEntry = false;
// 保存后立即按当前方向回填缓存,避免必须重进页面才显示
TryApplyCachedUnitByDirection(InoutDirection);
RaisePropertyChanged(nameof(NetWeightDisplay));
@@ -592,8 +666,9 @@ public class WeightRecordOperationViewModel : BaseViewModel
IsPlateNumberLocked = false;
ClearSupplierSelection();
ClearCustomerSelection();
ClearMixerMaterialSelection();
ClearMixerMaterialSelection();
ClearVehicleMatch();
IsManualWeightEntry = false;
RaisePropertyChanged(nameof(NetWeightDisplay));
AddLog("表单已清空");
}
@@ -845,15 +920,16 @@ public class WeightRecordOperationViewModel : BaseViewModel
// 按进出方向查询当天待补称单据:进厂=已称毛重,出厂=已称皮重。
var page = await _weightRecordService.PageAsync(1, 100, filterPlateNumber: plate);
var today = DateTime.Today;
var isOutbound = string.Equals(InoutDirection, "2", StringComparison.Ordinal);
var candidates = page.Records
.Where(r =>
string.Equals((r.PlateNumber ?? string.Empty).Trim(), plate, StringComparison.OrdinalIgnoreCase) &&
r.WeighDate.HasValue &&
r.WeighDate.Value.Date == today &&
(isOutbound
? (r.TareWeight.HasValue && !r.GrossWeight.HasValue)
: (r.GrossWeight.HasValue && !r.TareWeight.HasValue)))
var isOutbound = string.Equals(InoutDirection, "2", StringComparison.Ordinal);
bool effT(double? w) => w.HasValue && w.Value > 0;
var candidates = page.Records
.Where(r =>
string.Equals((r.PlateNumber ?? string.Empty).Trim(), plate, StringComparison.OrdinalIgnoreCase) &&
r.WeighDate.HasValue &&
r.WeighDate.Value.Date == today &&
(isOutbound
? (effT(r.TareWeight) && !effT(r.GrossWeight))
: (effT(r.GrossWeight) && !effT(r.TareWeight))))
.OrderByDescending(r => r.CreateTime ?? DateTime.MinValue)
.ToList();
@@ -865,8 +941,8 @@ public class WeightRecordOperationViewModel : BaseViewModel
BillNo = record.BillNo ?? "-",
PlateNumber = record.PlateNumber ?? "-",
FirstWeightDisplay = isOutbound
? (record.TareWeight.HasValue ? $"{record.TareWeight.Value:N2}" : "-")
: (record.GrossWeight.HasValue ? $"{record.GrossWeight.Value:N2}" : "-")
? (HasEffectiveWeighValue(record.TareWeight) ? $"{record.TareWeight!.Value:N2}" : "-")
: (HasEffectiveWeighValue(record.GrossWeight) ? $"{record.GrossWeight!.Value:N2}" : "-")
});
}
@@ -914,14 +990,14 @@ public class WeightRecordOperationViewModel : BaseViewModel
if (isOutbound)
{
TareWeight = selected.Source.TareWeight;
TareWeightCaptured = TareWeight.HasValue;
TareWeightCaptured = HasEffectiveWeighValue(TareWeight);
GrossWeight = null;
GrossWeightCaptured = false;
}
else
{
GrossWeight = selected.Source.GrossWeight;
GrossWeightCaptured = GrossWeight.HasValue;
GrossWeightCaptured = HasEffectiveWeighValue(GrossWeight);
TareWeight = null;
TareWeightCaptured = false;
}
@@ -953,6 +1029,7 @@ public class WeightRecordOperationViewModel : BaseViewModel
ClearCustomerSelection();
ClearMixerMaterialSelection();
ClearVehicleMatch();
IsManualWeightEntry = false;
RaisePropertyChanged(nameof(NetWeightDisplay));
AddLog("已切换进出方向,当前表单数据已清空");
}