224 lines
8.3 KiB
C#
224 lines
8.3 KiB
C#
using DM_Weight.Common;
|
|
using DM_Weight.Models;
|
|
using DM_Weight.Port;
|
|
using DM_Weight.util;
|
|
using Prism.Commands;
|
|
using Prism.Mvvm;
|
|
using Prism.Regions;
|
|
using Prism.Services.Dialogs;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Configuration;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Unity;
|
|
|
|
namespace DM_Weight.ViewModels
|
|
{
|
|
public class ReportDrugNameDialogViewModel : BindableBase, IRegionMemberLifetime, IDialogAware
|
|
{
|
|
private string? _reportDrugName;
|
|
public string? ReportDrugName
|
|
{
|
|
get => _reportDrugName;
|
|
set => SetProperty(ref _reportDrugName, value);
|
|
}
|
|
private DrugInfo? _leftDrug;
|
|
public DrugInfo? LeftDrug
|
|
{
|
|
get => _leftDrug;
|
|
set => SetProperty(ref _leftDrug, value);
|
|
}
|
|
private ObservableCollection<DrugInfo> _rightDrugNameList = new ObservableCollection<DrugInfo>();
|
|
|
|
public ObservableCollection<DrugInfo> RightDrugNameList
|
|
{
|
|
get => _rightDrugNameList;
|
|
set => SetProperty(ref _rightDrugNameList, value);
|
|
}
|
|
|
|
private DrugInfo? _rightDrugName;
|
|
public DrugInfo? RightDrugName
|
|
{
|
|
get => _rightDrugName;
|
|
set => SetProperty(ref _rightDrugName, value);
|
|
}
|
|
public static ReportDrugNameDialogViewModel vm;
|
|
public static ObservableCollection<DrugInfo> defaultAll = new ObservableCollection<DrugInfo>();
|
|
private ObservableCollection<DrugInfo> _allPremissions = defaultAll;
|
|
|
|
public event Action<IDialogResult> RequestClose;
|
|
|
|
public ReportDrugNameDialogViewModel()
|
|
{
|
|
vm = this;
|
|
}
|
|
|
|
public ObservableCollection<DrugInfo> AllPremissions
|
|
{
|
|
get => _allPremissions;
|
|
set => SetProperty(ref _allPremissions, value);
|
|
}
|
|
|
|
public bool KeepAlive => false;
|
|
public bool IsNavigationTarget(NavigationContext navigationContext)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
void RequestData()
|
|
{
|
|
AllPremissions = new ObservableCollection<DrugInfo>();
|
|
//string str = "SELECT d.drug_id,CONCAT(drug_name,' / ',drug_spec,' / ',manufactory) as drug_name_spec 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_id not in (" + CommonClass.ReadAppSetting("DrugNames") + ")";
|
|
//}
|
|
//List<DrugInfo> DrugInfos = SqlSugarHelper.Db.SqlQueryable<DrugInfo>(str).OrderBy(di => di.DrugId).ToList();
|
|
|
|
//AllPremissions.AddRange(DrugInfos);
|
|
|
|
|
|
string strRight = "SELECT d.drug_id,CONCAT(drug_name,' / ',drug_spec,' / ',manufactory) as drug_name_spec 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)
|
|
{
|
|
strRight += " where d.drug_id in (" + CommonClass.ReadAppSetting("DrugNames")+ ")";
|
|
}
|
|
List<DrugInfo> DrugInfosRight = SqlSugarHelper.Db.SqlQueryable<DrugInfo>(strRight).OrderBy(di => di.DrugId).ToList();
|
|
RightDrugNameList.AddRange(DrugInfosRight);
|
|
}
|
|
|
|
public bool CanCloseDialog()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public void OnDialogClosed()
|
|
{
|
|
}
|
|
|
|
public void OnDialogOpened(IDialogParameters parameters)
|
|
{
|
|
//查询报表中的药品名称
|
|
RequestData();
|
|
GetAllDrugInfos();
|
|
}
|
|
|
|
public DelegateCommand<DrugInfo> RightSelectedItemChangedCommand
|
|
{
|
|
get => new DelegateCommand<DrugInfo>((DrugInfo _selected) =>
|
|
{
|
|
RightDrugName = _selected;
|
|
});
|
|
}
|
|
public DelegateCommand ToRight => new DelegateCommand(() =>
|
|
{
|
|
if (LeftDrug != null)
|
|
{
|
|
RightDrugNameList.Insert(0, LeftDrug);
|
|
AllPremissions.RemoveAt(AllPremissions.ToList().FindIndex(it => it.DrugId == LeftDrug.DrugId));
|
|
}
|
|
});
|
|
public DelegateCommand ToLeft => new DelegateCommand(() =>
|
|
{
|
|
if (RightDrugName != null)
|
|
{
|
|
AllPremissions.Insert(0, RightDrugName);
|
|
RightDrugNameList.RemoveAt(RightDrugNameList.ToList().FindIndex(it => it.DrugId == RightDrugName.DrugId));
|
|
}
|
|
});
|
|
public DelegateCommand<DrugInfo> LeftSelectedItemChangedCommand
|
|
{
|
|
get => new DelegateCommand<DrugInfo>((DrugInfo _selected) =>
|
|
{
|
|
LeftDrug = _selected;
|
|
});
|
|
}
|
|
|
|
//保存
|
|
public DelegateCommand AddRole
|
|
{
|
|
get=>new DelegateCommand(()=>
|
|
{
|
|
if(RightDrugNameList!=null&& RightDrugNameList.Count>0)
|
|
{
|
|
string strDrugInfo = string.Empty;
|
|
for (int i = 0; i < RightDrugNameList.Count; i++)
|
|
{
|
|
strDrugInfo +="'"+ RightDrugNameList[i].DrugId+"',";
|
|
}
|
|
if (!string.IsNullOrEmpty(strDrugInfo))
|
|
{
|
|
strDrugInfo = strDrugInfo.Substring(0, strDrugInfo.Length - 1);
|
|
CommonClass.SaveAppSetting("DrugNames", strDrugInfo);
|
|
// 关闭当前窗口
|
|
RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
public string Title => "";
|
|
public DelegateCommand BtnCloseCommand
|
|
{
|
|
get => new DelegateCommand(() =>
|
|
{
|
|
//DialogParameters parameters = new DialogParameters();
|
|
//parameters.Add("",);
|
|
// 关闭当前窗口
|
|
RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
|
|
});
|
|
}
|
|
private ObservableCollection<DrugInfo>? _drugInfos= defaultAll;
|
|
public ObservableCollection <DrugInfo>? DrugInfos
|
|
{
|
|
get => _drugInfos;
|
|
set => SetProperty(ref _drugInfos, value);
|
|
}
|
|
private DrugInfo? _drugInfo;
|
|
|
|
public DrugInfo? DrugInfo
|
|
{
|
|
get => _drugInfo;
|
|
set
|
|
{
|
|
SetProperty(ref _drugInfo, value);
|
|
if (_drugInfo != null)
|
|
{
|
|
AllPremissions.Add(_drugInfo);// = _drugInfo.DrugManuNos.OrderByDescending(dm => dm.ManuNo).ToList();
|
|
}
|
|
}
|
|
}
|
|
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.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";
|
|
var DrugInfoslist = SqlSugarHelper.Db.SqlQueryable<DrugInfo>(str).OrderBy(di => di.DrugName).OrderBy(di => di.DrugId).ToList();
|
|
DrugInfos.AddRange(DrugInfoslist);
|
|
//DrugInfos_PY = list;
|
|
}
|
|
|
|
|
|
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))
|
|
{
|
|
var DrugInfosLst = SqlSugarHelper.Db.SqlQueryable<DrugInfo>(str).OrderBy(di => di.DrugName).OrderBy(di => di.DrugId).ToList();
|
|
DrugInfos.AddRange(DrugInfosLst);
|
|
return;
|
|
}
|
|
if (DrugInfos != null)
|
|
{
|
|
DrugInfos.Clear();
|
|
}
|
|
var DrugInfosList = SqlSugarHelper.Db.SqlQueryable<DrugInfo>(str).Where(di => di.DrugName.Contains(text) || di.PyCode.Contains(text)).OrderBy(di => di.DrugName).OrderBy(di => di.DrugId).ToList();
|
|
DrugInfos.AddRange(DrugInfosList);
|
|
}
|
|
}
|
|
}
|