434 lines
18 KiB
C#
434 lines
18 KiB
C#
using DevExpress.XtraEditors;
|
||
using HL_FristAidPlatform_DTO;
|
||
using HL_FristAidPlatform_Public;
|
||
using Microsoft.AspNetCore.SignalR.Client;
|
||
using Microsoft.IdentityModel.Protocols;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Configuration;
|
||
using System.Data;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
//using HL_FristAidPlatform_DynamicElectrocardiogram;
|
||
|
||
namespace HL_FristAidPlatform_MultiSystemPublic
|
||
{
|
||
public partial class Form_OneClickNotification : XtraForm
|
||
{
|
||
#region 变量
|
||
|
||
private string PatientId;
|
||
/// <summary>
|
||
/// 当前病人编号
|
||
/// </summary>
|
||
private string Cur_PatientGuid;
|
||
|
||
/// <summary>
|
||
/// 当前病人姓名
|
||
/// </summary>
|
||
private string Cur_PatientName = string.Empty;
|
||
|
||
/// <summary>
|
||
/// 当前病人性别
|
||
/// </summary>
|
||
private string Cur_PatientGender = string.Empty;
|
||
|
||
/// <summary>
|
||
/// 当前病人年龄
|
||
/// </summary>
|
||
private string Cur_PatientAge = string.Empty;
|
||
|
||
/// <summary>
|
||
/// 消息前缀
|
||
/// </summary>
|
||
private string NoticeTitle = string.Empty;
|
||
//定义一个连接对象
|
||
public HubConnection connection;
|
||
|
||
#endregion
|
||
|
||
|
||
//#region MultimediaManager
|
||
//private IMultimediaManager multimediaManager = MultimediaManagerFactory.GetSingleton();
|
||
//public IMultimediaManager MultimediaManager
|
||
//{
|
||
// get { return multimediaManager; }
|
||
//}
|
||
//#endregion
|
||
//#region RapidPassiveEngine
|
||
//private IRapidPassiveEngine rapidPassiveEngine = RapidEngineFactory.CreatePassiveEngine();
|
||
|
||
//public IRapidPassiveEngine RapidPassiveEngine
|
||
//{
|
||
// get { return rapidPassiveEngine; }
|
||
//}
|
||
//#endregion
|
||
|
||
//#region GroupOutter
|
||
//private DynamicGroupOutter groupOutter = new DynamicGroupOutter();
|
||
//public DynamicGroupOutter GroupOutter
|
||
//{
|
||
// get { return groupOutter; }
|
||
//}
|
||
//#endregion
|
||
|
||
//private CustomizeHandler customizeHandler;
|
||
/// <summary>
|
||
/// 一键通知
|
||
/// </summary>
|
||
/// <param name="_patientGuid">病人编号</param>
|
||
/// <param name="_patientName">病人姓名</param>
|
||
/// <param name="_patientGender">病人性别</param>
|
||
/// <param name="_patientAge">病人年龄</param>
|
||
public Form_OneClickNotification(string _patientGuid, string _patientName, string _patientGender, string _patientAge, string patientId)
|
||
{
|
||
InitializeComponent();
|
||
Cur_PatientGuid = _patientGuid;
|
||
Cur_PatientName = _patientName;
|
||
Cur_PatientGender = _patientGender;
|
||
Cur_PatientAge = _patientAge;
|
||
string gender = Cur_PatientGender == "1" ? "男" : "女";
|
||
NoticeTitle = Cur_PatientName + "," + gender + "," + Cur_PatientAge + "岁";
|
||
PatientId = patientId;
|
||
SignalRConnection();
|
||
}
|
||
public async void SignalRConnection()
|
||
{
|
||
connection = new HubConnectionBuilder().WithUrl(ConfigurationManager.AppSettings["WebApiUrl"] + "signalr/chatHub")
|
||
.Build();
|
||
await connection.StartAsync();
|
||
connection.Closed += async (error) =>
|
||
{
|
||
await Task.Delay(new Random().Next(0, 5) * 1000);
|
||
await connection.StartAsync();
|
||
};
|
||
}
|
||
/// <summary>
|
||
/// 窗体加载
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void Form_OneClickNotification_Load(object sender, EventArgs e)
|
||
{
|
||
BindData();
|
||
string id = Information.SystemModuleInfo.ID.ToString();
|
||
if (id == PublicClassForDataBase.Config10001)
|
||
txt_Notice.Text = "胸痛患者:" + NoticeTitle;
|
||
if (id == PublicClassForDataBase.Config10002)
|
||
txt_Notice.Text = "卒中患者:" + NoticeTitle;
|
||
if (id == PublicClassForDataBase.Config10003)
|
||
txt_Notice.Text = "创伤患者:" + NoticeTitle;
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 绑定数据
|
||
/// </summary>
|
||
public void BindData()
|
||
{
|
||
GetPatientInfo(Cur_PatientGuid);
|
||
BindNoticeType();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 绑定通知类型
|
||
/// </summary>
|
||
private void BindNoticeType()
|
||
{
|
||
try
|
||
{
|
||
DataTable ResultDT = DBHelpClass.Get("/api/base/T_Base_NoticeType/GetList?isUser=1");
|
||
PublicClass.SetLookUpList(ref LUEdit_NoticeType, ResultDT, 0, 2, true, "请选择");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
PublicClass.WriteErrorLog(this.Text, "绑定通知类型:\r\n" + ex);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取患者信息
|
||
/// </summary>
|
||
/// <param name="_patientGuid"></param>
|
||
private void GetPatientInfo(string _patientGuid)
|
||
{
|
||
try
|
||
{
|
||
string URL = string.Format("api/service/T_Service_Patient/GetModelByIdOrGuid?id={0}&guid={1}", 0, _patientGuid);
|
||
DataTable PatientDT = DBHelpClass.Get(URL);
|
||
if (PatientDT != null && PatientDT.Rows.Count > 0)
|
||
{
|
||
string EmergencyState = PublicClass.ToString(PatientDT.Rows[0]["EmergencyState"], "");
|
||
if (EmergencyState == "2")
|
||
{
|
||
lbl_Info.Visible = true;
|
||
LUEdit_NoticeType.ReadOnly = true;
|
||
txt_SelectUser.ReadOnly = true;
|
||
btn_SelUser.Enabled = false;
|
||
//ckb_IsSMS.ReadOnly = true;
|
||
//txt_NoticeSMS.ReadOnly = true;
|
||
txt_Notice.ReadOnly = true;
|
||
btn_Send.Enabled = false;
|
||
}
|
||
else
|
||
{
|
||
lbl_Info.Visible = false;
|
||
LUEdit_NoticeType.ReadOnly = false;
|
||
txt_SelectUser.ReadOnly = false;
|
||
btn_SelUser.Enabled = true;
|
||
//ckb_IsSMS.ReadOnly = false;
|
||
//txt_NoticeSMS.ReadOnly = false;
|
||
txt_Notice.ReadOnly = false;
|
||
btn_Send.Enabled = true;
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
PublicClass.WriteErrorLog(this.Text, "获取患者信息:\r\n" + ex);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 选择用户
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private async void btn_SelUser_Click(object sender, EventArgs e)
|
||
{
|
||
Form_SelectUser frm = new Form_SelectUser();
|
||
if (frm.ShowDialog() == DialogResult.OK)
|
||
{
|
||
txt_SelectUser.Tag = frm.SelUserIDS;
|
||
txt_SelectUser.Text = frm.SelUserNameS;
|
||
//string[] sUserName = txt_SelectUser.Text.ToString().Split(',');
|
||
////添加到指定的组
|
||
//foreach (var item in sUserName)
|
||
//{
|
||
// await connection.InvokeAsync("AddToGroup", "一键通知");
|
||
//}
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 选择短信内容
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void LUEdit_NoticeType_EditValueChanged(object sender, EventArgs e)
|
||
{
|
||
int TypeID = PublicClass.ToInt32(LUEdit_NoticeType.EditValue, 0);
|
||
DataTable DetailDT = DBHelpClass.GetDataRow(string.Format("/api/base/T_Base_NoticeType/{0}", TypeID));
|
||
if (DetailDT != null && DetailDT.Rows.Count > 0)
|
||
{
|
||
string Template = PublicClass.ToString(DetailDT.Rows[0]["Template"], "");
|
||
string Notice = string.Empty;
|
||
if (!string.IsNullOrEmpty(Template))
|
||
{
|
||
Notice = NoticeTitle + "," + Template;
|
||
}
|
||
else
|
||
{
|
||
Notice = NoticeTitle + ",请求" + LUEdit_NoticeType.Text.ToString();
|
||
}
|
||
string id = Information.SystemModuleInfo.ID.ToString();
|
||
if (id == PublicClassForDataBase.Config10001)
|
||
txt_Notice.Text = "胸痛患者:" + Notice;
|
||
if (id == PublicClassForDataBase.Config10002)
|
||
txt_Notice.Text = "卒中患者:" + Notice;
|
||
if (id == PublicClassForDataBase.Config10003)
|
||
txt_Notice.Text = "创伤患者:" + Notice;
|
||
if (id == PublicClassForDataBase.Config10004)
|
||
txt_Notice.Text = "危重孕产妇:" + Notice;
|
||
if (id == PublicClassForDataBase.Config10005)
|
||
txt_Notice.Text = "危重新生儿:" + Notice;
|
||
if (id == PublicClassForDataBase.Config10007)
|
||
txt_Notice.Text = "" + Notice;
|
||
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 发送通知
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private async void btn_Send_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
#region 发送通知
|
||
if (string.IsNullOrEmpty(txt_SelectUser.Text.ToString().Trim()))
|
||
{
|
||
XtraMessageBox.Show("请先选择要通知的用户!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||
btn_SelUser.Focus();
|
||
return;
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(txt_Notice.Text.ToString().Trim()))
|
||
{
|
||
XtraMessageBox.Show("请输入消息内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||
txt_Notice.Focus();
|
||
return;
|
||
}
|
||
//消息表
|
||
List<T_Service_NoticeDTO> listNotice = new List<T_Service_NoticeDTO>();
|
||
T_Service_NoticeDTO modelNotice = new T_Service_NoticeDTO();
|
||
modelNotice.GUID = Guid.NewGuid().ToString();
|
||
modelNotice.CreationDate = PublicClass.DateTimeNow();
|
||
modelNotice.CreatorID = Information.User.ID;
|
||
modelNotice.Creator = Information.User.FullName;
|
||
modelNotice.DeleteFlag = 0;
|
||
modelNotice.Content = txt_Notice.Text.ToString(); /*+ "|" + PatientId;*/
|
||
modelNotice.TypeID = PublicClass.ToInt32(LUEdit_NoticeType.EditValue, 0);
|
||
//modelNotice.IsSendSMS = ckb_IsSMS.Checked == true ? 0 : 1;
|
||
modelNotice.PatientGuid = Cur_PatientGuid;
|
||
listNotice.Add(modelNotice);
|
||
|
||
//初始化两个工厂
|
||
ClientFactory<T_Service_NoticeDTO> httpClient = new HttpClientFactory<T_Service_NoticeDTO>();
|
||
Client<T_Service_NoticeDTO> client = httpClient.VisitFactory();
|
||
|
||
//访问
|
||
ListEntity<T_Service_NoticeDTO> t = client.Post("api/service/T_Service_Notice/", listNotice);
|
||
if (t.Success)
|
||
{
|
||
XtraMessageBox.Show("通知发送成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
DialogResult = DialogResult.OK;
|
||
DataTable NoticeDT = DBHelpClass.JsonToDataRow(t.DataString);
|
||
long NoticeID = Convert.ToInt64(NoticeDT.Rows[0]["ID"].ToString());
|
||
long NoticeSMSID = 0;
|
||
|
||
|
||
|
||
|
||
#region 接收人
|
||
string[] sUserID = txt_SelectUser.Tag.ToString().Split(',');
|
||
foreach (string userid in sUserID)
|
||
{
|
||
|
||
//接收人表
|
||
List<T_Service_NoticeReceivingDTO> listNoticeReceiving = new List<T_Service_NoticeReceivingDTO>();
|
||
T_Service_NoticeReceivingDTO modelNoticeReceiving = new T_Service_NoticeReceivingDTO();
|
||
modelNoticeReceiving.GUID = Guid.NewGuid().ToString();
|
||
modelNoticeReceiving.UserID = Convert.ToInt64(userid);
|
||
modelNoticeReceiving.ReadState = 0;
|
||
modelNoticeReceiving.NoticeID = NoticeID;
|
||
modelNoticeReceiving.NoticeSMSID = NoticeSMSID;
|
||
listNoticeReceiving.Add(modelNoticeReceiving);
|
||
|
||
//初始化两个工厂
|
||
ClientFactory<T_Service_NoticeReceivingDTO> httpClient3 = new HttpClientFactory<T_Service_NoticeReceivingDTO>();
|
||
Client<T_Service_NoticeReceivingDTO> client3 = httpClient3.VisitFactory();
|
||
|
||
//访问
|
||
ListEntity<T_Service_NoticeReceivingDTO> t3 = client3.Post("api/service/T_Service_NoticeReceiving/", listNoticeReceiving);
|
||
//从客户端调用集线器方法 使用指定的方法名称和参数在服务器上调用中心方法
|
||
await connection.InvokeAsync("SendMessageToGroupAsync", modelNoticeReceiving.UserID.ToString(), txt_Notice.Text + "|" + PatientId);
|
||
}
|
||
//从客户端调用集线器方法 使用指定的方法名称和参数在服务器上调用中心方法
|
||
//await connection.InvokeAsync("WinFormsApp", Information.User.FullName, txt_Notice.Text);
|
||
|
||
//if (LUEdit_NoticeType.Text.Contains("远程会诊"))
|
||
//{
|
||
// customizeHandler = new CustomizeHandler();
|
||
// if (Login())
|
||
// {
|
||
|
||
// MainForm mainForm = new MainForm();
|
||
// //mainForm.Text = form.Text;
|
||
// mainForm.Show();
|
||
// mainForm.Initialize(RapidPassiveEngine, multimediaManager, GroupOutter, Information.User.ID.ToString(), PatientId);
|
||
// customizeHandler.Initialize(mainForm);
|
||
// }
|
||
//}
|
||
#endregion
|
||
|
||
//ClearText();
|
||
}
|
||
else
|
||
{
|
||
XtraMessageBox.Show("通知发送失败,请稍后重试!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
}
|
||
#endregion
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
PublicClass.WriteErrorLog(this.Text, "发送通知:\r\n" + ex);
|
||
}
|
||
}
|
||
|
||
//private bool Login()
|
||
//{
|
||
// //ESFramework 业务逻辑
|
||
// this.rapidPassiveEngine.WaitResponseTimeoutInSecs = 30;
|
||
// this.rapidPassiveEngine.HeartBeatSpanInSecs = 5;
|
||
// this.rapidPassiveEngine.SecurityLogEnabled = false;
|
||
|
||
// groupOutter.TryP2PWhenGroupmateConnected = false;
|
||
// groupOutter.RapidPassiveEngine = this.rapidPassiveEngine;
|
||
// DynamicGroupPassiveHandler groupPassiveHandler = new DynamicGroupPassiveHandler();
|
||
// groupPassiveHandler.Initialize(groupOutter);
|
||
|
||
// NDiskPassiveHandler nDiskPassiveHandler = new NDiskPassiveHandler();
|
||
|
||
// ComplexCustomizeHandler handler = new ComplexCustomizeHandler(this.customizeHandler, groupPassiveHandler, nDiskPassiveHandler);
|
||
// LogonResponse result = this.rapidPassiveEngine.Initialize(Information.User.ID.ToString(), "", ConfigurationManager.AppSettings["ServerIP"], int.Parse(ConfigurationManager.AppSettings["ServerPort"]), handler);
|
||
|
||
// if (result.LogonResult != LogonResult.Succeed)
|
||
// {
|
||
// if (result.LogonResult == LogonResult.HadLoggedOn)
|
||
// {
|
||
// MessageBox.Show("已经在其它地方登录!");
|
||
// }
|
||
// else
|
||
// {
|
||
// MessageBox.Show("用户或者密码错误!");
|
||
// }
|
||
// return false;
|
||
// }
|
||
|
||
// groupOutter.Initialize(this.rapidPassiveEngine.CurrentUserID);
|
||
// nDiskPassiveHandler.Initialize(this.rapidPassiveEngine.FileOutter, null);
|
||
|
||
// //OMCS 语音视频 参数设置
|
||
// multimediaManager.AutoReconnect = false;
|
||
// multimediaManager.SecurityLogEnabled = true;
|
||
// multimediaManager.AutoAdjustCameraEncodeQuality = false;
|
||
// multimediaManager.MicrophoneDeviceIndex = 0;
|
||
// multimediaManager.CameraDeviceIndex = 0;
|
||
// multimediaManager.CameraEncodeQuality = 8;
|
||
// multimediaManager.MaxCameraFrameRate = 12;
|
||
// multimediaManager.DesktopEncodeQuality = 3;
|
||
// multimediaManager.MaxDesktopFrameRate = 12;
|
||
// multimediaManager.Advanced.AllowDiscardFrameWhenBroadcast = true;
|
||
// multimediaManager.Advanced.MaxInterval4CameraKeyFrame = 20;
|
||
// multimediaManager.Advanced.MaxInterval4DesktopKeyFrame = 20;
|
||
|
||
// //try
|
||
// //{
|
||
// string[] cameraSizeStr = ConfigurationManager.AppSettings["CameraVideoSize"].Split(',');
|
||
// multimediaManager.CameraVideoSize = new System.Drawing.Size(int.Parse(cameraSizeStr[0]), int.Parse(cameraSizeStr[1]));
|
||
// //}
|
||
// //catch { }
|
||
|
||
// multimediaManager.Initialize(Information.User.ID.ToString(), "", ConfigurationManager.AppSettings["ServerIP"], int.Parse(ConfigurationManager.AppSettings["OmcsPort"]));
|
||
// multimediaManager.OutputAudio = true;
|
||
|
||
// return true;
|
||
//}
|
||
|
||
/// <summary>
|
||
/// 清除
|
||
/// </summary>
|
||
private void ClearText()
|
||
{
|
||
txt_SelectUser.Tag = "";
|
||
txt_SelectUser.Text = "";
|
||
txt_Notice.Text = "";
|
||
//txt_NoticeSMS.Text = "";
|
||
}
|
||
}
|
||
}
|