Files
wcs/货架标准上位机/ViewModels/MatDetailHistoryInfoViewModel.cs
hehaibing-1996 90a273f924 1.发送任务时添加货架编码识别
2.客户端功能优化:任务管理无法通过货架编码等进行模糊搜索
3.数据记录功能增加导出功能
2025-03-18 10:39:52 +08:00

385 lines
12 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;
using WCS.Model.ApiModel.MatDetailCurrentInfo;
using WCS.Model.ApiModel.Stocktaking;
using WCS.Model.ApiModel.MatDetailHistoryInfo;
using WCS.Model.ApiModel.AGV;
using System.Data.SQLite;
namespace .ViewModel
{
public class MatDetailHistoryInfoViewModel : BindableBase
{
public MatDetailHistoryInfoViewModel()
{
//初始化下拉列表框
//记录类型
RecordTypeItems = ["全部"];
var recordTypes = Enum.GetValues(typeof(RecordTypeEnum))
.Cast<RecordTypeEnum>()
.ToList();
foreach (var recordType in recordTypes)
{
RecordTypeItems.Add(recordType.ToString());
}
//操作功能
FunctionTypeItems = ["全部"];
var functionTypes = Enum.GetValues(typeof(FunctionTypeEnum))
.Cast<FunctionTypeEnum>()
.ToList();
foreach (var functionType in functionTypes)
{
FunctionTypeItems.Add(functionType.ToString());
}
}
#region Property
private List<MatDetailHistoryInfoModel> dataGridItemSource;
public List<MatDetailHistoryInfoModel> DataGridItemSource
{
get { return dataGridItemSource; }
set
{
SetProperty(ref dataGridItemSource, value);
}
}
private MatDetailHistoryInfoModel selectedataGridItem;
public MatDetailHistoryInfoModel SelectedataGridItem
{
get { return selectedataGridItem; }
set
{
SetProperty(ref selectedataGridItem, value);
}
}
#region
private string shelfCode;
public string ShelfCode
{
get { return shelfCode; }
set
{
SetProperty(ref shelfCode, value);
}
}
private List<string> recordTypeItems;
public List<string> RecordTypeItems
{
get { return recordTypeItems; }
set
{
SetProperty(ref recordTypeItems, value);
}
}
private string selectedRecordTypeItem;
public string SelectedRecordTypeItem
{
get { return selectedRecordTypeItem; }
set
{
SetProperty(ref selectedRecordTypeItem, value);
}
}
private List<string> functionTypeItems;
public List<string> FunctionTypeItems
{
get { return functionTypeItems; }
set
{
SetProperty(ref functionTypeItems, value);
}
}
private string selectedFunctionTypeItem;
public string SelectedFunctionTypeItem
{
get { return selectedFunctionTypeItem; }
set
{
SetProperty(ref selectedFunctionTypeItem, value);
}
}
/// <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()
{
SelectedRecordTypeItem = RecordTypeItems.First();
SelectedFunctionTypeItem = FunctionTypeItems.First();
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 isSelectedRecordType = Enum.TryParse<RecordTypeEnum>(SelectedRecordTypeItem, out RecordTypeEnum recordType);
var isSelectedFunctionType = Enum.TryParse<FunctionTypeEnum>(SelectedFunctionTypeItem, out FunctionTypeEnum functionType);
var body = new GetMatDetailHistoryInfosRequest()
{
FunctionType = isSelectedFunctionType ? functionType : null,
RecordType = isSelectedRecordType ? recordType : null,
ShelfCode = ShelfCode,
MatCode = MatCode,
MatName = MatName,
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
PageNumber = CurrentPage,
PageSize = PageSize,
};
var Result = ApiHelp.GetDataFromHttp<PageQueryResponse<MatDetailHistoryInfoModel>>(LocalFile.Config.ApiIpHost + "matDetailHistoryInfo/getMatDetailHistoryInfos", 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
}
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 + "matDetailHistoryInfo/deleteMatDetailHistoryInfo", body, "POST");
if (Result != null && Result.Code == 200)
{
BtnSearch();
Growl.Success("删除成功!" + Result?.Message);
}
else
{
Growl.Error($"{Result?.Message?.ToString()}");
}
}
}
return true;
});
}
/// <summary>
/// 导出数据为Excel文件
/// </summary>
public ICommand BtnExportCommand { get => new DelegateCommand(BtnExport); }
public async void BtnExport()
{
try
{
#region
Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog();
sfd.Title = "选择文件保存路径";
sfd.Filter = ".xlsx文件(*.xlsx)|*.xlsx";
sfd.FileName = "数据记录" + DateTime.Now.ToString("yyyyMMddhhmmss");
sfd.OverwritePrompt = true;
if (sfd.ShowDialog() != true)
{
return;
}
string path = sfd.FileName;
#endregion
var isSelectedRecordType = Enum.TryParse<RecordTypeEnum>(SelectedRecordTypeItem, out RecordTypeEnum recordType);
var isSelectedFunctionType = Enum.TryParse<FunctionTypeEnum>(SelectedFunctionTypeItem, out FunctionTypeEnum functionType);
var body = new GetMatDetailHistoryInfosRequest()
{
FunctionType = isSelectedFunctionType ? functionType : null,
RecordType = isSelectedRecordType ? recordType : null,
ShelfCode = ShelfCode,
MatCode = MatCode,
MatName = MatName,
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
PageNumber = CurrentPage,
PageSize = PageSize,
};
await ApiHelp.PostDownloadFileAsync(path, System.Net.Http.HttpMethod.Post, LocalFile.Config.ApiIpHost + "matDetailHistoryInfo/exportMatDetailHistoryInfo", body);
Growl.Success("导出成功!");
}
catch (Exception ex)
{
Growl.Error("导出失败:" + ex.Message);
}
}
#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
}
}