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.
95 lines
3.2 KiB
C#
95 lines
3.2 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 MaterialAddWindow : Window
|
|
{
|
|
private readonly IBaseMaterialInfoService? _materialInfoService;
|
|
private readonly MaterialInfoPage _parentPage;
|
|
|
|
public MaterialAddWindow(MaterialInfoPage parentPage)
|
|
{
|
|
InitializeComponent();
|
|
_materialInfoService = App.ServiceProvider.GetService<IBaseMaterialInfoService>();
|
|
_parentPage = parentPage;
|
|
}
|
|
|
|
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;
|
|
|
|
var material = new BaseMaterialInfo
|
|
{
|
|
materialCode = TxtMaterialCode.Text.Trim(),
|
|
materialName = TxtMaterialName.Text.Trim(),
|
|
materialType = TxtMaterialType.Text?.Trim(),
|
|
materialBarcode = TxtMaterialBarcode.Text?.Trim(),
|
|
minStorageCycle = int.TryParse(TxtMinStorageCycle.Text, out int minCycle) ? minCycle : (int?)null,
|
|
maxStorageCycle = int.TryParse(TxtMaxStorageCycle.Text, out int maxCycle) ? maxCycle : (int?)null,
|
|
isFlag = isFlagItem?.Tag != null ? int.TryParse(isFlagItem.Tag.ToString(), out int flag) ? flag : (int?)null : null,
|
|
remark = TxtRemark.Text?.Trim(),
|
|
createdTime = DateTime.Now
|
|
};
|
|
|
|
var success = _materialInfoService.Insert(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()
|
|
{
|
|
ClearForm();
|
|
_parentPage.LoadData();
|
|
Close();
|
|
}
|
|
|
|
private void ClearForm()
|
|
{
|
|
TxtMaterialCode.Text = "";
|
|
TxtMaterialName.Text = "";
|
|
TxtMaterialType.Text = "";
|
|
TxtMaterialBarcode.Text = "";
|
|
TxtMinStorageCycle.Text = "";
|
|
TxtMaxStorageCycle.Text = "";
|
|
TxtRemark.Text = "";
|
|
CmbIsFlag.SelectedIndex = 0;
|
|
}
|
|
}
|
|
} |