488 lines
15 KiB
C#
488 lines
15 KiB
C#
using DrawGraph;
|
|
using HelperDB;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
|
namespace DrawGraph
|
|
{
|
|
[JsonObject(MemberSerialization.OptOut)]
|
|
[Serializable]
|
|
public class PackObjManager
|
|
{
|
|
|
|
private string outFlat = "||";
|
|
|
|
private string msgStr = "";
|
|
|
|
private float x = 0f;
|
|
|
|
private float y = 0f;
|
|
|
|
[NonSerialized]
|
|
private ZedGraphControl zedControl = null;
|
|
|
|
private List<PackObjBase> listPob = new List<PackObjBase>();
|
|
|
|
private string name = "";
|
|
|
|
private string className = "";
|
|
|
|
private bool isLoading = true;
|
|
|
|
public int ControlIndex = 0;
|
|
|
|
[NoCreatControlAttributs]
|
|
public float X
|
|
{
|
|
get
|
|
{
|
|
return this.x;
|
|
}
|
|
set
|
|
{
|
|
this.x = value;
|
|
bool flag = !this.isLoading;
|
|
if (flag)
|
|
{
|
|
this.DrawPackObj(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
[NoCreatControlAttributs]
|
|
public float Y
|
|
{
|
|
get
|
|
{
|
|
return this.y;
|
|
}
|
|
set
|
|
{
|
|
this.y = value;
|
|
bool flag = !this.isLoading;
|
|
if (flag)
|
|
{
|
|
this.DrawPackObj(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
public string Name
|
|
{
|
|
get
|
|
{
|
|
return this.name;
|
|
}
|
|
set
|
|
{
|
|
this.name = value;
|
|
}
|
|
}
|
|
|
|
[JsonIgnore]
|
|
public string MsgStr
|
|
{
|
|
get
|
|
{
|
|
return this.msgStr;
|
|
}
|
|
set
|
|
{
|
|
this.msgStr = value;
|
|
}
|
|
}
|
|
|
|
[JsonIgnore]
|
|
public List<PackObjBase> ListPob
|
|
{
|
|
get
|
|
{
|
|
bool flag = this.listPob.Count > 0;
|
|
if (flag)
|
|
{
|
|
this.listPob.Sort(new Comparison<PackObjBase>(this.ComparePackObjByOrder));
|
|
}
|
|
return this.listPob;
|
|
}
|
|
set
|
|
{
|
|
this.listPob = value;
|
|
}
|
|
}
|
|
|
|
public string ClassName
|
|
{
|
|
get
|
|
{
|
|
return this.className;
|
|
}
|
|
set
|
|
{
|
|
this.className = value;
|
|
}
|
|
}
|
|
|
|
public int GetControlIndex()
|
|
{
|
|
return ++this.ControlIndex;
|
|
}
|
|
|
|
public PackObjManager()
|
|
{
|
|
this.ControlIndex = 0;
|
|
this.ListPob.Clear();
|
|
}
|
|
|
|
public PackObjManager(ZedGraphControl _zedControl)
|
|
{
|
|
this.ControlIndex = 0;
|
|
this.ListPob.Clear();
|
|
this.zedControl = _zedControl;
|
|
}
|
|
|
|
public bool RemovePob(PackObjBase pod)
|
|
{
|
|
bool result = false;
|
|
foreach (PackObjBase current in this.ListPob)
|
|
{
|
|
bool flag = current.PackName == pod.PackName;
|
|
if (flag)
|
|
{
|
|
result = this.ListPob.Remove(current);
|
|
break;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public int indexPob(PackObjBase pod)
|
|
{
|
|
int result;
|
|
for (int i = 0; i < this.ListPob.Count; i++)
|
|
{
|
|
bool flag = this.ListPob[i].PackName == pod.PackName;
|
|
if (flag)
|
|
{
|
|
result = i;
|
|
return result;
|
|
}
|
|
}
|
|
result = -1;
|
|
return result;
|
|
}
|
|
|
|
public bool LoadContent(string fileName, int parentId)
|
|
{
|
|
bool flag = true;
|
|
bool result;
|
|
try
|
|
{
|
|
bool flag2 = fileName == "" || this.zedControl == null;
|
|
if (flag2)
|
|
{
|
|
this.msgStr = "文件名不能为空,组件不能为空";
|
|
result = false;
|
|
return result;
|
|
}
|
|
string text = DBHelper.ExecuteScalar("SELECT [JsonDate] FROM [dbo].[OperationRecordTemplate] where Name='" + fileName + "' and ParentId="+ parentId+" " ).ToString(); //File.ReadAllText(fileName);
|
|
bool flag3 = text != null && text != "";
|
|
if (flag3)
|
|
{
|
|
string[] array = text.Split(this.outFlat.ToCharArray());
|
|
for (int i = 0; i < array.Length; i++)
|
|
{
|
|
bool flag4 = array[i].IndexOf("ControlIndex") >= 0;
|
|
if (flag4)
|
|
{
|
|
PackObjManager packObjManager = JsonConvert.DeserializeObject<PackObjManager>(array[i]);
|
|
this.X = packObjManager.X;
|
|
this.Y = packObjManager.Y;
|
|
this.name = packObjManager.Name;
|
|
this.ControlIndex = packObjManager.ControlIndex;
|
|
this.isLoading = false;
|
|
}
|
|
else
|
|
{
|
|
bool flag5 = array[i].IndexOf("ClassName") >= 0;
|
|
if (flag5)
|
|
{
|
|
JArray jos = (JArray)JsonConvert.DeserializeObject(array[i]);
|
|
List<PackObjBase> packObjListByJson = this.GetPackObjListByJson(jos);
|
|
this.ListPob = packObjListByJson;
|
|
}
|
|
}
|
|
}
|
|
this.SetPackObjParent(this.listPob);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.msgStr = ex.Message.ToString();
|
|
flag = false;
|
|
}
|
|
result = flag;
|
|
return result;
|
|
}
|
|
|
|
public void SetZedControl(ZedGraphControl _zedControl)
|
|
{
|
|
this.zedControl = _zedControl;
|
|
foreach (PackObjBase current in this.listPob)
|
|
{
|
|
current.SetZedControl(this.zedControl);
|
|
}
|
|
this.isLoading = false;
|
|
}
|
|
|
|
private List<PackObjBase> GetPackObjListByJson(JArray jos)
|
|
{
|
|
List<PackObjBase> list = new List<PackObjBase>();
|
|
for (int i = 0; i < jos.Count; i++)
|
|
{
|
|
PackObjBase packObjBase = BoardUtil.PackObjFactory(jos[i]["ClassName"].ToString(), this.zedControl, this);
|
|
Type type = packObjBase.GetType();
|
|
PropertyInfo[] properties = type.GetProperties();
|
|
PropertyInfo[] array = properties;
|
|
for (int j = 0; j < array.Length; j++)
|
|
{
|
|
PropertyInfo propertyInfo = array[j];
|
|
try
|
|
{
|
|
bool flag = jos[i][propertyInfo.Name] != null;
|
|
if (flag)
|
|
{
|
|
bool isEnum = propertyInfo.PropertyType.IsEnum;
|
|
if (isEnum)
|
|
{
|
|
object value = Enum.Parse(propertyInfo.PropertyType, jos[i][propertyInfo.Name].ToString(), false);
|
|
propertyInfo.SetValue(packObjBase, Convert.ChangeType(value, propertyInfo.PropertyType), null);
|
|
}
|
|
else
|
|
{
|
|
bool flag2 = propertyInfo.PropertyType == typeof(Color);
|
|
if (flag2)
|
|
{
|
|
ColorConverter colorConverter = new ColorConverter();
|
|
object value2 = colorConverter.ConvertFrom(jos[i][propertyInfo.Name].ToString());
|
|
try
|
|
{
|
|
propertyInfo.SetValue(packObjBase, Convert.ChangeType(value2, propertyInfo.PropertyType), null);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bool flag3 = propertyInfo.PropertyType == typeof(List<CodeTableItem>);
|
|
if (flag3)
|
|
{
|
|
List<CodeTableItem> value3 = JsonConvert.DeserializeObject<List<CodeTableItem>>(jos[i][propertyInfo.Name].ToString());
|
|
propertyInfo.SetValue(packObjBase, Convert.ChangeType(value3, propertyInfo.PropertyType), null);
|
|
}
|
|
else
|
|
{
|
|
propertyInfo.SetValue(packObjBase, Convert.ChangeType(jos[i][propertyInfo.Name].ToString(), propertyInfo.PropertyType), null);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
PropertyInfo expr_1CC = propertyInfo;
|
|
this.msgStr = ((expr_1CC != null) ? expr_1CC.ToString() : null) + ":" + ex.Message.ToString();
|
|
}
|
|
}
|
|
list.Add(packObjBase);
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public bool SaveFile(string fileName, int Id)
|
|
{
|
|
bool flag = false;
|
|
bool flag2 = this.Name == "";
|
|
bool result;
|
|
if (flag2)
|
|
{
|
|
this.MsgStr = "区域包管理器名称不能为空";
|
|
result = flag;
|
|
}
|
|
else
|
|
{
|
|
bool flag3 = fileName == "";
|
|
if (flag3)
|
|
{
|
|
fileName = string.Concat(new string[]
|
|
{
|
|
base.GetType().Name,
|
|
"_",
|
|
this.Name
|
|
});
|
|
}
|
|
List<PackObjBase> list = this.ListPob;
|
|
foreach (PackObjBase current in list)
|
|
{
|
|
bool flag5 = current.DataSourceName != "";
|
|
if (flag5)
|
|
{
|
|
current.PackText = "";
|
|
current.PackValue = "";
|
|
}
|
|
}
|
|
bool flag6 = list.Count > 0;
|
|
if (flag6)
|
|
{
|
|
string text2 = JsonConvert.SerializeObject(list);
|
|
text2 = text2 + this.outFlat + JsonConvert.SerializeObject(this);
|
|
try
|
|
{
|
|
DBHelper.ExecNonQuery(" update [OperationRecordTemplate] set jsondate=N'" + text2 + "' where [Name]='" + fileName + "' and ParentId='" + Id + "' ");
|
|
this.msgStr = fileName + "保存成功";
|
|
flag = true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.msgStr = ex.Message.ToString();
|
|
}
|
|
finally
|
|
{
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.msgStr = "没有数据需要保存";
|
|
}
|
|
result = flag;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public void DrawPackObj(bool isNoDrwsBoard = false)
|
|
{
|
|
bool flag = this.ListPob.Count > 0;
|
|
if (flag)
|
|
{
|
|
foreach (PackObjBase current in this.ListPob)
|
|
{
|
|
if (isNoDrwsBoard)
|
|
{
|
|
bool flag2 = current is BorderPackObj;
|
|
if (flag2)
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
current.IsSelect = false;
|
|
current.Draw();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void AllClear()
|
|
{
|
|
this.zedControl.MasterPane.GraphObjList.Clear();
|
|
this.zedControl.Controls.Clear();
|
|
this.zedControl.AxisChange();
|
|
this.zedControl.Refresh();
|
|
this.listPob.Clear();
|
|
}
|
|
|
|
private int ComparePackObjByOrder(PackObjBase x, PackObjBase y)
|
|
{
|
|
bool flag = x == null;
|
|
int result;
|
|
if (flag)
|
|
{
|
|
bool flag2 = y == null;
|
|
if (flag2)
|
|
{
|
|
result = 0;
|
|
}
|
|
else
|
|
{
|
|
result = -1;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bool flag3 = y == null;
|
|
if (flag3)
|
|
{
|
|
result = 1;
|
|
}
|
|
else
|
|
{
|
|
int num = x.MyOrder.CompareTo(y.MyOrder);
|
|
bool flag4 = num != 0;
|
|
if (flag4)
|
|
{
|
|
result = num;
|
|
}
|
|
else
|
|
{
|
|
result = x.MyOrder.CompareTo(y.MyOrder);
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public bool ListPobsAdd(PackObjBase bpo)
|
|
{
|
|
bool result = false;
|
|
PackObjBase packObjBase = this.ListPob.FirstOrDefault((PackObjBase s) => s.PackTag == bpo.PackTag);
|
|
bool flag = packObjBase == null;
|
|
if (flag)
|
|
{
|
|
result = true;
|
|
this.ListPob.Add(bpo);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private void SetPackObjParent(List<PackObjBase> pobs)
|
|
{
|
|
Predicate<PackObjBase> method = (x) => { return x.ParentName == ""; };
|
|
|
|
List<PackObjBase> list = pobs.FindAll(method);
|
|
foreach (PackObjBase current in list)
|
|
{
|
|
this.SetPackObjSubParent(pobs, current);
|
|
}
|
|
}
|
|
|
|
private void SetPackObjSubParent(List<PackObjBase> pobs, PackObjBase parentPob)
|
|
{
|
|
List<PackObjBase> list = pobs.FindAll((PackObjBase c) => c.ParentName == parentPob.PackName);
|
|
bool flag = list.Count > 0;
|
|
if (flag)
|
|
{
|
|
foreach (PackObjBase current in list)
|
|
{
|
|
current.SetParent = parentPob;
|
|
this.SetPackObjSubParent(pobs, current);
|
|
}
|
|
}
|
|
}
|
|
public List<PackObjBase> Clone()
|
|
{
|
|
List<PackObjBase> list = new List<PackObjBase>();
|
|
foreach (PackObjBase current in this.ListPob)
|
|
{
|
|
list.Add(current.Clone());
|
|
}
|
|
return list;
|
|
}
|
|
}
|
|
}
|