StableVersion4.3/HL_FristAidPlatform_EMRS/Form_PatientECG.cs

445 lines
18 KiB
C#

using DevExpress.XtraEditors;
using HL_FristAidPlatform_DTO;
using HL_FristAidPlatform_Public;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace HL_FristAidPlatform_EMRS
{
public partial class Form_PatientECG : XtraForm
{
private string patientGuid;
private DataTable dt;
private int systemId;
/// <summary>
/// 心电图(转换成二进制之后数据)
/// </summary>
private string Cur_PicData = string.Empty;
/// <summary>
/// 心电图(文件后缀)
/// </summary>
private string Cur_PicType = string.Empty;
/// <summary>
/// 等待窗体
/// </summary>
private Loading loading = new Loading();
public Form_PatientECG(string _patientGuid,int _systemId)
{
InitializeComponent();
patientGuid = _patientGuid;
systemId = _systemId;
}
private void Form_PatientECG_Load(object sender, EventArgs e)
{
BindECG();
}
public void BindECG()
{
string Url = string.Format("api/service/T_Service_ChestPain_ECG/GetByPatientGuid?patientGuid={0}&ecgType={1}", patientGuid, -1);
dt = DBHelpClass.Get(Url);
gridControl_ECG.DataSource = dt;
}
private void btn_Delete_Click(object sender, EventArgs e)
{
try
{
if (grv_ECG.DataRowCount > 0)
{
int selectRow = grv_ECG.GetSelectedRows()[0];
long ID = PublicClass.ToInt64(grv_ECG.GetRowCellValue(selectRow, "ID"), 0);
string GUID = grv_ECG.GetRowCellValue(selectRow, "GUID").ToString();
if (ID == 0)
{
XtraMessageBox.Show("请先选择要删除的心电图!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (XtraMessageBox.Show("确定要删除当前心电图?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
List<T_Service_ChestPain_ECGDTO> list = new List<T_Service_ChestPain_ECGDTO>();
T_Service_ChestPain_ECGDTO model = new T_Service_ChestPain_ECGDTO();
string Url = "api/service/T_Service_ChestPain_ECG/LogicalDelete";
model.ID = ID;
model.DeleteFlag = 1;
model.EditorID = Information.User.ID;
model.Editor = Information.User.FullName;
model.EditTime = PublicClass.DateTimeNow();
model.GUID = GUID;
list.Add(model);
//初始化两个工厂
ClientFactory<T_Service_ChestPain_ECGDTO> httpClient = new HttpClientFactory<T_Service_ChestPain_ECGDTO>();
Client<T_Service_ChestPain_ECGDTO> client = httpClient.VisitFactory();
if (client.Post(Url, list).Success)
{
XtraMessageBox.Show("删除心电图成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
PublicClass.EnabledControl(this.groupControl_Info, true, false);
//列表分页数据绑定
BindECG();
time_ECG_Time.TimeValue = "";
time_ECG_Diagnose_Time.TimeValue = "";
}
else
{
XtraMessageBox.Show("删除心电图失败,请稍后重试!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "删除:\r\n" + ex);
}
}
private void btn_Update_Click(object sender, EventArgs e)
{
BindDetail();
PublicClass.EnabledControl(groupControl_Info, false, false);
btn_Delete.Enabled = false;
}
/// <summary>
/// 绑定心电图详情
/// </summary>
private void BindDetail()
{
try
{
if (grv_ECG.DataRowCount > 0)
{
int selectRow = grv_ECG.GetSelectedRows()[0];
long ID = Convert.ToInt64(grv_ECG.GetRowCellValue(selectRow, "ID").ToString());
dt = DBHelpClass.GetDataRow(string.Format("api/service/T_Service_ChestPain_ECG/{0}", ID));
if (dt != null && dt.Rows.Count > 0)
{
lbl_ECG_Time.Tag = dt.Rows[0]["ID"].ToString();
lbl_ECG_Diagnose_Time.Tag = dt.Rows[0]["GUID"].ToString();
//心电图时间
time_ECG_Time.TimeValue = dt.Rows[0]["ECG_Time"].ToString();
//心电图诊断时间
time_ECG_Diagnose_Time.TimeValue = dt.Rows[0]["ECG_Diagnose_Time"].ToString();
#region 图片
//头像
string ECGImageFiles = PublicClass.ToString(dt.Rows[0]["ECGImageFiles"], "");
if (!string.IsNullOrEmpty(ECGImageFiles))
{
MemoryStream ms = new MemoryStream(Convert.FromBase64String(ECGImageFiles));
Image img = Image.FromStream(ms);
pictureEdit_Image.Image = img;
Bitmap Cur_ImageBitmap = new Bitmap(img);
Cur_PicData = PublicClass.Jpeg2String(Cur_ImageBitmap);
Cur_PicType = dt.Rows[0]["ECGImageType"].ToString();
}
else
{
pictureEdit_Image.Image = null;
Cur_PicData = "";
Cur_PicType = "";
}
#endregion
}
}
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "绑定心电图详情:\r\n" + ex);
}
}
private void btn_Save_Click(object sender, EventArgs e)
{
try
{
#region 验证
if (string.IsNullOrEmpty(time_ECG_Time.TimeValue))
{
XtraMessageBox.Show("请填写首份心电图时间!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
time_ECG_Time.Focus();
return;
}
if (string.IsNullOrEmpty(time_ECG_Diagnose_Time.TimeValue))
{
XtraMessageBox.Show("请填写首份心电图诊断时间!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
time_ECG_Diagnose_Time.Focus();
return;
}
if (string.IsNullOrEmpty(Cur_PicData))
{
XtraMessageBox.Show("请选择需要上传的心电图报告!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
btn_OpenFile.Focus();
return;
}
#endregion
loading.ShowMessage("", "正在上传心电图报告...");
if (Save_ECG())
{
PublicClass.EnabledControl(groupControl_Info, true, false);
loading.HideMessage();
XtraMessageBox.Show("保存心电图成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
//重新绑定
BindECG();
if (systemId == 2)
{
UpdateTreatmentInfo(patientGuid);
}
btn_Update.Enabled = true;
btn_Delete.Enabled = true;
}
else
{
loading.HideMessage();
XtraMessageBox.Show("保存心电图失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "保存:\r\n" + ex);
}
}
/// <summary>
/// 保存心电图
/// </summary>
/// <returns></returns>
private bool Save_ECG()
{
try
{
string Url = string.Empty;
#region 保存心电图
List<T_Service_ChestPain_ECGDTO> list_Model = new List<T_Service_ChestPain_ECGDTO>();
T_Service_ChestPain_ECGDTO model = new T_Service_ChestPain_ECGDTO();
//存在则修改 否则新增
if (dt != null && dt.Rows.Count > 0)
{
Url = "api/service/T_Service_ChestPain_ECG/UpdateNotNullColumns";
model.ID = PublicClass.ToInt64(lbl_ECG_Time.Tag, -1);
model.GUID = lbl_ECG_Diagnose_Time.Tag.ToString();
model.DeleteFlag = PublicClass.ToInt32(dt.Rows[0]["DeleteFlag"], -1);
model.CreatorID = PublicClass.ToInt64(dt.Rows[0]["CreatorID"], 0);
model.Creator = dt.Rows[0]["Creator"].ToString();
model.CreationDate = dt.Rows[0]["CreationDate"].ToString();
model.EditorID = Information.User.ID;
model.Editor = Information.User.FullName;
model.EditTime = PublicClass.DateTimeNow();
model.ECG_Type="1";
}
else
{
Url = "api/service/T_Service_ChestPain_ECG/AddNotNullColumns";
model.GUID = Guid.NewGuid().ToString();
model.DeleteFlag = 0;
model.CreatorID = Information.User.ID;
model.Creator = Information.User.FullName;
model.CreationDate = PublicClass.DateTimeNow();
}
model.PatientGuid = patientGuid;
model.ECG_Time = time_ECG_Time.TimeValue;
model.ECG_Diagnose_Time = time_ECG_Diagnose_Time.TimeValue;
//model.ECGImageFiles = Convert.FromBase64String(Cur_PicData);
model.ECGImageFiles = Cur_PicData;
model.ECGImageType = Cur_PicType;
model.ECG_Type = "1";
list_Model.Add(model);
//初始化两个工厂
ClientFactory<T_Service_ChestPain_ECGDTO> httpClient = new HttpClientFactory<T_Service_ChestPain_ECGDTO>();
Client<T_Service_ChestPain_ECGDTO> client = httpClient.VisitFactory();
#endregion
//访问
return client.Post(Url, list_Model).Success;
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "保存心电图:\r\n" + ex);
return false;
}
}
/// <summary>
/// 更新胸痛诊疗表中是否有心电图的字段值
/// </summary>
/// <param name="_patientGuid">患者编号</param>
private void UpdateTreatmentInfo(string _patientGuid)
{
string Url = string.Format("api/service/T_Service_ChestPain_TreatmentInfo/GetByPatientGuid?patientGuid={0}", _patientGuid);
DataTable Cur_TreatmentInfoDT = DBHelpClass.Get(Url);
if (Cur_TreatmentInfoDT != null && Cur_TreatmentInfoDT.Rows.Count > 0)
{
string Has_ECG_Image = PublicClass.ToString(Cur_TreatmentInfoDT.Rows[0]["Has_ECG_Image"], "");
if (Has_ECG_Image == "")
{
List<T_Service_ChestPain_TreatmentInfoDTO> list_Model = new List<T_Service_ChestPain_TreatmentInfoDTO>();
T_Service_ChestPain_TreatmentInfoDTO model = new T_Service_ChestPain_TreatmentInfoDTO();
Url = "api/service/T_Service_ChestPain_TreatmentInfo/UpdateNotNullColumns";
model.ID = PublicClass.ToInt64(Cur_TreatmentInfoDT.Rows[0]["ID"], -1);
model.GUID = Cur_TreatmentInfoDT.Rows[0]["GUID"].ToString();
model.DeleteFlag = PublicClass.ToInt32(Cur_TreatmentInfoDT.Rows[0]["DeleteFlag"], -1);
model.CreatorID = PublicClass.ToInt64(Cur_TreatmentInfoDT.Rows[0]["CreatorID"], 0);
model.Creator = Cur_TreatmentInfoDT.Rows[0]["Creator"].ToString();
model.CreationDate = Cur_TreatmentInfoDT.Rows[0]["CreationDate"].ToString();
model.EditorID = Information.User.ID;
model.Editor = Information.User.FullName;
model.EditTime = PublicClass.DateTimeNow();
model.Has_ECG_Image = "1";
list_Model.Add(model);
//初始化两个工厂
ClientFactory<T_Service_ChestPain_TreatmentInfoDTO> httpClient = new HttpClientFactory<T_Service_ChestPain_TreatmentInfoDTO>();
Client<T_Service_ChestPain_TreatmentInfoDTO> client = httpClient.VisitFactory();
}
}
}
/// <summary>
/// 显示图片
/// </summary>
private void ShowImage()
{
try
{
if (grv_ECG.DataRowCount > 0)
{
int selectRow = grv_ECG.GetSelectedRows()[0];
long id = PublicClass.ToInt64(grv_ECG.GetRowCellValue(selectRow, "ID"), 0);
if (id > 0)
{
DataTable DetailDT = DBHelpClass.GetDataRow(string.Format("api/service/T_Service_ChestPain_ECG/{0}", id));
if (DetailDT != null && DetailDT.Rows.Count > 0)
{
//图片
#region 图片
string FileImage = PublicClass.ToString(DetailDT.Rows[0]["ECGImageFiles"], "");
if (!string.IsNullOrEmpty(FileImage))
{
byte[] image = Convert.FromBase64String(FileImage);
Form_Image frm = new Form_Image(image);
frm.ShowDialog();
}
else
{
XtraMessageBox.Show("没有获取到文件图片,请确认!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
#endregion
}
}
}
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "显示图片:\r\n" + ex);
}
}
private void btn_OpenFile_Click(object sender, EventArgs e)
{
try
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Image Files(*.JPG;*.PNG;*.JPEG;;*.BMP)|*.JPG;*.PNG;;*.BMP;*.JPEG";
ofd.RestoreDirectory = true;
Cur_PicData = "";
if (ofd.ShowDialog() == DialogResult.OK)
{
int Config109 = PublicClass.ToInt32(PublicClassForDataBase.Config109, 5);
string FileName = ofd.FileName;
if (PublicClass.GetFileSize(FileName) <= Config109)
{
FileInfo file = new FileInfo(ofd.FileName);
string Cur_PicAddress = ofd.FileName;
Image imge = Image.FromFile(Cur_PicAddress);
Bitmap Cur_ImageBitmap = new Bitmap(imge);
Cur_PicType = file.Extension;
pictureEdit_Image.Image = Cur_ImageBitmap;
if (Cur_PicType.ToLower() == ".png")
{
//所选图标转换成二进制 png
Cur_PicData = PublicClass.Png2String(Cur_ImageBitmap);
}
else
{
//所选图标转换成二进制 jpg
Cur_PicData = PublicClass.Jpeg2String(Cur_ImageBitmap);
}
}
else
{
XtraMessageBox.Show(string.Format("选择的文件大小超出了限制,请将文件控制在{0}兆以内!", Config109), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "更换心电图:\r\n" + ex);
}
}
private void gridControl_ECG_MouseClick(object sender, MouseEventArgs e)
{
PublicClass.EnabledControl(this.groupControl_Info, true, false);
BindDetail();
btn_Update.Enabled = true;
btn_Delete.Enabled = true;
}
private void repositoryItemButtonEdit_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
switch (e.Button.Caption)
{
case "查看图片":
loading.ShowMessage();
ShowImage();
loading.HideMessage();
break;
default:
break;
}
}
private void Form_PatientECG_FormClosing(object sender, FormClosingEventArgs e)
{
Form_EMRInfo info;
info = (Form_EMRInfo)this.Owner;
info.ParentInfo(patientGuid);
this.Dispose();
}
}
}