using HelperDB;
using Newtonsoft.Json;
using AIMSExtension;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace DrawGraph
{
public class IconManage : AreaManageBase
{
public RectangleFramePackObj IconPpack;
public LinePackObj H5pack;
///
/// 当前手术对象
///
private OperationRecord myOpeRecord = null;
public IconManage() { }
public IconManage(object _operationRecor, ZedGraphControl _zedControl, TemplateManage _template, string _name) : base(_operationRecor, _zedControl, _template, _name)
{
init();
}
public void init()
{
//自己要用的手术对象
myOpeRecord = OpeRecord as OperationRecord;
}
///
/// 初始画的后置方法
///
public override void FollowUpMethod()
{
H5pack = template.GetPackObjectOTag("IconManage_LinePackObj_5");
if (H5pack != null)
{
eventstartX = H5pack.RealX;
eventy = H5pack.RealY;
eventendy = H5pack.RealEndY;
}
IconPpack = template.GetPackObjectOTag("IconManage_RectangleFramePackObj_2");
if (IconPpack != null)
{
eventy = IconPpack.RealY;
eventendy = IconPpack.RealEndY;
}
LinePackObj line = template.GetPackObjectOTag("IconManage_LinePackObj_6");
if (line != null)
{
eventstartX = line.RealX;
eventendX = line.RealEndX + 0.02;
}
}
#region 重写的事件
///
/// 鼠标点击画板
///
///
///
public override void MouseDown(ZedGraphControl sender, MouseEventArgs e)
{
//if (e.Button == System.Windows.Forms.MouseButtons.Left)
//{
// MessageBox.Show(this.GetType().Name + "is Click Left Button");
//}
}
public override void MouseMove(ZedGraphControl sender, MouseEventArgs e)
{
}
public override void MouseUp(ZedGraphControl sender, MouseEventArgs e)
{
}
public override void MouseDoubleClick(ZedGraphControl sender, MouseEventArgs e)
{
}
public override void KeyUp(ZedGraphControl sender, KeyEventArgs e)
{
}
#endregion 重写的事件结束
public override void Bind()
{
init();
DrawEvent();
}
///
/// 画事件
///
private void DrawEvent()
{
if (myOpeRecord.FactEventsList.Count > 0)
{
foreach (FactEvents temp in myOpeRecord.FactEventsList)
{
temp.clearAddObj(ZedControl);
}
reDrawEvent();
}
}
double eventy;
double eventendy;
double eventendX;
double eventstartX;
///
/// 重新画事件文本
///
private void reDrawEvent()
{
//画在第几行
int rowIndex = 0;
DateTime? drawDatetime = null;
FactEvents drawEvent = null;
string LastNumber = "";
double span = getYPositionByListIndex(1, eventy, eventendy, 2);
List eventListstr = new List();
eventListstr.Add("【事件】");
myOpeRecord.FactEventsList.Sort(new FactEventsComparer());
//循环加药集体
for (int i = 0; i < myOpeRecord.FactEventsList.Count; i++)
{
FactEvents temp = myOpeRecord.FactEventsList[i];
//ShowRespDate(temp, null);
//判断该事件是否存在当前时间段
if (IfInTimeExist(temp.EventBeginTime.Value, temp.EventEndTime.Value) == false) continue;
if (temp.EventBeginTime.Value.ToShortTimeString() == temp.EventEndTime.Value.ToShortTimeString())
{
eventListstr.Add(string.Format("{0}{1} {2} {3}{4}", getNumber(i), temp.EventBeginTime.Value.ToShortTimeString(), temp.EventName, "", temp.Remark == null ? "" : temp.Remark.ToString()));
}
else
{
eventListstr.Add(string.Format("{0}{1}->{2} {3} {4}{5}", getNumber(i), temp.EventBeginTime.Value.ToShortTimeString(), temp.EventEndTime.Value.ToShortTimeString(), temp.EventName, "", temp.Remark == null ? "" : temp.Remark.ToString()));
}
temp.setAnasArr(ZedControl, eventstartX, eventendX, myOpeRecord.PageBegin, myOpeRecord.PageBegin.AddMinutes(EVERY_PAGE_TIME_SPAN));
try
{
string EventName = temp.EventName;
if (EventName == "喉罩") EventName = "插管";
DataRow[] dr = myOpeRecord.PhysioParamList.Select("Name ='" + EventName + "' ", "");
if (dr.Length > 0)
{
temp.clearDNAndDT(ZedControl);
string tagName = dr[0]["imgPath"].ToString();
temp.drawIMG(ZedControl, tagName, eventy, 0.013);
}
else
{
int DValue = 0;
string drawNumber = "";
if (drawDatetime != null && temp.EventBeginTime > drawDatetime.Value.AddMinutes(-1) && temp.EventBeginTime < drawDatetime.Value.AddMinutes(10) && LastNumber != "" && drawEvent != null)
{
drawEvent.clearDNAndDT(ZedControl);
drawEvent = temp;
drawNumber = LastNumber + "-" + getNumber(i);
DValue = (int)(((TimeSpan)(temp.EventBeginTime - drawDatetime.Value)).TotalMinutes / 2);
}
else
{
LastNumber = getNumber(i);
drawNumber = LastNumber;
drawEvent = temp;
drawDatetime = temp.EventBeginTime.Value;
}
//画图上的序号
temp.drawNumber(ZedControl, drawNumber, eventy + span - 0.001, DValue, Color.DarkBlue);
}
rowIndex++;
}
catch (Exception exp)
{
PublicMethod.WriteLog(exp, "");
}
}
myOpeRecord.EventListstr = eventListstr;
}
#region 格式化字符串长度
///
/// 格式化字符串长度
///
/// 输入的字符串
/// 截取的长度
/// 被截取完的字符串
public static List stringformat(string str, int n)
{
///
///格式化字符串长度,超出部分显示省略号,区分汉字跟字母。汉字2个字节,字母数字一个字节
///
List strList = new List();
string temp = string.Empty;
if (System.Text.Encoding.Default.GetByteCount(str) <= n)//如果长度比需要的长度n小,返回原字符串
{
strList.Add(str);
}
else
{
int t = 0;
char[] q = str.ToCharArray();
for (int i = 0; i <= q.Length; i++)
{
if (t > n)
{
strList.Add(temp);
temp = "";
t = 0;
}
if (i == q.Length)// - 1
{
strList.Add(temp);
break;
}
//判断是否汉字:
if ((int)q[i] >= 0x4E00 && (int)q[i] <= 0x9FA5)
{
temp += q[i];
t += 2;
}
//判断半角如下:
else if (q[i].ToString().Length == Encoding.Default.GetByteCount(q[i].ToString()))
{
temp += q[i];
t++;
}
//判断全角如下:
else if (2 * q[i].ToString().Length == Encoding.Default.GetByteCount(q[i].ToString()))
{
temp += q[i];
t += 2;
}
else
{
temp += q[i];
t++;
}
}
}
return strList;
}
#endregion
private bool IfInTimeExist(DateTime Begin, DateTime End)
{
DateTime lastime = myOpeRecord.lastPageBegin.AddSeconds(59);
bool b = false;
if (End == null)
{
if (Begin > myOpeRecord.PageBegin && Begin < lastime)
{
b = true;
}
}
else
{
if (Begin >= myOpeRecord.PageBegin && Begin <= lastime)
{
b = true;
}
else if (End >= myOpeRecord.PageBegin && End <= lastime)
{
b = true;
}
else if (Begin < myOpeRecord.PageBegin && End > lastime)
{
b = true;
}
}
return b;
}
private DateTime GetInsertTime(DateTime pdTemp, bool IsInRToomTime = false)
{
DateTime insTime = pdTemp.Date.AddHours(pdTemp.Hour).AddMinutes(pdTemp.Minute);
if (collectInterval == 5)
{
int minute = pdTemp.Minute % 5;//计算5的整数分钟
if (minute >= 3)
insTime = insTime.AddMinutes(5 - minute);
else if (minute != 0 && IsInRToomTime == true)
insTime = insTime.AddMinutes(5 - minute);
else
insTime = insTime.AddMinutes(0 - minute);
}
else if (collectInterval == 10)
{
double minute = pdTemp.Minute % 10;//计算5的整数分钟
if (minute >= 5)
insTime = insTime.AddMinutes(10 - minute);
else
insTime = insTime.AddMinutes(0 - minute);
}
return insTime;
}
///
/// 根据顶部加药序号,确定数值生命体征的纵向位置(以1为单位)
///
///
///
public double getYPositionByListIndex(double index, double yTop, double yBottom, int rowCount)
{
double heightT = ZedControl.Height * (yBottom - yTop);
double setpTemp = heightT / rowCount;
//求一格在实际高度中的百分比
double bfb = (setpTemp / heightT);
//两线之间度*百分比得到一格的百分比高度
double ygBFB = (yBottom - yTop) * bfb;
double y = ygBFB * index;
return y;
}
public static string getNumber(int number)
{
try
{
string str = "①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮";
if (number >= 15)
str = "①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳㉑㉒㉓㉔㉕㉖㉗㉘㉙㉚㉛㉜㉝㉞㉟㊱㊲㊳㊴㊵㊶㊷㊸㊹㊺㊻㊼㊽㊾㊿";
str = str.Substring(number, 1);
return str;
}
catch (Exception)
{
return number.ToString() + ":";
}
}
}
}