using Newtonsoft.Json; using AIMSExtension; using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace DrawGraph { [Serializable, JsonObject(MemberSerialization.OptOut)] public class SapManage : AreaManageBase { /// /// 药品区域 /// public RectangleFramePackObj sapPpack; public LinesPackObj lines; public LinePackObj H3pack; public LinePackObj H5pack; public int RowsCount; private TipBox aSyncTip = null; /// /// 当前手术对象 /// private OperationRecord myOpeRecord = null; public List DrugsListstr = new List(); #region 初始化液体区域 public SapManage() { init(); } public SapManage(object _operationRecor, DrawGraph.ZedGraphControl _zedControl, TemplateManage _template, string _name) : base(_operationRecor, _zedControl, _template, _name) { init(); } public void init() { //自己要用的手术对象 myOpeRecord = OpeRecord as OperationRecord; } /// /// 初始画的后置方法 /// public override void FollowUpMethod() { H3pack = template.GetPackObjectOTag("SapManage_LinePackObj_3"); H5pack = template.GetPackObjectOTag("SapManage_LinePackObj_5"); sapPpack = template.GetPackObjectOTag("SapManage_RectangleFramePackObj_2"); lines = template.GetPackObjectOTag("SapManage_LinesPackObj_7"); RowsCount = Convert.ToInt32(lines.XPageSpan / lines.XMajorGridStep); } #endregion #region 重写的事件 /// /// 鼠标点击画板 /// /// /// public override void MouseDown(ZedGraphControl sender, MouseEventArgs e) { //if (ConfigSource.sysypyd != null && ConfigSource.sysypyd.Value.ToString() == "1") //{ //触发可编辑区域的事件 double y = Convert.ToDouble(Convert.ToDouble(e.Y) / Convert.ToDouble(ZedControl.Height)); double x = Convert.ToDouble(Convert.ToDouble(e.X) / Convert.ToDouble(ZedControl.Width)); ZedGraphControl sender1 = sender as ZedGraphControl; PointF mousePt = new PointF(e.X, e.Y); GraphPane pane = sender1.MasterPane.FindChartRect(mousePt); bool isDrugRange = isAddDrugRange(sender, x, y); if (isDrugRange && e.Button == System.Windows.Forms.MouseButtons.Left) { DateTime BeginTime = reDrugsTime(sender as ZedGraphControl, e); List record = new List(); double addDragRowHeight = (lines.RealEndY - lines.RealY) / RowsCount; foreach (FactDrug dsr in myOpeRecord.FactDrugList) { if (dsr.isEqual(y, BeginTime, addDragRowHeight)) { dsr.IsSelected = true; break; } } } } public override void MouseMove(ZedGraphControl sender, MouseEventArgs e) { //if (ConfigSource.sysypyd != null && ConfigSource.sysypyd.Value.ToString() == "1") //{ double x = Convert.ToDouble(Convert.ToDouble(e.X) / Convert.ToDouble(sender.Width)); double y = Convert.ToDouble(Convert.ToDouble(e.Y) / Convert.ToDouble(sender.Height)); double yP = 18 / Convert.ToDouble(sender.Height); string viewStr = ""; bool isDrugRange = isAddDrugRange(sender, x, y); if (isDrugRange) { DateTime BeginTime = reDrugsTime(sender as ZedGraphControl, e); double addDragRowHeight = (lines.RealEndY - lines.RealY) / RowsCount; bool isDrug = false; foreach (FactDrug dsr in myOpeRecord.FactDrugList) { if (dsr.isEqual(y, BeginTime, addDragRowHeight) || dsr.IsSelected) { isDrug = true; viewStr = dsr.DrugName + ":" + dsr.Dosage + dsr.DosageUnit; if (dsr.DrugBeginTime != null) viewStr += "\n开始时间:" + dsr.DrugBeginTime.ToString("yyyy-MM-dd HH:mm"); if (dsr.DrugEndTime != null && dsr.DrugEndTime != dsr.DrugBeginTime) viewStr += "\n结束时间:" + dsr.DrugEndTime.ToString("yyyy-MM-dd HH:mm"); aSyncTip.ViewStr = viewStr; aSyncTip.Show(x, y + yP); //因为被选中进行托动 if (dsr.IsSelected) { aSyncTip.ViewStr = viewStr; aSyncTip.Show(x, y + yP); TimeSpan ts = BeginTime - DateTime.Parse(dsr.DrugBeginTime.ToString()); double totalMinutes = ts.TotalMinutes; if (dsr.DrugEndTime != null) { dsr.DrugEndTime = dsr.DrugEndTime.AddMinutes(totalMinutes); } dsr.DrugBeginTime = BeginTime; dsr.ReDraw(sender); } ZedControl.Refresh(); break; } } if (!isDrug) { if (aSyncTip != null) { viewStr = BeginTime.ToString("HH:mm"); aSyncTip.ViewStr = viewStr; aSyncTip.Show(x, y + yP); ZedControl.Refresh(); } } } //} } public override void MouseUp(ZedGraphControl sender, MouseEventArgs e) { if (OpeRecord == null) return; //if (ConfigSource.sysypyd != null && ConfigSource.sysypyd.Value.ToString() == "1") //{ double y = Convert.ToDouble(Convert.ToDouble(e.Y) / Convert.ToDouble(ZedControl.Height)); double x = Convert.ToDouble(Convert.ToDouble(e.X) / Convert.ToDouble(ZedControl.Width)); bool isDrugRange = isAddDrugRange(sender, x, y); if (isDrugRange && e.Button == System.Windows.Forms.MouseButtons.Left) { //把移动药品强制保存 if (myOpeRecord != null && myOpeRecord.FactDrugList != null) { DateTime currentTime = reDrugsTime(sender as ZedGraphControl, e); foreach (FactDrug dsr in myOpeRecord.FactDrugList) { if (dsr.IsSelected) { dsr.IsSelected = false; int reValue = FactDrug.UpdateEntity(dsr); if (reValue > 0) { reDrawDrug(); } else { ZedControl.Refresh(); } break; } } } } //} } public override void MouseDoubleClick(ZedGraphControl sender, MouseEventArgs e) { if (myOpeRecord != null) { if (e.Button != System.Windows.Forms.MouseButtons.Left) return; //触发可编辑区域的事件 double y = Convert.ToDouble(Convert.ToDouble(e.Y) / Convert.ToDouble(ZedControl.Height)); double x = Convert.ToDouble(Convert.ToDouble(e.X) / Convert.ToDouble(ZedControl.Width)); ZedGraphControl sender1 = sender as ZedGraphControl; PointF mousePt = new PointF(e.X, e.Y); GraphPane pane = sender1.MasterPane.FindChartRect(mousePt); bool isDrugRange = isAddDrugRange(sender, x, y); if (isDrugRange && e.Button == System.Windows.Forms.MouseButtons.Left) { DateTime BeginTime = reDrugsTime(sender as ZedGraphControl, e); List record = new List(); double addDragRowHeight = (lines.RealEndY - lines.RealY) / RowsCount; foreach (FactDrug dsr in myOpeRecord.FactDrugList) { if (dsr.isEqualRow(y, BeginTime, addDragRowHeight)) { record.Add(dsr); } } if (record.Count > 0) { List records = new List(); foreach (var fact in record) { if (fact.ParentId == 0) { records.Add(fact); foreach (var item in myOpeRecord.FactDrugList) { if (item.ParentId == fact.Id) { records.Add(item); } } } else { foreach (var item in myOpeRecord.FactDrugList) { if (item.Id == fact.ParentId || item.ParentId == fact.ParentId) { records.Add(item); } } } } if (records.Count > 0) myOpeRecord.SpeedyDrugsMethod(records, BeginTime); } else myOpeRecord.SpeedyDrugsMethod(null, BeginTime); } } } public override void KeyUp(ZedGraphControl sender, KeyEventArgs e) { } #endregion 重写的事件结束 #region 绑定区域数据 public override void Bind() { aSyncTip = TipBox.CreateInstance("async"); init(); DrawDrug(); } /// /// 画加药 /// private void DrawDrug() { try { foreach (FactDrug temp in myOpeRecord.FactDrugList) { if (isSapDrugs(temp) && temp.ParentId == 0) { temp.clearAddObj(ZedControl); } } reDrawDrug(); } catch (Exception exp) { PublicMethod.WriteLog(exp); } } /// /// 重新画加药文本 /// private void reDrawDrug() { try { //画在第几行 int rowDrugsIndex = 0; //y的高度//主要高度 double drugsy = 0; //加药最后位置 double maxDrugsy = sapPpack.RealEndY; //持续加药当前时间 DateTime curTimeTemp = OperationRecord.getOpeMaxTime(myOpeRecord); DateTime serverTime = DateTime.Now; if (curTimeTemp > serverTime) curTimeTemp = serverTime; //超出的药画备注 镇痛药备注 List SapListstr = new List(); SapListstr.Add("【手术用液】"); myOpeRecord.BeforeDrugs = ""; myOpeRecord.AnalgesiaDrug = ""; //当前时间段加药集合 myOpeRecord.FactDrugList.ForEach(drug => { if (drug.IsContinue == 1 && drug.DrugBeginTime == drug.DrugEndTime) drug.End = curTimeTemp; else if (drug.DrugEndTime != null) drug.End = drug.DrugEndTime; }); List _FactDrugList = myOpeRecord.FactDrugList.Where(s => IfInTimeExist(s.DrugBeginTime, s.End) == true).ToList(); //加药按加药时间排序 _FactDrugList.Sort(new FactDrugComparer()); for (int i = 0; i < _FactDrugList.Count; i++) { FactDrug temp = _FactDrugList[i]; if (temp.GiveDrugType == "麻醉前用药" || temp.GiveDrugType == "术后镇痛药" || temp.DrugChannel == "备用" || temp.DrugChannel == "配药" || temp.Access == "下") continue;// || temp.GiveDrugType == "麻醉诱导用药" //子药不画 if (temp.ParentId > 0) continue; bool isEqual = false; bool isChildEqual = false; if (isSapDrugs(temp)) { //以行号返回具休的位置 drugsy = sapPpack.RealY + getYPositionByListIndex(rowDrugsIndex, sapPpack.RealY, sapPpack.RealEndY, RowsCount); SetDrug(temp, curTimeTemp, drugsy); temp.ChildFactDrugList = new List(); temp.ChildFactDrugList = _FactDrugList.Where(a => a.ParentId == temp.Id).ToList(); //判断是否重复的 主药或组药 for (int j = 0; j < i; j++) { FactDrug addDrug1 = _FactDrugList[j]; if (addDrug1.ChildFactDrugList == null) addDrug1.ChildFactDrugList = new List(); //如果加药品ID相同并且加加药ID不同,则认为加了同一种加药 if (addDrug1.Equal(temp) && temp.ParentId == 0 && addDrug1.ParentId == 0 && addDrug1.ChildFactDrugList.Count == 0 && temp.ChildFactDrugList.Count == 0) { addDrug1.clearDNAndDT(ZedControl); //因为相同则取得相同对象的Y,为当前的对象的高度 drugsy = addDrug1.nowY; isEqual = true; continue; } else if (addDrug1.Equal(temp) && temp.ChildFactDrugList != null && addDrug1.ChildFactDrugList != null && EqualChildDrugs(temp.ChildFactDrugList, addDrug1.ChildFactDrugList)) { isChildEqual = true; TimeSpan tsp = temp.DrugBeginTime - addDrug1.DrugBeginTime; //清除画图对象的名称及总药 addDrug1.clearDNAndDT(ZedControl); drugsy = addDrug1.nowY; if (drugsy <= maxDrugsy) temp.drawText(H3pack.RealX + 0.003f, drugsy); else ListAddDrugs(SapListstr, i, temp); foreach (FactDrug item in temp.ChildFactDrugList) { foreach (FactDrug addDrug1item in addDrug1.ChildFactDrugList) { //如果加药品ID相同并且加加药ID不同,则认为加了同一种加药 if (addDrug1item.Equal(item)) { SetDrug(item, curTimeTemp, drugsy); //清除画图对象的名称及总药 addDrug1item.clearDNAndDT(ZedControl); ////因为相同则取得相同对象的Y,为当前的对象的高度 drugsy = addDrug1item.nowY; if (drugsy <= maxDrugsy) item.drawText(H3pack.RealX + 0.003f, drugsy); else ListAddDrugs(SapListstr, i, item); continue; } } } break; } } if (isChildEqual == true) continue; if (drugsy <= maxDrugsy) { temp.drawText(H3pack.RealX + 0.003f, drugsy); if (isEqual == false) rowDrugsIndex++; } else ListAddDrugs(SapListstr, i, temp); if (temp.ChildFactDrugList.Count > 0) { foreach (FactDrug sItem in temp.ChildFactDrugList) { drugsy = sapPpack.RealY + getYPositionByListIndex(rowDrugsIndex, sapPpack.RealY, sapPpack.RealEndY, RowsCount); SetDrug(sItem, curTimeTemp, drugsy); if (drugsy <= maxDrugsy) { sItem.drawText(H3pack.RealX + 0.006f, drugsy); rowDrugsIndex++; } else { ListAddDrugs(SapListstr, i, sItem); } } if (drugsy <= maxDrugsy) DrawZuDragsLine(H3pack.RealX + 0.003f, drugsy, temp.nowY, temp); } } } myOpeRecord.SapsListstr = SapListstr; } catch (Exception ex) { throw ex; } } public bool EqualChildDrugs(List childDrugs, List secondchildDrugs) { bool b = false; foreach (var item in childDrugs) { bool istrue = false; foreach (var secitem in secondchildDrugs) { if (secitem.Equal(item)) { istrue = true; } } if (istrue == true) { b = true; } else { b = false; break; } } return b; } private void DrawZuDragsLine(double x, double y, double zhuy, FactDrug temp) { double height = getYPositionByListIndex(1, sapPpack.RealY, sapPpack.RealEndY, RowsCount) / 2; ZUtil.DrawLine2(x, zhuy + height, x, y + height, ZedControl, "zhuyDrugs" + temp.Id, Color.Red); ZUtil.DrawLine2(x, zhuy + height, x + 0.0055f, zhuy + height, ZedControl, "zhuyDrugstop" + temp.Id, Color.Red); ZUtil.DrawLine2(x, y + height, x + 0.0055f, y + height, ZedControl, "zhuyDrugsend" + temp.Id, Color.Red); } private void SetDrug(FactDrug temp, DateTime curTimeTemp, double y) { if (temp.IsContinue == 1 && temp.DrugBeginTime == temp.DrugEndTime) temp.End = curTimeTemp; temp.EqualDose = null; temp.setAnasArr(ZedControl, H5pack.RealX, sapPpack.RealEndX, myOpeRecord.PageBegin, myOpeRecord.PageBegin.AddMinutes(EVERY_PAGE_TIME_SPAN)); temp.nowY = y; } private static void ListAddDrugs(List DrugListstr, int i, FactDrug temp) { string dose = ""; if (temp.Density != 0) { dose += ((double)temp.Density).ToString(); if (temp.DensityUnit != null) { dose += temp.DensityUnit; } } if (dose.Trim() != "") dose += " "; if (temp.Velocity != "") { dose += temp.Velocity; if (temp.VelocityUnit != null) { dose += temp.VelocityUnit; } } if (dose.Trim() != "") dose += " "; if (temp.Dosage != 0) { dose += ((double)temp.Dosage).ToString(); if (temp.DosageUnit != null) { dose += temp.DosageUnit; } } DrugListstr.Add(string.Format("({0}){1} {2} {3}{4}{5}", i + 1, (temp.DrugBeginTime == temp.DrugEndTime) ? temp.DrugBeginTime.ToShortTimeString() : temp.DrugBeginTime.ToShortTimeString() + "->" + temp.DrugEndTime.ToShortTimeString(), temp.DrugName.Trim(), dose, "", temp.DrugChannel == null ? "" : " " + temp.DrugChannel.ToString())); //DrugListstr.Append(" "); } private bool isSapDrugs(FactDrug record) { bool isSap = false; if (record.DrugChannel != null && record.DrugChannel == "ivgtt") { if (record.DosageUnit != null && record.DosageUnit.ToLower() == "ml") { if (record.Dosage >= 50) { isSap = true; } } if (record.BloodType != null && record.BloodType != "") { isSap = true; } } return isSap; } /// /// 返回是否进入加药范围 /// /// /// private bool isAddDrugRange(ZedGraphControl sender, double x, double y) { bool reValue = false; if (y > lines.RealY && y < lines.RealEndY) { if (x > H3pack.RealX && x < lines.RealEndX) { reValue = true; } } return reValue; } private DateTime reDrugsTime(ZedGraphControl sender, MouseEventArgs e) { try { double x, x2; double[] y; double[] y2; //double yTemp = ZedControl.Height * lines.RealEndY + 80; PointF mousePt = new PointF(e.X, 1300); ZedGraphControl sender1 = sender as ZedGraphControl; GraphPane pane = sender1.MasterPane.FindChartRect(mousePt); if (pane != null) { pane.ReverseTransform(mousePt, out x, out x2, out y, out y2); XDate xd = new XDate(x); return xd.DateTime; } else { return DateTime.Now; } } catch (Exception) { return DateTime.Now; } } #endregion #region 当前区域公用事件方法 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; } /// /// 根据顶部加药序号,确定数值生命体征的纵向位置(以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; } #endregion } }