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.
107 lines
3.5 KiB
C#
107 lines
3.5 KiB
C#
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Sln.Wcs.Model.Domain;
|
|
using Sln.Wcs.Repository.service;
|
|
using Sln.Wcs.UI.Controls;
|
|
|
|
namespace Sln.Wcs.UI.Page.BasicInfo.MaterialInfo
|
|
{
|
|
public partial class MaterialInfoPage : UserControl
|
|
{
|
|
private readonly IBaseMaterialInfoService? _materialInfoService;
|
|
|
|
public MaterialInfoPage()
|
|
{
|
|
InitializeComponent();
|
|
_materialInfoService = App.ServiceProvider.GetService<IBaseMaterialInfoService>();
|
|
LoadData();
|
|
}
|
|
|
|
public void LoadData()
|
|
{
|
|
if (_materialInfoService != null)
|
|
{
|
|
var list = _materialInfoService.Query();
|
|
MaterialGrid.ItemsSource = list;
|
|
}
|
|
}
|
|
|
|
private void BtnQuery_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (_materialInfoService == null) return;
|
|
|
|
var code = TxtQueryCode.Text?.Trim();
|
|
var name = TxtQueryName.Text?.Trim();
|
|
var list = _materialInfoService.Query()
|
|
.Where(m => string.IsNullOrEmpty(code) || m.materialCode.Contains(code))
|
|
.Where(m => string.IsNullOrEmpty(name) || (m.materialName != null && m.materialName.Contains(name)))
|
|
.ToList();
|
|
MaterialGrid.ItemsSource = list;
|
|
}
|
|
|
|
private void BtnAdd_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var window = new MaterialAddWindow(this);
|
|
window.Owner = Window.GetWindow(this);
|
|
window.ShowDialog();
|
|
}
|
|
|
|
private void BtnEdit_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (MaterialGrid.SelectedItem is BaseMaterialInfo material)
|
|
{
|
|
var window = new MaterialEditWindow(this, material);
|
|
window.Owner = Window.GetWindow(this);
|
|
window.ShowDialog();
|
|
}
|
|
}
|
|
|
|
private void BtnDelete_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (_materialInfoService == null) return;
|
|
|
|
if (MaterialGrid.SelectedItem is BaseMaterialInfo material)
|
|
{
|
|
var result = CustomMessageBox.Show($"确认删除物料: {material.materialName}?", "删除确认", MessageBoxButton.YesNo);
|
|
if (result == MessageBoxResult.Yes)
|
|
{
|
|
var success = _materialInfoService.Delete(material);
|
|
if (success)
|
|
{
|
|
CustomMessageBox.Show("删除成功", "提示", MessageBoxButton.OK);
|
|
LoadData();
|
|
}
|
|
else
|
|
{
|
|
CustomMessageBox.Show("删除失败", "错误", MessageBoxButton.OK);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
[ValueConversion(typeof(int), typeof(string))]
|
|
public class MaterialFlagConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (value == null) return "否";
|
|
|
|
return (int)value switch
|
|
{
|
|
1 => "是",
|
|
0 => "否",
|
|
_ => "否"
|
|
};
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
} |