This commit is contained in:
hehaibing-1996
2024-05-15 18:59:24 +08:00
parent cc65e985aa
commit 432a96198f
75 changed files with 2174 additions and 272 deletions

View File

@ -26,11 +26,22 @@ using WCS.Model.ApiModel.MatBaseInfo;
using System.Collections.ObjectModel;
using HandyControl.Tools.Extension;
using .Tool;
using System.Printing;
using System.Printing.IndexedProperties;
namespace .ViewModel
{
public class MatInfoViewModel : BindableBase
{
public MatInfoViewModel()
{
IsPrintedItemSource = new List<ComboBoxItem>()
{
new ComboBoxItem(){Text = "全部",Value = null},
new ComboBoxItem(){Text = "否",Value = false },
new ComboBoxItem(){Text = "是",Value = true},
};
}
#region Property
private ObservableCollection<MatInfoModel> dataGridItemSource;
public ObservableCollection<MatInfoModel> DataGridItemSource
@ -52,6 +63,35 @@ namespace 货架标准上位机.ViewModel
}
}
private List<ComboBoxItem> isPrintedItemSource;
public List<ComboBoxItem> IsPrintedItemSource
{
get => isPrintedItemSource;
set { SetProperty(ref isPrintedItemSource, value); }
}
public class ComboBoxItem
{
public string Text { get; set; }
public bool? Value { get; set; }
}
private bool? isPrinted;
public bool? IsPrinted
{
get => isPrinted;
set { SetProperty(ref isPrinted, value); }
}
private string matBatch;
public string MatBatch
{
get => matBatch;
set { SetProperty(ref matBatch, value); }
}
/// <summary>
/// 物料编码
/// </summary>
@ -125,7 +165,6 @@ namespace 货架标准上位机.ViewModel
return;
}
#region
//var dia = Dialog.Show(new TextDialog());
try
{
var body = new GetMatInfoRequest()
@ -134,11 +173,13 @@ namespace 货架标准上位机.ViewModel
MatName = MatName,
MatSpec = MatSpec,
MatSN = MatSN,
MatBatch = MatBatch,
IsPrinted = IsPrinted,
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
PageNumber = CurrentPage,
PageSize = 10,
PageSize = PageSize,
};
var Result = ApiHelp.GetDataFromHttp<PageQueryResponse<MatInfoModel>>(LocalFile.Config.ApiIpHost + "matBaseInfo/getMatInfo", body, "POST");
@ -166,7 +207,7 @@ namespace 货架标准上位机.ViewModel
public ICommand BtnDeleteCommand { get => new DelegateCommand(BtnDelete); }
public async void BtnDelete()
{
Growl.Ask($"是否删除所有勾选数据]!", isConfirmed =>
Growl.Ask($"是否删除所有勾选数据]!", isConfirmed =>
{
if (isConfirmed)
{
@ -187,7 +228,7 @@ namespace 货架标准上位机.ViewModel
DeviceType = LocalFile.Config.DeviceType,
MatBaseInfoIds = matBaseInfoIds,
};
var Result = ApiHelp.GetDataFromHttp<ResponseBase<UserModel>>(LocalFile.Config.ApiIpHost + "matBaseInfo/deleteMatBaseInfo", body, "POST");
var Result = ApiHelp.GetDataFromHttp<ResponseBase<UserModel>>(LocalFile.Config.ApiIpHost + "matBaseInfos/deleteMatBaseInfo", body, "POST");
if (Result != null && Result.Code == 200)
{
CurrentPage = 1;
@ -204,10 +245,99 @@ namespace 货架标准上位机.ViewModel
}
public ICommand BtnPrintCommand { get => new DelegateCommand(BtnPrint); }
public async void BtnPrint()
public void BtnPrint()
{
var matBaseInfo = DataGridItemSource?.Where(t => t.IsSelected == true).ToList();
//TO DO后台批量打印
var matBaseInfos = DataGridItemSource?.Where(t => t.IsSelected == true).ToList();
if (matBaseInfos == null || matBaseInfos.Count == 0)
{
Growl.Warning("请选择需要打印的物料!");
return;
}
//重复打印提示
#region
var printedMatBaseInfo = matBaseInfos.Where(t => t.IsPrinted).ToList();
if (printedMatBaseInfo != null && printedMatBaseInfo.Count > 0)
{
//拼接提示字符串
var messageStr = "以下条码已打印:\r\n" +
string.Join("\r\n", printedMatBaseInfo.Select(t => $"[{t.MatSN}]已打印{t.PrintedTimes}次!").ToList())
+ "\r\n\r\n是否继续打印(重复打印可能造成条码重复)";
var result = HandyControl.Controls.MessageBox.Show(messageStr, "重复打印提示", MessageBoxButton.OKCancel);
if (result == MessageBoxResult.Cancel)
{
return;
}
}
#endregion
//批量打印
Task.Run(() =>
{
try
{
ProcessDialog process = null;
Dialog dia = null;
var totalCount = matBaseInfos.Count();
int currentCount = 0;
App.Current.Dispatcher.Invoke(() =>
{
process = new ProcessDialog();
dia = Dialog.Show(process);
});
matBaseInfos.ForEach(t =>
{
PrintTender.PrintTag(new PrintClass()
{
MatSn = t.MatSN,
MatName = t.MatName,
MatCode = t.MatCode,
MatBatch = t.MatBatch,
MatQty = t.MatQty.ToString(),
MatSpec = t.MatSpec,
});
currentCount++;
if (process != null)
process.viewModel.ProcessValue = Convert.ToInt32(((decimal)currentCount / totalCount) * 100);
});
App.Current.Dispatcher.Invoke(() =>
{
dia.Close();
dia.Collapse();
});
#region
try
{
var body = new PrintedMatInfoRequest()
{
PrintedMatInfoIds = matBaseInfos.Select(t => t.Id).ToList(),
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
};
var Result = ApiHelp.GetDataFromHttp<ResponseCommon>(LocalFile.Config.ApiIpHost + "matBaseInfo/printedMatInfo", body, "POST");
if (Result != null && Result.Code == 200)
{
//回传成功
}
else
{
//回传失败
}
}
catch (Exception ex)
{
Logs.Write("回传“打印成功”失败:" + ex.Message);
}
#endregion
}
catch (Exception ex)
{
Logs.Write("打印条码失败:" + ex.Message);
}
});
}
#endregion
@ -238,6 +368,14 @@ namespace 货架标准上位机.ViewModel
set { SetProperty(ref totalCount, value); }
}
private int pageSize = 10;
public int PageSize
{
get => pageSize;
set { SetProperty(ref pageSize, value); }
}
public ICommand BtnFirstPageCommand { get => new DelegateCommand(BtnFirstPage); }
public void BtnFirstPage()
{