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.
133 lines
5.0 KiB
C#
133 lines
5.0 KiB
C#
using Sln.Wcs.Model.Domain;
|
|
using Sln.Wcs.Repository.service;
|
|
using Sln.Wcs.UI.Controls;
|
|
using System;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Sln.Wcs.UI.Page.BasicInfo.LocationInfo
|
|
{
|
|
public partial class LocationEditWindow : Window
|
|
{
|
|
private readonly IBaseLocationInfoService _locationService;
|
|
private readonly BaseLocationInfo _location;
|
|
|
|
public LocationEditWindow(BaseLocationInfo location)
|
|
{
|
|
InitializeComponent();
|
|
_locationService = App.ServiceProvider.GetService<IBaseLocationInfoService>();
|
|
_location = location;
|
|
LoadData();
|
|
}
|
|
|
|
private void LoadData()
|
|
{
|
|
TxtLocationCode.Text = _location.locationCode;
|
|
TxtLocationName.Text = _location.locationName;
|
|
TxtLocationArea.Text = _location.locationArea;
|
|
TxtStoreCode.Text = _location.storeCode;
|
|
TxtLocationRows.Text = _location.locationRows?.ToString() ?? "";
|
|
TxtLocationColumns.Text = _location.locationColumns?.ToString() ?? "";
|
|
TxtLocationLayers.Text = _location.locationLayers?.ToString() ?? "";
|
|
TxtAgvPosition.Text = _location.agvPosition;
|
|
TxtDeviceCode.Text = _location.deviceCode;
|
|
TxtMaterialCode.Text = _location.materialCode;
|
|
TxtPalletBarcode.Text = _location.palletBarcode;
|
|
TxtStackCount.Text = _location.stackCount;
|
|
TxtRemark.Text = _location.remark;
|
|
|
|
SetSelectedStatus(_location.locationStatus ?? 0);
|
|
SetSelectedIsFlag(_location.isFlag ?? 0);
|
|
}
|
|
|
|
private void SetSelectedStatus(int status)
|
|
{
|
|
foreach (ComboBoxItem item in CmbLocationStatus.Items)
|
|
{
|
|
if (item.Tag != null && int.TryParse(item.Tag.ToString(), out int tagValue) && tagValue == status)
|
|
{
|
|
CmbLocationStatus.SelectedItem = item;
|
|
return;
|
|
}
|
|
}
|
|
CmbLocationStatus.SelectedIndex = 0;
|
|
}
|
|
|
|
private void SetSelectedIsFlag(int isFlag)
|
|
{
|
|
foreach (ComboBoxItem item in CmbIsFlag.Items)
|
|
{
|
|
if (item.Tag != null && int.TryParse(item.Tag.ToString(), out int tagValue) && tagValue == isFlag)
|
|
{
|
|
CmbIsFlag.SelectedItem = item;
|
|
return;
|
|
}
|
|
}
|
|
CmbIsFlag.SelectedIndex = 0;
|
|
}
|
|
|
|
private void BtnClose_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
DialogResult = false;
|
|
Close();
|
|
}
|
|
|
|
private void BtnCancel_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
DialogResult = false;
|
|
Close();
|
|
}
|
|
|
|
private void BtnConfirm_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
_location.locationName = TxtLocationName.Text.Trim();
|
|
_location.locationArea = TxtLocationArea.Text.Trim();
|
|
_location.storeCode = TxtStoreCode.Text.Trim();
|
|
_location.locationRows = int.TryParse(TxtLocationRows.Text, out int rows) ? rows : null;
|
|
_location.locationColumns = int.TryParse(TxtLocationColumns.Text, out int cols) ? cols : null;
|
|
_location.locationLayers = int.TryParse(TxtLocationLayers.Text, out int layers) ? layers : null;
|
|
_location.locationStatus = GetSelectedStatus(CmbLocationStatus);
|
|
_location.agvPosition = TxtAgvPosition.Text.Trim();
|
|
_location.deviceCode = TxtDeviceCode.Text.Trim();
|
|
_location.materialCode = TxtMaterialCode.Text.Trim();
|
|
_location.palletBarcode = TxtPalletBarcode.Text.Trim();
|
|
_location.stackCount = TxtStackCount.Text.Trim();
|
|
_location.isFlag = GetSelectedIsFlag(CmbIsFlag);
|
|
_location.remark = TxtRemark.Text.Trim();
|
|
_location.updatedBy = Environment.UserName;
|
|
_location.updatedTime = DateTime.Now;
|
|
|
|
_locationService.Update(_location);
|
|
CustomMessageBox.Show("更新成功", "提示");
|
|
DialogResult = true;
|
|
Close();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
CustomMessageBox.Show($"更新失败: {ex.Message}", "错误");
|
|
}
|
|
}
|
|
|
|
private int GetSelectedStatus(ComboBox cmb)
|
|
{
|
|
if (cmb.SelectedItem is ComboBoxItem item && item.Tag != null)
|
|
{
|
|
return int.TryParse(item.Tag.ToString(), out int status) ? status : 0;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
private int GetSelectedIsFlag(ComboBox cmb)
|
|
{
|
|
if (cmb.SelectedItem is ComboBoxItem item && item.Tag != null)
|
|
{
|
|
return int.TryParse(item.Tag.ToString(), out int flag) ? flag : 0;
|
|
}
|
|
return 0;
|
|
}
|
|
}
|
|
}
|