using AIMS.Infrastructure.CA; using AIMSExtension; using DevComponents.DotNetBar.Controls; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Windows.Forms; namespace DrawGraph { /// /// 麻醉前访视单 /// public class TempDataManage : AreaManageBase { private OperationRecord myOpeRecord = null; AbleEditPackObj ableEdit2; AbleEditPackObj ableEdit3; 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"); ableEdit3 = template.GetPackObjectOTag("TempDataManage_AbleEditPackObj_397_OperationRecord_InstrumentList_PackPanel"); } #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) { SelectDictText.Hidden(); //传过来的数据是不是可编辑的 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 SelectDictText aSyncSelectDict = null; public override void Bind() { aSyncSelectDict = SelectDictText.CreateInstance(); //SelectDictText.SetValue += ASyncSelectDict_SetValue; 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"); } } if (ableEdit3 != null) { for (int i = 593; i < 617; i++) { TextPackObj packObj = template.GetPackObjectOTag("TempDataManage_TextPackObj_" + i); if (packObj != null) { packObj.PackText = ""; packObj.PackValue = ""; packObj.Draw(); } } } 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; ableEdit.CControl.Click -= new EventHandler(txt_Click); ableEdit.CControl.Click += new EventHandler(txt_Click); 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.Leave -= new EventHandler(txt_Leave); ableEdit.CControl.Leave += new EventHandler(txt_Leave); } else if (ableEdit.ControlType == EControlType.Directorys) { DevComponents.DotNetBar.Controls.TokenEditor tokenEditor = ableEdit.CControl as DevComponents.DotNetBar.Controls.TokenEditor; tokenEditor.EditTextBox.DoubleClick -= EditTextBox_DoubleClick; tokenEditor.EditTextBox.DoubleClick += EditTextBox_DoubleClick; tokenEditor.EditTextBox.TextChanged -= EditTextBox_TextChanged; tokenEditor.EditTextBox.TextChanged += EditTextBox_TextChanged; tokenEditor.Leave -= TokenEditor_Leave; tokenEditor.Leave += TokenEditor_Leave; tokenEditor.ValidateToken -= new DevComponents.DotNetBar.Controls.ValidateTokenEventHandler(this.tokenEditor_ValidateToken); tokenEditor.ValidateToken += new DevComponents.DotNetBar.Controls.ValidateTokenEventHandler(this.tokenEditor_ValidateToken); } 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) { 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.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); ((TextBox)ableEdit.CControl).BorderStyle = BorderStyle.Fixed3D; ableEdit.CControl.MouseWheel += new MouseEventHandler(numericUpDown1_MouseWheel); ableEdit.CControl.Leave -= new EventHandler(txt_Leave); ableEdit.CControl.Leave += new EventHandler(txt_Leave); } else { ableEdit.CControl.Leave -= new EventHandler(txt_Leave); ableEdit.CControl.Leave += new EventHandler(txt_Leave); } SetAbleEditView(ableEdit); } } } ////取消滚轮事件 //void numericUpDown1_MouseWheel(object sender, MouseEventArgs e) //{ // base.MouseWheelParam(); //} 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) { ((TextBox)sender).Enabled = true; 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) { if (ableEdit2 != null) { GraphObj gos = ZedControl.MasterPane.GraphObjList[TextPrefix.IM + "InstrumentListTagPicturePanel"]; if (gos != null) { ZedControl.MasterPane.GraphObjList.Remove(gos); } if (myOpeRecord.InstrumentList != 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"); } } if (ableEdit3 != null && myOpeRecord.InstrumentList != null && myOpeRecord.InstrumentList.JsonTextData != null && myOpeRecord.InstrumentList.JsonTextData != "") { //593-616 List list = JsonConvert.DeserializeObject>(myOpeRecord.InstrumentList.JsonTextData); foreach (JsonTextForDoc m in list) { if (m.Id.Trim() == "") continue; TextPackObj packObj = template.GetPackObjectOTag(m.Tag); packObj.PackText = m.Value; packObj.PackValue = m.Value; packObj.Draw(); } } } 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) { 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, bool isUpdate = false) { 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); } } CheckBox radio = conl as CheckBox; 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 == "CA" || ableEdit.ControlTitleText == "签名") { value = ableEdit.PackValue; text = DBManage.GetDictionaryValuesById(ableEdit.PackValue, ableEdit.ControlTitleText); if (ableEdit.ControlTitleText.Contains("CA") || ableEdit.ControlTitleText.Contains("签名")) { if (ableEdit.PackValue != null && ableEdit.PackValue != "") { SetCAAbleEditPackObj(ableEdit); } } } else { text = ableEdit.CControl.Text; value = ableEdit.CControl.Text; } break; case EControlType.Directorys: text = ableEdit.CControl.Text; value = ableEdit.CControl.Text; break; default: text = ableEdit.CControl.Text; value = ableEdit.CControl.Text; break; } //设置属性的值 template.SetObjValue(OpeRecord, ableEdit.ClassDataSourceName, text, value, isUpdate); //如果有逻辑区域,则区域进行更新。 template.NotificationAreaBindingUpdate(template.ProjectName + "逻辑"); } } 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; case EControlType.Directory: if (ableEdit.ControlTitleText == "CA" || ableEdit.ControlTitleText == "签名") Workerqm_Click(ableEdit, e, 2); else TYZD_Click(ableEdit, e, true); break; default: text = ableEdit.CControl.Text; value = ableEdit.CControl.Text; break; } } catch (Exception ex) { PublicMethod.WriteLog(ex); } finally { template.ZedControl.Refresh(); } } private void txt_Click(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; if (SelectDictText.dgvZd.Visible == true) { SelectDictText.Hidden(); } } 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; try { if (ableEdit.ControlType == EControlType.RadioButtonList) { if ((sender as CheckBox).Checked == true) { foreach (CheckBox chk in (sender as CheckBox).Parent.Controls) { chk.CheckedChanged -= new EventHandler(txt_Leave); if (chk != sender) { chk.Checked = false; } chk.CheckedChanged += new EventHandler(txt_Leave); } } } SetAbleEditView(ableEdit, true); } catch (Exception ex) { //写日志 PublicMethod.WriteLog(ex); } 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; } } } //通用字典分组窗体打开 private void TYZD_Click(AbleEditPackObj sender, EventArgs e, bool isRadio = false) { try { AbleEditPackObj ableEdit = sender; if (ableEdit == null) return; if (myOpeRecord == null) return; if (ableEdit.ControlType == EControlType.Directory) { SelDict(sender, e, ableEdit.ControlTitleText, isRadio); } else if (ableEdit.ControlType == EControlType.Directorys) { SetDirectorysMethod(ableEdit); } } catch (Exception ex) { AIMSExtension.PublicMethod.WriteLog(ex); } } private void SetDirectorysMethod(AbleEditPackObj ableEdit) { DevComponents.DotNetBar.Controls.TokenEditor tokenEditor = ableEdit.CControl as DevComponents.DotNetBar.Controls.TokenEditor; tokenEditor.EditTextBox.DoubleClick -= EditTextBox_DoubleClick; tokenEditor.EditTextBox.DoubleClick += EditTextBox_DoubleClick; tokenEditor.EditTextBox.TextChanged -= EditTextBox_TextChanged; tokenEditor.EditTextBox.TextChanged += EditTextBox_TextChanged; tokenEditor.Leave -= TokenEditor_Leave; tokenEditor.Leave += TokenEditor_Leave; tokenEditor.ValidateToken -= new DevComponents.DotNetBar.Controls.ValidateTokenEventHandler(this.tokenEditor_ValidateToken); tokenEditor.ValidateToken += new DevComponents.DotNetBar.Controls.ValidateTokenEventHandler(this.tokenEditor_ValidateToken); EditTextBox_DoubleClick(tokenEditor.EditTextBox, null); tokenEditor.EditTextBox.Select(); } private void SelDict(AbleEditPackObj sender, EventArgs e, string _DictType, bool isRadio = false) { AbleEditPackObj ableEdit = sender; if (ableEdit == null) return; ableEdit.CControl.Leave -= new EventHandler(txt_Leave); ableEdit.CControl.KeyUp -= new KeyEventHandler(CControl_KeyUp); ableEdit.CControl.KeyUp += new KeyEventHandler(CControl_KeyUp); ableEdit.CControl.KeyPress -= new KeyPressEventHandler(CControl_KeyPress); ableEdit.CControl.KeyPress += new KeyPressEventHandler(CControl_KeyPress); if (myOpeRecord != null) { Control conl = sender.CControl; if (conl is TextBox) { ((TextBox)conl).BorderStyle = BorderStyle.Fixed3D; ((TextBox)conl).Focus(); if (sender.PackValue != null && sender.PackValue.Trim() != "" && isRadio == false) { if (((TextBox)conl).Text.LastIndexOf(',') != sender.PackText.Length) ((TextBox)conl).Text = ((TextBox)conl).Text + ","; } ((TextBox)conl).Select(((TextBox)conl).Text.Length, 1); } aSyncSelectDict.Show(template, OpeRecord, sender, _DictType, isRadio); ableEdit.CControl.Leave += new EventHandler(txt_Leave); } } private void ASyncSelectDict_SetValue(string Text, string Key, AbleEditPackObj aEdit) { aEdit.PackValue = Text; aEdit.PackText = Text; template.SetObjValue(OpeRecord, aEdit.ClassDataSourceName, Text, Text, true); aEdit.CControl.Leave -= new EventHandler(txt_Leave); aEdit.CControl.Leave += new EventHandler(txt_Leave); } private void CControl_KeyUp(object sender, KeyEventArgs e) { if (myOpeRecord != null) { Control conl = sender as Control; if (e.KeyCode == Keys.Down) { if (SelectDictText.dgvZd.CurrentRow.Index + 1 != SelectDictText.dgvZd.Rows.Count - 1) { SelectDictText.dgvZd.CurrentCell = SelectDictText.dgvZd.Rows[SelectDictText.dgvZd.CurrentRow.Index + 1].Cells[1]; } } else if (e.KeyCode == Keys.Up) { if (SelectDictText.dgvZd.CurrentRow.Index != 0) { SelectDictText.dgvZd.CurrentCell = SelectDictText.dgvZd.Rows[SelectDictText.dgvZd.CurrentRow.Index - 1].Cells[1]; } } } } private void CControl_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar.ToString() == "\r") { if (SelectDictText.dgvZd.SelectedRows.Count > 0) { SelectDictText.SetContent(SelectDictText.dgvZd.SelectedRows[0].Index); } } } private void EditTextBox_DoubleClick(object sender, EventArgs e) { TextBox txt = sender as TextBox; TokenEditorManage.SelectDictList(OpeRecord as OperationRecord, txt, false); } private void EditTextBox_TextChanged(object sender, EventArgs e) { TextBox txt = sender as TextBox; TokenEditorManage.SelectDictList(OpeRecord as OperationRecord, txt, false); } private void tokenEditor_ValidateToken(object sender, DevComponents.DotNetBar.Controls.ValidateTokenEventArgs ea) { DevComponents.DotNetBar.Controls.TokenEditor tokenEditor = sender as DevComponents.DotNetBar.Controls.TokenEditor; AbleEditPackObj aEdit = tokenEditor.Tag as AbleEditPackObj; if (ea.IsNewToken) { tokenEditor.EditTextBox.TextChanged -= EditTextBox_TextChanged; tokenEditor.SelectedTokens.Add(new EditToken(ea.Token.Value, ea.Token.Value)); ea.Token = null; tokenEditor.EditTextBox.Text = ""; tokenEditor.IsPopupOpen = false; tokenEditor.EditTextBox.TextChanged += EditTextBox_TextChanged; } } private void TokenEditor_Leave(object sender, EventArgs e) { DevComponents.DotNetBar.Controls.TokenEditor tokenEditor = sender as DevComponents.DotNetBar.Controls.TokenEditor; AbleEditPackObj aEdit = tokenEditor.Tag as AbleEditPackObj; TokenEditorManage.SaveDictItemText(template, OpeRecord as OperationRecord, tokenEditor, aEdit); } private void Workerqm_Click(AbleEditPackObj sender, EventArgs e, int _workersType) { AbleEditPackObj ableEdit = sender; if (ableEdit == null) return; if (myOpeRecord != null) { KeyValuePair _controlName = new KeyValuePair(ableEdit.PackValue, ableEdit.PackText); KeyValuePair keyValuePairs = SelectWorker(ableEdit.PackTag, _controlName, _workersType, PublicMethod.DepId, true); if (keyValuePairs.Key != null) { string value = keyValuePairs.Key.ToString(); string text = keyValuePairs.Value.ToString(); ableEdit.PackValue = value; ableEdit.PackText = text; SetCAAbleEditPackObj(ableEdit); //设置属性的值 ableEdit.IsVisible = false;// !ableEdit.IsVisible; template.SetObjValue(OpeRecord, ableEdit.ClassDataSourceName, text, value, true); ZedControl.Refresh(); } else { ableEdit.IsVisible = !ableEdit.IsVisible; } } } private void SetCAAbleEditPackObj(AbleEditPackObj ableEdit) { DataTable Person = null; try { if (!string.IsNullOrWhiteSpace(ableEdit.PackValue)) Person = DBManage.GetPerson(int.Parse(ableEdit.PackValue)); } catch (Exception) { Person = null; } if (Person != null && Person.Rows.Count > 0) { string Id = Person.Rows[0][3].ToString(); string Name = Person.Rows[0][0].ToString(); string Contact = Person.Rows[0][1].ToString(); string SignatureStr = Person.Rows[0][2].ToString(); string SignDataStr = PublicMethod.ImgToBase64Str(ZedControl.GetImage()); if (SignatureStr == null || SignatureStr == "") SignatureStr = new SignManage().GetSignStr(SignDataStr, "麻醉记录单", Id, Name, Contact); if (SignatureStr != null && SignatureStr != "") { ableEdit.PackText = Name; Image img = PublicMethod.BytesToImage(Convert.FromBase64String(SignatureStr)); if (img != null) ableEdit.PickImage = img; } } if (ableEdit != null && string.IsNullOrWhiteSpace(ableEdit.PackValue)) { ableEdit.PickImage = null; ableEdit.PackText = ""; } } /// /// 选择人员 /// /// 传递取值控件 /// 人员类型(0医生,1护士,2麻醉医生,3,麻醉护士,9其他) /// 科室Id /// 是否单选 /// CA签名数据信息 public KeyValuePair SelectWorker(string Tag, KeyValuePair sender, int _workersType, int _deptId, bool isRadio = false) { KeyValuePair _controlName = new KeyValuePair(); SelectPerson personDoc = new SelectPerson(); personDoc.PersonType = _workersType == 2 ? "麻醉医生" : "护士"; DialogResult dialogResult = personDoc.ShowDialog(); if (dialogResult == DialogResult.OK) { if (personDoc.SelectPersonData != null && personDoc.SelectPersonData != "") { string PersonId = personDoc.SelectPersonData.ToString(); _controlName = new KeyValuePair(PersonId, personDoc.SelectPersonName); } else { _controlName = new KeyValuePair("", ""); } } return _controlName; } } }