|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Drawing.Imaging;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Automation.Text;
|
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
|
using System.Windows.Data;
|
|
|
|
|
|
using System.Windows.Documents;
|
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
|
using System.Windows.Shapes;
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
using Sln.Wcs.Function.Functions;
|
|
|
|
|
|
using Sln.Wcs.Model.Domain;
|
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Sln_Wpf.Page.AddWindows
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// AddMaterialWindow.xaml 的交互逻辑
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public partial class AddMaterialWindow : Window
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 返回结果:新增的物料信息
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public BaseMaterialInfo NewMaterial { get; private set; }
|
|
|
|
|
|
private ISqlSugarClient? sqlSugarClient;
|
|
|
|
|
|
private materialinfoSqlFunction AddSqlFunction;
|
|
|
|
|
|
private int WorkingType;
|
|
|
|
|
|
|
|
|
|
|
|
public AddMaterialWindow()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
AddSqlFunction = new materialinfoSqlFunction(App.ServiceProvider);
|
|
|
|
|
|
WorkingType = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public AddMaterialWindow(BaseMaterialInfo baseMaterialInfo)
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
NewMaterial = baseMaterialInfo;
|
|
|
|
|
|
AddSqlFunction = new materialinfoSqlFunction(App.ServiceProvider);
|
|
|
|
|
|
sqlSugarClient = App.ServiceProvider.GetService<ISqlSugarClient>();
|
|
|
|
|
|
SetComboBoxIndexByValue(CmbMaterialType, NewMaterial.MaterialType);
|
|
|
|
|
|
SetComboBoxIndexByValue(CmbMaterialCategory, NewMaterial.MaterialCategory);
|
|
|
|
|
|
SetComboBoxIndexByValue(CmbStatus,NewMaterial.Status.ToString());
|
|
|
|
|
|
TxtMaterialCode.Text = NewMaterial.MaterialCode;
|
|
|
|
|
|
TxtMaterialName.Text = NewMaterial.MaterialName;
|
|
|
|
|
|
WorkingType = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SetComboBoxIndexByValue(ComboBox comboBox, string value)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (ComboBoxItem item in comboBox.Items)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item.Tag.ToString() == value)
|
|
|
|
|
|
{
|
|
|
|
|
|
comboBox.SelectedItem = item;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取 ComboBox 选中项的 Tag 值
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private string GetSelectedTagValue(ComboBox comboBox)
|
|
|
|
|
|
{
|
|
|
|
|
|
var selectedItem = comboBox.SelectedItem as ComboBoxItem;
|
|
|
|
|
|
if (selectedItem != null && selectedItem.Tag != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return selectedItem.Tag.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取 ComboBox 选中项的显示文本
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private string GetSelectedDisplayText(ComboBox comboBox)
|
|
|
|
|
|
{
|
|
|
|
|
|
var selectedItem = comboBox.SelectedItem as ComboBoxItem;
|
|
|
|
|
|
return selectedItem?.Content?.ToString() ?? "";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取状态值(INT类型:0-禁用 1-启用)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private int GetStatusValue()
|
|
|
|
|
|
{
|
|
|
|
|
|
var selectedItem = CmbStatus.SelectedItem as ComboBoxItem;
|
|
|
|
|
|
if (selectedItem != null && selectedItem.Tag != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Convert.ToInt32(selectedItem.Tag);
|
|
|
|
|
|
}
|
|
|
|
|
|
return 1; // 默认启用
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取状态显示文本
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private string GetStatusText()
|
|
|
|
|
|
{
|
|
|
|
|
|
return GetSelectedDisplayText(CmbStatus);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 确认添加按钮
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void BtnConfirm_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(WorkingType == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 验证输入
|
|
|
|
|
|
if (!ValidateInput())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// 创建物料信息对象
|
|
|
|
|
|
NewMaterial = new BaseMaterialInfo
|
|
|
|
|
|
{
|
|
|
|
|
|
// 字符串类型字段
|
|
|
|
|
|
MaterialCode = TxtMaterialCode.Text.Trim(),
|
|
|
|
|
|
MaterialName = TxtMaterialName.Text.Trim(),
|
|
|
|
|
|
MaterialType = GetSelectedTagValue(CmbMaterialType),
|
|
|
|
|
|
MaterialCategory = GetSelectedTagValue(CmbMaterialCategory),
|
|
|
|
|
|
|
|
|
|
|
|
// INT类型字段(数据库中存储的是INT值)
|
|
|
|
|
|
Status = GetStatusValue(),
|
|
|
|
|
|
|
|
|
|
|
|
// 设置默认值(新增时自动填充)
|
|
|
|
|
|
IsDeleted = false,
|
|
|
|
|
|
CreateTime = DateTime.Now,
|
|
|
|
|
|
UpdateTime = DateTime.Now
|
|
|
|
|
|
};
|
|
|
|
|
|
AddSqlFunction.insertFunction(NewMaterial);
|
|
|
|
|
|
DialogResult = true;
|
|
|
|
|
|
Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// 验证输入
|
|
|
|
|
|
if (!ValidateInput())
|
|
|
|
|
|
return;
|
|
|
|
|
|
sqlSugarClient.Updateable<BaseMaterialInfo>().Where(it => it.MaterialCode == TxtMaterialCode.Text.Trim()).SetColumns(it => new BaseMaterialInfo()
|
|
|
|
|
|
{
|
|
|
|
|
|
MaterialCode = TxtMaterialCode.Text.Trim(),
|
|
|
|
|
|
MaterialName = TxtMaterialName.Text.Trim(),
|
|
|
|
|
|
MaterialType = GetSelectedTagValue(CmbMaterialType),
|
|
|
|
|
|
MaterialCategory = GetSelectedTagValue(CmbMaterialCategory),
|
|
|
|
|
|
// INT类型字段(数据库中存储的是INT值)
|
|
|
|
|
|
Status = GetStatusValue(),
|
|
|
|
|
|
// 设置默认值(新增时自动填充)
|
|
|
|
|
|
IsDeleted = false,
|
|
|
|
|
|
CreateTime = DateTime.Now,
|
|
|
|
|
|
UpdateTime = DateTime.Now
|
|
|
|
|
|
}).ExecuteCommand();
|
|
|
|
|
|
DialogResult = true;
|
|
|
|
|
|
Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 取消按钮
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void BtnCancel_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
DialogResult = false;
|
|
|
|
|
|
Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 验证输入
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private bool ValidateInput()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 验证物料编号
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(TxtMaterialCode.Text))
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show("请输入物料编号", "验证失败", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
|
|
|
TxtMaterialCode.Focus();
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 验证物料名称
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(TxtMaterialName.Text))
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show("请输入物料名称", "验证失败", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
|
|
|
TxtMaterialName.Focus();
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 窗口拖拽
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.ButtonState == MouseButtonState.Pressed)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.DragMove();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 最小化
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void BtnMinimize_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.WindowState = WindowState.Minimized;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 关闭
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void BtnClose_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
DialogResult = false;
|
|
|
|
|
|
Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|