StableVersion4.3/HL_FristAidPlatform_MultiSy.../Form_Meeting_Detail.cs

504 lines
20 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_MultiSystemPublic
{
/// <summary>
/// 会议详情
/// </summary>
public partial class Form_Meeting_Detail : XtraForm
{
#region 变量
/// <summary>
/// 当前会议编号
/// </summary>
private long Cur_MeetingId = 0;
/// <summary>
/// 当前会议编号(GUID)
/// </summary>
private string Cur_MeetingGuid = string.Empty;
/// <summary>
/// 当前维护的会议 用于修改和单击列表
/// </summary>
private DataTable Cur_Meeting_DT = new DataTable();
/// <summary>
/// 等待窗体
/// </summary>
private Loading loading = new Loading();
#endregion 变量
/// <summary>
/// 会议详情
/// </summary>
/// <param name="meetingGuid">会议编号</param>
public Form_Meeting_Detail(long meetingId)
{
InitializeComponent();
Cur_MeetingId = meetingId;
}
/// <summary>
/// 窗体加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form_Meeting_Detail_Load(object sender, EventArgs e)
{
//加载基础数据
BindData();
//绑定详情
Bind_Detail();
}
/// <summary>
/// 窗体快捷键注册
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form_Meeting_Detail_KeyDown(object sender, KeyEventArgs e)
{
//同时按下 Ctrl+S 时执行保存方法
if (e.KeyCode == Keys.S && e.Control)
{
btn_Save_Click(null, null);
}
}
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Save_Click(object sender, EventArgs e)
{
Save();
}
#region BindData
/// <summary>
/// 查询绑定
/// </summary>
private void BindData()
{
BindType();
}
/// <summary>
/// 绑定会议类型
/// </summary>
private void BindType()
{
try
{
DataTable ResultDT = PublicClass.EnumToDataTable(typeof(Enumerate.MeetintType), "Name", "ID");
PublicClass.SetLookUpList(lookUp_Type, ResultDT, "ID", "Name", true);
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "绑定会议类型:\r\n" + ex);
}
}
#endregion BindData
#region 方法
/// <summary>
/// 绑定详情
/// </summary>
private void Bind_Detail()
{
try
{
if (Cur_MeetingId > 0)
{
string Url = $"api/service/T_Service_Meeting/{Cur_MeetingId}";
Cur_Meeting_DT = DBHelpClass.GetDataRow(Url);
if (Cur_Meeting_DT != null && Cur_Meeting_DT.Rows.Count > 0)
{
Cur_MeetingGuid = Cur_Meeting_DT.Rows[0]["GUID"].ToString();
//会议类型
lookUp_Type.EditValue = PublicClass.ToString(Cur_Meeting_DT.Rows[0]["Type"], "");
//编号
txt_Name.Tag = Cur_Meeting_DT.Rows[0]["ID"].ToString();
//会议名称
txt_Name.Text = Cur_Meeting_DT.Rows[0]["Name"].ToString();
//GUID
txt_Venue.Tag = Cur_MeetingGuid;
//会议地点
txt_Venue.Text = Cur_Meeting_DT.Rows[0]["Venue"].ToString();
//主持人
txt_Host.Text = Cur_Meeting_DT.Rows[0]["Host"].ToString();
//会议内容
txt_Content.Text = Cur_Meeting_DT.Rows[0]["Content"].ToString();
//预定召开日期
time_ScheduledDate.TimeValue = Cur_Meeting_DT.Rows[0]["ScheduledDate"].ToString();
//实际召开日期
time_ActualDate.TimeValue = Cur_Meeting_DT.Rows[0]["ActualDate"].ToString();
//会议备注
txt_Remark.Text = Cur_Meeting_DT.Rows[0]["Remark"].ToString();
//绑定图片列表
Bind_ImageList();
}
}
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "绑定认证版本详情:\r\n" + ex);
}
}
/// <summary>
/// 保存
/// </summary>
private void Save()
{
try
{
#region 保存认证版本
if (PublicClass.ToString(lookUp_Type.EditValue, "") == "")
{
XtraMessageBox.Show("请选择会议类型!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
lookUp_Type.Focus();
return;
}
if (string.IsNullOrEmpty(txt_Name.Text.ToString().Trim()))
{
XtraMessageBox.Show("会议名称不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txt_Name.Focus();
return;
}
List<T_Service_MeetingDTO> list = new List<T_Service_MeetingDTO>();
T_Service_MeetingDTO model = new T_Service_MeetingDTO();
string Url = string.Empty;
if (Cur_Meeting_DT != null && Cur_Meeting_DT.Rows.Count > 0)
{
Url = "api/service/T_Service_Meeting/Update";
model.ID = Convert.ToInt32(txt_Name.Tag.ToString());
model.GUID = txt_Venue.Tag.ToString();
model.DeleteFlag = PublicClass.ToInt32(Cur_Meeting_DT.Rows[0]["DeleteFlag"], 0);
model.SystemModuleID = PublicClass.ToInt64(Cur_Meeting_DT.Rows[0]["SystemModuleID"], 0);
model.HospitalGuid = Cur_Meeting_DT.Rows[0]["HospitalGuid"].ToString();
model.NoticeNumber = PublicClass.ToInt32(Cur_Meeting_DT.Rows[0]["NoticeNumber"], 0);
model.NoticeDate = Cur_Meeting_DT.Rows[0]["NoticeDate"].ToString();
model.NotifierID = PublicClass.ToInt32(Cur_Meeting_DT.Rows[0]["NotifierID"], 0);
model.Notifier = Cur_Meeting_DT.Rows[0]["Notifier"].ToString();
model.DeleteFlag = PublicClass.ToInt32(Cur_Meeting_DT.Rows[0]["DeleteFlag"], 0);
model.CreationDate = Cur_Meeting_DT.Rows[0]["CreationDate"].ToString();
model.CreatorID = PublicClass.ToInt32(Cur_Meeting_DT.Rows[0]["CreatorID"], 0);
model.Creator = Cur_Meeting_DT.Rows[0]["Creator"].ToString();
model.EditorID = Information.User.ID;
model.Editor = Information.User.FullName;
model.EditTime = PublicClass.DateTimeNow();
}
else
{
Url = "api/service/T_Service_Meeting/AddNotNullColumns";
model.GUID = Guid.NewGuid().ToString();
model.DeleteFlag = 0;
model.SystemModuleID = Information.SystemModuleInfo.ID;
model.HospitalGuid = Information.Hospital.GUID;
model.CreatorID = Information.User.ID;
model.Creator = Information.User.FullName;
model.CreationDate = PublicClass.DateTimeNow();
}
int Type = PublicClass.ToInt32(lookUp_Type.EditValue, 0);
model.Type = Type == -1 ? 0 : Type;
model.Name = txt_Name.Text.Trim();
model.Venue = txt_Venue.Text.Trim();
model.Host = txt_Host.Text.Trim();
model.Content = txt_Content.Text.Trim();
model.Remark = txt_Remark.Text.Trim();
model.ScheduledDate = time_ScheduledDate.TimeValue;
model.ActualDate = time_ActualDate.TimeValue;
list.Add(model);
//初始化两个工厂
ClientFactory<T_Service_MeetingDTO> httpClient = new HttpClientFactory<T_Service_MeetingDTO>();
Client<T_Service_MeetingDTO> client = httpClient.VisitFactory();
//访问
ListEntity<T_Service_MeetingDTO> t = client.Post(Url, list);
if (t.Success)
{
XtraMessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
Cur_MeetingGuid = model.GUID;
DialogResult = DialogResult.OK;
}
else
{
XtraMessageBox.Show("保存失败,请稍后重试!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
DialogResult = DialogResult.No;
}
#endregion
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "保存认证版本:\r\n" + ex);
}
}
#endregion 方法
/// <summary>
/// 根据会议编号绑定图片列表
/// </summary>
private void Bind_ImageList()
{
try
{
string Url = $"api/service/T_Service_Meeting_Image?meetingGuid={Cur_MeetingGuid}";
DataTable Cur_BindDT = DBHelpClass.Get(Url);
grid_List.DataSource = Cur_BindDT;
}
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)
{
#region 验证
//如果会议编号为空,先执行会议信息保存
if (string.IsNullOrEmpty(Cur_MeetingGuid))
{
Save();
}
#endregion
#region 上传后直接保存
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Image Files(*.JPG;*.PNG;*.JPEG;;*.BMP)|*.JPG;*.PNG;;*.BMP;*.JPEG";
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
loading.ShowMessage("请稍后", "正在为您上传会议图片...");
try
{
int Config109 = PublicClass.ToInt32(PublicClassForDataBase.Config109, 5);
string FileName = openFileDialog.FileName;
if (PublicClass.GetFileSize(FileName) <= Config109)
{
FileInfo file = new FileInfo(FileName);
Bitmap bitmap = new Bitmap(FileName);
string FileStr = string.Empty;
if (file.Extension.ToLower() == ".png")
{
FileStr = PublicClass.Png2String(bitmap);
}
else
{
FileStr = PublicClass.Jpeg2String(bitmap);
}
if (Save_Image(Cur_MeetingGuid, FileName, FileStr))
{
loading.HideMessage();
XtraMessageBox.Show("上传会议图片成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
//重新绑定
Bind_ImageList();
}
}
else
{
loading.HideMessage();
XtraMessageBox.Show(string.Format("选择的文件大小超出了限制,请将文件控制在{0}兆以内!", Config109), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch (Exception ex)
{
loading.HideMessage();
PublicClass.WriteErrorLog(this.Text, "上传心电图:\r\n" + ex);
}
}
#endregion
}
/// <summary>
/// 保存会议图片
/// </summary>
/// <param name="meetingGuid">会议编号</param>
/// <param name="imageName">图片名称</param>
/// <param name="imageStr">图片文件流</param>
/// <returns></returns>
private bool Save_Image(string meetingGuid, string imageName, string imageStr)
{
try
{
string Url = string.Empty;
#region 保存会议图片
List<T_Service_Meeting_ImageDTO> list = new List<T_Service_Meeting_ImageDTO>();
T_Service_Meeting_ImageDTO model = new T_Service_Meeting_ImageDTO();
Url = "api/service/T_Service_Meeting_Image/AddNotNullColumns";
model.GUID = Guid.NewGuid().ToString();
model.DeleteFlag = 0;
model.CreatorID = Information.User.ID;
model.Creator = Information.User.FullName;
model.CreationDate = PublicClass.DateTimeNow();
model.MeetingGUID = meetingGuid;
model.PhotoName = imageName;
model.PhotoData = Convert.FromBase64String(imageStr);
list.Add(model);
//初始化两个工厂
ClientFactory<T_Service_Meeting_ImageDTO> httpClient = new HttpClientFactory<T_Service_Meeting_ImageDTO>();
Client<T_Service_Meeting_ImageDTO> client = httpClient.VisitFactory();
#endregion
bool isTrue = client.Post(Url, list).Success;
//访问
return isTrue;
}
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;
case "删除图片":
DeleteImage();
break;
default:
break;
}
}
/// <summary>
/// 显示图片
/// </summary>
private void ShowImage()
{
try
{
if (grv_List.DataRowCount > 0)
{
int selectRow = grv_List.GetSelectedRows()[0];
long id = PublicClass.ToInt64(grv_List.GetRowCellValue(selectRow, "ID"), 0);
if (id > 0)
{
DataTable DetailDT = DBHelpClass.GetDataRow(string.Format("api/service/T_Service_Meeting_Image/{0}", id));
if (DetailDT != null && DetailDT.Rows.Count > 0)
{
//图片
#region 图片
string FileImage = PublicClass.ToString(DetailDT.Rows[0]["PhotoData"], "");
if (!string.IsNullOrEmpty(FileImage))
{
byte[] image = Convert.FromBase64String(FileImage);
Form_ImageShow frm = new 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>
private void DeleteImage()
{
try
{
if (grv_List.DataRowCount > 0)
{
int selectRow = grv_List.GetSelectedRows()[0];
long ID = PublicClass.ToInt64(grv_List.GetRowCellValue(selectRow, "ID"), 0);
if (ID == 0)
{
XtraMessageBox.Show("请先选择要删除的会议图片!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (XtraMessageBox.Show("确定要删除当前会议图片?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
List<T_Service_Meeting_ImageDTO> list = new List<T_Service_Meeting_ImageDTO>();
T_Service_Meeting_ImageDTO model = new T_Service_Meeting_ImageDTO();
string Url = "api/service/T_Service_Meeting_Image/LogicalDelete";
model.ID = ID;
model.DeleteFlag = 1;
model.EditorID = Information.User.ID;
model.Editor = Information.User.FullName;
model.EditTime = PublicClass.DateTimeNow();
list.Add(model);
//初始化两个工厂
ClientFactory<T_Service_Meeting_ImageDTO> httpClient = new HttpClientFactory<T_Service_Meeting_ImageDTO>();
Client<T_Service_Meeting_ImageDTO> client = httpClient.VisitFactory();
if (client.Post(Url, list).Success)
{
XtraMessageBox.Show("删除会议图片成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
//列表分页数据绑定
Bind_ImageList();
}
else
{
XtraMessageBox.Show("删除会议图片失败,请稍后重试!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "删除:\r\n" + ex);
}
}
}
}