Files
wcs/货架标准上位机/ViewModels/MatDetailCurrentInfoViewModel.cs
hehaibing-1996 a4c02a9173 1.PDA绑定相关接口
2.货架存量 后端接口
2025-01-13 20:08:03 +08:00

442 lines
14 KiB
C#

using HandyControl.Controls;
using MiniExcelLibs;
using Ping9719.WpfEx.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using .Views.Controls;
using .Api;
using WCS.Model;
using WCS.Model.ApiModel.Home;
using WCS.Model.ApiModel.StoreInfo;
using WCS.BLL.DbModels;
using WCS.Model.ApiModel.MatBaseInfo;
using WCS.Model.ApiModel.User;
using WCS.Model.ApiModel;
using Newtonsoft.Json.Bson;
using WCS.Model.ApiModel.LocationInfo;
namespace .ViewModel
{
public class MatDetailCurrentInfoViewModel : BindableBase
{
public MatDetailCurrentInfoViewModel()
{
}
#region Property
private List<LocationInfoModel> dataGridItemSource;
public List<LocationInfoModel> DataGridItemSource
{
get { return dataGridItemSource; }
set
{
SetProperty(ref dataGridItemSource, value);
}
}
private LocationInfoModel selectedataGridItem;
public LocationInfoModel SelectedataGridItem
{
get { return selectedataGridItem; }
set
{
SetProperty(ref selectedataGridItem, value);
}
}
#region
private string locationCode;
public string LocationCode
{
get { return locationCode; }
set
{
SetProperty(ref locationCode, value);
}
}
private List<LocationAreaInfoModel> locationAreaItems;
public List<LocationAreaInfoModel> LocationAreaItems
{
get { return locationAreaItems; }
set
{
SetProperty(ref locationAreaItems, value);
}
}
private LocationAreaInfoModel? selectedLocationAreaItems;
public LocationAreaInfoModel? SelectedLocationAreaItems
{
get { return selectedLocationAreaItems; }
set
{
SetProperty(ref selectedLocationAreaItems, value);
}
}
public void InitLocationAreaItems()
{
//调用接口更新!
Task.Run(() =>
{
LocationAreaItems = new List<LocationAreaInfoModel>();
LocationAreaItems.Add(new LocationAreaInfoModel { Id = null, LocationAreaName = "全部" });
var body = new RequestBase()
{
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
};
var Result = ApiHelp.GetDataFromHttp<PageQueryResponse<LocationAreaInfoModel>>(LocalFile.Config.ApiIpHost + "locationInfo/getLocationAreas", body, "POST");
if (Result != null && Result.Data != null && Result.Data.Lists.Count() > 0)
{
LocationAreaItems.AddRange(Result.Data.Lists);
}
SelectedLocationAreaItems = LocationAreaItems.FirstOrDefault();
});
}
#endregion
#region
/// <summary>
/// 货架编号
/// </summary>
private string shelfCode;
public string ShelfCode
{
get { return shelfCode; }
set
{
SetProperty(ref shelfCode, value);
}
}
private List<ShelfTypeModel> shelfTypeItems;
public List<ShelfTypeModel> ShelfTypeItems
{
get { return shelfTypeItems; }
set
{
SetProperty(ref shelfTypeItems, value);
}
}
private ShelfTypeModel? selectedShelfTypeItem;
public ShelfTypeModel? SelectedShelfTypeItem
{
get { return selectedShelfTypeItem; }
set
{
SetProperty(ref selectedShelfTypeItem, value);
}
}
public void InitShelfTypeItems()
{
//调用接口更新!
Task.Run(() =>
{
ShelfTypeItems = new List<ShelfTypeModel>();
ShelfTypeItems.Add(new ShelfTypeModel { Id = null, ShelfTypeName = "全部" });
var body = new RequestBase()
{
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
};
var Result = ApiHelp.GetDataFromHttp<PageQueryResponse<ShelfTypeModel>>(LocalFile.Config.ApiIpHost + "home/getShelfTypes", body, "POST");
if (Result != null && Result.Data != null && Result.Data.Lists.Count() > 0)
{
ShelfTypeItems.AddRange(Result.Data.Lists);
}
SelectedShelfTypeItem = ShelfTypeItems.FirstOrDefault();
});
}
#endregion
#region
/// <summary>
/// 物料编码
/// </summary>
private string matCode;
public string MatCode
{
get { return matCode; }
set
{
SetProperty(ref matCode, value);
}
}
/// <summary>
/// 物料名称
/// </summary>
private string matName;
public string MatName
{
get { return matName; }
set
{
SetProperty(ref matName, value);
}
}
#endregion
#endregion
#region Command
public ICommand BtnResetCommand { get => new DelegateCommand(BtnReset); }
public void BtnReset()
{
if (LocationAreaItems != null)
{
SelectedLocationAreaItems = LocationAreaItems.FirstOrDefault();
}
LocationCode = string.Empty;
if (ShelfTypeItems != null)
{
SelectedShelfTypeItem = ShelfTypeItems.FirstOrDefault();
}
ShelfCode = string.Empty;
MatCode = string.Empty;
MatName = string.Empty;
}
public ICommand BtnSearchCommand { get => new DelegateCommand(BtnSearchReset); }
public void BtnSearchReset()
{
BtnSearch(true);
}
public void BtnSearch(bool IsPageReset = true)
{
if (CurrentPage == 0 || IsPageReset)
{
CurrentPage = 1;
return;
}
#region
var dia = Dialog.Show(new TextDialog());
try
{
var body = new GetLocationInfosRequest()
{
LocationAreaId = SelectedLocationAreaItems == null ? null : SelectedLocationAreaItems.Id,
LocationCode = LocationCode,
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
PageNumber = CurrentPage,
PageSize = PageSize,
};
var Result = ApiHelp.GetDataFromHttp<PageQueryResponse<LocationInfoModel>>(LocalFile.Config.ApiIpHost + "locationInfo/getLocationInfos", body, "POST");
if (Result != null && Result.Data != null && Result.Data.Lists != null)
{
DataGridItemSource = Result.Data.Lists;
MaxPage = Result.Data.MaxPage;
TotalCount = Result.Data.TotalCount;
}
}
catch (Exception ex)
{
Growl.Error("加载数据失败:" + ex.Message);
}
finally
{
dia.Close();
}
#endregion
}
/// <summary>
/// 物料新增操作
/// </summary>
public ICommand BtnAddCommand { get => new DelegateCommand(BtnAdd); }
public async void BtnAdd()
{
var addView = new LocationInfoAddOrUpdateView("新增位置");
addView.ShowDialog();
if (addView.DialogResult == true)
{
//添加或修改成功后重新查询
CurrentPage = 1;
}
}
public ICommand BtnEditCommand { get => new DelegateCommand(BtnEdit); }
public async void BtnEdit()
{
//查询勾选的第一个数据
var info = DataGridItemSource?.Where(t => t.IsSelected == true).FirstOrDefault();
if (info == null)
{
Growl.Warning("请选择需要修改的数据!");
}
else
{
var addView = new LocationInfoAddOrUpdateView("修改位置", info);
addView.ShowDialog();
if (addView.DialogResult == true)
{
CurrentPage = 1;
}
}
}
public ICommand BtnDeleteCommand { get => new DelegateCommand(BtnDelete); }
public void BtnDelete()
{
Growl.Ask($"是否删除所有勾选的数据?", isConfirmed =>
{
if (isConfirmed)
{
//查询勾选的第一个数据
var needDeleteIds = DataGridItemSource?.Where(t => t.IsSelected == true)
.Select(t => t.Id)
.ToList();
if (needDeleteIds == null)
{
Growl.Warning("请选择需要修改的数据!");
}
else
{
var body = new DeleteInfosRequest()
{
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
needDeleteIds = needDeleteIds,
};
var Result = ApiHelp.GetDataFromHttp<ResponseBase<UserModel>>(LocalFile.Config.ApiIpHost + "locationInfo/deleteLocationInfo", body, "POST");
if (Result != null && Result.Code == 200)
{
BtnSearch();
Growl.Success("删除成功!" + Result?.Message);
}
else
{
Growl.Error($"{Result?.Message?.ToString()}");
}
}
}
return true;
});
////查询勾选的第一个数据
//var info = DataGridItemSource?.Where(t => t.IsSelected == true).FirstOrDefault();
//if (info == null)
//{
// Growl.Warning("请选择需要删除的数据!");
//}
//else
//{
// var body = new AddShelfInfoRequest<ShelfInfoModel>()
// {
// UserName = LocalStatic.CurrentUser,
// DeviceType = LocalFile.Config.DeviceType,
// ShelfInfo = info,
// AddOrUpdate = AddOrUpdate.Delete
// };
// var Result = ApiHelp.GetDataFromHttp<ResponseBase<object>>(LocalFile.Config.ApiIpHost + "storeInfo/addOrUpdateShelfInfo", body, "POST");
// if (Result != null && Result.Code == 200)
// {
// Growl.Success("删除成功!");
// CurrentPage = 1;
// }
// else
// {
// Growl.Error($"{Result?.Message?.ToString()}");
// }
//}
}
#endregion
#region PageOperation
private int currentPage;
public int CurrentPage
{
get { return currentPage; }
set
{
SetProperty(ref currentPage, value);
BtnSearch(false);
}
}
private int maxPage;
public int MaxPage
{
get { return maxPage; }
set { SetProperty(ref maxPage, value); }
}
//总数量
private int totalCount;
public int TotalCount
{
get { return totalCount; }
set { SetProperty(ref totalCount, value); }
}
private int pageSize = 10;
public int PageSize
{
get => pageSize;
set
{
SetProperty(ref pageSize, value);
BtnSearch(true);
}
}
public ICommand BtnFirstPageCommand { get => new DelegateCommand(BtnFirstPage); }
public void BtnFirstPage()
{
CurrentPage = 1;
}
public ICommand BtnPrePageCommand { get => new DelegateCommand(BtnPrePage); }
public void BtnPrePage()
{
if (CurrentPage > 1)
{
CurrentPage--;
}
}
public ICommand BtnNextPageCommand { get => new DelegateCommand(BtnNextPage); }
public void BtnNextPage()
{
if (CurrentPage < MaxPage)
{
CurrentPage++;
}
}
public ICommand BtnLastPageCommand { get => new DelegateCommand(BtnLastPage); }
public void BtnLastPage()
{
if (CurrentPage != MaxPage)
{
CurrentPage = MaxPage;
}
}
#endregion
}
}