using KeenRayLargePC.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace KeenRayLargePC.Views
{
/// <summary>
/// HistoryPage.xaml 的交互逻辑
/// </summary>
public partial class HistoryPage : Page
{
//标志位占2个字节
int iFlagByteLong = 2;
//长度占2个字节
int iMsgByteLong = 2;
//public List<HistoryPageListViewModel> HistoryPatientList = null;
public HistoryPage()
{
InitializeComponent();
//*ASCII值是42,#ASCII值是35
byte[] aaaaa = new byte[26] { 97,42, 98, 42, 99, 42, 100, 42, 101, 42, 102, 42, 35, 65, 42, 66, 42, 67, 42, 68, 42, 69, 42, 70, 42, 35 };
GetHistoryListFunc(aaaaa);
}
public List<HistoryPageListViewModel> GetHistoryListFunc(byte[] byt_bufferVar)
{
List<HistoryPageListViewModel> histroryList = new List<HistoryPageListViewModel>();
//Socket将用户信息按字节发送过来,接收端以字符的方式解析: 英文字符“*”表示一个属性结束。英文字符“#”表示一个用户信息结束。以此来接收用户信息,并将用户信息放到列表集合中,给列表显示。
string str = System.Text.Encoding.Default.GetString(byt_bufferVar);
//循环扫描,将用户信息提取出来
while (str.Length > 0)
{
//找出单用户包含的字符串
int iUserIndex = str.IndexOf('#');
//拷贝
string strSingleUser = str.Substring(0, iUserIndex);
//属性
int iPropertyNum = 0;
string strPatientId = null;
string strPatientName = null;
string strPatientSex = null;
string strPatientAge = null;
string stStudyBodyDesc = null;
string strPatientSize = null;
//将该用户的属性,逐个地拷贝出来(共6个属性)
while (strSingleUser.Length > 0)
{
int iPropertyIndex = strSingleUser.IndexOf('*');
string strProperty = strSingleUser.Substring(0, iPropertyIndex);
strSingleUser = strSingleUser.Remove(0, iPropertyIndex + 1);
switch (iPropertyNum)
{
case 0:
strPatientId = strProperty.ToString();
break;
case 1:
strPatientName = strProperty.ToString();
break;
case 2:
strPatientSex = strProperty.ToString();
break;
case 3:
strPatientAge = strProperty.ToString();
break;
case 4:
stStudyBodyDesc = strProperty.ToString();
break;
case 5:
strPatientSize = strProperty.ToString();
break;
default:
break;
}
iPropertyNum++;
}
//拷贝后、删除该用户
str = str.Remove(0, iUserIndex + 1);
histroryList.Add(new HistoryPageListViewModel { PatientId = strPatientId, PatientName = strPatientName, PatientSex = strPatientSex, PatientAge = strPatientAge, StudyBodyDesc = stStudyBodyDesc, PatientSize = strPatientSize });
}
App.Current.Dispatcher.Invoke((Action)delegate ()
{
this.lvSeriesList.ItemsSource = histroryList;
});
return histroryList;
}
}
}