using AIMSExtension; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Windows.Forms; namespace DrawGraph { /// /// 麻醉前访视单 /// public class TempDataManage : AreaManageBase { private OperationRecord myOpeRecord = null; private bool valChang = false; //值不变 AbleEditPackObj ableEdit2; public TempDataManage() { } public TempDataManage(object _operationRecor, DrawGraph.ZedGraphControl _zedControl, TemplateManage _template, string _name) : base(_operationRecor, _zedControl, _template, _name) { } public void init() { //自己要用的手术对象 myOpeRecord = OpeRecord as OperationRecord; ableEdit2 = template.GetPackObjectOTag("TempDataManage_AbleEditPackObj_357_OperationRecord_InstrumentList_TagPicturePanel"); } #region 重写的事件 /// /// 鼠标点击画板 /// /// /// public override void MouseDown(ZedGraphControl sender, MouseEventArgs e) { } 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) { } public override void editAr_Click(object sender, EventArgs e) { //传过来的数据是不是可编辑的 AbleEditPackObj editPack = sender as AbleEditPackObj; if (editPack == null) return; //找到这个组件 AbleEditPackObj aEdit1 = PackManage.ListPob.FirstOrDefault(s => s is AbleEditPackObj && s.PackTag == editPack.PackTag) as AbleEditPackObj; if (aEdit1 == null) return; txt_DoubleClick(aEdit1.CControl, null); } public override void Bind() { base.Bind(); init(); if (ableEdit2 != null) { GraphObj gos = ZedControl.MasterPane.GraphObjList[TextPrefix.IM + "InstrumentListTagPicturePanel2"]; if (gos == null) { ZUtil.DrawImage("bjtp", ableEdit2.RealEndX, ableEdit2.RealY, (ableEdit2.RealEndX - ableEdit2.RealX), (ableEdit2.RealEndY - ableEdit2.RealY) / 2, ZedControl, TextPrefix.IM + "InstrumentListTagPicturePanel2"); } } List ables = PackManage.ListPob.Where(s => s is AbleEditPackObj).ToList(); foreach (PackObjBase pack in ables) { AbleEditPackObj ableEdit = pack as AbleEditPackObj; if (ableEdit != null) { ableEdit.IsVisible = true; if (ableEdit.ControlType == EControlType.DateTimePicker) { ableEdit.CControl.Leave -= new EventHandler(txt_Leave); ableEdit.CControl.Leave += new EventHandler(txt_Leave); } else if (ableEdit.ControlType == EControlType.Directory) { ableEdit.CControl.DoubleClick -= new EventHandler(txt_DoubleClick); ableEdit.CControl.DoubleClick += new EventHandler(txt_DoubleClick); ableEdit.CControl.TextChanged -= new EventHandler(txt_Leave); ableEdit.CControl.TextChanged += new EventHandler(txt_Leave); } else if (ableEdit.ControlType == EControlType.CheckBox) { Panel pan = ableEdit.CControl as Panel; if (pan != null) { foreach (Control conl in pan.Controls) { CheckBox chBox = conl as CheckBox; if (chBox != null) { chBox.CheckedChanged -= new EventHandler(txt_Leave); chBox.CheckedChanged += new EventHandler(txt_Leave); } } } } else if (ableEdit.ControlType == EControlType.RadioButtonList) { Panel pan = ableEdit.CControl as Panel; if (pan != null) { foreach (Control conl in pan.Controls) { RadioButton chBox = conl as RadioButton; if (chBox != null) { chBox.CheckedChanged -= new EventHandler(txt_Leave); chBox.CheckedChanged += new EventHandler(txt_Leave); chBox.Click -= new EventHandler(radio_click); chBox.Click += new EventHandler(radio_click); } } } } else { if (ableEdit.ControlType == EControlType.TextBox) { ableEdit.CControl.KeyDown -= new KeyEventHandler(text_keyDown); ableEdit.CControl.KeyDown += new KeyEventHandler(text_keyDown); ableEdit.CControl.GotFocus -= new EventHandler(txt_Focus); ableEdit.CControl.GotFocus += new EventHandler(txt_Focus); } ableEdit.CControl.Leave -= new EventHandler(txt_Leave); ableEdit.CControl.Leave += new EventHandler(txt_Leave); } SetAbleEditView(ableEdit); } } } private void txt_Focus(object sender, EventArgs e) { TextBox control = (TextBox)sender; if (control == null) return; AbleEditPackObj ableEdit = control.Tag as AbleEditPackObj; if (ableEdit == null) return; if (control.Focused == true && (ableEdit.PackValue == ableEdit.DefaultValue || ableEdit.PackValue == "")) control.Clear(); } private void text_keyDown(object sender, KeyEventArgs e) { if (e.Modifiers.CompareTo(Keys.Control) == 0 && e.KeyCode == Keys.V) { string val = Clipboard.GetText(); val = val.Replace("\r", "").Replace("\n", ""); Clipboard.SetText(val); } } /// /// 在画完表单后,显示多选单选的默认项 /// public override void FollowUpMethod() { base.FollowUpMethod(); List ables = PackManage.ListPob.Where(s => s is AbleEditPackObj).ToList(); foreach (PackObjBase pack in ables) { AbleEditPackObj ableEdit = pack as AbleEditPackObj; SetAbleEditView(ableEdit); } } public override void BindTempData() { if (myOpeRecord != null && myOpeRecord.Id != null) { GraphObj gos = ZedControl.MasterPane.GraphObjList[TextPrefix.IM + "InstrumentListTagPicturePanel"]; if (gos != null) { ZedControl.MasterPane.GraphObjList.Remove(gos); } if (myOpeRecord.InstrumentList != null && ableEdit2 != null && myOpeRecord.InstrumentList.TagPicture != null && myOpeRecord.InstrumentList.TagPicture != "") { MemoryStream ms = new MemoryStream(Convert.FromBase64String(myOpeRecord.InstrumentList.TagPicture)); System.Drawing.Image image = System.Drawing.Image.FromStream(ms); ZUtil.DrawImage(image, ableEdit2.RealX, ableEdit2.RealY, (ableEdit2.RealEndX - ableEdit2.RealX), (ableEdit2.RealEndY - ableEdit2.RealY), ZedControl, TextPrefix.IM + "InstrumentListTagPicturePanel"); } } List ables = PackManage.ListPob.Where(s => s is AbleEditPackObj).ToList(); foreach (PackObjBase pack in ables) { pack.Draw(); } } /// /// 公共验证方法 /// /// public override bool Verification() { List editPack = PackManage.ListPob.Where(s => s is AbleEditPackObj).ToList(); foreach (PackObjBase pack in editPack) { AbleEditPackObj ablePack = pack as AbleEditPackObj; if (ablePack != null) { if (ablePack.ValidType == EValidType.IsRequired) { if (ablePack.PackValue.Trim() == "") { MessageBox.Show(pack.Descript + "不能为空"); return false; } }; if (ablePack.PackValue != "" && ablePack.ValidType == EValidType.IsNumber) { try { int.Parse(ablePack.PackValue); } catch (Exception exp) { MessageBox.Show(pack.Descript + "不能为空且必须是数值型"); return false; } }; if (ablePack.TextLength != 0) { if (ablePack.PackValue.Length >= ablePack.TextLength) { MessageBox.Show(ablePack.Descript + "长度不能超过" + ablePack.TextLength + "字"); } } } } return true; } #endregion 重写的事件结束 /// /// 设置可编辑组件的显示样式 /// /// private void SetAbleEditView(AbleEditPackObj ableEdit) { string span = ""; double spanSum = Math.Round((float)(ableEdit.OneUnitCount / 18)); for (int i = 0; i < spanSum; i++) { if (ableEdit.IsHorizontal == ELineType.Horizontal) { span += " "; } else { span += "\n"; } } string text = "", value = ""; if (ableEdit != null && ableEdit.CControl != null) { switch (ableEdit.ControlType) { case EControlType.RadioButtonList: foreach (Control conl in ableEdit.CControl.Controls) { string spanT = span.Clone().ToString(); if (ableEdit.DfArrangement == EIsBool.True) { if (spanT.Length - conl.Text.Length >= conl.Text.Length) { spanT = spanT.Remove(spanT.Length - conl.Text.Length, conl.Text.Length); } } RadioButton radio = conl as RadioButton; if (radio.Checked) { text += "☑" + conl.Text + spanT; value = conl.Text; } else { text += "□" + conl.Text + spanT; } } break; case EControlType.CheckBox: foreach (Control conl in ableEdit.CControl.Controls) { string spanT = span.Clone().ToString(); if (ableEdit.DfArrangement == EIsBool.True) { if (spanT.Length - conl.Text.Length >= conl.Text.Length) { spanT = spanT.Remove(spanT.Length - conl.Text.Length, conl.Text.Length); } } CheckBox radio = conl as CheckBox; if (radio.Checked) { text += "☑" + conl.Text + spanT; value += conl.Text + ","; } else { text += "□" + conl.Text + spanT; } } value = value.TrimEnd(','); break; case EControlType.Directory: if (ableEdit.ControlTitleText.Contains("模板")) { text = ableEdit.CControl.Text; value = ableEdit.CControl.Text; } else { value = ableEdit.PackValue; string typeName = ableEdit.ControlTitleText; //如果是“人员,2”这种需要把人员取出来 if (ableEdit.ControlTitleText.Contains(",") || ableEdit.ControlTitleText.Contains(",")) { string[] strs = ableEdit.ControlTitleText.Replace(",", ",").Split(','); typeName = strs[0]; } text = DocumentEntityMethod.GetDictionaryValuesById(ableEdit.PackValue, typeName); } break; default: text = ableEdit.CControl.Text; value = ableEdit.CControl.Text; break; } //设置属性的值 template.SetObjValue(OpeRecord, ableEdit.ClassDataSourceName, text, value); //如果有逻辑区域,则区域进行更新。 template.NotificationAreaBindingUpdate(template.ProjectName + "逻辑"); } } private void setDefaultDateTime(object sender) { Control control = (Control)sender; if (control == null) return; AbleEditPackObj ableEdit = control.Tag as AbleEditPackObj; if (ableEdit == null) return; string DataSourceName = ableEdit.ClassDataSourceName; if (ableEdit.ControlTitleText != "") { ((DateTimePicker)control).Format = DateTimePickerFormat.Custom; ((DateTimePicker)control).CustomFormat = ableEdit.ControlTitleText; } if (ableEdit.PackText == "") { //control.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:00");//ToShortDateString } } private void txt_DoubleClick(object sender, EventArgs e) { Control control = (Control)sender; if (control == null) return; AbleEditPackObj ableEdit = control.Tag as AbleEditPackObj; if (ableEdit == null) return; string DataSourceName = ableEdit.ClassDataSourceName; try { string text = "", value = ""; switch (ableEdit.ControlType) { case EControlType.DateTimePicker: text = DateTime.Now.ToString(); value = DateTime.Now.ToString(); control.Text = text; break; default: text = ableEdit.CControl.Text; value = ableEdit.CControl.Text; break; } } catch (Exception ex) { } finally { template.ZedControl.Refresh(); } } private void radio_click(object sender, EventArgs e) { RadioButton control = (RadioButton)sender; if (control == null) return; if (!valChang) { control.Checked = false; } valChang = false; } private void txt_Leave(object sender, EventArgs e) { Control control = (Control)sender; if (control == null) return; AbleEditPackObj ableEdit = control.Tag as AbleEditPackObj; if (ableEdit == null) return; //拿到数据源(格式:OperationRecord.PatientRef.Bed) bool updateOk = true; try { SetAbleEditView(ableEdit); if (ableEdit.ControlType == EControlType.RadioButtonList) { RadioButton rb = (RadioButton)sender; if (control == null) return; AbleEditPackObj ableEdit1 = control.Tag as AbleEditPackObj; AbleEditPackObj selectAbleEdit = null; //值变了 valChang = true; } } catch (Exception ex) { //写日志 updateOk = false; } finally { } } //设置打印模式,组件不显示 public override void setPrint(bool isVisible) { //预览状态时所可编辑组件的组件隐藏 List ables = PackManage.ListPob.Where(s => s is AbleEditPackObj).ToList(); foreach (PackObjBase pack1 in ables) { AbleEditPackObj ableEdit = pack1 as AbleEditPackObj; if (ableEdit != null) { ableEdit.IsVisible = isVisible; if (isVisible == true) ableEdit.IsViewBoard = EIsBool.True; else ableEdit.IsViewBoard = EIsBool.False; } } } } }