配合示方生成混炼示方优化

This commit is contained in:
2026-07-30 17:40:31 +08:00
parent 5c27bacd11
commit dea9b7a58c
15 changed files with 541 additions and 107 deletions

View File

@@ -34,6 +34,44 @@ public class WeightRecordEditDialogViewModel : BaseViewModel, IDialogResultable<
public bool IsAddMode => string.IsNullOrWhiteSpace(Record?.Id);
public string DialogTitle => IsAddMode ? "新增磅单" : "编辑磅单";
/// <summary>毛重输入:变更后自动重算净重</summary>
public double? GrossWeightInput
{
get => Record?.GrossWeight;
set
{
if (Record == null || Nullable.Equals(Record.GrossWeight, value)) return;
Record.GrossWeight = value;
RaisePropertyChanged(nameof(GrossWeightInput));
RecalcNetWeight();
}
}
/// <summary>皮重输入:变更后自动用毛重-皮重填充净重</summary>
public double? TareWeightInput
{
get => Record?.TareWeight;
set
{
if (Record == null || Nullable.Equals(Record.TareWeight, value)) return;
Record.TareWeight = value;
RaisePropertyChanged(nameof(TareWeightInput));
RecalcNetWeight();
}
}
/// <summary>净重(只读展示,由毛重/皮重自动计算)</summary>
public double? NetWeightInput
{
get => Record?.NetWeight;
private set
{
if (Record == null || Nullable.Equals(Record.NetWeight, value)) return;
Record.NetWeight = value;
RaisePropertyChanged(nameof(NetWeightInput));
}
}
public ObservableCollection<KeyValuePair<string, string>> InoutDirectionOptions { get; } = new();
private bool _result;
@@ -121,6 +159,7 @@ public class WeightRecordEditDialogViewModel : BaseViewModel, IDialogResultable<
};
RaisePropertyChanged(nameof(IsAddMode));
RaisePropertyChanged(nameof(DialogTitle));
RaiseWeightInputsChanged();
}
public void InitializeForEdit(MesXslWeightRecord record)
@@ -151,6 +190,31 @@ public class WeightRecordEditDialogViewModel : BaseViewModel, IDialogResultable<
RaisePropertyChanged(nameof(HasSelectedMixerMaterials));
RaisePropertyChanged(nameof(IsAddMode));
RaisePropertyChanged(nameof(DialogTitle));
RaiseWeightInputsChanged();
// 编辑打开时若已有毛重+皮重,立即校正净重展示
RecalcNetWeight();
}
private void RaiseWeightInputsChanged()
{
RaisePropertyChanged(nameof(GrossWeightInput));
RaisePropertyChanged(nameof(TareWeightInput));
RaisePropertyChanged(nameof(NetWeightInput));
}
/// <summary>毛重、皮重均有效时:净重 = 毛重 - 皮重(保留两位小数)</summary>
private void RecalcNetWeight()
{
if (Record == null) return;
if (Record.GrossWeight.HasValue && Record.GrossWeight.Value > 0
&& Record.TareWeight.HasValue && Record.TareWeight.Value > 0)
{
NetWeightInput = Math.Round(Record.GrossWeight.Value - Record.TareWeight.Value, 2);
}
else
{
NetWeightInput = null;
}
}
private async Task SaveAsync()
@@ -168,12 +232,8 @@ public class WeightRecordEditDialogViewModel : BaseViewModel, IDialogResultable<
return;
}
// 净重自动计算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;
// 保存前再算一次,防止未触发属性变更时净重未更新
RecalcNetWeight();
// 写入密炼物料
Record.MixerMaterialIds = _mixerMaterialIds;