You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
741 lines
26 KiB
741 lines
26 KiB
using AForge.Video.DirectShow;
|
|
using PEIS.Base;
|
|
using PEIS.Entity;
|
|
using PEIS.Event;
|
|
using PEIS.Presenter;
|
|
using PEIS.Utils;
|
|
using PEIS.Utils.SS860;
|
|
using PEIS.View.Base;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Drawing.Imaging;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading;
|
|
using System.Windows.Forms;
|
|
|
|
namespace PEIS.View.Enrollment
|
|
{
|
|
public partial class NewEnrollmentPersonForm : ViewBase, INewEnrollmentPersonView
|
|
{
|
|
private bool _editStatus = false;
|
|
private readonly EnrollmentPatient _regInfo = null;
|
|
private BasePatient _baseInfo = null;
|
|
private FilterInfoCollection videoDevices;
|
|
|
|
public NewEnrollmentPersonForm(EnrollmentPatient item, bool editStatus)
|
|
{
|
|
InitializeComponent();
|
|
Shown += NewEnrollmentPersonForm_Shown;
|
|
FormClosing += NewEnrollmentPersonForm_FormClosing;
|
|
|
|
_regInfo = item;
|
|
_editStatus = editStatus;
|
|
ReadIDCard.Enabled = !editStatus;
|
|
NewBaseBtn.Enabled = !editStatus;
|
|
NameTextBox.Enabled = !editStatus;
|
|
Text = editStatus ? "编辑登记信息" : "新增登记信息";
|
|
|
|
|
|
// 查询
|
|
NameTextBox.Leave += NameTextBox_Leave;
|
|
// 选择
|
|
NameTextBox.KeyDown += NameTextBox_KeyDown;
|
|
// 新建
|
|
NewBaseBtn.Click += NewBaseBtn_Click;
|
|
// 读取身份证
|
|
ReadIDCard.Click += ReadIDCard_Click;
|
|
// 拍照
|
|
TakePhotoBtn.Click += TakePhotoBtn_Click;
|
|
// 确认
|
|
ConfirmBtn.Click += ConfirmBtn_Click;
|
|
// 取消
|
|
CancelBtn.Click += CancelBtn_Click;
|
|
// 手机号校验
|
|
Tel1.Leave += Tel1_Leave;
|
|
// 职业病判断
|
|
ExamTypeComboBox.SelectedValueChanged += ExamTypeComboBox_SelectedValueChanged;
|
|
|
|
|
|
if (editStatus && Global.currentUser.Code == Global._hospital.DoctCode)
|
|
{
|
|
NameTextBox.Enabled = true;
|
|
SexGroupBox.Enabled = true;
|
|
IDCard.ReadOnly = false;
|
|
BirthdayDateTimePicker.Enabled = true;
|
|
CardTypeComboBox.Enabled = true;
|
|
}
|
|
}
|
|
|
|
private void ExamTypeComboBox_SelectedValueChanged(object sender, EventArgs e)
|
|
{
|
|
var type = ExamTypeComboBox.SelectedValue?.ToString();
|
|
if (type.Contains("职业"))
|
|
{
|
|
JobTypes.Enabled = true;
|
|
WorkYears.Enabled = true;
|
|
HazardYears.Enabled = true;
|
|
JobStatusComboBox.Enabled = true;
|
|
HazardFactorsComboBox.Enabled = true;
|
|
}
|
|
else
|
|
{
|
|
JobTypes.Enabled = false;
|
|
WorkYears.Enabled = false;
|
|
HazardYears.Enabled = false;
|
|
JobStatusComboBox.Enabled = false;
|
|
HazardFactorsComboBox.Enabled = false;
|
|
}
|
|
}
|
|
|
|
private void CameraPlayer_NewFrame(object sender, ref Bitmap image)
|
|
{
|
|
|
|
// 获取摄像头图像
|
|
Bitmap originalImage = (Bitmap)image.Clone();
|
|
|
|
// 计算裁剪区域
|
|
int cropX = (originalImage.Width - 420) / 2;
|
|
int cropY = (originalImage.Height - 300) / 2;
|
|
|
|
Rectangle cropRectangle = new Rectangle(cropX, cropY, 420, 300);
|
|
|
|
// 裁剪图像
|
|
Bitmap croppedImage = originalImage.Clone(cropRectangle, originalImage.PixelFormat);
|
|
|
|
// 调整图像显示到 VideoSourcePlayer 控件
|
|
image = new Bitmap(300, 420);
|
|
using (Graphics g = Graphics.FromImage(image))
|
|
{
|
|
g.DrawImage(croppedImage, new Rectangle(0, 0, 300, 420));
|
|
}
|
|
|
|
// 刷新 VideoSourcePlayer 控件
|
|
CameraPlayer.Invalidate();
|
|
croppedImage.Dispose();
|
|
}
|
|
|
|
private void Tel1_Leave(object sender, EventArgs e)
|
|
{
|
|
// 正则校验手机号
|
|
string pattern = @"^1[3456789]\d{9}$";
|
|
Regex regex = new Regex(pattern);
|
|
if (!regex.IsMatch(Tel1.Text))
|
|
{
|
|
Global.Msg("info", "手机号格式错误!");
|
|
}
|
|
}
|
|
|
|
private void NameTextBox_Leave(object sender, EventArgs e)
|
|
{
|
|
if (string.IsNullOrEmpty(NameTextBox.Text.Trim()))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if(_editStatus && Global.currentUser.Code == Global._hospital.DoctCode)
|
|
{
|
|
return;
|
|
}
|
|
OnGetBaseInfoByName();
|
|
}
|
|
|
|
private void NewEnrollmentPersonForm_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
Close_Camera();
|
|
}
|
|
|
|
private void NewEnrollmentPersonForm_Shown(object sender, EventArgs e)
|
|
{
|
|
ThreadPool.QueueUserWorkItem(state => GetConfig());
|
|
Open_Camera();
|
|
}
|
|
|
|
private void CancelBtn_Click(object sender, EventArgs e)
|
|
{
|
|
Close();
|
|
}
|
|
|
|
private void NameTextBox_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (_editStatus && Global.currentUser.Code == Global._hospital.DoctCode)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (e.KeyData == Keys.Enter)
|
|
{
|
|
Action<BasePatient> action = result => SelectPerson(result);
|
|
SelectPatientForm selectPatientForm = new SelectPatientForm(action, NameTextBox.Text.Trim());
|
|
selectPatientForm.ShowDialog();
|
|
}
|
|
}
|
|
|
|
public void SelectPerson(BasePatient item)
|
|
{
|
|
if (item == null) return;
|
|
|
|
NameTextBox.Text = item?.Name;
|
|
Male.Checked = item?.Sex == "1";
|
|
Female.Checked = item?.Sex == "2";
|
|
CardTypeComboBox.Text = item?.CardType;
|
|
IDCard.Text = item?.CardNo;
|
|
Nation.Text = item?.Nation;
|
|
BirthdayDateTimePicker.Value = item?.Birthday ?? DateTime.Now;
|
|
ExamDate.Value = item?.ExamDate?? DateTime.Now;
|
|
ExamTypeComboBox.SelectedValue = item?.ExamType ?? "健康体检";
|
|
MaritalComboBox.SelectedValue = item?.Marriage ?? "未知";
|
|
OccupationComboBox.SelectedValue = item?.Occupation ?? "其它劳动者";
|
|
EducationComboBox.SelectedValue = item?.Education ?? "其它";
|
|
Contactor1.Text = item?.Name;
|
|
Contactor2.Text = item?.Contactor2;
|
|
Tel1.Text = item?.Tel1;
|
|
Tel2.Text = item?.Tel2;
|
|
Address1.Text = item?.Address1;
|
|
Company.Text = item?.Company;
|
|
Description.Text = item?.Description;
|
|
Photo.Image = Base64ToImage(item?.Photo);
|
|
JobTypes.Text = item?.JobTypes;
|
|
JobStatusComboBox.SelectedValue = item?.JobStatus ?? "岗前";
|
|
WorkYears.Text = item?.WorkYears;
|
|
HazardYears.Text = item?.HazardYears;
|
|
|
|
if (item.ExamType != null && item.ExamType.Contains("职业"))
|
|
{
|
|
HazardFactorsComboBox.SetEditValue(item?.HazardFactors.Split(';').Select(s => (object)s.Trim()).ToList());
|
|
}
|
|
|
|
OnGetPid();
|
|
}
|
|
|
|
private void NewBaseBtn_Click(object sender, EventArgs e)
|
|
{
|
|
Action<BasePatient> action = result => SelectPerson(result);
|
|
|
|
NewPersonForm personForm = new NewPersonForm(action);
|
|
personForm.ShowDialog();
|
|
}
|
|
|
|
private void ReadIDCard_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
//RdCardModel idCard = new RdCardModel()
|
|
//{
|
|
// IDNO = "5301"
|
|
//};
|
|
|
|
try
|
|
{
|
|
RdCardModel idCard = ReadCardInfo.Get();
|
|
if (idCard == null) return;
|
|
|
|
NameTextBox.Text = idCard.IDNO;
|
|
NameTextBox_Leave(sender, e);
|
|
}
|
|
catch (Exception a)
|
|
{
|
|
Global.MsgErr(a.Message);
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
private void TakePhotoBtn_Click(object sender, EventArgs e)
|
|
{
|
|
Bitmap img = CameraPlayer.GetCurrentVideoFrame();
|
|
if (img == null) return;
|
|
//Photo.Image = img;
|
|
Photo.Image = ScaleImage(img, 300, 420);
|
|
}
|
|
|
|
private void ConfirmBtn_Click(object sender, EventArgs e)
|
|
{
|
|
if (string.IsNullOrEmpty(NameTextBox.Text.Trim()))
|
|
{
|
|
Global.Msg("err", "请输入姓名!");
|
|
return;
|
|
}
|
|
if (string.IsNullOrEmpty(Contactor1.Text.Trim()))
|
|
{
|
|
Global.Msg("err", "请输入联系人1!");
|
|
return;
|
|
}
|
|
if (string.IsNullOrEmpty(Tel1.Text.Trim()))
|
|
{
|
|
Global.Msg("err", "请输入联系电话1!");
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
// 正则校验手机号
|
|
string pattern = @"^1[3456789]\d{9}$";
|
|
Regex regex = new Regex(pattern);
|
|
if (!regex.IsMatch(Tel1.Text))
|
|
{
|
|
Global.Msg("info", "手机号格式错误!");
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(Address1.Text.Trim()))
|
|
{
|
|
Global.Msg("err", "请输入联系地址1!");
|
|
return;
|
|
}
|
|
|
|
var ExamType = ExamTypeComboBox.SelectedValue?.ToString();
|
|
|
|
if (ExamType.Contains("职业"))
|
|
{
|
|
if(string.IsNullOrEmpty(JobTypes.Text.Trim()))
|
|
{
|
|
Global.Msg("err", "请输入工种!");
|
|
return;
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(WorkYears.Text.Trim()))
|
|
{
|
|
Global.Msg("err", "请输入工龄!");
|
|
return;
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(HazardYears.Text.Trim()))
|
|
{
|
|
Global.Msg("err", "请输入接害工龄!");
|
|
return;
|
|
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(JobStatusComboBox.SelectedValue?.ToString().Trim()))
|
|
{
|
|
Global.Msg("err", "请选择工作情况!");
|
|
return;
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(HazardFactorsComboBox.Text.Trim()))
|
|
{
|
|
Global.Msg("err", "请选择接害因素!");
|
|
return;
|
|
}
|
|
}
|
|
|
|
EnrollmentPatient item = new EnrollmentPatient()
|
|
{
|
|
Name = NameTextBox.Text.Trim(),
|
|
Sex = Male.Checked ? "1" : "2",
|
|
Nation = Nation.Text.Trim(),
|
|
Birthday = BirthdayDateTimePicker.Value,
|
|
Age = Convert.ToInt64(CalculateAge()[0]),
|
|
AgeClass = CalculateAge()[1],
|
|
CardType = CardTypeComboBox.SelectedValue?.ToString(),
|
|
CardNo = IDCard.Text.Trim(),
|
|
Marriage = MaritalComboBox.SelectedValue?.ToString(),
|
|
Occupation = OccupationComboBox.SelectedValue?.ToString(),
|
|
Education = EducationComboBox.SelectedValue?.ToString(),
|
|
ExamDate = ExamDate.Value.Date,
|
|
Type = ExamTypeComboBox.SelectedValue?.ToString(),
|
|
Contactor1 = NameTextBox.Text.Trim(),
|
|
Contactor2 = Contactor2.Text.Trim(),
|
|
Tel1 = Tel1.Text.Trim(),
|
|
Tel2 = Tel2.Text.Trim(),
|
|
Photo = ImageToBase64(),
|
|
Address1 = Address1.Text.Trim(),
|
|
Company = Company.Text.Trim(),
|
|
Description = Description.Text.Trim(),
|
|
SpellCode = PingYinHelper.GetTotalPingYin(NameTextBox.Text.Trim()).FirstPingYin.Count == 0 ? null : PingYinHelper.GetTotalPingYin(NameTextBox.Text.Trim()).FirstPingYin[0]
|
|
};
|
|
|
|
|
|
if (ExamType.Contains("职业"))
|
|
{
|
|
item.JobTypes = JobTypes.Text.Trim();
|
|
item.WorkYears = WorkYears.Text.Trim();
|
|
item.HazardYears = HazardYears.Text.Trim();
|
|
item.JobStatus = JobStatusComboBox.SelectedValue?.ToString();
|
|
item.HazardFactors = HazardFactorsComboBox.Text;
|
|
}
|
|
|
|
|
|
var _hazardListeee = HazardFactorsComboBox.EditValue as List<object>;
|
|
|
|
if (_editStatus) // 编辑
|
|
{
|
|
item.ID = _regInfo.ID;
|
|
item.PID = _regInfo?.PID;
|
|
OnUpdateRegItem(item);
|
|
|
|
// 判断是否更改为职业体检
|
|
if (ExamType.Contains("职业"))
|
|
{
|
|
// 避免重复开设,删除个人所有项目
|
|
DAOHelp.ExecuteSql($@"UPDATE Enrollment_FeeItem SET EID = -{_regInfo?.ID}, CreateTime = GETDATE(), CreatorCode = '{Global.currentUser.Code}', Creator = '{Global.currentUser.Name}', IsSend = 0 WHERE EID = {_regInfo?.ID}");
|
|
|
|
List<FeeItem> _feeItemsList = new List<FeeItem>();
|
|
|
|
// 接害类型
|
|
var _hazardList = HazardFactorsComboBox.EditValue as List<object>;
|
|
|
|
foreach (var hItem in _hazardList?.Select(s => s?.ToString()).ToList())
|
|
{
|
|
var feeItem = DAOHelp.GetDataBySQL<FeeItem>($@"EXEC sp_HazardFactors_FeeItem '{item.JobStatus.Trim()}', '{hItem.Trim()}' ");
|
|
_feeItemsList.AddRange(feeItem);
|
|
}
|
|
|
|
// 去除重复项
|
|
var _distFeeItem = _feeItemsList.GroupBy(g => g.KeyNo).Select(s => s.First()).ToList();
|
|
|
|
foreach (var dItem in _distFeeItem)
|
|
{
|
|
EnrollmentFeeItem eItem = new EnrollmentFeeItem();
|
|
Int32 index = 0;
|
|
|
|
eItem.EID = _regInfo?.ID;
|
|
eItem.FID = dItem.ID;
|
|
eItem.FeeItemCode = dItem.FeeItemCode;
|
|
eItem.FeeItemName = dItem.FeeItemName;
|
|
eItem.Quantity = 1;
|
|
eItem.Unit = dItem.Unit;
|
|
eItem.Price = dItem.Price;
|
|
eItem.SettlePrice = dItem.SettlePrice;
|
|
eItem.ItemClass = dItem.ItemClass;
|
|
eItem.CreateTime = DateTime.Now;
|
|
eItem.CreatorCode = Global.currentUser.Code;
|
|
eItem.Creator = Global.currentUser.Name;
|
|
eItem.DeptCode = dItem.DeptCode;
|
|
eItem.DeptName = dItem.DeptName;
|
|
eItem.Seq = index;
|
|
eItem.KeyNo = dItem.KeyNo;
|
|
eItem.IsOccupational = true;
|
|
|
|
eItem.Save();
|
|
}
|
|
|
|
}
|
|
}
|
|
else //新增
|
|
{
|
|
item.PID = _baseInfo?.ID;
|
|
item.CreateTime = DateTime.Now;
|
|
item.CreatorCode = Global.currentUser.Code;
|
|
item.Creator = Global.currentUser.Name;
|
|
if (item.Save())
|
|
{
|
|
// 新增成功后判断是否职业体检
|
|
if (ExamType.Contains("职业"))
|
|
{
|
|
List<FeeItem> _feeItemsList = new List<FeeItem>();
|
|
|
|
// 获取新增的体检ID
|
|
var _list = DAOHelp.GetDataBySQL<EnrollmentPatient>($@"SELECT TOP 1 ID FROM Enrollment_Patient WHERE CardNo = '{item.CardNo}' AND Name = '{item.Name}' ORDER BY ID DESC");
|
|
if (_list == null) return;
|
|
|
|
var EPItem = _list[0];
|
|
|
|
// 接害类型
|
|
var _hazardList = HazardFactorsComboBox.EditValue as List<object>;
|
|
|
|
foreach (var hItem in _hazardList?.Select(s => s?.ToString()).ToList())
|
|
{
|
|
var feeItem = DAOHelp.GetDataBySQL<FeeItem>($@"EXEC sp_HazardFactors_FeeItem '{item.JobStatus.Trim()}', '{hItem.Trim()}' ");
|
|
_feeItemsList.AddRange(feeItem);
|
|
}
|
|
|
|
// 去除重复项
|
|
var _distFeeItem = _feeItemsList.GroupBy(g => g.KeyNo).Select(s => s.First()).ToList();
|
|
|
|
foreach (var dItem in _distFeeItem)
|
|
{
|
|
EnrollmentFeeItem eItem = new EnrollmentFeeItem();
|
|
Int32 index = 0;
|
|
|
|
eItem.EID = EPItem.ID;
|
|
eItem.FID = dItem.ID;
|
|
eItem.FeeItemCode = dItem.FeeItemCode;
|
|
eItem.FeeItemName = dItem.FeeItemName;
|
|
eItem.Quantity = 1;
|
|
eItem.Unit = dItem.Unit;
|
|
eItem.Price = dItem.Price;
|
|
eItem.SettlePrice = dItem.SettlePrice;
|
|
eItem.ItemClass = dItem.ItemClass;
|
|
eItem.CreateTime = DateTime.Now;
|
|
eItem.CreatorCode = Global.currentUser.Code;
|
|
eItem.Creator = Global.currentUser.Name;
|
|
eItem.DeptCode = dItem.DeptCode;
|
|
eItem.DeptName = dItem.DeptName;
|
|
eItem.Seq = index;
|
|
eItem.KeyNo = dItem.KeyNo;
|
|
eItem.IsOccupational = true;
|
|
|
|
eItem.Save();
|
|
}
|
|
|
|
}
|
|
Global.Msg("info", "保存成功!");
|
|
}
|
|
}
|
|
|
|
Close();
|
|
}
|
|
|
|
public void GetConfig()
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
MaritalComboBox.DataSource = Global._lstConfig.Where(w => w.Key == "Marriage").OrderBy(p => p.Seq).ToList();
|
|
MaritalComboBox.DisplayMember = "Value";
|
|
MaritalComboBox.ValueMember = "Value";
|
|
|
|
EducationComboBox.DataSource = Global._lstConfig.Where(w => w.Key == "Education").OrderBy(p => p.Seq).ToList();
|
|
EducationComboBox.DisplayMember = "Value";
|
|
EducationComboBox.ValueMember = "Value";
|
|
|
|
OccupationComboBox.DataSource = Global._lstConfig.Where(w => w.Key == "Occupation").OrderBy(p => p.Seq).ToList();
|
|
OccupationComboBox.DisplayMember = "Value";
|
|
OccupationComboBox.ValueMember = "Value";
|
|
|
|
ExamTypeComboBox.DataSource = Global._lstConfig.Where(w => w.Key == "ExamType").ToList();
|
|
ExamTypeComboBox.DisplayMember = "Value";
|
|
ExamTypeComboBox.ValueMember = "Value";
|
|
|
|
CardTypeComboBox.DataSource = Global._lstConfig.Where(w => w.Key == "CardType").ToList();
|
|
CardTypeComboBox.DisplayMember = "Value";
|
|
CardTypeComboBox.ValueMember = "Value";
|
|
|
|
JobStatusComboBox.DataSource = Global._lstDictHazardTypes.Where(a => a.ParentID == null).ToList();
|
|
JobStatusComboBox.DisplayMember = "Name";
|
|
JobStatusComboBox.ValueMember = "Name";
|
|
|
|
|
|
foreach (var item in Global._lstDictHazardTypes.Where(a => a.ParentID != null).ToList())
|
|
{
|
|
HazardFactorsComboBox.Properties.Items.Add(item.Name);
|
|
}
|
|
HazardFactorsComboBox.Properties.DisplayMember = "Name";
|
|
HazardFactorsComboBox.Properties.ValueMember = "Name";
|
|
|
|
SelectPerson(new BasePatient(_regInfo));
|
|
}));
|
|
}
|
|
|
|
protected override object CreatePresenter()
|
|
{
|
|
return new NewEnrollmentPersonPresenter(this);
|
|
}
|
|
|
|
#region 摄像头
|
|
|
|
// 开启
|
|
public void Open_Camera()
|
|
{
|
|
// AForge
|
|
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
|
|
|
|
if (videoDevices.Count != 0)
|
|
{
|
|
try
|
|
{
|
|
FilterInfo info = videoDevices[0]; //选取第一个,此处可作灵活改动
|
|
VideoCaptureDevice videoSource = new VideoCaptureDevice(info.MonikerString);
|
|
videoSource.VideoResolution = videoSource.VideoCapabilities[0];
|
|
CameraPlayer.NewFrame += CameraPlayer_NewFrame;
|
|
//videoSource.DisplayPropertyPage(this.Handle);
|
|
|
|
Invoke(new Action(() =>
|
|
{
|
|
CameraPlayer.VideoSource = videoSource;
|
|
CameraPlayer.Start();
|
|
}));
|
|
}
|
|
catch
|
|
{
|
|
Global.Msg("err", "所选视频设备不支持");
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Global.MsgWarn("没有找到摄像头");
|
|
return;
|
|
}
|
|
}
|
|
|
|
// 关闭
|
|
public void Close_Camera()
|
|
{
|
|
|
|
Invoke(new Action(() =>
|
|
{
|
|
CameraPlayer.SignalToStop();
|
|
CameraPlayer.WaitForStop();
|
|
CameraPlayer.Stop();
|
|
CameraPlayer.VideoSource = null;
|
|
videoDevices.Clear();
|
|
}));
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 年龄、照片格式处理
|
|
|
|
// 计算年龄
|
|
public string[] CalculateAge()
|
|
{
|
|
DateTime birthday = BirthdayDateTimePicker.Value.Date;
|
|
DateTime today = DateTime.Today;
|
|
|
|
int age = today.Year - birthday.Year; // 计算年龄
|
|
|
|
if (birthday > today.AddYears(-age)) // 如果当前日期还未过生日,则年龄减一
|
|
{
|
|
age--;
|
|
}
|
|
|
|
int months = today.Month - birthday.Month; // 计算月份差值
|
|
|
|
if (months <= 0 && age == 0) // 如果月份差值为负数,则减一年,月份加12
|
|
{
|
|
months += 12;
|
|
}
|
|
|
|
return age != 0 ? new string[]
|
|
{
|
|
age.ToString(),
|
|
"岁"
|
|
} : new string[]
|
|
{
|
|
months.ToString(),
|
|
"月"
|
|
};
|
|
}
|
|
// 转换照片格式
|
|
public string ImageToBase64()
|
|
{
|
|
if (Photo.Image == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
try
|
|
{
|
|
using (MemoryStream ms = new MemoryStream())
|
|
{
|
|
Photo.Image.Save(ms, ImageFormat.Png);
|
|
byte[] imageBytes = ms.ToArray();
|
|
return Convert.ToBase64String(imageBytes);
|
|
}
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
Global.Msg("err", ex.Message);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public Image Base64ToImage(string base64Str)
|
|
{
|
|
if (base64Str == null || base64Str == "")
|
|
{
|
|
return null;
|
|
}
|
|
|
|
byte[] imageBytes = Convert.FromBase64String(base64Str);
|
|
try
|
|
{
|
|
using (MemoryStream ms = new MemoryStream(imageBytes))
|
|
{
|
|
Image image = Image.FromStream(ms);
|
|
return image;
|
|
}
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
Global.Msg("err", ex.Message);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static Image ScaleImage(Image image, int newWidth, int newHeight)
|
|
{
|
|
// 创建缩小后的图像
|
|
Image scaledImage = new Bitmap(newWidth, newHeight);
|
|
|
|
// 使用Graphics对象绘制缩小后的图像
|
|
using (Graphics graphics = Graphics.FromImage(scaledImage))
|
|
{
|
|
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
|
|
graphics.DrawImage(image, 0, 0, newWidth, newHeight);
|
|
}
|
|
|
|
return scaledImage;
|
|
}
|
|
#endregion
|
|
|
|
#region 事件接口
|
|
|
|
// 更新登记信息
|
|
public event EventHandler<Args<EnrollmentPatient>> UpdateRegItem;
|
|
public void ShowUpdateRegInfo(bool status)
|
|
{
|
|
if (status)
|
|
{
|
|
Global.Msg("info", "保存成功!");
|
|
}
|
|
}
|
|
protected virtual void OnUpdateRegItem(EnrollmentPatient item)
|
|
{
|
|
UpdateRegItem?.Invoke(this, new Args<EnrollmentPatient>
|
|
{
|
|
Item = item
|
|
});
|
|
}
|
|
|
|
// 通过姓名匹配
|
|
public event EventHandler<Args<string>> GetBaseInfoByName;
|
|
public void ShowBaseInfoByName(List<BasePatient> items)
|
|
{
|
|
Action<BasePatient> action = result => SelectPerson(result);
|
|
switch (items.Count)
|
|
{
|
|
case 0:
|
|
Global.Msg("info", "没有匹配记录,请新建体检信息!");
|
|
|
|
NewPersonForm personForm = new NewPersonForm(action);
|
|
personForm.ShowDialog();
|
|
break;
|
|
case 1:
|
|
SelectPerson(items[0]);
|
|
break;
|
|
default:
|
|
{
|
|
SelectPatientForm selectPatientForm = new SelectPatientForm(action, NameTextBox.Text.Trim());
|
|
selectPatientForm.ShowDialog();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
protected virtual void OnGetBaseInfoByName()
|
|
{
|
|
GetBaseInfoByName?.Invoke(this, new Args<string>{ Name = NameTextBox.Text });
|
|
}
|
|
|
|
// 通过证件类型、证件号查询PID
|
|
public event EventHandler<Args<BasePatient>> GetPid;
|
|
public void ShowPid(BasePatient item)
|
|
{
|
|
Invoke(new Action(() => _baseInfo = item));
|
|
}
|
|
protected virtual void OnGetPid()
|
|
{
|
|
GetPid?.Invoke(this, new Args<BasePatient>
|
|
{
|
|
Name = CardTypeComboBox.Text.Trim(),
|
|
Code = IDCard.Text.Trim()
|
|
});
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |