Prism 应用系列(三) MVVM架构中,采用命令Command和命令参数CommandParameter传递ListView的ListItems给一个对象object,再将对象拿出来转成集合

一、简介

参考:http://www.itkeyword.com/doc/2377036552008887x822

我的目标,如我的标题所示。我们需要注意:

ListView.SelectedItem——表示列表的1行。

ListView.SelectedItems——表示列表的多行。

方法1: 绑定SelectedItems

  <prism:InvokeCommandAction Command="{Binding SelectionChangedCommand}" CommandParameter="{Binding SelectedItems, ElementName=lvPatientList}" />

 

方法2:直接绑定列表的名字 lvPatientList

 这时候,我们可以采用如下的方法,把SelectedItems拿出来:

/// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="obj"></param>
        private void DeleteFun(object obj)
        {
            ListView lv = obj as ListView;
            if (lv.SelectedIndex < 0)
            {
                EMessageBox.Show("请选择要删除的数据!", "提示", EMessageBoxButton.OK, EMessageBoxImage.Information);
                return;
            }

            List<ListViewModel> list = new List<ListViewModel>();
            foreach (ListViewModel item in lv.SelectedItems)
            {
                list.Add(item);
            }

            if (EMessageBox.Show("是否确定要删除此条数据?", "提示", EMessageBoxButton.YesNo, EMessageBoxImage.Information) == EMessageBoxResult.Yes)
            {
                PreStudyInfoDal dal = new PreStudyInfoDal();
                dal.DeletePatientInfo(list);
                RefreshFun();
            }
        }

其中,SelectedIndex 表示:

<ListView x:Name="lvPatientList" Height="536" Width="1904" Style="{StaticResource ListViewStyle_HistoryPage1}" ItemContainerStyle="{StaticResource ListViewItemContainerStyle}" ItemsSource="{Binding PatientInfoList}" SelectedIndex="{Binding SelectIndex}" >

SelectedItems就是我们选中的多行了。

 二、附件

histroy.xaml:

<UserControl x:Class="KeenRay.Modules.History.Views.History"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:KeenRay.Modules.History.Views"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:controls="clr-namespace:KeenRay.Controls;assembly=KeenRay.Controls"
             mc:Ignorable="d" 
             xmlns:prism="http://prismlibrary.com/"
             prism:ViewModelLocator.AutoWireViewModel="True"
             d:DesignHeight="950" d:DesignWidth="1920">

    <i:Interaction.Triggers>
        <!--高级查询-->
        <prism:InteractionRequestTrigger SourceObject="{Binding AdvancedSearchNotificationRequest}">
            <prism:PopupWindowAction IsModal="True" CenterOverAssociatedObject="True">
                <prism:PopupWindowAction.WindowContent>
                    <local:AdvancedSearch/>
                </prism:PopupWindowAction.WindowContent>
            </prism:PopupWindowAction>
        </prism:InteractionRequestTrigger>
        
        <!--编辑-->
        <prism:InteractionRequestTrigger SourceObject="{Binding ModifyNotificationRequest}">
            <prism:PopupWindowAction IsModal="True" CenterOverAssociatedObject="True">
                <prism:PopupWindowAction.WindowContent>
                    <local:Modify/>
                </prism:PopupWindowAction.WindowContent>
            </prism:PopupWindowAction>
        </prism:InteractionRequestTrigger>
    </i:Interaction.Triggers>
    <Grid>
        <Grid.RowDefinitions>
            <!--84 = 52 + 14 + 18 -->
            <RowDefinition Height="8"/>
            <RowDefinition Height="84"/>
            <RowDefinition Height="60"/>
            <!--536 = 620 - 84 - 60 -->
            <RowDefinition Height="476"/>
            <RowDefinition Height="8"/>
            <RowDefinition Height="306"/>
            <!--<RowDefinition Height="246"/>-->
            <RowDefinition Height="8"/>
        </Grid.RowDefinitions>

        <Canvas Grid.Row="1" Margin="8,0,8,0" >
            <Border Grid.RowSpan="3" Width="1904" Height="620" Background="#FFF3F3F3"/>
            <Grid Height="52" Width="502" Canvas.Left="26" Canvas.Top="18">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="42"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="11.5"/>
                </Grid.ColumnDefinitions>
                <Border  BorderThickness="1.5" SnapsToDevicePixels="True" CornerRadius="5" Grid.ColumnSpan="3" Height="52">
                    <Border.BorderBrush>
                        <RadialGradientBrush>
                            <GradientStop Color="#FFE3E3E3" Offset="0"/>
                            <GradientStop Color="#FFBCBCBC" Offset="1"/>
                        </RadialGradientBrush>
                    </Border.BorderBrush>
                    <Border.Background>
                        <SolidColorBrush Color="White"/>
                    </Border.Background>
                </Border>
                <Button Grid.Column="0"  Style="{StaticResource ButtonStyleForSearchBox}" Margin="0,-4,0,4" />
                <TextBox Grid.Column="1" Style="{StaticResource TextBoxStyleForSearchBox}" Height="40" Name="tbox_SearchBoxText" Text="{Binding SearchBoxContent,Mode=TwoWay}" KeyUp="tbox_SearchBoxText_KeyUp" Grid.ColumnSpan="2" Margin="5,6,7,6"/>
            </Grid>
            <controls:ImageButton x:Name="btn_Search_History" Canvas.Left="555" Canvas.Top="18"  Width="122" Height="52" ToolTip="{DynamicResource History.Search.Query.Tooltip}" DefaultImage="{StaticResource Public.Search.Query.Enable.Icon}"  PressedImage="{StaticResource Public.Search.Query.Touches.Icon}" Command="{Binding HistoryCommands}" CommandParameter="Search"/>
            <controls:ImageButton x:Name="btn_ListSearch_History" Canvas.Left="707" Canvas.Top="18"  Width="122" Height="52" ToolTip="{DynamicResource History.Search.ListQuery.Tooltip}" DefaultImage="{StaticResource Public.Search.ListQuery.Enable.Icon}"  PressedImage="{StaticResource Public.Search.ListQuery.Touches.Icon}" Command="{Binding HistoryCommands}" CommandParameter="ListSearch"/>

            <controls:ImageButton x:Name="btn_Edit_History" Canvas.Left="881" Canvas.Top="18" Width="122" Height="52" ToolTip="{DynamicResource History.Search.Edit.Tooltip}" DefaultImage="{StaticResource Public.Search.Edit.Enable.Icon}"  PressedImage="{StaticResource Public.Search.Edit.Touches.Icon}" Command="{Binding HistoryCommands}" CommandParameter="Edit"/>
            <controls:ImageButton x:Name="btn_Delete_History" Canvas.Left="1030" Canvas.Top="18" Width="122" Height="52" ToolTip="{DynamicResource History.Search.Delete.Tooltip}" DefaultImage="{StaticResource Public.Search.Delete.Enable.Icon}"  PressedImage="{StaticResource Public.Search.Delete.Touches.Icon}" Command="{Binding HistoryCommands}" CommandParameter="Delete"/>
            <!-- 456 + 27 + 122 = 605 -->
            <controls:ImageButton x:Name="btn_Checking" Canvas.Top="18" Canvas.Right="605" Width="122" Height="52" Content="{DynamicResource History.Search.Checking.Content}" FontSize="18" FontFamily="Microsoft Yahei" Foreground="#FF4E7BBF" DefaultImage="{StaticResource Public.EmptyButton122x52.Enable.Icon}"  PressedImage="{StaticResource Public.EmptyButton122x52.Touches.Icon}" Command="{Binding HistoryCommands}" CommandParameter="Checking"/>
            <!-- 307 + 27 + 122 = 456 -->
            <controls:ImageButton x:Name="btn_Sendpacs" Canvas.Top="18" Canvas.Right="456" Width="122" Height="52" ToolTip="{DynamicResource History.Search.Sendpacs.Tooltip}" DefaultImage="{StaticResource History.Sendpacs.Enable.Icon}"  PressedImage="{StaticResource History.Sendpacs.Touches.Icon}" Command="{Binding HistoryCommands}" CommandParameter="Sendpacs"/>
            <!-- 157 + 122 + 28 = 307 -->
            <controls:ImageButton x:Name="btn_Sendipads" Canvas.Top="18" Canvas.Right="307" Width="122" Height="52" ToolTip="{DynamicResource History.Search.Sendipads.Tooltip}" DefaultImage="{StaticResource History.Sendipads.Enable.Icon}"  PressedImage="{StaticResource History.Sendipads.Touches.Icon}" Command="{Binding HistoryCommands}" CommandParameter="Sendipads"/>
            <!-- 122 + 27 + 8 = 157 -->
            <controls:ImageButton x:Name="btn_Sendu" Canvas.Top="18" Canvas.Right="157" Width="122" Height="52" ToolTip="{DynamicResource History.Search.Sendu.Tooltip}" DefaultImage="{StaticResource History.Sendu.Enable.Icon}"  PressedImage="{StaticResource History.Sendu.Touches.Icon}" Command="{Binding HistoryCommands}" CommandParameter="Sendu"/>
            <controls:ImageButton x:Name="btn_Sendd" Canvas.Top="18" Canvas.Right="8" Width="122" Height="52" ToolTip="{DynamicResource History.Search.Sendd.Tooltip}" DefaultImage="{StaticResource History.Sendd.Enable.Icon}"  PressedImage="{StaticResource History.Sendd.Touches.Icon}" Command="{Binding HistoryCommands}" CommandParameter="Sendd"/>
        </Canvas>

        <Canvas Grid.Row="2" Grid.RowSpan="2" Margin="8,0,8,0" Background="#FFEFEFEF">
            <ListView x:Name="lvPatientList" Height="536" Width="1904" Style="{StaticResource ListViewStyle_HistoryPage1}" ItemContainerStyle="{StaticResource ListViewItemContainerStyle}" ItemsSource="{Binding PatientInfoList}" SelectedIndex="{Binding SelectIndex}" >
                <!--点击事件-->
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="SelectionChanged">
                        <prism:InvokeCommandAction Command="{Binding SelectionChangedCommand}" CommandParameter="{Binding lvPatientList}" />
                        <!--<prism:InvokeCommandAction Command="{Binding SelectionChangedCommand}" CommandParameter="{Binding SelectedItems, ElementName=lvPatientList}" />-->
                    </i:EventTrigger>
                </i:Interaction.Triggers>
                <ListView.View>
                    <GridView ColumnHeaderContainerStyle="{StaticResource DefaultGridViewColumnHeader57x1527}">
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.PatientInfo.Content}" Width="135" DisplayMemberBinding="{Binding Path=PatientInfo}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.CheckingNum.Content}" Width="150" DisplayMemberBinding="{Binding Path=StudyID}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.Name.Content}" Width="78" DisplayMemberBinding="{Binding Path=PatientName}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.Sex.Content}" Width="78" DisplayMemberBinding="{Binding Path=PatientSex}"/>

                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.Age.Content}" Width="78" DisplayMemberBinding="{Binding Path=PatientAge}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.Birth.Content}" Width="104" DisplayMemberBinding="{Binding Path=PatientBrith}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.Height.Content}" Width="118" DisplayMemberBinding="{Binding Path=PatientHeight}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.Weight.Content}" Width="106" DisplayMemberBinding="{Binding Path=PatientWeight}"/>

                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.RecordSource.Content}" Width="112" DisplayMemberBinding="{Binding Path=RecordSource}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.CheckingTime.Content}" Width="103" DisplayMemberBinding="{Binding Path=StudyTime}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.EquipmentType.Content}" Width="103" DisplayMemberBinding="{Binding Path=EquipmentType}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.CheckParts.Content}" Width="226" DisplayMemberBinding="{Binding Path=StudyPart}"/>

                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.SequencesNum.Content}" Width="112" DisplayMemberBinding="{Binding Path=SequenceAmount}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.CheckStutas.Content}" Width="112" DisplayMemberBinding="{Binding Path=StudyStutas}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.SuspendState.Content}" Width="112" DisplayMemberBinding="{Binding Path=SuspendState}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.FilmPrint.Content}" Width="112" DisplayMemberBinding="{Binding Path=FilmPrint}"/>

                        <!--<GridViewColumn Header="{DynamicResource History.ListView_Checking.PatientInfo.Content}" Width="135"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.CheckingNum.Content}" Width="150" />
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.Name.Content}" Width="78" />
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.Sex.Content}" Width="78" />

                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.Age.Content}" Width="78" />
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.Birth.Content}" Width="104" DisplayMemberBinding="{Binding Path=PatientBrith}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.Height.Content}" Width="118" DisplayMemberBinding="{Binding Path=PatientHeight}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.Weight.Content}" Width="106" DisplayMemberBinding="{Binding Path=PatientWeight}"/>

                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.RecordSource.Content}" Width="112" DisplayMemberBinding="{Binding Path=RecordSource}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.CheckingTime.Content}" Width="103" DisplayMemberBinding="{Binding Path=StudyTime}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.EquipmentType.Content}" Width="103" DisplayMemberBinding="{Binding Path=EquipmentType}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.CheckParts.Content}" Width="226" DisplayMemberBinding="{Binding Path=StudyPart}"/>

                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.SequencesNum.Content}" Width="112" DisplayMemberBinding="{Binding Path=SequenceAmount}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.CheckStutas.Content}" Width="112" DisplayMemberBinding="{Binding Path=StudyStutas}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.SuspendState.Content}" Width="112" DisplayMemberBinding="{Binding Path=SuspendState}"/>
                        <GridViewColumn Header="{DynamicResource History.ListView_Checking.FilmPrint.Content}" Width="112" DisplayMemberBinding="{Binding Path=FilmPrint}"/>-->

                    </GridView>
                </ListView.View>
            </ListView>
        </Canvas>

        <!--<Canvas Grid.Row="3" Width="1904" >
            <Label  Height="60" Width="1904">
                <Label.Background>
                    <VisualBrush Visual="{StaticResource Public.ListSelection.Background.Icon}"/>
                </Label.Background>
            </Label>
        </Canvas>-->

        <Grid Grid.Row="5" Margin="8,0,8,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1527"/>
                <ColumnDefinition Width="8"/>
                <ColumnDefinition Width="371"/>
            </Grid.ColumnDefinitions>

            <Canvas Grid.Column="0" Height="304" Width="1527">
                <ListView  x:Name="lvSeriesList" Height="305" Width="1527"  Style="{StaticResource ListViewStyle_HistoryPage1}" ItemContainerStyle="{StaticResource ListViewItemContainerStyle}">
                    <ListView.View>
                        <GridView ColumnHeaderContainerStyle="{StaticResource DefaultGridViewColumnHeader57x1527}">
                            <GridViewColumn Header="{DynamicResource History.ListView_SequencesNum.SequencesNum.Content}" Width="258" DisplayMemberBinding="{Binding Path=SequenceNum}"/>
                            <GridViewColumn Header="{DynamicResource History.ListView_SequencesNum.PictureNum.Content}" Width="140" DisplayMemberBinding="{Binding Path=PictureAmount}"/>
                            <GridViewColumn Header="{DynamicResource History.ListView_SequencesNum.CheckType.Content}" Width="142" DisplayMemberBinding="{Binding Path=StudyType}"/>
                            <GridViewColumn Header="{DynamicResource History.ListView_Checking.CheckParts.Content}" Width="142" DisplayMemberBinding="{Binding Path=StudyPart}"/>
                            <GridViewColumn Header="{DynamicResource History.ListView_SequencesNum.SequenceAcquisitionTime.Content}" Width="140" DisplayMemberBinding="{Binding Path=SequenceAcquisitionTime}"/>
                            <GridViewColumn Header="{DynamicResource History.ListView_SequencesNum.Print.Content}" Width="142" DisplayMemberBinding="{Binding Path=PrintStatus}"/>
                            <GridViewColumn Header="{DynamicResource History.ListView_SequencesNum.Archive.Content}" Width="142" DisplayMemberBinding="{Binding Path=PushServiceStatus}"/>
                        </GridView>
                    </ListView.View>
                </ListView>
            </Canvas>
            <Canvas Grid.Column="2">
                <Border Canvas.Top="0" Canvas.Right="0" Width="371" Height="306" Background="#FFF3F3F3" />
                <Border Canvas.Top="10" Canvas.Right="10" Width="351" Height="286" Background="#F8060606" CornerRadius="4"/>
            </Canvas>
        </Grid>
    </Grid>
</UserControl>

HistoryViewModel.cs:

using KeenRay.Modules.History.Models;
using KeenRay.Modules.History.Notifications;
using KrayDbContext;
using KrayDbContext.Model;
using Prism.Commands;
using Prism.Interactivity.InteractionRequest;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace KeenRay.Modules.History.ViewModels
{

    public class HistoryViewModel :BindableBase
    {
        #region 通知集
        /// <summary>
        /// 高级查询通知
        /// </summary>
        public InteractionRequest<AdvancedSearchNotification> AdvancedSearchNotificationRequest { get; set; }

        /// <summary>
        /// 修改通知
        /// </summary>
        public InteractionRequest<ModifyNotification> ModifyNotificationRequest { get; set; }
        #endregion

        #region 命令集
        /// <summary>
        /// 历史页所有按钮的命令
        /// </summary>
        public DelegateCommand<string> HistoryCommands { get; set; }

        /// <summary>
        /// 列表选中命令
        /// </summary>
        //public DelegateCommand<PatientInfoHistroryModel> SelectionChangedCommand { get; private set; }
        //public DelegateCommand<List<PatientInfoHistroryModel>> SelectionChangedCommand { get; private set; }
        public DelegateCommand<object> SelectionChangedCommand { get; private set; }
        #endregion

        #region 属性
        private string searchBoxContent;

        /// <summary>
        /// 文本框查询
        /// </summary>
        public string SearchBoxContent
        {
            get { return searchBoxContent; }
            set { SetProperty(ref searchBoxContent, value); }
        }
        /// <summary>
        /// 患者信息列表的某行
        /// </summary>
        PatientInfoHistroryModel SelectedOnePerson = new PatientInfoHistroryModel();
        List<PatientInfoHistroryModel> SelectedMorePersons = new List<PatientInfoHistroryModel>();
        public PatientInfoHistroryModel PatientInfoSelectedPerson
        {
            get { return SelectedOnePerson; }
            set { SetProperty(ref SelectedOnePerson, value); }
        }

        private List<PatientInfoHistroryModel> patientInfoList = new List<PatientInfoHistroryModel>();

        /// <summary>
        /// 患者信息列表
        /// </summary>
        public List<PatientInfoHistroryModel> PatientInfoList
        {
            get { return patientInfoList; }
            set { SetProperty(ref patientInfoList, value); }
        }

        private int _selectIndex = -1;

        /// <summary>
        /// 病人信息列表索引号
        /// </summary>
        public int SelectIndex
        {
            get { return _selectIndex; }
            set { SetProperty(ref _selectIndex, value); }
        }
        #endregion


        /// <summary>
        /// 默认构造函数
        /// </summary>
        public HistoryViewModel()
        {
            AdvancedSearchNotificationRequest    = new InteractionRequest<AdvancedSearchNotification>();
            ModifyNotificationRequest            = new InteractionRequest<ModifyNotification>();
            HistoryCommands                      = new DelegateCommand<string>(HistoryCommandsFunc);
            //SelectionChangedCommand              = new DelegateCommand<PatientInfoHistroryModel>(SelectionChangedCommandFunc);    
            //SelectionChangedCommand             = new DelegateCommand<List<PatientInfoHistroryModel>> (SelectionChangedCommandFunc);
            SelectionChangedCommand              = new DelegateCommand<object>(SelectionChangedCommandFunc);
        }

        /// <summary>
        /// 历史页Commands函数
        /// </summary>
        /// <param name="commandParameter"></param>
        private void HistoryCommandsFunc(string commandParameter)
        {
            switch (commandParameter)
            {
                case "Search":
                    SearchCommandFunc();
                    break;
                case "ListSearch":
                    AdvancedSearchCommandFunc();
                    break;
                case "Edit":
                    EditCommandFunc();
                    break;
                case "Delete":
                    DeleteCommandFunc();
                    break;
                case "Checking":
                    CheckingCommandFunc();
                    break;
                case "Sendpacs":
                    SendpacsCommandFunc();
                    break;
                case "Sendipads":
                    SendipadsCommandFunc();
                    break;
                case "Sendu":
                    SenduCommandFunc();
                    break;
                case "Sendd":
                    SenddCommandFunc();
                    break;
                default:
                    break;
            }
        }

        /// <summary>
        /// 查询
        /// </summary>
        private void SearchCommandFunc()
        {
            try
            {
                PatientInfoList.Clear();
                OperateDataSheetViewModel operateDataSheet = new OperateDataSheetViewModel();
                operateDataSheet.SearchFunc(SearchBoxContent);
                PatientInfoList = operateDataSheet.GetPatientInfoFunc();    
            }
            catch(Exception e)
            {
                MessageBox.Show("病人历史记录信息表发生普通查询错误,错误信息:--------------" + e.ToString());
            }
        }

        /// <summary>
        /// 高级查询
        /// </summary>
        private void AdvancedSearchCommandFunc()
        {
            try
            {
                AdvancedSearchNotification advancedSearchNotification1 = new AdvancedSearchNotification();
                advancedSearchNotification1.Title = "高级查询";
                AdvancedSearchNotificationRequest.Raise(advancedSearchNotification1, returned =>
                {
                    if (returned != null && returned.Confirmed)
                    {
                        OperateDataSheetViewModel operateDataSheet = new OperateDataSheetViewModel();
                        operateDataSheet.AdvancedSearchFunc(returned);
                        PatientInfoList = operateDataSheet.GetPatientInfoFunc();
                    }
                });
            }
            catch (Exception e)
            {
                MessageBox.Show("病人历史记录信息表发生高级查询错误,错误信息:--------------" + e.ToString());
            }
        }

        /// <summary>
        /// 列表选中事件
        /// </summary>
        //private void SelectionChangedCommandFunc(PatientInfoHistroryModel patientInfoHistroryModelVar)

        //private void SelectionChangedCommandFunc(List<PatientInfoHistroryModel> SelectedListPersons)   
        private void SelectionChangedCommandFunc(object obj)
        {
            try
            {   
                List<PatientInfoHistroryModel> SelectedPersons = new List<PatientInfoHistroryModel>();
                PatientInfoHistroryModel SelectedPersons2 = new PatientInfoHistroryModel();
                SelectedPersons = obj as List<PatientInfoHistroryModel>;
                SelectedPersons2 = obj as PatientInfoHistroryModel;
                ListView listView = obj as ListView;
                //SelectedItemsCollection
                //SelectedItemsCollection a = obj as SelectedItemsCollection;
                //SelectedItems a = obj as SelectedItems;
                System.Collections.IList items = (System.Collections.IList)obj;
                var collection = items.Cast<PatientInfoHistroryModel>();
                var someModelList = collection.ToList();

                if (someModelList.Count == 1)
                {
                    MessageBox.Show("选中一个用户");
                }
                else if (someModelList.Count > 1)
                {
                    MessageBox.Show("选中多个个用户");
                }

                //foreach (PatientInfoHistroryModel item in someModelList)
                //{
                //    SelectedPersons.Add(item);
                //}
                //if (SelectedPersons2.PatientInfo != null)
                //{
                //    MessageBox.Show("选中一个用户");
                //}
                //else
                //{
                //    MessageBox.Show("选中多个个用户");
                //}
                //ListView listView = obj as ListView;
                ////未选中
                //if (listView.Items.Count == 0)
                //{
                //    //return;
                //}
                ////选中一行

                //else if (listView.Items.Count == 1)
                //{
                //    SelectedOnePerson = obj as PatientInfoHistroryModel;
                //}
                ////选择多行
                //else if (listView.Items.Count > 1)
                //{
                //    SelectedMorePersons = obj as List<PatientInfoHistroryModel>;
                //}
                //SelectedOnePerson = patientInfoHistroryModelVar;

            }
            catch (Exception e)
            {
                MessageBox.Show("病人历史记录信息表发生普通查询错误,错误信息:--------------" + e.ToString());
            }
        }

        /// <summary>
        /// 编辑
        /// </summary>
        private void EditCommandFunc()
        {
            try
            {
                ModifyNotification modifyNotification = new ModifyNotification();
                modifyNotification.Title = "编辑";
                //modifyNotification.Content = SelectedOnePerson;
                modifyNotification.PatientInfo = SelectedOnePerson.PatientInfo;
                modifyNotification.StudyID = SelectedOnePerson.StudyID;
                modifyNotification.PatientName = SelectedOnePerson.PatientName;
                modifyNotification.PatientSex = SelectedOnePerson.PatientSex;
                modifyNotification.PatientAge = SelectedOnePerson.PatientAge;
                modifyNotification.PatientBrith = SelectedOnePerson.PatientBrith;
                modifyNotification.PatientHeight = SelectedOnePerson.PatientHeight;
                modifyNotification.PatientWeight = SelectedOnePerson.PatientWeight;
                modifyNotification.RecordSource = SelectedOnePerson.RecordSource;
                modifyNotification.StudyTime = SelectedOnePerson.StudyTime;
                modifyNotification.EquipmentType = SelectedOnePerson.EquipmentType;
                modifyNotification.StudyPart = SelectedOnePerson.StudyPart;
                modifyNotification.SequenceAmount = SelectedOnePerson.SequenceAmount;
                modifyNotification.StudyStutas = SelectedOnePerson.StudyStutas;
                modifyNotification.SuspendState = SelectedOnePerson.SuspendState;
                modifyNotification.FilmPrint = SelectedOnePerson.FilmPrint;

                //弹出窗口
                ModifyNotificationRequest.Raise(modifyNotification, returned =>
                {
                    if (returned != null && returned.Confirmed)
                    {
                        OperateDataSheetViewModel operateDataSheet = new OperateDataSheetViewModel();
                        //更新数据库
                        operateDataSheet.EditFunc(returned);
                        //刷新列表,重新显示
                        PatientInfoList = operateDataSheet.GetPatientInfoFunc();
                    }
                });
            }
            catch (Exception e)
            {
                MessageBox.Show("病人历史记录信息表发生普通查询错误,错误信息:--------------" + e.ToString());
            }         
        }

        /// <summary>
        /// 删除
        /// </summary>
        private void DeleteCommandFunc()
        {
            try
            {
                //if ()
                //{
                //}
                //else if ()
                //{

                //}
            }
            catch (Exception e)
            {
                MessageBox.Show("病人历史记录信息表发生删除错误,错误信息:--------------" + e.ToString());
            }
        }

        /// <summary>
        /// 检查
        /// </summary>
        private void CheckingCommandFunc()
        {
            try
            {

            }
            catch (Exception e)
            {
                MessageBox.Show("病人历史记录信息表发生检查错误,错误信息:--------------" + e.ToString());
            }
        }

        /// <summary>
        /// 发送至pacs
        /// </summary>
        private void SendpacsCommandFunc()
        {
            try
            {

            }
            catch (Exception e)
            {
                MessageBox.Show("病人历史记录信息表发生pacs错误,错误信息:--------------" + e.ToString());
            }
        }

        /// <summary>
        /// 发送至ipads
        /// </summary>
        private void SendipadsCommandFunc()
        {
            try
            {

            }
            catch (Exception e)
            {
                MessageBox.Show("病人历史记录信息表发生ipads错误,错误信息:--------------" + e.ToString());
            }
        }

        /// <summary>
        /// Sendu
        /// </summary>
        private void SenduCommandFunc()
        {
            try
            {

            }
            catch (Exception e)
            {
                MessageBox.Show("病人历史记录信息表发生Sendu错误,错误信息:--------------" + e.ToString());
            }
        }

        /// <summary>
        /// Sendd
        /// </summary>
        private void SenddCommandFunc()
        {
            try
            {

            }
            catch (Exception e)
            {
                MessageBox.Show("病人历史记录信息表发生Sendd错误,错误信息:--------------" + e.ToString());
            }
        }
    }
}

猜你喜欢

转载自blog.csdn.net/xpj8888/article/details/87350128