StableVersion4.3/HL_FristAidPlatform_ChestPain/Form_ChestPain_ECG.cs

588 lines
25 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using DevExpress.XtraEditors;
using HL_FristAidPlatform_DTO;
using HL_FristAidPlatform_MultiSystemPublic;
using HL_FristAidPlatform_Public;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HL_FristAidPlatform_ChestPain
{
public partial class Form_ChestPain_ECG : XtraForm
{
#region 变量
/// <summary>
/// 当前病人编号
/// </summary>
private string Cur_PatientGuid = string.Empty;
/// <summary>
/// 首份心电图文件类型 V2.1
/// </summary>
private string FristECG_FileType = string.Empty;
/// <summary>
/// 首份心电图文件 V2.1
/// </summary>
private string FristECG_FileStr = string.Empty;
/// <summary>
/// 当前患者所有的肌钙蛋白报告
/// </summary>
private DataTable Cur_BindDT = new DataTable();
/// <summary>
/// 当前修改的记录信息
/// </summary>
private DataTable Cur_DetailDT = new DataTable();
/// <summary>
/// 心电图(转换成二进制之后数据)
/// </summary>
private string Cur_PicData = string.Empty;
/// <summary>
/// 心电图(文件后缀)
/// </summary>
private string Cur_PicType = string.Empty;
/// <summary>
/// 等待窗体
/// </summary>
private Loading loading = new Loading();
#endregion
/// <summary>
/// 心电图管理
/// </summary>
/// <param name="_patientGuid"></param>
public Form_ChestPain_ECG(string _patientGuid)
{
InitializeComponent();
Cur_PatientGuid = _patientGuid;
}
/// <summary>
/// 窗体加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form_ChestPain_ECG_Load(object sender, EventArgs e)
{
Bind_List();
BindDetail();
}
/// <summary>
/// 绑定心电图列表
/// </summary>
private void Bind_List()
{
try
{
string Url = string.Format("api/service/T_Service_ChestPain_ECG/GetByPatientGuid?patientGuid={0}&ecgType={1}", Cur_PatientGuid, -1);
Cur_BindDT = DBHelpClass.Get(Url);
gridControl_ECG.DataSource = Cur_BindDT;
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "绑定心电图列表:\r\n" + ex);
}
}
/// <summary>
/// 保存
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private async void btn_Save_Click(object sender, EventArgs e)
{
ASYNCPostECG();
}
async Task ASYNCPostECG()
{
try
{
if (Cur_BindDT.Rows.Count >= 3 && Cur_DetailDT.Rows.Count == 0)
{
if (XtraMessageBox.Show("当前已有三份心电图的报告,因数据填报平台只需传送三份心电报告!\r\n如果继续新增将按添加的先后顺序传送前三份到数据填报平台请知晓\r\n请问是否继续新增", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
}
#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())
{
loading.HideMessage();
XtraMessageBox.Show("保存心电图成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
// 重新绑定
Bind_List();
int selectRow = grv_ECG.GetSelectedRows()[0];
string firstECG = PublicClass.ToString(grv_ECG.GetRowCellValue(selectRow, "FirstECG"), "");
if (firstECG == "1")
{
if (!string.IsNullOrEmpty(time_ECG_Time.TimeValue))
PublicClassForDataBase.UpdateTime_ChestPain(Cur_PatientGuid, time_ECG_Time.TimeValue, PublicClassForDataBase.Config1004);
if (!string.IsNullOrEmpty(time_ECG_Diagnose_Time.TimeValue))
PublicClassForDataBase.UpdateTime_ChestPain(Cur_PatientGuid, time_ECG_Diagnose_Time.TimeValue, PublicClassForDataBase.Config1006);
}
PublicClass.EnabledControl(groupControl_Info, true, false);
UpdateTreatmentInfo(Cur_PatientGuid);
btn_Add.Enabled = true;
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>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Add_Click(object sender, EventArgs e)
{
if (Cur_BindDT.Rows.Count >= 3)
{
if (XtraMessageBox.Show("当前已有三份心电图的报告,因数据填报平台只需传送三份心电报告!\r\n如果继续新增将按添加的先后顺序传送前三份到数据填报平台请知晓\r\n请问是否继续新增", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
PublicClass.EnabledControl(groupControl_Info, true, true);
return;
}
}
PublicClass.EnabledControl(groupControl_Info, false, true);
Cur_DetailDT = new DataTable();
lbl_ECG_Time.Tag = "";
lbl_ECG_Diagnose_Time.Tag = "";
Cur_PicData = "";
Cur_PicType = "";
pictureEdit_Image.Image = null;
btn_Update.Enabled = false;
btn_Delete.Enabled = false;
}
/// <summary>
/// 修改
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Update_Click(object sender, EventArgs e)
{
BindDetail();
PublicClass.EnabledControl(groupControl_Info, false, false);
btn_Add.Enabled = false;
btn_Delete.Enabled = false;
}
/// <summary>
/// 删除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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();
string FirstECG = grv_ECG.GetRowCellValue(selectRow, "FirstECG").ToString();
if (FirstECG == "1")
{
XtraMessageBox.Show("不能删除首份心电图!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
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);
//列表分页数据绑定
Bind_List();
}
else
{
XtraMessageBox.Show("删除心电图失败,请稍后重试!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "删除:\r\n" + ex);
}
}
/// <summary>
/// 更换心电图
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
if (!string.IsNullOrEmpty(Cur_PicData))
{
MemoryStream ms = new MemoryStream(Convert.FromBase64String(Cur_PicData));
Image img = Image.FromStream(ms);
pictureEdit_Image.Image = img;
Cur_PicType = Cur_DetailDT.Rows[0]["ECGImageType"].ToString();
}
}
else
{
Cur_PicData = PublicClass.Jpeg2String(Cur_ImageBitmap);
//所选图标转换成二进制 jpg
if (!string.IsNullOrEmpty(Cur_PicData))
{
MemoryStream ms = new MemoryStream(Convert.FromBase64String(Cur_PicData));
Image img = Image.FromStream(ms);
pictureEdit_Image.Image = img;
Cur_PicType = Cur_DetailDT.Rows[0]["ECGImageType"].ToString();
}
}
}
else
{
XtraMessageBox.Show(string.Format("选择的文件大小超出了限制,请将文件控制在{0}兆以内!", Config109), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "更换心电图:\r\n" + ex);
}
}
/// <summary>
/// 显示详情
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void gridControl_ECG_MouseClick(object sender, MouseEventArgs e)
{
PublicClass.EnabledControl(this.groupControl_Info, true, false);
BindDetail();
btn_Add.Enabled = true;
btn_Update.Enabled = true;
btn_Delete.Enabled = true;
}
/// <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());
Cur_DetailDT = DBHelpClass.GetDataRow(string.Format("api/service/T_Service_ChestPain_ECG/{0}", ID));
if (Cur_DetailDT != null && Cur_DetailDT.Rows.Count > 0)
{
lbl_ECG_Time.Tag = Cur_DetailDT.Rows[0]["ID"].ToString();
lbl_ECG_Diagnose_Time.Tag = Cur_DetailDT.Rows[0]["GUID"].ToString();
//心电图时间
time_ECG_Time.TimeValue = Cur_DetailDT.Rows[0]["ECG_Time"].ToString();
//心电图诊断时间
time_ECG_Diagnose_Time.TimeValue = Cur_DetailDT.Rows[0]["ECG_Diagnose_Time"].ToString();
#region 图片
//头像
string ECGImageFiles = PublicClass.ToString(Cur_DetailDT.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 = Cur_DetailDT.Rows[0]["ECGImageType"].ToString();
}
else
{
pictureEdit_Image.Image = null;
Cur_PicData = "";
Cur_PicType = "";
}
#endregion
}
}
}
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 (Cur_DetailDT != null && Cur_DetailDT.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(Cur_DetailDT.Rows[0]["DeleteFlag"], -1);
model.CreatorID = PublicClass.ToInt64(Cur_DetailDT.Rows[0]["CreatorID"], 0);
model.Creator = Cur_DetailDT.Rows[0]["Creator"].ToString();
model.CreationDate = Cur_DetailDT.Rows[0]["CreationDate"].ToString();
model.EditorID = Information.User.ID;
model.Editor = Information.User.FullName;
model.EditTime = PublicClass.DateTimeNow();
}
else
{
if (Cur_BindDT == null && Cur_BindDT.Rows.Count <= 0)
model.FirstECG = "1";
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 = Cur_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;
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
var resul = client.Post(Url, list_Model);
//访问
return true;
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "保存心电图:\r\n" + ex);
return false;
}
}
/// <summary>
/// 列表操作
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void repositoryItemButtonEdit_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
switch (e.Button.Caption)
{
case "查看图片":
loading.ShowMessage();
ShowImage();
loading.HideMessage();
break;
default:
break;
}
}
/// <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);
HL_FristAidPlatform_MultiSystemPublic.Form_ImageShow frm = new HL_FristAidPlatform_MultiSystemPublic.Form_ImageShow(image);
frm.ShowDialog();
}
else
{
XtraMessageBox.Show("没有获取到文件图片,请确认!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
#endregion
}
}
}
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "显示图片:\r\n" + ex);
}
}
/// <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();
}
}
}
private void Form_ChestPain_ECG_FormClosed(object sender, FormClosedEventArgs e)
{
Form_ChestPain_Treatment treatment;
treatment = (Form_ChestPain_Treatment)this.Owner;
treatment.Bind_ECGList();
this.Close();
}
private void grv_ECG_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
{
if (e.Info.IsRowIndicator && e.RowHandle >= 0)
e.Info.DisplayText = (e.RowHandle + 1).ToString();
}
}
}