510 lines
21 KiB
C#
510 lines
21 KiB
C#
using AIMSBLL;
|
||
using AIMSExtension;
|
||
using AIMSModel;
|
||
using DevComponents.DotNetBar.Controls;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Drawing;
|
||
using System.Drawing.Drawing2D;
|
||
using System.Linq;
|
||
using System.Net;
|
||
using System.Reflection;
|
||
using System.Text;
|
||
using System.Windows.Forms;
|
||
|
||
namespace AIMS
|
||
{
|
||
public static class ControlExtension
|
||
{
|
||
/// <summary>
|
||
/// 用药途径集合
|
||
/// </summary>
|
||
public static List<BasicDictionary> _channelList;
|
||
/// <summary>
|
||
/// 剂量单位集合
|
||
/// </summary>
|
||
public static List<BasicDictionary> _dUnitList;
|
||
/// <summary>
|
||
/// 速度单位集合
|
||
/// </summary>
|
||
public static List<BasicDictionary> _VelocityUnit;
|
||
/// <summary>
|
||
/// 浓度单位集合
|
||
/// </summary>
|
||
public static List<BasicDictionary> _DensityUnit;
|
||
/// <summary>
|
||
/// 加药方式集合
|
||
/// </summary>
|
||
public static List<BasicDictionary> _drugEffectList;
|
||
/// <summary>
|
||
///血型集合
|
||
/// </summary>
|
||
public static List<BasicDictionary> _bloodTypeList;
|
||
|
||
const float cos30 = 0.866f;
|
||
const float sin30 = 0.5f;
|
||
public static void BindWaterMark(this Control ctrl, string Text)
|
||
{
|
||
if (ctrl == null || ctrl.IsDisposed)
|
||
return;
|
||
// 绘制水印
|
||
if (ctrl.HaveEventHandler("Paint", "BindWaterMark"))
|
||
return;
|
||
ctrl.Paint += (sender, e) =>
|
||
{
|
||
System.Windows.Forms.Control paintCtrl = sender as System.Windows.Forms.Control;
|
||
var g = e.Graphics;
|
||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
|
||
|
||
// 计算控件位置
|
||
int offsetX = 0;
|
||
int offsetY = 0;
|
||
while (paintCtrl.Parent != null)
|
||
{
|
||
offsetX += paintCtrl.Location.X;
|
||
offsetY += paintCtrl.Location.Y;
|
||
paintCtrl = paintCtrl.Parent;
|
||
}
|
||
|
||
// 平移画布到窗体左上角
|
||
g.TranslateTransform(0 - offsetX, 0 - offsetY + 32);
|
||
|
||
//逆时针旋转30度
|
||
g.RotateTransform(-30);
|
||
|
||
for (int x = 0; x < e.ClipRectangle.Right + 64 + offsetX; x += 128)
|
||
{
|
||
for (int y = 0; y < e.ClipRectangle.Bottom + 64 + offsetY; y += 128)
|
||
{
|
||
// 计算文字起点位置
|
||
float x1 = cos30 * x - sin30 * y;
|
||
float y1 = sin30 * x + cos30 * y;
|
||
|
||
//画上文字
|
||
g.DrawString(Text, new Font("微软雅黑", 14, FontStyle.Regular),
|
||
new SolidBrush(Color.FromArgb(50, 100, 100, 100)), x1, y1);
|
||
}
|
||
}
|
||
};
|
||
// 子控件绑定绘制事件
|
||
foreach (System.Windows.Forms.Control child in ctrl.Controls)
|
||
BindWaterMark(child, Text);
|
||
}
|
||
public static void BindWaterMark2(this Control ctrl, string Text, int x, int y, Color color)
|
||
{
|
||
if (ctrl == null || ctrl.IsDisposed)
|
||
return;
|
||
// 绘制水印
|
||
if (ctrl.HaveEventHandler("Paint", "BindWaterMark"))
|
||
return;
|
||
ctrl.Paint += (sender, e) =>
|
||
{
|
||
System.Windows.Forms.Control paintCtrl = sender as System.Windows.Forms.Control;
|
||
var g = e.Graphics;
|
||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
|
||
|
||
|
||
g.DrawString(Text, new Font("微软雅黑", 23, FontStyle.Regular),
|
||
new SolidBrush(color), x, y);
|
||
};
|
||
//// 子控件绑定绘制事件
|
||
//foreach (System.Windows.Forms.Control child in ctrl.Controls)
|
||
// BindWaterMark2(child, Text);
|
||
}
|
||
public static void BindWaterMark(this Control ctrl, string Text, float x1, float y1)
|
||
{
|
||
if (ctrl == null || ctrl.IsDisposed)
|
||
return;
|
||
// 绘制水印
|
||
if (ctrl.HaveEventHandler("Paint", "BindWaterMark"))
|
||
return;
|
||
ctrl.Paint += (sender, e) =>
|
||
{
|
||
System.Windows.Forms.Control paintCtrl = sender as System.Windows.Forms.Control;
|
||
var g = e.Graphics;
|
||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
|
||
|
||
//// 计算控件位置
|
||
//int offsetX = 0;
|
||
//int offsetY = 0;
|
||
//while (paintCtrl.Parent != null)
|
||
//{
|
||
// offsetX += paintCtrl.Location.X;
|
||
// offsetY += paintCtrl.Location.Y;
|
||
// paintCtrl = paintCtrl.Parent;
|
||
//}
|
||
|
||
//// 平移画布到窗体左上角
|
||
//g.TranslateTransform(0 - offsetX, 0 - offsetY + 32);
|
||
|
||
//逆时针旋转30度
|
||
//g.RotateTransform(-30);
|
||
|
||
//画上文字
|
||
g.DrawString(Text, new Font("微软雅黑", 20, FontStyle.Regular),
|
||
new SolidBrush(Color.FromArgb(50, 100, 100, 100)), x1, y1);
|
||
};
|
||
// 子控件绑定绘制事件
|
||
foreach (System.Windows.Forms.Control child in ctrl.Controls)
|
||
BindWaterMark(child, Text, x1, y1);
|
||
}
|
||
|
||
public static bool HaveEventHandler(this Control control, string eventName, string methodName)
|
||
{
|
||
//获取Control类定义的所有事件的信息
|
||
PropertyInfo pi = (control.GetType()).GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);
|
||
//获取Control对象control的事件处理程序列表
|
||
EventHandlerList ehl = (EventHandlerList)pi.GetValue(control, null);
|
||
|
||
//获取Control类 eventName 事件的字段信息
|
||
FieldInfo fieldInfo = (typeof(Control)).GetField(string.Format("Event{0}", eventName), BindingFlags.Static | BindingFlags.NonPublic);
|
||
//用获取的 eventName 事件的字段信息,去匹配 control 对象的事件处理程序列表,获取control对象 eventName 事件的委托对象
|
||
//事件使用委托定义的,C#中的委托时多播委托,可以绑定多个事件处理程序,当事件发生时,这些事件处理程序被依次执行
|
||
//因此Delegate对象,有一个GetInvocationList方法,用来获取这个委托已经绑定的所有事件处理程序
|
||
Delegate d = ehl[fieldInfo.GetValue(null)];
|
||
|
||
if (d == null)
|
||
return false;
|
||
|
||
foreach (Delegate del in d.GetInvocationList())
|
||
{
|
||
string anonymous = string.Format("<{0}>", methodName);
|
||
//判断一下某个事件处理程序是否已经被绑定到 eventName 事件上
|
||
if (del.Method.Name == methodName || del.Method.Name.StartsWith(anonymous))
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
public static bool ValidDataGridViewExistsItemName(System.Windows.Forms.DataGridView dgv, string ColumeName, string name)
|
||
{
|
||
bool result = false;
|
||
foreach (System.Windows.Forms.DataGridViewRow dataGridViewRow in ((System.Collections.IEnumerable)dgv.Rows))
|
||
{
|
||
if (dataGridViewRow.Cells[ColumeName].Value.ToString().Equals(name))
|
||
{
|
||
result = true;
|
||
break;
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
|
||
public static void SetDgvAttribute(System.Windows.Forms.DataGridView dgv)
|
||
{
|
||
dgv.AllowUserToResizeColumns = false;
|
||
dgv.AllowUserToResizeRows = false;
|
||
dgv.AllowUserToAddRows = false;
|
||
dgv.AllowUserToDeleteRows = false;
|
||
dgv.ReadOnly = true;
|
||
dgv.BackgroundColor = System.Drawing.Color.Snow;
|
||
|
||
}
|
||
public static void EnabledControl(System.Windows.Forms.Control ctCtrl, bool IsEnabled)
|
||
{
|
||
foreach (System.Windows.Forms.Control control in ctCtrl.Controls)
|
||
{
|
||
if (control.Controls.Count > 0)
|
||
{
|
||
if (control.Enabled)
|
||
{
|
||
EnabledControl(control, IsEnabled);
|
||
}
|
||
}
|
||
else if (control is System.Windows.Forms.TextBox)
|
||
{
|
||
(control as System.Windows.Forms.TextBox).Enabled = IsEnabled;
|
||
}
|
||
else if (control is System.Windows.Forms.ComboBox)
|
||
{
|
||
(control as System.Windows.Forms.ComboBox).Enabled = IsEnabled;
|
||
}
|
||
else if (control is System.Windows.Forms.RichTextBox)
|
||
{
|
||
(control as System.Windows.Forms.RichTextBox).Enabled = IsEnabled;
|
||
}
|
||
else if (control is System.Windows.Forms.DateTimePicker)
|
||
{
|
||
(control as System.Windows.Forms.DateTimePicker).Enabled = IsEnabled;
|
||
}
|
||
else if (control is System.Windows.Forms.ListBox)
|
||
{
|
||
(control as System.Windows.Forms.ListBox).Enabled = IsEnabled;
|
||
}
|
||
else if (control is System.Windows.Forms.RadioButton)
|
||
{
|
||
(control as System.Windows.Forms.RadioButton).Enabled = IsEnabled;
|
||
}
|
||
else if (control is System.Windows.Forms.CheckBox)
|
||
{
|
||
(control as System.Windows.Forms.CheckBox).Enabled = IsEnabled;
|
||
}
|
||
else if (control is DevComponents.Editors.IntegerInput)
|
||
{
|
||
(control as DevComponents.Editors.IntegerInput).Enabled = IsEnabled;
|
||
}
|
||
else if (control is DevComponents.Editors.DateTimeAdv.DateTimeInput)
|
||
{
|
||
(control as DevComponents.Editors.DateTimeAdv.DateTimeInput).Enabled = IsEnabled;
|
||
}
|
||
|
||
|
||
}
|
||
}
|
||
|
||
public static void ClearControl(System.Windows.Forms.Control ctCtrl)
|
||
{
|
||
foreach (System.Windows.Forms.Control control in ctCtrl.Controls)
|
||
{
|
||
if (control.Controls.Count > 0)
|
||
{
|
||
if (control.Enabled)
|
||
{
|
||
ClearControl(control);
|
||
}
|
||
}
|
||
else if (control is System.Windows.Forms.TextBox)
|
||
{
|
||
if (!((control as System.Windows.Forms.TextBox).Name == "txtAnaesAutograph") && !((control as System.Windows.Forms.TextBox).Name == "txtOperAutograph") && !((control as System.Windows.Forms.TextBox).Name == "txtNurseAutograph"))
|
||
{
|
||
(control as System.Windows.Forms.TextBox).Text = "";
|
||
}
|
||
}
|
||
//else if (control is System.Windows.Forms.ComboBox)
|
||
//{
|
||
// (control as System.Windows.Forms.ComboBox).SelectedIndex = -1;
|
||
//}
|
||
else if (control is System.Windows.Forms.RichTextBox)
|
||
{
|
||
(control as System.Windows.Forms.RichTextBox).Text = "";
|
||
}
|
||
else if (control is System.Windows.Forms.DateTimePicker)
|
||
{
|
||
(control as System.Windows.Forms.DateTimePicker).Text = HelperDB.DbHelperSQL.SystemDate().ToString();
|
||
}
|
||
else if (control is System.Windows.Forms.ListBox)
|
||
{
|
||
(control as System.Windows.Forms.ListBox).Items.Clear();
|
||
}
|
||
else if (control is System.Windows.Forms.RadioButton)
|
||
{
|
||
(control as System.Windows.Forms.RadioButton).Checked = false;
|
||
}
|
||
else if (control is System.Windows.Forms.CheckBox)
|
||
{
|
||
(control as System.Windows.Forms.CheckBox).Checked = false;
|
||
}
|
||
else if (control is DevComponents.Editors.IntegerInput)
|
||
{
|
||
(control as DevComponents.Editors.IntegerInput).Text = "0";
|
||
}
|
||
else if (control is DevComponents.Editors.DateTimeAdv.DateTimeInput)
|
||
{
|
||
(control as DevComponents.Editors.DateTimeAdv.DateTimeInput).Text = "";
|
||
}
|
||
else if (control is System.Windows.Forms.PictureBox)
|
||
{
|
||
(control as System.Windows.Forms.PictureBox).Image = null;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
public static void GetOperationSite(Label labelSite, ComboBoxEx comboBoxEx)
|
||
{
|
||
if (PublicMethod.OperationSite.Count <= 2)
|
||
{
|
||
labelSite.Visible = false;
|
||
comboBoxEx.Visible = false;
|
||
}
|
||
else
|
||
{
|
||
labelSite.Visible = true;
|
||
comboBoxEx.Visible = true;
|
||
comboBoxEx.DataSource = PublicMethod.OperationSite;
|
||
if (PublicMethod.LastOperationSite != null && PublicMethod.LastOperationSite != "")
|
||
{
|
||
comboBoxEx.Text = PublicMethod.LastOperationSite;
|
||
}
|
||
}
|
||
}
|
||
public static List<OperationRoom> SiteRooms;
|
||
public static void GetOperationSiteRoom(Label labelSite, ComboBoxEx comboBoxEx, ComboBox cboRoom, string DefaultSite = "")
|
||
{
|
||
if (PublicMethod.OperationSite.Count <= 2)
|
||
{
|
||
labelSite.Visible = false;
|
||
comboBoxEx.Visible = false;
|
||
}
|
||
else
|
||
{
|
||
labelSite.Visible = true;
|
||
comboBoxEx.Visible = true;
|
||
comboBoxEx.DataSource = PublicMethod.OperationSite;
|
||
if (PublicMethod.LastOperationSite != null && PublicMethod.LastOperationSite != "")
|
||
{
|
||
comboBoxEx.Text = PublicMethod.LastOperationSite;
|
||
}
|
||
if (DefaultSite != "")
|
||
{
|
||
comboBoxEx.Text = DefaultSite;
|
||
}
|
||
}
|
||
if (comboBoxEx.Visible == false || comboBoxEx.Text == "")
|
||
{
|
||
SiteRooms = BOperationRoom.GetOperationRooms("IsValid=1 and Site<>'恢复室'");
|
||
SiteRooms.Insert(0, new OperationRoom() { Id = -1, Name = "" });
|
||
}
|
||
else
|
||
{
|
||
SiteRooms = BOperationRoom.GetOperationRooms("IsValid=1 and Site='" + comboBoxEx.Text + "'");
|
||
SiteRooms.Insert(0, new OperationRoom() { Id = -1, Name = "" });
|
||
}
|
||
|
||
if (cboRoom != null)
|
||
{
|
||
cboRoom.DataSource = SiteRooms;
|
||
cboRoom.DisplayMember = "Name";
|
||
cboRoom.ValueMember = "Id";
|
||
//判断如果当前手术间编号不为空,则显示当前手术间
|
||
OperationRoom oprm = GetOperationRoom(SiteRooms);
|
||
if (oprm != null && oprm.Id.Value > 0)
|
||
{
|
||
cboRoom.SelectedValue = oprm.Id.Value;
|
||
cboRoom.Text = oprm.Name.ToString();
|
||
}
|
||
if (cboRoom.Text == "" && PublicMethod.SelectRoom != 0)
|
||
{
|
||
cboRoom.SelectedValue = PublicMethod.SelectRoom;
|
||
}
|
||
}
|
||
}
|
||
|
||
public static OperationRoom GetOperationRoom(List<OperationRoom> list)
|
||
{
|
||
try
|
||
{
|
||
//得到计算机名
|
||
string strPcName = Dns.GetHostName();
|
||
//得到本机IP地址数组
|
||
IPHostEntry ipEntry = Dns.GetHostEntry(strPcName);
|
||
//遍历数组
|
||
foreach (OperationRoom room in list)
|
||
{
|
||
foreach (var IPadd in ipEntry.AddressList)
|
||
{
|
||
//判断当前字符串是否为正确IP地址
|
||
if (PublicMethod.IsRightIP(IPadd.ToString()))
|
||
{
|
||
if (room.Ip == IPadd.ToString() || room.Ip2 == IPadd.ToString() || room.Ip3 == IPadd.ToString())
|
||
{
|
||
return room;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return null;
|
||
}
|
||
catch (Exception)
|
||
{
|
||
return null;
|
||
}
|
||
}
|
||
|
||
|
||
public static void SetOperationSite(ComboBoxEx comboBoxEx)
|
||
{
|
||
if (comboBoxEx.Text != PublicMethod.LastOperationSite)
|
||
{
|
||
PublicMethod.LastOperationSite = comboBoxEx.Text;
|
||
List<string> list = PublicMethod.xmlUse.GetNode("LastOperationSite");
|
||
if (list != null && list.Count > 0)
|
||
{
|
||
PublicMethod.xmlUse.SetNode("LastOperationSite", PublicMethod.LastOperationSite);
|
||
}
|
||
}
|
||
}
|
||
public static void SetOperationSiteRoom(ComboBoxEx comboBoxEx, ComboBox cboRoom)
|
||
{
|
||
if (comboBoxEx.Text != PublicMethod.LastOperationSite)
|
||
{
|
||
PublicMethod.LastOperationSite = comboBoxEx.Text;
|
||
PublicMethod.SelectRoom = 0;
|
||
List<string> list = PublicMethod.xmlUse.GetNode("LastOperationSite");
|
||
if (list != null && list.Count > 0)
|
||
{
|
||
PublicMethod.xmlUse.SetNode("LastOperationSite", PublicMethod.LastOperationSite);
|
||
}
|
||
}
|
||
if (comboBoxEx.Visible == false || comboBoxEx.Text == "")
|
||
{
|
||
SiteRooms = BOperationRoom.GetOperationRooms("IsValid=1 and Site<>'恢复室'");
|
||
SiteRooms.Insert(0, new OperationRoom() { Id = -1, Name = "" });
|
||
}
|
||
else
|
||
{
|
||
SiteRooms = BOperationRoom.GetOperationRooms("IsValid=1 and Site='" + comboBoxEx.Text + "'");
|
||
SiteRooms.Insert(0, new OperationRoom() { Id = -1, Name = "" });
|
||
}
|
||
|
||
if (cboRoom != null)
|
||
{
|
||
cboRoom.DataSource = SiteRooms;
|
||
cboRoom.DisplayMember = "Name";
|
||
cboRoom.ValueMember = "Id";
|
||
//判断如果当前手术间编号不为空,则显示当前手术间
|
||
OperationRoom oprm = GetOperationRoom(SiteRooms);
|
||
if (oprm != null && oprm.Id.Value > 0)
|
||
{
|
||
cboRoom.SelectedValue = oprm.Id.Value;
|
||
cboRoom.Text = oprm.Name.ToString();
|
||
}
|
||
if (cboRoom.Text == "" && PublicMethod.SelectRoom != 0)
|
||
{
|
||
cboRoom.SelectedValue = PublicMethod.SelectRoom;
|
||
}
|
||
}
|
||
}
|
||
|
||
public static void UPDocument(int PatientId, int ApplyId, int RecoredId, int RecoverId, string DocumentId, string DocumentName)
|
||
{
|
||
try
|
||
{
|
||
PrintDocumentUP printDocumentUP = BPrintDocumentUP.SelectSingle("PatientId=@PatientId and DocumentId=@DocumentId", new ParameterList("@PatientId", PatientId, "@DocumentId", DocumentId));
|
||
if (printDocumentUP == null)
|
||
{
|
||
printDocumentUP = new PrintDocumentUP();
|
||
}
|
||
printDocumentUP.PatientId = PatientId;
|
||
printDocumentUP.ApplyId = ApplyId;
|
||
printDocumentUP.RecorId = RecoredId;
|
||
printDocumentUP.RecoverId = RecoverId;
|
||
printDocumentUP.DocumentId = DocumentId.ToString();
|
||
printDocumentUP.DocumentName = DocumentName;
|
||
printDocumentUP.IsUpload = "0";
|
||
printDocumentUP.OperatorId = PublicMethod.OperatorId;
|
||
printDocumentUP.OperatorTime = DateTime.Now;
|
||
if (printDocumentUP.Id != null && printDocumentUP.Id.Value > 0)
|
||
{
|
||
BPrintDocumentUP.Update(printDocumentUP);
|
||
}
|
||
else
|
||
{
|
||
BPrintDocumentUP.Insert(printDocumentUP);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
PublicMethod.WriteLog(ex);
|
||
}
|
||
}
|
||
}
|
||
}
|