276 lines
8.1 KiB
C#
276 lines
8.1 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 System.Windows.Media;
|
|
using SqlSugar;
|
|
using HandyControl.Data;
|
|
using System.Windows;
|
|
using Newtonsoft.Json.Linq;
|
|
using 货架标准上位机.Views.Controls;
|
|
using WCS.Model.ApiModel.User;
|
|
using 货架标准上位机.Api;
|
|
using WCS.Model;
|
|
using WCS.Model.ApiModel;
|
|
using System.Windows.Controls;
|
|
using WCS.Model.ApiModel.InterfaceRecord;
|
|
using WCS.BLL.DbModels;
|
|
using WCS.Model.ApiModel.MatBaseInfo;
|
|
using System.Collections.ObjectModel;
|
|
using HandyControl.Tools.Extension;
|
|
using 货架标准上位机.Tool;
|
|
|
|
namespace 货架标准上位机.ViewModel
|
|
{
|
|
public class MatInfoViewModel : BindableBase
|
|
{
|
|
#region Property
|
|
private ObservableCollection<MatInfoModel> dataGridItemSource;
|
|
public ObservableCollection<MatInfoModel> DataGridItemSource
|
|
{
|
|
get { return dataGridItemSource; }
|
|
set
|
|
{
|
|
SetProperty(ref dataGridItemSource, value);
|
|
}
|
|
}
|
|
|
|
public MatInfoModel selectedataGridItem;
|
|
public MatInfoModel SelectedataGridItem
|
|
{
|
|
get { return selectedataGridItem; }
|
|
set
|
|
{
|
|
SetProperty(ref selectedataGridItem, 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);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 物料规格
|
|
/// </summary>
|
|
private string matSpec;
|
|
public string MatSpec
|
|
{
|
|
get { return matSpec; }
|
|
set
|
|
{
|
|
SetProperty(ref matSpec, value);
|
|
}
|
|
}
|
|
|
|
private string matSN;
|
|
public string MatSN
|
|
{
|
|
get { return matSN; }
|
|
set
|
|
{
|
|
SetProperty(ref matSN, value);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Command
|
|
public ICommand BtnResetCommand { get => new DelegateCommand(BtnReset); }
|
|
public void BtnReset()
|
|
{
|
|
MatCode = string.Empty;
|
|
MatName = string.Empty;
|
|
MatSpec = string.Empty;
|
|
MatSN = 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 GetMatInfoRequest()
|
|
{
|
|
MatCode = MatCode,
|
|
MatName = MatName,
|
|
MatSpec = MatSpec,
|
|
MatSN = MatSN,
|
|
|
|
UserName = LocalStatic.CurrentUser,
|
|
DeviceType = LocalFile.Config.DeviceType,
|
|
PageNumber = CurrentPage,
|
|
PageSize = 10,
|
|
|
|
};
|
|
var Result = ApiHelp.GetDataFromHttp<PageQueryResponse<MatInfoModel>>(LocalFile.Config.ApiIpHost + "matBaseInfo/getMatInfo", body, "POST");
|
|
if (Result != null && Result.Data != null && Result.Data.Lists != null)
|
|
{
|
|
DataGridItemSource = new ObservableCollection<MatInfoModel>(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 BtnDeleteCommand { get => new DelegateCommand(BtnDelete); }
|
|
public async void BtnDelete()
|
|
{
|
|
Growl.Ask($"是否删除所有勾选得数据]!", isConfirmed =>
|
|
{
|
|
if (isConfirmed)
|
|
{
|
|
//查询勾选的第一个数据
|
|
var matBaseInfoIds = DataGridItemSource?.Where(t => t.IsSelected == true)
|
|
.Select(t => t.Id)
|
|
.ToList();
|
|
|
|
if (matBaseInfoIds == null)
|
|
{
|
|
Growl.Warning("请选择需要修改的数据!");
|
|
}
|
|
else
|
|
{
|
|
var body = new DeleteMatBaseInfosRequest()
|
|
{
|
|
UserName = LocalStatic.CurrentUser,
|
|
DeviceType = LocalFile.Config.DeviceType,
|
|
MatBaseInfoIds = matBaseInfoIds,
|
|
};
|
|
var Result = ApiHelp.GetDataFromHttp<ResponseBase<UserModel>>(LocalFile.Config.ApiIpHost + "matBaseInfo/deleteMatBaseInfo", body, "POST");
|
|
if (Result != null && Result.Code == 200)
|
|
{
|
|
CurrentPage = 1;
|
|
Growl.Success("删除成功!" + Result?.Message);
|
|
}
|
|
else
|
|
{
|
|
Growl.Error($"{Result?.Message?.ToString()}");
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
});
|
|
}
|
|
|
|
public ICommand BtnPrintCommand { get => new DelegateCommand(BtnPrint); }
|
|
public async void BtnPrint()
|
|
{
|
|
var matBaseInfo = DataGridItemSource?.Where(t => t.IsSelected == true).ToList();
|
|
//TO DO后台批量打印
|
|
}
|
|
#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); }
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|