using DM_Weight.Models; 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; using System; using System.Collections; using System.Collections.Generic; 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种药品 private List _rejectionReportList = new List();//= staticRejectionReportList; public List RejectionReportList { get => _rejectionReportList; set { SetProperty(ref _rejectionReportList, value); } } //public static AddReportDateViewModel vm; //操作人(第一个人) private List _sendUserList = new List(); public List 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 _sendUserCheckList = new List(); public List 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 _returnUserList = new List(); public List 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 _returnUserCheckList = new List(); public List 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 _addUserList = new List(); public List 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 _addUserCheckList = new List(); public List 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; public AddReportDateViewModel(IEventAggregator eventAggregator) { _eventAggregator = eventAggregator; //vm = this; } //private List _drugInfos; //public List 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 StaticSelects = new() //{ // new OrderTakeSelect // { // Code = "DrugName", // Name = "药品名称" // }, // new OrderTakeSelect // { // Code = "PyCode", // Name = "拼音码" // }, // new OrderTakeSelect // { // Code = "DrugBarcode", // Name = "药品条码" // }, // new OrderTakeSelect // { // Code = "DrugId", // Name = "药品编码" // } //}; //private List _selects = StaticSelects; //public List Selects //{ // get { return _selects; } // set // { // SetProperty(ref _selects, value); // } //} //private OrderTakeSelect _selectedItem = StaticSelects[0]; ///// ///// 查询条件 查询字段 ///// //public OrderTakeSelect SelectedItem //{ // get { return _selectedItem; } // set // { // SetProperty(ref _selectedItem, value); // RequestData(); // } //} //private string? _searchValue; ///// ///// 查询条件 查询字段值 ///// //public string? SearchValue //{ // get { return _searchValue; } // set // { // SetProperty(ref _searchValue, value); // RequestData(); // } //} private List _manunos; public List 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); } } } public DelegateCommand Download { get => new DelegateCommand(() => { GridReportUtil.RejectionReport(StartDate, EndDate); }); } ////发药数据添加 //public DelegateCommand AddSendReportDateCommand //{ // get => new DelegateCommand(() => // { // if (SelectedDrug != null) // { // int iRet=SqlSugarHelper.Db.Insertable(new RejectionReport() // { // SendDate = DateTime.Parse(RejReport.SendDate.ToString("yyyy-MM-dd HH:mm")), // SendUser = SendUser.Nickname, // ReceiveUser = SendUserCheck.Nickname,//Jiaojie_ChannelStocks // RealNum= RejReport.RealNum, // DrugId = SelectedDrug.DrugId, // DrugName = SelectedDrug.DrugName, // DrugSpec = SelectedDrug.DrugSpec, // BaseNum = SelectedDrug.drugBase.BaseQuantity + "支",//总基数 // OperationTime=DateTime.Now, // }).ExecuteCommand(); // if (iRet > 0) // { // AlertMsg alertMsg = new AlertMsg // { // Message = "保存成功", // Type = MsgType.INFO // }; // _eventAggregator.GetEvent().Publish(alertMsg); // } // else // { // AlertMsg alertMsg = new AlertMsg // { // Message = "发药数据保存失败,数据异常", // Type = MsgType.ERROR // }; // _eventAggregator.GetEvent().Publish(alertMsg); // } // } // else // { // AlertMsg alertMsg = new AlertMsg // { // Message = "请先选择药品", // Type = MsgType.ERROR // }; // _eventAggregator.GetEvent().Publish(alertMsg); // } // }); //} ////还药数据添加 //public DelegateCommand AddReturnReportDateCommand //{ // get => new DelegateCommand(() => // { // if (SelectedDrug != null) // { // int iRet= SqlSugarHelper.Db.Insertable(new RejectionReport() // { // ReturnTime = DateTime.Parse(RejReport.ReturnTime).ToString("yyyy-MM-dd HH:mm"), // ReturnUser = User.UserName, // ReturnReceiveUser = UserCheck.Nickname,//Jiaojie_ChannelStocks // InfactNum= RejReport.InfactNum, // EmptyNum= RejReport.EmptyNum, // DrugId = SelectedDrug.DrugId, // DrugName = SelectedDrug.DrugName, // DrugSpec = SelectedDrug.DrugSpec, // BaseNum = SelectedDrug + "支", // }).ExecuteCommand(); // if (iRet > 0) // { // AlertMsg alertMsg = new AlertMsg // { // Message = "保存成功", // Type = MsgType.INFO // }; // _eventAggregator.GetEvent().Publish(alertMsg); // } // else // { // AlertMsg alertMsg = new AlertMsg // { // Message = "还药数据保存失败,数据异常", // Type = MsgType.ERROR // }; // _eventAggregator.GetEvent().Publish(alertMsg); // } // } // else // { // AlertMsg alertMsg = new AlertMsg // { // Message = "请先选择药品", // Type = MsgType.ERROR // }; // _eventAggregator.GetEvent().Publish(alertMsg); // } // }); //} ////日消耗数据添加 //public DelegateCommand AddUseReportDateCommand //{ // get => new DelegateCommand(() => // { // if (SelectedDrug != null) // { // int iRet= SqlSugarHelper.Db.Insertable(new RejectionReport() // { // //ReturnTime = DateTime.Parse(RejReport.ReturnTime).ToString("yyyy-MM-dd HH:mm"), // AddUser = User.UserName, // AddCheckUser = UserCheck.Nickname,//Jiaojie_ChannelStocks // UseBottle = RejReport.UseBottle, // UseOrderNo = RejReport.UseOrderNo, // UseAdd=RejReport.UseAdd, // DrugId = SelectedDrug.DrugId, // DrugName = SelectedDrug.DrugName, // DrugSpec = SelectedDrug.DrugSpec, // BaseNum = SelectedDrug + "支", // }).ExecuteCommand(); // if(iRet>0) // { // AlertMsg alertMsg = new AlertMsg // { // Message = "保存成功", // Type = MsgType.INFO // }; // _eventAggregator.GetEvent().Publish(alertMsg); // } // else // { // AlertMsg alertMsg = new AlertMsg // { // Message = "日消耗保存失败,数据异常", // Type = MsgType.ERROR // }; // _eventAggregator.GetEvent().Publish(alertMsg); // } // } // else // { // AlertMsg alertMsg = new AlertMsg // { // Message = "请先选择药品", // Type = MsgType.ERROR // }; // _eventAggregator.GetEvent().Publish(alertMsg); // } // }); //} 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 RealNum = report.RealNum, ReturnTime = ReturnTime, ReturnUser = ReturnUser.UserName, ReturnReceiveUser = ReturnUserCheck.Nickname,//Jiaojie_ChannelStocks InfactNum = report.InfactNum, EmptyNum = report.EmptyNum, 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().Publish(alertMsg); return false; } return true; }); if (f.Data) { AlertMsg alertMsg = new AlertMsg { Message = "保存成功", Type = MsgType.INFO }; _eventAggregator.GetEvent().Publish(alertMsg); } if (!f.IsSuccess) { AlertMsg alertMsg = new AlertMsg { Message = "日消耗保存失败,数据异常", Type = MsgType.ERROR }; _eventAggregator.GetEvent().Publish(alertMsg); } } catch (Exception ex) { AlertMsg alertMsg = new AlertMsg { Message = "日消耗保存失败,抛出异常", Type = MsgType.ERROR }; _eventAggregator.GetEvent().Publish(alertMsg); } }); } //这个方法用于拦截请求,continuationCallback(true)就是不拦截,continuationCallback(false)拦截本次操作 public void ConfirmNavigationRequest(NavigationContext navigationContext, Action 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(str).OrderBy(di => di.DrugName).OrderBy(di => di.DrugId).ToList(); // return; // } // if (DrugInfos != null) // { // DrugInfos.Clear(); // } // DrugInfos = SqlSugarHelper.Db.SqlQueryable(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().Includes(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) { str += " where d.drug_name in (" + ConfigurationManager.AppSettings["DrugNames"] + ")"; } List DrugInfos = SqlSugarHelper.Db.SqlQueryable(str).OrderBy(di => di.DrugName).OrderBy(di => di.DrugId).ToList(); if (DrugInfos != null && DrugInfos.Count > 0) { 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() // .WhereIF(SelectedDrug != null, (di) => di.DrugId.Equals(SelectedDrug.DrugId)) // .Select(di => di) // .ToList(); //} //void RequestData() //{ // int totalCount = 0; // DrugInfos = SqlSugarHelper.Db.Queryable() // .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() .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) { } } }