2025-07-02 16:15:16 +08:00
using DM_Weight.Common ;
using DM_Weight.Models ;
2025-05-27 10:27:47 +08:00
using DM_Weight.msg ;
using DM_Weight.Port ;
using DM_Weight.Report ;
using DM_Weight.select ;
using DM_Weight.util ;
using Prism.Commands ;
using Prism.Events ;
using Prism.Mvvm ;
using Prism.Regions ;
2025-07-02 16:15:16 +08:00
using Prism.Services.Dialogs ;
2025-05-27 10:27:47 +08:00
using System ;
using System.Collections ;
using System.Collections.Generic ;
2025-07-02 16:15:16 +08:00
using System.Collections.ObjectModel ;
2025-05-27 10:27:47 +08:00
using System.Configuration ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
namespace DM_Weight.ViewModels
{
public class AddReportDateViewModel : BindableBase , IConfirmNavigationRequest , IRegionMemberLifetime
{
//private int _pageNum = 1;
//public int PageNum
//{
// get => _pageNum;
// set
// {
// SetProperty(ref _pageNum, value);
// RequestData();
// }
//}
//private int _pageCount = 1;
//public int PageCount
//{
// get => _pageCount;
// set
// {
// SetProperty(ref _pageCount, value);
// }
//}
//private int _pageSize = 8;
//public int PageSize
//{
// get => _pageSize;
// set
// {
// SetProperty(ref _pageSize, value);
// }
//}
//private int _totalCount = 0;
//public int TotalCount
//{
// get => _totalCount;
// set
// {
// SetProperty(ref _totalCount, value);
// }
//查询9种药品
2025-07-02 16:15:16 +08:00
IDialogService _dialogService ;
private ObservableCollection < RejectionReport > _rejectionReportList = new ObservableCollection < RejectionReport > ( ) ; //= staticRejectionReportList;
public ObservableCollection < RejectionReport > RejectionReportList
2025-05-27 10:27:47 +08:00
{
get = > _rejectionReportList ;
set
{
SetProperty ( ref _rejectionReportList , value ) ;
}
}
//public static AddReportDateViewModel vm;
//操作人(第一个人)
private List < UserList > _sendUserList = new List < UserList > ( ) ;
public List < UserList > SendUserList
{
get = > _sendUserList ;
set
{
SetProperty ( ref _sendUserList , value ) ;
}
}
private UserList _sendUser = new UserList ( ) ;
public UserList SendUser
{
get = > _sendUser ;
set
{
SetProperty ( ref _sendUser , value ) ;
}
}
//复核人(第二个人)
private List < UserList > _sendUserCheckList = new List < UserList > ( ) ;
public List < UserList > SendUserCheckList
{
get = > _sendUserCheckList ;
set
{
SetProperty ( ref _sendUserCheckList , value ) ;
}
}
private UserList _sendUserCheck = new UserList ( ) ;
public UserList SendUserCheck
{
get = > _sendUserCheck ;
set
{
SetProperty ( ref _sendUserCheck , value ) ;
}
}
//还药人
private List < UserList > _returnUserList = new List < UserList > ( ) ;
public List < UserList > ReturnUserList
{
get = > _returnUserList ;
set
{
SetProperty ( ref _returnUserList , value ) ;
}
}
private UserList _returnUser = new UserList ( ) ;
public UserList ReturnUser
{
get = > _returnUser ;
set
{
SetProperty ( ref _returnUser , value ) ;
}
}
//还药(第二个人)接收者
private List < UserList > _returnUserCheckList = new List < UserList > ( ) ;
public List < UserList > ReturnUserCheckList
{
get = > _returnUserCheckList ;
set
{
SetProperty ( ref _returnUserCheckList , value ) ;
}
}
private UserList _returnUserCheck = new UserList ( ) ;
public UserList ReturnUserCheck
{
get = > _returnUserCheck ;
set
{
SetProperty ( ref _returnUserCheck , value ) ;
}
}
//补充者
private List < UserList > _addUserList = new List < UserList > ( ) ;
public List < UserList > AddUserList
{
get = > _addUserList ;
set
{
SetProperty ( ref _addUserList , value ) ;
}
}
private UserList _addUser = new UserList ( ) ;
public UserList AddUser
{
get = > _addUser ;
set
{
SetProperty ( ref _addUser , value ) ;
}
}
//补充者(第二个人)核对者
private List < UserList > _addUserCheckList = new List < UserList > ( ) ;
public List < UserList > AddUserCheckList
{
get = > _addUserCheckList ;
set
{
SetProperty ( ref _addUserCheckList , value ) ;
}
}
private UserList _addUserCheck = new UserList ( ) ;
public UserList AddUserCheck
{
get = > _addUserCheck ;
set
{
SetProperty ( ref _addUserCheck , value ) ;
}
}
//private RejectionReport _Report = new RejectionReport() { SendDate = DateTime.Now, ReturnTime = DateTime.Now.ToString(), };
//public RejectionReport RejReport
//{
// get => _Report;
// set
// {
// SetProperty(ref _Report, value);
// }
//}
IEventAggregator _eventAggregator ;
2025-07-02 16:15:16 +08:00
public AddReportDateViewModel ( IEventAggregator eventAggregator , IDialogService DialogService )
2025-05-27 10:27:47 +08:00
{
_eventAggregator = eventAggregator ;
2025-07-02 16:15:16 +08:00
_dialogService = DialogService ;
2025-05-27 10:27:47 +08:00
//vm = this;
}
//private List<DrugInfo> _drugInfos;
//public List<DrugInfo> DrugInfos
//{
// get { return _drugInfos; }
// set { SetProperty(ref _drugInfos, value); }
//}
//private DrugInfo _selectedDrug = new();
//public DrugInfo SelectedDrug
//{
// get
// {
// return _selectedDrug;
// }
// set
// {
// if (value != null)
// {
// SetProperty(ref _selectedDrug, value);
// GetManuNos();
// }
// else
// {
// SetProperty(ref _selectedDrug, new());
// Manunos = null;
// SelectedDrug.drugBase = new();
// }
// }
//}
//public static List<OrderTakeSelect> StaticSelects = new()
//{
// new OrderTakeSelect
// {
// Code = "DrugName",
// Name = "药品名称"
// },
// new OrderTakeSelect
// {
// Code = "PyCode",
// Name = "拼音码"
// },
// new OrderTakeSelect
// {
// Code = "DrugBarcode",
// Name = "药品条码"
// },
// new OrderTakeSelect
// {
// Code = "DrugId",
// Name = "药品编码"
// }
//};
//private List<OrderTakeSelect> _selects = StaticSelects;
//public List<OrderTakeSelect> Selects
//{
// get { return _selects; }
// set
// {
// SetProperty(ref _selects, value);
// }
//}
//private OrderTakeSelect _selectedItem = StaticSelects[0];
///// <summary>
///// 查询条件 查询字段
///// </summary>
//public OrderTakeSelect SelectedItem
//{
// get { return _selectedItem; }
// set
// {
// SetProperty(ref _selectedItem, value);
// RequestData();
// }
//}
//private string? _searchValue;
///// <summary>
///// 查询条件 查询字段值
///// </summary>
//public string? SearchValue
//{
// get { return _searchValue; }
// set
// {
// SetProperty(ref _searchValue, value);
// RequestData();
// }
//}
private List < DrugManuNo > _manunos ;
public List < DrugManuNo > Manunos
{
get { return _manunos ; }
set { SetProperty ( ref _manunos , value ) ; }
}
private DrugManuNo _selectedManuno = new DrugManuNo ( ) ;
public DrugManuNo SelectedManuno
{
get { return _selectedManuno ; }
set { SetProperty ( ref _selectedManuno , value ? ? new ( ) ) ; }
}
public bool KeepAlive = > false ;
private DateTime ? _startDate = new DateTime ( DateTime . Now . Year , DateTime . Now . Month , DateTime . Now . Day ) ;
public DateTime ? StartDate
{
get = > _startDate ;
set
{
if ( value ! = null )
{
SetProperty ( ref _startDate , new DateTime ( value ? . Year ? ? 0 , value ? . Month ? ? 0 , value ? . Day ? ? 0 ) ) ;
}
else
{
SetProperty ( ref _startDate , value ) ;
}
}
}
//发药时间
private DateTime _sendDate = DateTime . Now ;
public DateTime SendDate
{
get = > _sendDate ;
set
{
SetProperty ( ref _sendDate , value ) ;
}
}
//还药时间
private string _returnTime = string . Empty ;
public string ReturnTime
{
get = > _returnTime ;
set
{
SetProperty ( ref _returnTime , value ) ;
}
}
private DateTime ? _endDate = new DateTime ( DateTime . Now . Year , DateTime . Now . Month , DateTime . Now . Day , 23 , 59 , 59 ) ;
public DateTime ? EndDate
{
get = > _endDate ;
set
{
if ( value ! = null )
{
TimeSpan ershisi = new TimeSpan ( 23 , 59 , 59 ) ;
SetProperty ( ref _endDate , new DateTime ( value ? . Year ? ? 0 , value ? . Month ? ? 0 , value ? . Day ? ? 0 , 23 , 59 , 59 ) ) ;
}
else
{
SetProperty ( ref _endDate , value ) ;
}
}
}
2025-07-02 16:15:16 +08:00
//修改药品
public DelegateCommand EditDrugName
{
get = > new DelegateCommand ( async ( ) = >
{
// 此处延时1毫秒, 等待页面渲染
await Task . Delay ( TimeSpan . FromMilliseconds ( 1 ) ) ;
DialogParameters dialogParameters = new DialogParameters ( ) ;
//dialogParameters.Add("orderInfo", SelectedOrder);
DialogServiceExtensions . ShowDialogHost ( _dialogService , "ReportDrugNameDialog" , dialogParameters , DoDialogResult , "RootDialog" ) ;
} ) ;
}
private void DoDialogResult ( IDialogResult dialogResult )
{
// 委托 被动执行 被子窗口执行
// dialogResult 第一方面可以拿到任意参数 第二方面 可判断关闭状态
//if(dialogResult.Result == ButtonResult.OK)
//{
2025-05-27 10:27:47 +08:00
2025-07-02 16:15:16 +08:00
GetAllDrugInfos ( ) ;
//}
//MessageBox.Show("返回值:" + dialogResult.Result.ToString());
}
2025-05-27 10:27:47 +08:00
public DelegateCommand Download
{
get = > new DelegateCommand ( ( ) = >
{
GridReportUtil . RejectionReport ( StartDate , EndDate ) ;
} ) ;
}
public DelegateCommand AddReportDateCommand
{
get = > new DelegateCommand ( ( ) = >
{
try
{
var f = SqlSugarHelper . Db . UseTran ( ( ) = >
{
if ( RejectionReportList ! = null & & RejectionReportList . Count > 0 )
{
int iRet = 0 ;
for ( int i = 0 ; i < RejectionReportList . Count ; i + + )
{
RejectionReport report = RejectionReportList [ i ] ;
iRet = SqlSugarHelper . Db . Insertable ( new RejectionReport ( )
{
SendDate = SendDate ,
SendUser = SendUser . Nickname ,
ReceiveUser = SendUserCheck . Nickname , //Jiaojie_ChannelStocks
2025-07-02 16:15:16 +08:00
RealNum = report . RealNum , //实发、实物、空安瓿三个值一样,要求写一个即可避免他们重复输入
2025-05-27 10:27:47 +08:00
ReturnTime = ReturnTime ,
ReturnUser = ReturnUser . UserName ,
ReturnReceiveUser = ReturnUserCheck . Nickname , //Jiaojie_ChannelStocks
2025-07-02 16:15:16 +08:00
InfactNum = report . RealNum ,
EmptyNum = report . RealNum ,
2025-05-27 10:27:47 +08:00
AddUser = AddUser . UserName ,
AddCheckUser = AddUserCheck . Nickname , //Jiaojie_ChannelStocks
UseBottle = report . UseBottle ,
UseOrderNo = report . UseOrderNo ,
UseAdd = report . UseAdd ,
DrugId = report . DrugId ,
DrugName = report . DrugName ,
DrugSpec = report . DrugSpec ,
BaseNum = report . BaseNum + "支" ,
OperationTime = DateTime . Now
} ) . ExecuteCommand ( ) ;
}
}
else
{
AlertMsg alertMsg = new AlertMsg
{
Message = "请输入数据" ,
Type = MsgType . ERROR
} ;
_eventAggregator . GetEvent < SnackbarEvent > ( ) . Publish ( alertMsg ) ;
return false ;
}
return true ;
} ) ;
if ( f . Data )
{
AlertMsg alertMsg = new AlertMsg
{
Message = "保存成功" ,
Type = MsgType . INFO
} ;
_eventAggregator . GetEvent < SnackbarEvent > ( ) . Publish ( alertMsg ) ;
}
if ( ! f . IsSuccess )
{
AlertMsg alertMsg = new AlertMsg
{
Message = "日消耗保存失败,数据异常" ,
Type = MsgType . ERROR
} ;
_eventAggregator . GetEvent < SnackbarEvent > ( ) . Publish ( alertMsg ) ;
}
}
catch ( Exception ex )
{
AlertMsg alertMsg = new AlertMsg
{
Message = "日消耗保存失败,抛出异常" ,
Type = MsgType . ERROR
} ;
_eventAggregator . GetEvent < SnackbarEvent > ( ) . Publish ( alertMsg ) ;
}
} ) ;
}
//这个方法用于拦截请求,continuationCallback(true)就是不拦截, continuationCallback(false)拦截本次操作
public void ConfirmNavigationRequest ( NavigationContext navigationContext , Action < bool > continuationCallback )
{
continuationCallback ( true ) ;
}
//public void UpdateComboBoxItems(string text)
//{
// string str = @"SELECT d.drug_id,d.py_code,d.drug_barcode,d.drug_name,d.drug_brand_name,d.drug_spec,d.dosage,d.pack_unit,
// d.manufactory,d.max_stock,CONCAT(drug_name,' / ',drug_spec,' / ',manufactory) as drug_name_spec FROM `drug_info` d";
// if (string.IsNullOrEmpty(text))
// {
// DrugInfos = SqlSugarHelper.Db.SqlQueryable<DrugInfo>(str).OrderBy(di => di.DrugName).OrderBy(di => di.DrugId).ToList();
// return;
// }
// if (DrugInfos != null)
// {
// DrugInfos.Clear();
// }
// DrugInfos = SqlSugarHelper.Db.SqlQueryable<DrugInfo>(str).Where(di => di.DrugName.Contains(text) || di.PyCode.Contains(text)).OrderBy(di => di.DrugName).OrderBy(di => di.DrugId).ToList();
//}
//接收导航传过来的参数
public void OnNavigatedTo ( NavigationContext navigationContext )
{
//查询表格数据
//RequestData();
//获取用户数据
GetUsers ( ) ;
GetAllDrugInfos ( ) ;
}
private void GetAllDrugInfos ( )
{
//var list = SqlSugarHelper.Db.Queryable<DrugInfo>().Includes<DrugManuNo>(di => di.DrugManuNos).OrderBy(di => di.DrugId).ToList();
//DrugInfos = list;
string str = "SELECT d.drug_id,d.drug_barcode,d.drug_name,d.drug_brand_name,d.drug_spec,d.dosage,d.pack_unit,d.manufactory,d.max_stock,CONCAT(drug_name,' / ',drug_spec,' / ',manufactory) as drug_name_spec,db.baseQuantity as PyCode FROM `drug_info` d left join drug_base db on d.drug_id=db.drugid and db.machine_id='DM3'" ;
if ( ConfigurationManager . AppSettings [ "DrugNames" ] ! = null )
{
2025-07-02 16:15:16 +08:00
str + = " where d.drug_id in (" + CommonClass . ReadAppSetting ( "DrugNames" ) + ")" ;
2025-05-27 10:27:47 +08:00
}
List < DrugInfo > DrugInfos = SqlSugarHelper . Db . SqlQueryable < DrugInfo > ( str ) . OrderBy ( di = > di . DrugName ) . OrderBy ( di = > di . DrugId ) . ToList ( ) ;
if ( DrugInfos ! = null & & DrugInfos . Count > 0 )
{
2025-07-02 16:15:16 +08:00
RejectionReportList . Clear ( ) ;
2025-05-27 10:27:47 +08:00
for ( int i = 0 ; i < DrugInfos . Count ; i + + )
{
RejectionReport report = new RejectionReport ( ) ;
report . DrugId = DrugInfos [ i ] . DrugId ;
report . DrugName = DrugInfos [ i ] . DrugName ;
report . DrugSpec = DrugInfos [ i ] . DrugSpec ;
report . InfactNum = 0 ;
report . RealNum = 0 ;
report . BaseNum = DrugInfos [ i ] . PyCode ;
RejectionReportList . Add ( report ) ;
}
}
}
//void GetManuNos()
//{
// Manunos = SqlSugarHelper.Db.Queryable<DrugManuNo>()
// .WhereIF(SelectedDrug != null, (di) => di.DrugId.Equals(SelectedDrug.DrugId))
// .Select(di => di)
// .ToList();
//}
//void RequestData()
//{
// int totalCount = 0;
// DrugInfos = SqlSugarHelper.Db.Queryable<DrugInfo>()
// .Includes(di => di.drugBase)
// .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugId"), (di) => di.DrugId.ToString().Contains(SearchValue))
// .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugName"), (di) => di.DrugName.Contains(SearchValue))
// .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("PyCode"), (di) => di.PyCode.Contains(SearchValue))
// .WhereIF(!String.IsNullOrEmpty(SearchValue) && SelectedItem.Code.Equals("DrugBarcode"), (di) => di.DrugBarcode.Contains(SearchValue))
// //.Select(di => di)
// .ToPageList(PageNum, PageSize, ref totalCount);
// foreach (DrugInfo di in DrugInfos)
// {
// if (di.drugBase == null)
// {
// di.drugBase = new DrugBase();
// }
// }
// TotalCount = totalCount;
// PageCount = (int)Math.Ceiling((double)TotalCount / PageSize);
//}
void GetUsers ( )
{
//获取用户数据
SendUserList = SqlSugarHelper . Db . Queryable < UserList > ( )
. Where ( u = > u . MachineId . Equals ( ConfigurationManager . AppSettings [ "machineId" ] ) )
. ToList ( ) ;
//获取用户数据
SendUserCheckList = SendUserList . Select ( item = > ( UserList ) item . Clone ( ) ) . ToList ( ) ;
ReturnUserList = SendUserList . Select ( item = > ( UserList ) item . Clone ( ) ) . ToList ( ) ;
ReturnUserCheckList = SendUserList . Select ( item = > ( UserList ) item . Clone ( ) ) . ToList ( ) ;
AddUserList = SendUserList . Select ( item = > ( UserList ) item . Clone ( ) ) . ToList ( ) ;
AddUserCheckList = SendUserList . Select ( item = > ( UserList ) item . Clone ( ) ) . ToList ( ) ;
}
//每次导航的时候, 该实列用不用重新创建, true是不重新创建,false是重新创建
public bool IsNavigationTarget ( NavigationContext navigationContext )
{
return true ;
}
//这个方法用于拦截请求
public void OnNavigatedFrom ( NavigationContext navigationContext )
{
}
}
}