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

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; get => _rightDrugName;
set => SetProperty(ref _rightDrugName, value); set => SetProperty(ref _rightDrugName, value);
} }
public static ReportDrugNameDialogViewModel vm;
public static ObservableCollection<DrugInfo> defaultAll = new ObservableCollection<DrugInfo>(); public static ObservableCollection<DrugInfo> defaultAll = new ObservableCollection<DrugInfo>();
private ObservableCollection<DrugInfo> _allPremissions = defaultAll; private ObservableCollection<DrugInfo> _allPremissions = defaultAll;
public event Action<IDialogResult> RequestClose; public event Action<IDialogResult> RequestClose;
public ReportDrugNameDialogViewModel()
{
vm = this;
}
public ObservableCollection<DrugInfo> AllPremissions public ObservableCollection<DrugInfo> AllPremissions
{ {
get => _allPremissions; get => _allPremissions;
@ -66,14 +71,14 @@ namespace DM_Weight.ViewModels
void RequestData() void RequestData()
{ {
AllPremissions = new ObservableCollection<DrugInfo>(); 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'"; //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) //if (ConfigurationManager.AppSettings["DrugNames"] != null)
{ //{
str += " where d.drug_id not in (" + CommonClass.ReadAppSetting("DrugNames") + ")"; // str += " where d.drug_id not in (" + CommonClass.ReadAppSetting("DrugNames") + ")";
} //}
List<DrugInfo> DrugInfos = SqlSugarHelper.Db.SqlQueryable<DrugInfo>(str).OrderBy(di => di.DrugId).ToList(); //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'"; 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(); RequestData();
GetAllDrugInfos();
} }
public DelegateCommand<DrugInfo> RightSelectedItemChangedCommand public DelegateCommand<DrugInfo> RightSelectedItemChangedCommand
@ -165,5 +171,53 @@ namespace DM_Weight.ViewModels
RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); 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

@ -30,41 +30,50 @@
</Button> </Button>
</Grid> </Grid>
<!--<GroupBox Margin="6" Grid.Row="1" Header="编辑/新增" materialDesign:ColorZoneAssist.Mode="PrimaryLight">--> <!--<GroupBox Margin="6" Grid.Row="1" Header="编辑/新增" materialDesign:ColorZoneAssist.Mode="PrimaryLight">-->
<Grid Grid.Row="1"> <Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition/>
<RowDefinition /> <RowDefinition/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid Grid.Row="0"> <StackPanel Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal" Margin="10" HorizontalAlignment="Left" VerticalAlignment="Center">
<Grid.ColumnDefinitions> <ComboBox
<ColumnDefinition /> Margin="6 0 6 0"
<ColumnDefinition /> materialDesign:HintAssist.Hint="药品名称/拼音码"
</Grid.ColumnDefinitions> IsEditable="True"
<Grid.RowDefinitions> ItemsSource="{Binding DrugInfos}"
<RowDefinition/> SelectedItem="{Binding DrugInfo}"
<RowDefinition/> DisplayMemberPath="drug_name_spec" IsEnabled="True" IsTextSearchEnabled="False" KeyUp="ComboBox_KeyUp"/>
</Grid.RowDefinitions> </StackPanel>
<StackPanel Grid.Column="1" Grid.RowSpan="2" Orientation="Horizontal" Margin="10" HorizontalAlignment="Right" VerticalAlignment="Center"> <StackPanel Grid.Column="1" Grid.ColumnSpan="2" Orientation="Horizontal" Margin="10" HorizontalAlignment="Right" VerticalAlignment="Center">
<Button Command="{Binding AddRole}" Content="保存" /> <Button Command="{Binding AddRole}" Content="保存" />
</StackPanel> </StackPanel>
</Grid> </Grid>
<Grid Grid.Row="1"> <Grid Grid.Row="1">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition /> <ColumnDefinition />
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
<ColumnDefinition /> <ColumnDefinition />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<GroupBox Header="全部药品" Grid.Column="0" Margin="10"> <GroupBox Header="查询药品" Grid.Column="0" Margin="10">
<ScrollViewer Grid.Row="1" Grid.Column="1"> <ScrollViewer Grid.Row="1" Grid.Column="1">
<TreeView x:Name="LeftTree" MinWidth="220" ItemsSource="{Binding AllPremissions}" > <TreeView x:Name="LeftTree" MinWidth="220" ItemsSource="{Binding AllPremissions}" >
<i:Interaction.Triggers> <i:Interaction.Triggers>
<i:EventTrigger EventName="SelectedItemChanged"> <i:EventTrigger EventName="SelectedItemChanged">
<i:InvokeCommandAction Command="{Binding Path=LeftSelectedItemChangedCommand}" <i:InvokeCommandAction Command="{Binding Path=LeftSelectedItemChangedCommand}"
CommandParameter="{Binding ElementName=LeftTree, Path=SelectedItem}"/> CommandParameter="{Binding ElementName=LeftTree, Path=SelectedItem}"/>
</i:EventTrigger> </i:EventTrigger>
</i:Interaction.Triggers> </i:Interaction.Triggers>
<TreeView.ItemTemplate> <TreeView.ItemTemplate>
<!--<HierarchicalDataTemplate ItemsSource="{Binding drug_name_spec}"> <!--<HierarchicalDataTemplate ItemsSource="{Binding drug_name_spec}">
<TextBlock Text="{Binding drug_name_spec}" /> <TextBlock Text="{Binding drug_name_spec}" />
</HierarchicalDataTemplate>--> </HierarchicalDataTemplate>-->
<DataTemplate> <DataTemplate>
@ -73,48 +82,48 @@
</StackPanel> </StackPanel>
</DataTemplate> </DataTemplate>
</TreeView.ItemTemplate> </TreeView.ItemTemplate>
</TreeView> </TreeView>
</ScrollViewer> </ScrollViewer>
</GroupBox> </GroupBox>
<StackPanel Grid.Column="1" Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center"> <StackPanel Grid.Column="1" Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button <Button
Margin="0 4 0 4" Margin="0 4 0 4"
Style="{StaticResource MaterialDesignPaperLightButton}" Style="{StaticResource MaterialDesignPaperLightButton}"
ToolTip="右移" ToolTip="右移"
IsEnabled="{Binding LeftPremission, Converter={StaticResource NullableToEnabelConverter}}" IsEnabled="{Binding LeftPremission, Converter={StaticResource NullableToEnabelConverter}}"
Command="{Binding ToRight}" Command="{Binding ToRight}"
Content="{materialDesign:PackIcon ChevronRight}"/> Content="{materialDesign:PackIcon ChevronRight}"/>
<Button <Button
Margin="0 4 0 4" Margin="0 4 0 4"
Style="{StaticResource MaterialDesignPaperLightButton}" Style="{StaticResource MaterialDesignPaperLightButton}"
ToolTip="左移" ToolTip="左移"
IsEnabled="{Binding RightPremission, Converter={StaticResource NullableToEnabelConverter}}" IsEnabled="{Binding RightPremission, Converter={StaticResource NullableToEnabelConverter}}"
Command="{Binding ToLeft}" Command="{Binding ToLeft}"
Content="{materialDesign:PackIcon ChevronLeft}"/> Content="{materialDesign:PackIcon ChevronLeft}"/>
</StackPanel> </StackPanel>
<GroupBox Header="已选药品" Grid.Column="2" Margin="10"> <GroupBox Header="已选药品" Grid.Column="2" Margin="10">
<ScrollViewer Grid.Row="1" Grid.Column="1"> <ScrollViewer Grid.Row="1" Grid.Column="1">
<TreeView x:Name="RightTree" MinWidth="220" ItemsSource="{Binding RightDrugNameList}"> <TreeView x:Name="RightTree" MinWidth="220" ItemsSource="{Binding RightDrugNameList}">
<i:Interaction.Triggers> <i:Interaction.Triggers>
<i:EventTrigger EventName="SelectedItemChanged"> <i:EventTrigger EventName="SelectedItemChanged">
<i:InvokeCommandAction Command="{Binding Path=RightSelectedItemChangedCommand}" <i:InvokeCommandAction Command="{Binding Path=RightSelectedItemChangedCommand}"
CommandParameter="{Binding ElementName=RightTree, Path=SelectedItem}"/> CommandParameter="{Binding ElementName=RightTree, Path=SelectedItem}"/>
</i:EventTrigger> </i:EventTrigger>
</i:Interaction.Triggers> </i:Interaction.Triggers>
<TreeView.ItemTemplate> <TreeView.ItemTemplate>
<DataTemplate> <DataTemplate>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding drug_name_spec}"/> <TextBlock Text="{Binding drug_name_spec}"/>
</StackPanel> </StackPanel>
</DataTemplate> </DataTemplate>
</TreeView.ItemTemplate> </TreeView.ItemTemplate>
</TreeView> </TreeView>
</ScrollViewer> </ScrollViewer>
</GroupBox> </GroupBox>
<materialDesign:Snackbar Background="{Binding SnackbarBackground}" MessageQueue="{Binding SnackbarMessageQueue}"/> <materialDesign:Snackbar Background="{Binding SnackbarBackground}" MessageQueue="{Binding SnackbarMessageQueue}"/>
</Grid>
</Grid> </Grid>
</Grid>
<!--</GroupBox>--> <!--</GroupBox>-->
</Grid> </Grid>
</UserControl> </UserControl>

View File

@ -1,4 +1,5 @@
using System; using DM_Weight.ViewModels;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -20,9 +21,23 @@ namespace DM_Weight.Views.Dialog
/// </summary> /// </summary>
public partial class ReportDrugNameDialog : UserControl public partial class ReportDrugNameDialog : UserControl
{ {
//ReportDrugNameDialogViewModel vms;
public ReportDrugNameDialog() public ReportDrugNameDialog()
{ {
InitializeComponent(); 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;
} }
} }
} }