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 _rightDrugNameList = new ObservableCollection(); public ObservableCollection RightDrugNameList { get => _rightDrugNameList; set => SetProperty(ref _rightDrugNameList, value); } private DrugInfo? _rightDrugName; public DrugInfo? RightDrugName { get => _rightDrugName; set => SetProperty(ref _rightDrugName, value); } public static ObservableCollection defaultAll = new ObservableCollection(); private ObservableCollection _allPremissions = defaultAll; public event Action RequestClose; public ObservableCollection AllPremissions { get => _allPremissions; set => SetProperty(ref _allPremissions, value); } public bool KeepAlive => false; public bool IsNavigationTarget(NavigationContext navigationContext) { return true; } void RequestData() { AllPremissions = new ObservableCollection(); 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 DrugInfos = SqlSugarHelper.Db.SqlQueryable(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 DrugInfosRight = SqlSugarHelper.Db.SqlQueryable(strRight).OrderBy(di => di.DrugId).ToList(); RightDrugNameList.AddRange(DrugInfosRight); } public bool CanCloseDialog() { return true; } public void OnDialogClosed() { } public void OnDialogOpened(IDialogParameters parameters) { //查询报表中的药品名称 RequestData(); } public DelegateCommand RightSelectedItemChangedCommand { get => new DelegateCommand((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 LeftSelectedItemChangedCommand { get => new DelegateCommand((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)); }); } } }