手动录入报表信息时修改药品弹窗添加药品查询

This commit is contained in:
马巧 2025-07-04 16:48:43 +08:00
parent 9dfb1a4363
commit 3fdbb790ba
3 changed files with 141 additions and 63 deletions

View File

@ -45,12 +45,17 @@ namespace DM_Weight.ViewModels
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;
@ -66,14 +71,14 @@ namespace DM_Weight.ViewModels
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();
//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);
//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'";
@ -98,6 +103,7 @@ namespace DM_Weight.ViewModels
{
//查询报表中的药品名称
RequestData();
GetAllDrugInfos();
}
public DelegateCommand<DrugInfo> RightSelectedItemChangedCommand
@ -165,5 +171,53 @@ namespace DM_Weight.ViewModels
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);
}
}
}

View File

@ -44,7 +44,16 @@
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<StackPanel Grid.Column="1" Grid.RowSpan="2" Orientation="Horizontal" Margin="10" HorizontalAlignment="Right" VerticalAlignment="Center">
<StackPanel Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal" Margin="10" HorizontalAlignment="Left" VerticalAlignment="Center">
<ComboBox
Margin="6 0 6 0"
materialDesign:HintAssist.Hint="药品名称/拼音码"
IsEditable="True"
ItemsSource="{Binding DrugInfos}"
SelectedItem="{Binding DrugInfo}"
DisplayMemberPath="drug_name_spec" IsEnabled="True" IsTextSearchEnabled="False" KeyUp="ComboBox_KeyUp"/>
</StackPanel>
<StackPanel Grid.Column="1" Grid.ColumnSpan="2" Orientation="Horizontal" Margin="10" HorizontalAlignment="Right" VerticalAlignment="Center">
<Button Command="{Binding AddRole}" Content="保存" />
</StackPanel>
</Grid>
@ -54,7 +63,7 @@
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<GroupBox Header="全部药品" Grid.Column="0" Margin="10">
<GroupBox Header="查询药品" Grid.Column="0" Margin="10">
<ScrollViewer Grid.Row="1" Grid.Column="1">
<TreeView x:Name="LeftTree" MinWidth="220" ItemsSource="{Binding AllPremissions}" >
<i:Interaction.Triggers>

View File

@ -1,4 +1,5 @@
using System;
using DM_Weight.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -20,9 +21,23 @@ namespace DM_Weight.Views.Dialog
/// </summary>
public partial class ReportDrugNameDialog : UserControl
{
//ReportDrugNameDialogViewModel vms;
public ReportDrugNameDialog()
{
InitializeComponent();
//vms = ReportDrugNameDialogViewModel.vm;
}
private void ComboBox_KeyUp(object sender, KeyEventArgs e)
{
ComboBox comboBox = sender as ComboBox;
ReportDrugNameDialogViewModel.vm.UpdateComboBoxItems(comboBox.Text);
if (ReportDrugNameDialogViewModel.vm.DrugInfos.Count > 0)
{
comboBox.IsDropDownOpen = true;
}
TextBox textBox = (TextBox)comboBox.Template.FindName("PART_EditableTextBox", comboBox);
textBox.SelectionStart = textBox.Text.Length;
}
}
}