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.
452 lines
18 KiB
C#
452 lines
18 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
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.Navigation;
|
|
using System.Windows.Shapes;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Newtonsoft.Json.Linq;
|
|
using Sln.Wcs.Model.Domain;
|
|
using Sln_Wpf.Page.AddWindows;
|
|
using SqlSugar;
|
|
|
|
namespace Sln_Wpf.Page
|
|
{
|
|
/// <summary>
|
|
/// WarehouseInfo.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class WarehouseInfo : UserControl
|
|
{
|
|
private List<BaseLocation> _locations;
|
|
private List<BaseMaterialInfo> _materials;
|
|
private List<BaseInoutRecord> _inoutRecords;
|
|
|
|
private BaseLocation _selectedLocation;
|
|
private BaseMaterialInfo _selectedMaterial;
|
|
private BaseInoutRecord _selectedInoutRecord;
|
|
|
|
private ISqlSugarClient? sqlSugarClient;
|
|
public WarehouseInfo()
|
|
{
|
|
InitializeComponent();
|
|
sqlSugarClient = App.ServiceProvider.GetService<ISqlSugarClient>();
|
|
sqlSugarClient.AsTenant().ChangeDatabase("wcs");
|
|
_locations = sqlSugarClient.Queryable<BaseLocation>().ToList();
|
|
_materials = sqlSugarClient.Queryable<BaseMaterialInfo>().ToList();
|
|
BindLocationData();
|
|
BindMaterialData();
|
|
}
|
|
|
|
private void BindLocationData()
|
|
{
|
|
var displayData = _locations.Select(l => new
|
|
{
|
|
l.WorkshopId,
|
|
l.WorkshopLevel,
|
|
l.WarehouseId,
|
|
l.MachineId,
|
|
l.LocationCode,
|
|
l.AgvPositionCode,
|
|
l.ContainerCode,
|
|
l.ActiveFlag,
|
|
l.LocationStatus,
|
|
StatusColor = l.LocationStatus == 1 ? Brushes.Red : (l.LocationStatus == 0 ? Brushes.Green : Brushes.Red)
|
|
}).ToList();
|
|
|
|
LocationDataGrid.ItemsSource = displayData;
|
|
}
|
|
|
|
private void BindMaterialData()
|
|
{
|
|
var displayData = _materials.Select(m => new
|
|
{
|
|
m.MaterialCode,
|
|
m.MaterialName,
|
|
m.MaterialType,
|
|
m.MaterialCategory,
|
|
m.Status,
|
|
}).ToList();
|
|
|
|
MaterialDataGrid.ItemsSource = displayData;
|
|
}
|
|
private void BindInoutData()
|
|
{
|
|
var displayData = _inoutRecords.Select(r => new
|
|
{
|
|
r.InoutFlag,
|
|
InoutFlagColor = r.InoutFlag == 1 ? Brushes.Green : Brushes.Red,
|
|
r.MaterialType,
|
|
r.MaterialCode,
|
|
r.WarehouseId,
|
|
r.Createuser,
|
|
CreateTime = r.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
|
|
}).ToList();
|
|
|
|
InoutDataGrid.ItemsSource = displayData;
|
|
}
|
|
private void LoadFilters()
|
|
{
|
|
// 加载工坊筛选
|
|
var workshops = _locations.Select(l => l.WorkshopId).Distinct().ToList();
|
|
FilterWorkshop.Items.Clear();
|
|
FilterWorkshop.Items.Add("全部工坊");
|
|
foreach (var workshop in workshops)
|
|
{
|
|
FilterWorkshop.Items.Add(workshop);
|
|
}
|
|
}
|
|
|
|
private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
#region 库位管理事件
|
|
private void BtnLocationAdd_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var addWindow = new AddLocationWindow();
|
|
addWindow.Owner = Window.GetWindow(this);
|
|
|
|
if (addWindow.ShowDialog() == true)
|
|
{
|
|
_locations.Add(addWindow.NewLocation);
|
|
BindLocationData();
|
|
LoadFilters();
|
|
//UpdateStats();
|
|
MessageBox.Show($"库位 {addWindow.NewLocation.LocationCode} 添加成功!", "添加成功", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
}
|
|
|
|
private void BtnLocationEdit_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (_selectedLocation == null)
|
|
{
|
|
MessageBox.Show("请先选择要编辑的库位", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
return;
|
|
}
|
|
|
|
var editWindow = new AddLocationWindow(_selectedLocation);
|
|
editWindow.Owner = Window.GetWindow(this);
|
|
|
|
if (editWindow.ShowDialog() == true)
|
|
{
|
|
var updated = editWindow.NewLocation;
|
|
_selectedLocation.WorkshopId = updated.WorkshopId;
|
|
_selectedLocation.WorkshopLevel = updated.WorkshopLevel;
|
|
_selectedLocation.WarehouseId = updated.WarehouseId;
|
|
_selectedLocation.MachineId = updated.MachineId;
|
|
_selectedLocation.LocationCode = updated.LocationCode;
|
|
_selectedLocation.AgvPositionCode = updated.AgvPositionCode;
|
|
_selectedLocation.ContainerCode = updated.ContainerCode;
|
|
_selectedLocation.ActiveFlag = updated.ActiveFlag;
|
|
_selectedLocation.LocationStatus = updated.LocationStatus;
|
|
|
|
BindLocationData();
|
|
MessageBox.Show("库位信息更新成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
}
|
|
|
|
private void BtnLocationDelete_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (_selectedLocation == null)
|
|
{
|
|
MessageBox.Show("请先选择要删除的库位", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
return;
|
|
}
|
|
|
|
var result = MessageBox.Show($"确定要删除库位 {_selectedLocation.LocationCode} 吗?", "确认删除", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
if (result == MessageBoxResult.Yes)
|
|
{
|
|
_locations.Remove(_selectedLocation);
|
|
var flag = sqlSugarClient.Deleteable<BaseLocation>().Where(d => d.LocationCode == _selectedLocation.LocationCode).ExecuteCommand();
|
|
BindLocationData();
|
|
LoadFilters();
|
|
//UpdateStats();
|
|
_selectedLocation = null;
|
|
if (flag > 0)
|
|
MessageBox.Show("删除成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
}
|
|
|
|
private void BtnLocationQuery_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
string keyword = SearchLocationKeyword.Text;
|
|
string filterWorkshop = FilterWorkshop.SelectedItem?.ToString();
|
|
string filterStatus = FilterStatus.SelectedItem?.ToString();
|
|
|
|
var queryData = _locations.AsEnumerable();
|
|
|
|
if (!string.IsNullOrEmpty(filterWorkshop) && filterWorkshop != "全部工坊")
|
|
{
|
|
queryData = queryData.Where(l => l.WorkshopId == GetSelectedTagValue(FilterWorkshop));
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(filterStatus) && filterStatus != "全部状态")
|
|
{
|
|
queryData = queryData.Where(l => l.LocationStatus == GetSelectedTagValue(FilterStatus));
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(keyword) && keyword != "请输入库位编号")
|
|
{
|
|
queryData = queryData.Where(l => l.LocationCode.Contains(keyword));
|
|
}
|
|
|
|
var displayData = queryData.Select(l => new
|
|
{
|
|
l.WorkshopId,
|
|
l.WorkshopLevel,
|
|
l.WarehouseId,
|
|
l.MachineId,
|
|
l.LocationCode,
|
|
l.AgvPositionCode,
|
|
l.ContainerCode,
|
|
l.ActiveFlag,
|
|
l.LocationStatus,
|
|
StatusColor = l.LocationStatus == 1 ? Brushes.Red : (l.LocationStatus == 0 ? Brushes.Green : Brushes.Red)
|
|
}).ToList();
|
|
|
|
LocationDataGrid.ItemsSource = displayData;
|
|
MessageBox.Show($"查询完成,共找到 {displayData.Count} 条记录", "查询结果", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
|
|
private int GetSelectedTagValue(ComboBox comboBox)
|
|
{
|
|
var selectedItem = comboBox.SelectedItem as ComboBoxItem;
|
|
if (selectedItem != null && selectedItem.Tag != null)
|
|
{
|
|
return Convert.ToInt32(selectedItem.Tag);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
private void LocationDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
var selected = LocationDataGrid.SelectedItem;
|
|
if (selected != null)
|
|
{
|
|
var locationCode = selected.GetType().GetProperty("LocationCode")?.GetValue(selected)?.ToString();
|
|
_selectedLocation = _locations.FirstOrDefault(l => l.LocationCode == locationCode);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 物料信息事件
|
|
|
|
private void BtnMaterialAdd_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var addWindow = new AddMaterialWindow();
|
|
addWindow.Owner = Window.GetWindow(this);
|
|
|
|
if (addWindow.ShowDialog() == true)
|
|
{
|
|
_materials.Add(addWindow.NewMaterial);
|
|
BindMaterialData();
|
|
MessageBox.Show($"物料 {addWindow.NewMaterial.MaterialCode} 添加成功!", "添加成功", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
}
|
|
|
|
private void BtnMaterialEdit_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (_selectedMaterial == null)
|
|
{
|
|
MessageBox.Show("请先选择要编辑的物料", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
return;
|
|
}
|
|
|
|
var editWindow = new AddMaterialWindow(_selectedMaterial);
|
|
editWindow.Owner = Window.GetWindow(this);
|
|
|
|
if (editWindow.ShowDialog() == true)
|
|
{
|
|
var updated = editWindow.NewMaterial;
|
|
_selectedMaterial.MaterialCode = updated.MaterialCode;
|
|
_selectedMaterial.MaterialName = updated.MaterialName;
|
|
_selectedMaterial.MaterialType = updated.MaterialType;
|
|
_selectedMaterial.MaterialCategory = updated.MaterialCategory;
|
|
_selectedMaterial.Status = updated.Status;
|
|
|
|
BindMaterialData();
|
|
MessageBox.Show("物料信息更新成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
}
|
|
|
|
private void BtnMaterialDelete_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (_selectedMaterial == null)
|
|
{
|
|
MessageBox.Show("请先选择要删除的物料", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
return;
|
|
}
|
|
|
|
var result = MessageBox.Show($"确定要删除物料 {_selectedMaterial.MaterialCode} {_selectedMaterial.MaterialName} 吗?", "确认删除", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
if (result == MessageBoxResult.Yes)
|
|
{
|
|
_materials.Remove(_selectedMaterial);
|
|
var flag = sqlSugarClient.Deleteable<BaseMaterialInfo>().Where(d => d.MaterialCode == _selectedMaterial.MaterialCode).ExecuteCommand();
|
|
BindMaterialData();
|
|
//UpdateStats();
|
|
_selectedMaterial = null;
|
|
if(flag > 0)
|
|
MessageBox.Show("删除成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
}
|
|
|
|
private void BtnMaterialQuery_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
string keyword = SearchMaterialKeyword.Text;
|
|
string filterType = (FilterMaterialType.SelectedItem as ComboBoxItem)?.Content.ToString();
|
|
string filterStatus = (FilterMaterialStatus.SelectedItem as ComboBoxItem)?.Content.ToString();
|
|
|
|
var queryData = _materials.AsEnumerable();
|
|
|
|
if (!string.IsNullOrEmpty(filterType) && filterType != "全部类型")
|
|
{
|
|
queryData = queryData.Where(m => m.MaterialType == filterType);
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(filterStatus) && filterStatus != "全部状态")
|
|
{
|
|
//queryData = queryData.Where(m => m.Status == filterStatus);
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(keyword) && keyword != "请输入物料编号/名称")
|
|
{
|
|
queryData = queryData.Where(m => m.MaterialCode.Contains(keyword) || m.MaterialName.Contains(keyword));
|
|
}
|
|
|
|
var displayData = queryData.Select(m => new
|
|
{
|
|
m.MaterialCode,
|
|
m.MaterialName,
|
|
m.MaterialType,
|
|
m.MaterialCategory,
|
|
m.Status,
|
|
}).ToList();
|
|
|
|
MaterialDataGrid.ItemsSource = displayData;
|
|
MessageBox.Show($"查询完成,共找到 {displayData.Count} 条记录", "查询结果", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
|
|
private void MaterialDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
var selected = MaterialDataGrid.SelectedItem;
|
|
if (selected != null)
|
|
{
|
|
var materialCode = selected.GetType().GetProperty("MaterialCode")?.GetValue(selected)?.ToString();
|
|
_selectedMaterial = _materials.FirstOrDefault(m => m.MaterialCode == materialCode);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 出入库记录事件
|
|
|
|
private void BtnInoutAdd_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
/*var addWindow = new AddInoutRecordWindow(_materials, _locations);
|
|
addWindow.Owner = Window.GetWindow(this);
|
|
|
|
if (addWindow.ShowDialog() == true)
|
|
{
|
|
_inoutRecords.Add(addWindow.NewRecord);
|
|
BindInoutData();
|
|
UpdateStats();
|
|
MessageBox.Show($"出入库记录添加成功!", "添加成功", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}*/
|
|
}
|
|
|
|
private void BtnInoutDelete_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (_selectedInoutRecord == null)
|
|
{
|
|
MessageBox.Show("请先选择要删除的记录", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
return;
|
|
}
|
|
|
|
var result = MessageBox.Show($"确定要删除该出入库记录吗?", "确认删除", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
if (result == MessageBoxResult.Yes)
|
|
{
|
|
_inoutRecords.Remove(_selectedInoutRecord);
|
|
BindInoutData();
|
|
_selectedInoutRecord = null;
|
|
MessageBox.Show("删除成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
}
|
|
|
|
private void BtnInoutQuery_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
string keyword = SearchInoutKeyword.Text;
|
|
string filterFlag = FilterInoutFlag.SelectedItem?.ToString();
|
|
DateTime? startDate = FilterStartDate.SelectedDate;
|
|
DateTime? endDate = FilterEndDate.SelectedDate;
|
|
|
|
var queryData = _inoutRecords.AsEnumerable();
|
|
|
|
// 按出入库标志筛选
|
|
if (!string.IsNullOrEmpty(filterFlag) && filterFlag != "全部")
|
|
{
|
|
queryData = queryData.Where(r => r.InoutFlag == filterFlag switch { "入库" => 1, "出库" => 2, "" => 3, _ => throw new NotImplementedException() });
|
|
}
|
|
|
|
|
|
|
|
// 按时间范围筛选
|
|
if (startDate.HasValue)
|
|
{
|
|
queryData = queryData.Where(r => r.CreateTime.Date >= startDate.Value.Date);
|
|
}
|
|
if (endDate.HasValue)
|
|
{
|
|
queryData = queryData.Where(r => r.CreateTime.Date <= endDate.Value.Date);
|
|
}
|
|
|
|
// 按关键字搜索(物料编号或人员)
|
|
if (!string.IsNullOrEmpty(keyword) && keyword != "请输入物料编号/人员")
|
|
{
|
|
queryData = queryData.Where(r => r.MaterialCode.Contains(keyword) || r.Createuser.Contains(keyword));
|
|
}
|
|
|
|
var displayData = queryData.Select(r => new
|
|
{
|
|
r.InoutFlag,
|
|
InoutFlagColor = r.InoutFlag == 1 ? Brushes.Green : Brushes.Red,
|
|
r.MaterialType,
|
|
r.MaterialCode,
|
|
r.WarehouseId,
|
|
r.Createuser,
|
|
CreateTime = r.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
|
|
}).ToList();
|
|
|
|
InoutDataGrid.ItemsSource = displayData;
|
|
MessageBox.Show($"查询完成,共找到 {displayData.Count} 条记录", "查询结果", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
}
|
|
|
|
private void InoutDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
var selected = InoutDataGrid.SelectedItem;
|
|
if (selected != null)
|
|
{
|
|
using (var dynamicRow = selected as dynamic)
|
|
{
|
|
var createTime = dynamicRow?.CreateTime?.ToString();
|
|
var materialCode = dynamicRow?.MaterialCode?.ToString();
|
|
_selectedInoutRecord = _inoutRecords.FirstOrDefault(r =>
|
|
r.MaterialCode == materialCode &&
|
|
r.CreateTime.ToString("yyyy-MM-dd HH:mm:ss") == createTime);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|