You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
3.8 KiB
C#
104 lines
3.8 KiB
C#
using Microsoft.Extensions.DependencyInjection;
|
|
using Sln.Wcs.Model.Domain;
|
|
using Sln.Wcs.Repository.service;
|
|
using Sln.Wcs.UI.Controls;
|
|
using System;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
|
|
namespace Sln.Wcs.UI.Page.BasicInfo.MaterialInfo
|
|
{
|
|
public partial class MaterialEditWindow : Window
|
|
{
|
|
private readonly IBaseMaterialInfoService? _materialInfoService;
|
|
private readonly MaterialInfoPage _parentPage;
|
|
private readonly BaseMaterialInfo _material;
|
|
|
|
public MaterialEditWindow(MaterialInfoPage parentPage, BaseMaterialInfo material)
|
|
{
|
|
InitializeComponent();
|
|
_materialInfoService = App.ServiceProvider.GetService<IBaseMaterialInfoService>();
|
|
_parentPage = parentPage;
|
|
_material = material;
|
|
|
|
// 初始化表单数据
|
|
TxtMaterialCode.Text = material.materialCode;
|
|
TxtMaterialName.Text = material.materialName;
|
|
TxtMaterialType.Text = material.materialType;
|
|
TxtMaterialBarcode.Text = material.materialBarcode;
|
|
TxtMinStorageCycle.Text = material.minStorageCycle?.ToString();
|
|
TxtMaxStorageCycle.Text = material.maxStorageCycle?.ToString();
|
|
TxtRemark.Text = material.remark;
|
|
|
|
// 设置是否标识下拉框
|
|
if (material.isFlag.HasValue)
|
|
{
|
|
foreach (ComboBoxItem item in CmbIsFlag.Items)
|
|
{
|
|
if (item.Tag != null && int.TryParse(item.Tag.ToString(), out int tagValue) && tagValue == material.isFlag.Value)
|
|
{
|
|
item.IsSelected = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void BtnConfirm_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (_materialInfoService == null) return;
|
|
|
|
if (string.IsNullOrWhiteSpace(TxtMaterialCode.Text))
|
|
{
|
|
CustomMessageBox.Show("请输入物料编号", "提示", MessageBoxButton.OK);
|
|
return;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(TxtMaterialName.Text))
|
|
{
|
|
CustomMessageBox.Show("请输入物料名称", "提示", MessageBoxButton.OK);
|
|
return;
|
|
}
|
|
|
|
var isFlagItem = CmbIsFlag.SelectedItem as ComboBoxItem;
|
|
|
|
// 更新物料信息
|
|
_material.materialCode = TxtMaterialCode.Text.Trim();
|
|
_material.materialName = TxtMaterialName.Text.Trim();
|
|
_material.materialType = TxtMaterialType.Text?.Trim();
|
|
_material.materialBarcode = TxtMaterialBarcode.Text?.Trim();
|
|
_material.minStorageCycle = int.TryParse(TxtMinStorageCycle.Text, out int minCycle) ? minCycle : (int?)null;
|
|
_material.maxStorageCycle = int.TryParse(TxtMaxStorageCycle.Text, out int maxCycle) ? maxCycle : (int?)null;
|
|
_material.isFlag = isFlagItem?.Tag != null ? int.TryParse(isFlagItem.Tag.ToString(), out int flag) ? flag : (int?)null : null;
|
|
_material.remark = TxtRemark.Text?.Trim();
|
|
_material.updatedTime = DateTime.Now;
|
|
|
|
var success = _materialInfoService.Update(_material);
|
|
if (success)
|
|
{
|
|
CustomMessageBox.Show("修改成功", "提示", MessageBoxButton.OK);
|
|
CloseAndRefresh();
|
|
}
|
|
else
|
|
{
|
|
CustomMessageBox.Show("修改失败", "错误", MessageBoxButton.OK);
|
|
}
|
|
}
|
|
|
|
private void BtnCancel_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
CloseAndRefresh();
|
|
}
|
|
|
|
private void BtnClose_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
CloseAndRefresh();
|
|
}
|
|
|
|
private void CloseAndRefresh()
|
|
{
|
|
_parentPage.LoadData();
|
|
Close();
|
|
}
|
|
}
|
|
} |