120 lines
4.0 KiB
C#
120 lines
4.0 KiB
C#
using HandyControl.Controls;
|
||
using SqlSugar;
|
||
using System;
|
||
using System.Windows;
|
||
using WCS.BLL.DbModels;
|
||
using WCS.Model;
|
||
using WCS.Model.ApiModel.StoreInfo;
|
||
using WCS.Model.ApiModel.User;
|
||
using 货架标准上位机.Api;
|
||
using 货架标准上位机.ViewModel;
|
||
|
||
namespace 货架标准上位机
|
||
{
|
||
public partial class ShelfInfoAddOrUpdateView : System.Windows.Window
|
||
{
|
||
public ShelfInfoAddOrUpdateViewModel ViewModel = new ShelfInfoAddOrUpdateViewModel();
|
||
|
||
public ShelfInfoAddOrUpdateView(string _titleText, ShelfInfoModel _shelfInfoModel = null)
|
||
{
|
||
InitializeComponent();
|
||
this.DataContext = ViewModel;
|
||
//绑定标题
|
||
if (!string.IsNullOrEmpty(_titleText))
|
||
{
|
||
Title.Text = _titleText;
|
||
}
|
||
ViewModel.SetValues(_shelfInfoModel);
|
||
}
|
||
|
||
|
||
private void btnOk_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
#region 校验填写的值
|
||
if (string.IsNullOrEmpty(ViewModel.ShelfCode))
|
||
{
|
||
Growl.Warning("请输入货架编码!");
|
||
txtShelfCode.Focus();
|
||
return;
|
||
}
|
||
if (ViewModel.RowCounts == 0)
|
||
{
|
||
Growl.Warning("请输入货架行数!");
|
||
txtRowCounts.Focus();
|
||
return;
|
||
}
|
||
if (ViewModel.ColumnCounts == 0)
|
||
{
|
||
Growl.Warning("请输入货架列数!");
|
||
txtColumnCounts.Focus();
|
||
return;
|
||
}
|
||
if (ViewModel.LightId == 0)
|
||
{
|
||
Growl.Warning("请输入报警灯Id!");
|
||
txtLightId.Focus();
|
||
return;
|
||
}
|
||
if (string.IsNullOrEmpty(ViewModel.ClientIp))
|
||
{
|
||
Growl.Warning("请输入TCP信息!");
|
||
txtClientIp.Focus();
|
||
return;
|
||
}
|
||
if (string.IsNullOrEmpty(ViewModel.GroupName))
|
||
{
|
||
Growl.Warning("请输入货架区域!");
|
||
txtGroupName.Focus();
|
||
return;
|
||
}
|
||
if (ViewModel.IsBind && string.IsNullOrEmpty(ViewModel.BindShelfCode))
|
||
{
|
||
Growl.Warning("需要绑定的货架需要输入绑定后货架编码!");
|
||
txtBindShelfCode.Focus();
|
||
return;
|
||
}
|
||
#endregion
|
||
|
||
#region 保存/修改值
|
||
var IsAdd = Title.Text == "新增货架";
|
||
var body = new AddShelfInfoRequest<ShelfInfoModel>()
|
||
{
|
||
UserName = LocalStatic.CurrentUser,
|
||
DeviceType = LocalFile.Config.DeviceType,
|
||
ShelfInfo = ViewModel.GetValues(),
|
||
AddOrUpdate = IsAdd ? AddOrUpdate.Add : AddOrUpdate.Update
|
||
};
|
||
var Result = ApiHelp.GetDataFromHttp<ResponseBase<object>>(LocalFile.Config.ApiIpHost + "storeInfo/addOrUpdateShelfInfo", body, "POST");
|
||
if (Result != null && Result.Code == 200)
|
||
{
|
||
if (IsAdd)
|
||
Growl.Success("添加成功!");
|
||
else
|
||
Growl.Success("修改成功!");
|
||
this.DialogResult = true;
|
||
this.Close();
|
||
}
|
||
else
|
||
{
|
||
Growl.Error($"{Result?.Message?.ToString()}");
|
||
}
|
||
#endregion
|
||
}
|
||
//绑定数据
|
||
catch (Exception ex)
|
||
{
|
||
Growl.Error($"操作异常:{ex.Message}");
|
||
return;
|
||
}
|
||
}
|
||
|
||
private void closeClick(object sender, RoutedEventArgs e)
|
||
{
|
||
this.DialogResult = false;
|
||
this.Close();
|
||
}
|
||
}
|
||
}
|