Files
wcs/货架标准上位机/ViewModels/AGVTaskViewModel.cs
2025-02-22 11:33:36 +08:00

400 lines
13 KiB
C#

using HandyControl.Controls;
using Ping9719.WpfEx.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;
using SqlSugar;
using .Views.Controls;
using .Api;
using WCS.Model;
using WCS.Model.ApiModel;
using WCS.Model.ApiModel.MatBaseInfo;
using System.Collections.ObjectModel;
using WCS.Model.ApiModel.Stocktaking;
using System.Security.AccessControl;
using WCS.Model.ApiModel.AGV;
namespace .ViewModel
{
public class AGVTaskViewModel : BindableBase
{
public AGVTaskViewModel()
{
//初始化下拉列表框
TaskStatus.Add("全部");
var statuses = Enum.GetValues(typeof(TaskStatusEnum))
.Cast<TaskStatusEnum>()
.ToList();
foreach (var status in statuses)
{
TaskStatus.Add(status.ToString());
}
}
#region Property
private ObservableCollection<AGVTaskModel> dataGridItemSource;
public ObservableCollection<AGVTaskModel> DataGridItemSource
{
get { return dataGridItemSource; }
set
{
SetProperty(ref dataGridItemSource, value);
}
}
public AGVTaskModel selectedataGridItem;
public AGVTaskModel SelectedataGridItem
{
get { return selectedataGridItem; }
set
{
SetProperty(ref selectedataGridItem, value);
}
}
/// <summary>
/// 货架编码
/// </summary>
private string shelfCode;
public string ShelfCode
{
get { return shelfCode; }
set
{
SetProperty(ref shelfCode, value);
}
}
/// <summary>
/// 任务创建人
/// </summary>
private string createUser;
public string CreateUser
{
get { return createUser; }
set
{
SetProperty(ref createUser, value);
}
}
/// <summary>
/// 起点
/// </summary>
private string startLocationCode;
public string StartLocationCode
{
get { return startLocationCode; }
set
{
SetProperty(ref startLocationCode, value);
}
}
/// <summary>
/// 终点
/// </summary>
private string endLocationCode;
public string EndLocationCode
{
get { return endLocationCode; }
set
{
SetProperty(ref endLocationCode, value);
}
}
/// <summary>
/// 结束位置
/// </summary>
private List<string> stocktakingStatuses = new List<string>();
public List<string> TaskStatus
{
get { return stocktakingStatuses; }
set
{
SetProperty(ref stocktakingStatuses, value);
}
}
private string selectedTaskStatus;
public string SelectedTaskStatus
{
get { return selectedTaskStatus; }
set
{
SetProperty(ref selectedTaskStatus, value);
}
}
#endregion
#region Command
public ICommand BtnResetCommand { get => new DelegateCommand(BtnReset); }
public void BtnReset()
{
ShelfCode = string.Empty;
CreateUser = string.Empty;
StartLocationCode = string.Empty;
EndLocationCode = string.Empty;
SelectedTaskStatus = TaskStatus.Where(t => t.Contains("正在执行")).First();
}
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;
}
var isSelected = Enum.TryParse<TaskStatusEnum>(SelectedTaskStatus, out TaskStatusEnum status);
#region
var dia = Dialog.Show(new TextDialog());
try
{
var body = new GetAGVTasksRequest()
{
ShelfCode = ShelfCode,
StartLocationCode = StartLocationCode,
EndLocationCode = EndLocationCode,
CreateUser = CreateUser,
TaskStatus = isSelected ? status : null,
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
PageNumber = CurrentPage,
PageSize = PageSize,
};
var Result = ApiHelp.GetDataFromHttp<PageQueryResponse<AGVTaskModel>>(LocalFile.Config.ApiIpHost + "AgvTask/getAGVTasks", body, "POST");
if (Result != null && Result.Data != null && Result.Data.Lists != null)
{
DataGridItemSource = new ObservableCollection<AGVTaskModel>(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 BtnCommitCommand { get => new DelegateCommand(BtnCommit); }
public async void BtnCommit()
{
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 + "PDAStocktaking/commitStocktakingInfos", body, "POST");
if (Result != null && Result.Code == 200)
{
CurrentPage = 1;
Growl.Success("提交成功!" + Result?.Message);
}
else
{
Growl.Error($"{Result?.Message?.ToString()}");
}
}
}
return true;
});
}
/// <summary>
/// 物料修改操作
/// </summary>
public ICommand BtnEditCommand { get => new DelegateCommand(BtnEdit); }
public async void BtnEdit()
{
////查询勾选的第一个数据
//var matDetailStocktakingInfo = DataGridItemSource?.Where(t => t.IsSelected == true).FirstOrDefault();
//if (matDetailStocktakingInfo == null)
//{
// Growl.Warning("请选择需要修改的数据!");
// return;
//}
//else
//{
// var updateView = new MatDetailStocktakingInfoUpdateView("修改盘点数据", matDetailStocktakingInfo);
// updateView.ShowDialog();
// if (updateView.DialogResult == true)
// {
// matDetailStocktakingInfo = updateView.matDetailStocktakingInfo;
// var body = new UpdateStocktakingInfoRequest()
// {
// MatDetailStocktakingInfoId = matDetailStocktakingInfo.Id,
// StocktakingQty = matDetailStocktakingInfo.StocktakingQty,
// UserName = LocalStatic.CurrentUser,
// DeviceType = LocalFile.Config.DeviceType,
// };
// var Result = ApiHelp.GetDataFromHttp<ResponseBase<object>>(LocalFile.Config.ApiIpHost + "PDAStocktaking/updateStocktakingInfos", body, "POST");
// if (Result != null && Result.Code == 200)
// {
// CurrentPage = 1;
// Growl.Success("修改成功!");
// }
// else
// {
// Growl.Error($"{Result?.Message?.ToString()}");
// }
// }
//}
}
/// <summary>
/// 物料删除操作
/// </summary>
public ICommand BtnDeleteCommand { get => new DelegateCommand(BtnDelete); }
public async 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 + "PDAStocktaking/deleteStocktakingInfos", body, "POST");
if (Result != null && Result.Code == 200)
{
CurrentPage = 1;
Growl.Success("删除成功!" + Result?.Message);
}
else
{
Growl.Error($"{Result?.Message?.ToString()}");
}
}
}
return true;
});
}
#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
}
}