From 85131b43d236f5ae36f4aba3e286478ad1c5eef8 Mon Sep 17 00:00:00 2001 From: leomon Date: Wed, 7 Jun 2023 18:11:03 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=91=E8=A7=86=E9=87=87=E9=9B=86=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AIMS/FormLogin.cs | 2 + .../frmAanesthesiaPainlessRecord.cs | 5 +- .../frmAanesthesiaRecord.Designer.cs | 14 ++++ .../frmAanesthesiaRecord.cs | 22 +++++- .../frmAanesthesiaRecover.cs | 3 + .../frmSelectPatientNew2.cs | 10 ++- AIMS/Program.cs | 68 ++++++++++++++----- AIMSExtension/PublicMethod.cs | 43 ++++++++++++ 8 files changed, 146 insertions(+), 21 deletions(-) diff --git a/AIMS/FormLogin.cs b/AIMS/FormLogin.cs index 9dc6701..067ac46 100644 --- a/AIMS/FormLogin.cs +++ b/AIMS/FormLogin.cs @@ -81,6 +81,8 @@ namespace AIMS PublicMethod.LastOperationSite = list[0]; } PublicMethod.WriteLog("登录", PersonObj.Id.Value); + + PublicMethod.StartCollectorDataProgram(); Hide(); //在这里为编辑器注册 new System.Threading.Thread(Reg).Start(); diff --git a/AIMS/OperationAanesthesia/frmAanesthesiaPainlessRecord.cs b/AIMS/OperationAanesthesia/frmAanesthesiaPainlessRecord.cs index d255151..39582c8 100644 --- a/AIMS/OperationAanesthesia/frmAanesthesiaPainlessRecord.cs +++ b/AIMS/OperationAanesthesia/frmAanesthesiaPainlessRecord.cs @@ -1378,7 +1378,8 @@ namespace AIMS.OperationAanesthesia if (LastMonitorDataTime != null && LastMonitorDataTime.Value.ToString("yyyy-MM-dd HH:mm") == dtTime.ToString("yyyy-MM-dd HH:mm")) return; if (LastMonitorDataTime != null && LastMonitorDataTime.Value > dtTime) return; try - { + { + PublicMethod.StartCollectorDataProgram(); LastMonitorDataTime = dtTime; DateTime InsertTime = Convert.ToDateTime(dtTime.ToString("yyyy-MM-dd HH:mm:00.000")); int date = 0; @@ -1636,6 +1637,8 @@ namespace AIMS.OperationAanesthesia timerGetTextCollectorData.Tick -= new System.EventHandler(timerGetTextCollectorData_Tick); timerGetTextCollectorData.Tick += new System.EventHandler(timerGetTextCollectorData_Tick); timerGetTextCollectorData.Start(); + + PublicMethod.StartCollectorDataProgram(); } private void DisposeTimer() diff --git a/AIMS/OperationAanesthesia/frmAanesthesiaRecord.Designer.cs b/AIMS/OperationAanesthesia/frmAanesthesiaRecord.Designer.cs index 73062be..2163e60 100644 --- a/AIMS/OperationAanesthesia/frmAanesthesiaRecord.Designer.cs +++ b/AIMS/OperationAanesthesia/frmAanesthesiaRecord.Designer.cs @@ -96,6 +96,7 @@ this.plPrint = new System.Windows.Forms.Panel(); this.plRefresh = new System.Windows.Forms.Panel(); this.lblRoom = new System.Windows.Forms.Label(); + this.label11 = new System.Windows.Forms.Label(); this.label22 = new System.Windows.Forms.Label(); this.labOperatorName = new System.Windows.Forms.Label(); this.label19 = new System.Windows.Forms.Label(); @@ -1083,6 +1084,7 @@ this.panel7.BackColor = System.Drawing.SystemColors.Control; this.panel7.Controls.Add(this.panel21); this.panel7.Controls.Add(this.lblRoom); + this.panel7.Controls.Add(this.label11); this.panel7.Controls.Add(this.label22); this.panel7.Controls.Add(this.labOperatorName); this.panel7.Controls.Add(this.label19); @@ -1218,6 +1220,17 @@ this.lblRoom.TabIndex = 9; this.lblRoom.Text = " "; // + // label11 + // + this.label11.AutoSize = true; + this.label11.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.label11.Location = new System.Drawing.Point(448, 8); + this.label11.Name = "label11"; + this.label11.Size = new System.Drawing.Size(0, 20); + this.label11.TabIndex = 8; + this.toolTip1.SetToolTip(this.label11, "点击重新启动采集程序"); + this.label11.Click += new System.EventHandler(this.label11_Click); + // // label22 // this.label22.AutoSize = true; @@ -2174,5 +2187,6 @@ private System.Windows.Forms.ComboBox cmbBGType; private System.Windows.Forms.Panel PanelSave; private System.Windows.Forms.Panel paneltop; + private System.Windows.Forms.Label label11; } } \ No newline at end of file diff --git a/AIMS/OperationAanesthesia/frmAanesthesiaRecord.cs b/AIMS/OperationAanesthesia/frmAanesthesiaRecord.cs index 38b52be..d8f6b95 100644 --- a/AIMS/OperationAanesthesia/frmAanesthesiaRecord.cs +++ b/AIMS/OperationAanesthesia/frmAanesthesiaRecord.cs @@ -13,8 +13,10 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; +using System.Diagnostics; using System.Drawing; using System.Drawing.Printing; +using System.IO; using System.Linq; using System.Windows.Forms; @@ -1494,8 +1496,10 @@ namespace AIMS.OperationAanesthesia return; if (LastMonitorDataTime != null && LastMonitorDataTime.Value.ToString("yyyy-MM-dd HH:mm") == dtTime.ToString("yyyy-MM-dd HH:mm")) return; if (LastMonitorDataTime != null && LastMonitorDataTime.Value > dtTime) return; + try { + PublicMethod.StartCollectorDataProgram(); LastMonitorDataTime = dtTime; DateTime InsertTime = Convert.ToDateTime(dtTime.ToString("yyyy-MM-dd HH:mm:00.000")); int date = 0; @@ -1612,7 +1616,9 @@ namespace AIMS.OperationAanesthesia if (((TimeSpan)(DateTime.Now - _record.lastPageBegin)).TotalHours > 24 || NowRoom == null) return; timerGetCollectorData_Tick(); if (State != AIMSExtension.EditState.BROWSE) + { ShowMonitorDataToRight(); + } } catch (Exception) { @@ -1643,7 +1649,7 @@ namespace AIMS.OperationAanesthesia { DeviceCacheData deviceCacheData = lists[0]; NowPhysioData nowPhysioData = JsonConvert.DeserializeObject(deviceCacheData.JsonData); - + label11.Text = "最后采集时间:" + deviceCacheData.UpdateTime; if (nowPhysioData.HR != null && nowPhysioData.HR.ToString() != string.Empty && nowPhysioData.HR.ToString() != "NaN" && nowPhysioData.HR.ToString() != "NULL") { double value = Double.Parse(nowPhysioData.HR.ToString()); @@ -1691,6 +1697,7 @@ namespace AIMS.OperationAanesthesia } else { + label11.Text = "当前无采集数据"; lblHR.Text = "--"; lblRESP.Text = "--"; lblSpo2.Text = "--"; @@ -1753,6 +1760,8 @@ namespace AIMS.OperationAanesthesia timerGetTextCollectorData.Tick -= new System.EventHandler(timerGetTextCollectorData_Tick); timerGetTextCollectorData.Tick += new System.EventHandler(timerGetTextCollectorData_Tick); timerGetTextCollectorData.Start(); + + PublicMethod.StartCollectorDataProgram(); } private void DisposeTimer() @@ -2403,6 +2412,8 @@ namespace AIMS.OperationAanesthesia ClearTimeText(); //关闭采集的服务 DisposeTimer(); + + label11.Text = ""; lblHR.Text = "--"; lblRESP.Text = "--"; lblSpo2.Text = "--"; @@ -2560,5 +2571,14 @@ namespace AIMS.OperationAanesthesia } } #endregion + + private void label11_Click(object sender, EventArgs e) + { + DialogResult dialog = MessageBox.Show("是否重启采集程序!", "系统提示", MessageBoxButtons.YesNo); + if (dialog == DialogResult.Yes) + { + PublicMethod.StartCollectorDataProgram(true); + } + } } } diff --git a/AIMS/OperationAanesthesia/frmAanesthesiaRecover.cs b/AIMS/OperationAanesthesia/frmAanesthesiaRecover.cs index 387f74d..639cb4e 100644 --- a/AIMS/OperationAanesthesia/frmAanesthesiaRecover.cs +++ b/AIMS/OperationAanesthesia/frmAanesthesiaRecover.cs @@ -1002,6 +1002,7 @@ namespace AIMS.OperationAanesthesia // return; //} + PublicMethod.StartCollectorDataProgram(); LastMonitorDataTime = dtTime; DateTime InsertTime = Convert.ToDateTime(dtTime.ToString("yyyy-MM-dd HH:mm:00.000")); int date = 0; @@ -1231,6 +1232,8 @@ namespace AIMS.OperationAanesthesia timerGetTextCollectorData.Tick -= new System.EventHandler(timerGetTextCollectorData_Tick); timerGetTextCollectorData.Tick += new System.EventHandler(timerGetTextCollectorData_Tick); timerGetTextCollectorData.Start(); + + PublicMethod.StartCollectorDataProgram(); } private void DisposeTimer() diff --git a/AIMS/OperationAanesthesia/frmSelectPatientNew2.cs b/AIMS/OperationAanesthesia/frmSelectPatientNew2.cs index 26fea0c..4ce14f2 100644 --- a/AIMS/OperationAanesthesia/frmSelectPatientNew2.cs +++ b/AIMS/OperationAanesthesia/frmSelectPatientNew2.cs @@ -345,7 +345,15 @@ namespace AIMS.OperationAanesthesia if (isMainOpen == false) { - frmAnasRecord.ShowDialog(); + if (frmAnasRecord.State == AIMSExtension.EditState.BROWSE) + { + frmAnasRecord.Show(); + frmAnasRecord.BringToFront(); + frmAnasRecord.TopMost = true; + } + else + frmAnasRecord.ShowDialog(); + FillDgv(); } else diff --git a/AIMS/Program.cs b/AIMS/Program.cs index 4ad07a0..6fe2aa8 100644 --- a/AIMS/Program.cs +++ b/AIMS/Program.cs @@ -22,26 +22,57 @@ namespace AIMS [STAThread] static void Main(string[] args) { - if (PublicMethod.FindProcess("AIMSAutoUpdate")) - { - return; - } - BindExceptionHandler(); + /** + * 当前用户是管理员的时候,直接启动应用程序 + * 如果不是管理员,则使用启动对象启动程序,以确保使用管理员身份运行 + */ + //获得当前登录的Windows用户标示 + System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent(); + //创建Windows用户主题 Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - //Process instance = RunningInstance(); - //if (instance == null) - //{ - UpdateProgram(args); - Task.Factory.StartNew(() => { PreLoad(); }); - Application.Run(new FormLogin()); - //} - //else - //{ - // /*1.2 已经有一个实例在运行*/ - // HandleRunningInstance(instance); - //} + System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity); + //判断当前登录用户是否为管理员 + if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator)) + { + //如果是管理员,则直接运行 + + if (PublicMethod.FindProcess("AIMSAutoUpdate")) + { + return; + } + BindExceptionHandler(); + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + + //Process instance = RunningInstance(); + //if (instance == null) + //{ + UpdateProgram(args); + Task.Factory.StartNew(() => { PreLoad(); }); + Application.Run(new FormLogin()); + //} + //else + //{ + // /*1.2 已经有一个实例在运行*/ + // HandleRunningInstance(instance); + //} + } + else + { + //创建启动对象 + System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); + //设置运行文件 + startInfo.FileName = System.Windows.Forms.Application.ExecutablePath; + //设置启动参数 + startInfo.Arguments = String.Join(" ", args); + //设置启动动作,确保以管理员身份运行 + startInfo.Verb = "runas"; + //如果不是管理员,则启动UAC + System.Diagnostics.Process.Start(startInfo); + //退出 + System.Windows.Forms.Application.Exit(); + } } static void PreLoad() { @@ -175,5 +206,6 @@ namespace AIMS [DllImport("User32.dll")] private static extern bool SetForegroundWindow(System.IntPtr hWnd); #endregion + } } diff --git a/AIMSExtension/PublicMethod.cs b/AIMSExtension/PublicMethod.cs index 28ed34e..07ee14d 100644 --- a/AIMSExtension/PublicMethod.cs +++ b/AIMSExtension/PublicMethod.cs @@ -2,8 +2,10 @@ using System; using System.Collections.Generic; using System.Data; +using System.Diagnostics; using System.IO; using System.Net; +using System.Reflection.Emit; using System.Runtime.InteropServices; using System.Security.Cryptography; using System.Text; @@ -608,5 +610,46 @@ namespace AIMSExtension //错误 return false; } + + + public static void StartCollectorDataProgram(bool isKill = false) + { + try + { + //判断监护仪程序是否存在进程 + //没有的话重新启动 + //判断文件是否存在 + if (isKill == true) + { + System.Diagnostics.Process[] myProcesses = System.Diagnostics.Process.GetProcesses(); + foreach (System.Diagnostics.Process myProcess in myProcesses) + { + if (myProcess.ProcessName == "DataCollector2") + { + myProcess.CloseMainWindow(); + myProcess.Kill(); + myProcess.WaitForExit(); + myProcess.Close(); + continue; + } + } + } + if (Directory.Exists(@"C:\采集程序")) + { + if (!PublicMethod.FindProcess("DataCollector2")) + { + Process myprocess = new Process(); + ProcessStartInfo startInfo = new ProcessStartInfo(@"C:\采集程序\DataCollector.exe"); + myprocess.StartInfo = startInfo; + myprocess.StartInfo.UseShellExecute = false; + myprocess.Start(); + } + } + } + catch (Exception ex) + { + PublicMethod.WriteLog(ex); + } + } } }