AIMS/DrawGraph/AreaManage/TempDataManage.cs
2022-11-05 23:11:38 +08:00

579 lines
24 KiB
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using AIMSExtension;
using DevComponents.Editors.DateTimeAdv;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using static System.Net.Mime.MediaTypeNames;
namespace DrawGraph
{
/// <summary>
/// 麻醉前访视单
/// </summary>
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<AbleEditPackObj>("TempDataManage_AbleEditPackObj_357_OperationRecord_InstrumentList_TagPicturePanel");
ableEdit3 = template.GetPackObjectOTag<AbleEditPackObj>("TempDataManage_AbleEditPackObj_397_OperationRecord_InstrumentList_PackPanel");
}
#region
/// <summary>
/// 鼠标点击画板
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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<PackObjBase>(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<TextPackObj>("TempDataManage_TextPackObj_" + i);
if (packObj != null)
{
packObj.PackText = "";
packObj.PackValue = "";
packObj.Draw();
}
}
}
List<PackObjBase> ables = PackManage.ListPob.Where<PackObjBase>(s => s is AbleEditPackObj).ToList<PackObjBase>();
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.Leave -= new EventHandler(txt_Leave);
ableEdit.CControl.Leave += 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)
{
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.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);
}
}
/// <summary>
/// 在画完表单后,显示多选单选的默认项
/// </summary>
public override void FollowUpMethod()
{
base.FollowUpMethod();
List<PackObjBase> ables = PackManage.ListPob.Where<PackObjBase>(s => s is AbleEditPackObj).ToList<PackObjBase>();
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<JsonTextForDoc> list = JsonConvert.DeserializeObject<List<JsonTextForDoc>>(myOpeRecord.InstrumentList.JsonTextData);
foreach (JsonTextForDoc m in list)
{
if (m.Id.Trim() == "")
continue;
TextPackObj packObj = template.GetPackObjectOTag<TextPackObj>(m.Tag);
packObj.PackText = m.Value;
packObj.PackValue = m.Value;
packObj.Draw();
}
}
}
List<PackObjBase> ables = PackManage.ListPob.Where<PackObjBase>(s => s is AbleEditPackObj).ToList<PackObjBase>();
foreach (PackObjBase pack in ables)
{
pack.Draw();
}
}
/// <summary>
/// 公共验证方法
/// </summary>
/// <returns></returns>
public override bool Verification()
{
List<PackObjBase> editPack = PackManage.ListPob.Where<PackObjBase>(s => s is AbleEditPackObj).ToList<PackObjBase>();
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
/// <summary>
/// 设置可编辑组件的显示样式
/// </summary>
/// <param name="ableEdit"></param>
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:
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:
TYZD_Click(ableEdit, e, true);
break;
default:
text = ableEdit.CControl.Text;
value = ableEdit.CControl.Text;
break;
}
}
catch (Exception ex)
{
}
finally
{
template.ZedControl.Refresh();
}
}
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<PackObjBase> ables = PackManage.ListPob.Where<PackObjBase>(s => s is AbleEditPackObj).ToList<PackObjBase>();
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)
{
AbleEditPackObj ableEdit = sender;
if (ableEdit == null) return;
try
{
if (myOpeRecord != null)
{
SelDict(sender, e, ableEdit.ControlTitleText, isRadio);
}
}
catch (Exception ex)
{
AIMSExtension.PublicMethod.WriteLog(ex);
}
}
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.TextChanged -= new EventHandler(CControl_TextChanged);
//ableEdit.CControl.TextChanged += new EventHandler(CControl_TextChanged);
//ableEdit.CControl.MouseDown -= new MouseEventHandler(CControl_MouseDown);
//ableEdit.CControl.MouseDown += new MouseEventHandler(CControl_MouseDown);
//ableEdit.CControl.KeyUp -= new KeyEventHandler(CControl_KeyUp);
//ableEdit.CControl.KeyUp += new KeyEventHandler(CControl_KeyUp);
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);
//SetAbleEditView(ableEdit);
}
}
private void ASyncSelectDict_SetValue(string Text, 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_TextChanged(object sender, EventArgs e)
//{
// if (myOpeRecord != null)
// {
// Control conl = sender as Control;
// aSyncSelectDict.ShowSel(conl, OpeRecord);
// }
//}
//private void CControl_KeyUp(object sender, KeyEventArgs e)
//{
// if (myOpeRecord != null)
// {
// Control conl = sender as Control;
// if (conl.Text != SelectDictText.Value)
// if (e.KeyCode == Keys.Delete || e.KeyCode == Keys.Back)
// {
// aSyncSelectDict.DelSel(conl, OpeRecord);
// }
// }
//}
//private void CControl_MouseDown(object sender, MouseEventArgs e)
//{
// if (myOpeRecord != null)
// {
// TextBox conl = sender as TextBox;
// string leftStr = conl.Text.Substring(0, conl.SelectionStart);
// string rightStr = conl.Text.Substring(conl.SelectionStart, conl.Text.Length - conl.SelectionStart);
// int startIndex = 0;
// int endLength = conl.Text.Length;
// if (leftStr.Contains(","))
// {
// int beginindex = leftStr.LastIndexOf(',');
// startIndex = beginindex + 1;
// if (rightStr.Contains(","))
// {
// endLength = rightStr.IndexOf(",") + (leftStr.Length - beginindex);
// }
// }
// else
// {
// if (rightStr.Contains(","))
// {
// endLength = rightStr.IndexOf(",") + leftStr.Length + 1;
// }
// }
// conl.Select(startIndex, endLength);
// }
//}
}
}