009_DI-Elec/newFront/c#前端/SWS.CAD/ViewModels/CheckInApproveViewModel.cs
2025-09-04 18:28:02 +08:00

221 lines
6.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using Prism.Commands;
using Prism.Services.Dialogs;
using SWS.CAD.ViewModels.myViewModelBase;
using SWS.Commons;
using SWS.Model;
using SWS.Service;
using Unity;
using MessageBox = System.Windows.Forms.MessageBox;
namespace SWS.CAD.ViewModels
{
public class CheckInApproveViewModel : DialogBase
{
#region
/// <summary>
/// 已审核
/// </summary>
public ICommand Commad_Approve { get; }
/// <summary>
/// 未审核
/// </summary>
public ICommand Commad_NotApprove { get; }
/// <summary>
/// 全选
/// </summary>
public ICommand Commad_CheckedAll { get; }
/// <summary>
/// 清空选择
/// </summary>
public ICommand Commad_ClearChecked { get; }
#endregion
private ObservableCollection<CheckInLogNeedApproveModel> _listData;
/// <summary>
/// 数据源
/// </summary>
public ObservableCollection<CheckInLogNeedApproveModel> listData
{
get { return _listData; }
set { _listData = value; RaisePropertyChanged(nameof(listData)); }
}
private List<CheckInLogNeedApproveModel> _listAllData = new List<CheckInLogNeedApproveModel>();
/// <summary>
/// 所有审核数据 ec_drawing_syn
/// </summary>
public List<CheckInLogNeedApproveModel> listAllData
{
get { return _listAllData; }
set { _listAllData = value; }
}
Visibility visibility = Visibility.Visible;
/// <summary>
/// 是否显示批量审核按钮
/// </summary>
public Visibility IsShowApprove
{
get
{
return visibility;
}
set
{
visibility = value;
RaisePropertyChanged(nameof(IsShowApprove));
ReadOnly = value == Visibility.Collapsed;
}
}
Boolean _ReadOnly = false;
/// <summary>
/// 是否显示批量审核按钮
/// </summary>
public Boolean ReadOnly
{
get
{
return _ReadOnly;
}
set { _ReadOnly = value; RaisePropertyChanged(nameof(ReadOnly)); }
}
NotificationService _notificationService { get; set; }
public CheckInApproveViewModel()
{
title = "检入审核";
_notificationService = GlobalObject.container.Resolve<NotificationService>();
Commad_Approve = new DelegateCommand(onApprove);
Commad_NotApprove = new DelegateCommand(onNotApprove);
Commad_CheckedAll = new DelegateCommand(onCheckedAll);
Commad_ClearChecked = new DelegateCommand(onClearChecked);
}
public string Title => "";
public event Action<IDialogResult> RequestClose;
public override void onWindow_loaded(object para)
{
GetAllData();
}
#region
/// <summary>
/// 获取所有数据
/// </summary>
/// <param name="approve">获取数据后显示数据0未审核 1已审核</param>
private async void GetAllData(int approve = 0)
{
var list = await _notificationService.GetCheckInLogNeedApprove();
listAllData.Clear();
foreach (var item in list)
{
foreach (var item2 in item)
{ listAllData.Add(item2); }
}
if (approve == 0)
{ onNotApprove(); }
else if (approve == 1)
{ onApprove(); }
}
#endregion
#region
/// <summary>
/// 已审核
/// </summary>
public void onApprove()
{
var list = listAllData.Where(a => a.ApproveByAdmin == 1);
listData = new ObservableCollection<CheckInLogNeedApproveModel>(list);
IsShowApprove = Visibility.Collapsed;
}
#endregion
#region
/// <summary>
/// 未审核
/// </summary>
public void onNotApprove()
{
var list = listAllData.Where(a => a.ApproveByAdmin == 0);
listData = new ObservableCollection<CheckInLogNeedApproveModel>(list);
IsShowApprove = Visibility.Visible;
}
#endregion
#region
/// <summary>
/// 全选
/// </summary>
public void onCheckedAll()
{
if (ReadOnly)
{ return; }
foreach (var item in listData)
{
item.IsSelected = true;
}
}
#endregion
#region
/// <summary>
/// 清空选择
/// </summary>
public void onClearChecked()
{
if (ReadOnly)
{ return; }
foreach (var item in listData)
{
item.IsSelected = false;
}
}
#endregion
#region
public override async void ExecuteOKCommandAsync(object parameter)
{
var list = listAllData.Where(a => a.IsSelected == true);
if (!list.Any())
{
MessageBox.Show("请先勾选数据再进行批量审核!");
return;
}
var listId = list.Select(a => a.DrawingSynID).ToList();
string IDs = string.Join(",", listId);
var msg = await _notificationService.ApproveCheckInLog(IDs);
if (!string.IsNullOrEmpty(msg))
{ MessageBox.Show("审核失败:" + msg); }
else
{
MessageBox.Show("审核成功!");
GetAllData();
}
}
#endregion
#region
public override void ExecuteCloseCommand(object parameter)
{
// 关闭窗口 (需要通过 CommandParameter 传入窗口实例)
if (parameter is System.Windows.Window window)
{
window.Close();
}
this.Dispose();
}
#endregion
}
}