using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace MultiLayout
{
///
///
///
public class FlyLayout : INotifyPropertyChanged
{
public List GageTabItems { get; set; }
private int dynareawidth = 250;
///
/// 动态区宽度
///
public int DynAreaWidth
{
get
{
return dynareawidth;
}
set
{
if (value < 100)
value = 100;
if (dynareawidth != value)
{
dynareawidth = value;
}
}
}
///
/// 动态区显示
///
public bool IsDynAreaVisible { get; set; } = true;
///
/// 隐藏 logo
///
public bool IsLogoHidden { get; set; }
#region 上一次界面状态
public System.Drawing.Rectangle Rect { get; set; } = new System.Drawing.Rectangle(0, 0, 1024, 768);
public WindowState WindowState { get; set; } = WindowState.Maximized;
#endregion
///
/// 基本路径,全部参数都应该放在这个文件夹内
///
public const string BasePath = "layout";
///
///
///
public FlyLayout()
{
}
///
/// 加载
///
public void Load()
{
string path = System.IO.Path.Combine(BasePath, "graphcustom.json");
if (!File.Exists(path))
return;
try
{
string json = File.ReadAllText(path);
Newtonsoft.Json.JsonConvert.PopulateObject(json, this);
}
catch
{
}
if (GageTabItems == null)
GageTabItems = new List();
foreach (var gageTabItem in GageTabItems)
{
if (gageTabItem.Components == null)
{
gageTabItem.Components = new List();
}
if (gageTabItem.DynAreaItems == null)
{
gageTabItem.DynAreaItems = new List();
}
if (gageTabItem.MenuItems == null)
{
gageTabItem.MenuItems = new List();
}
if (gageTabItem.Items == null)
{
gageTabItem.Items = new List();
}
foreach (var item in gageTabItem.Items)
{
if (item.Graphs == null)
{
item.Graphs = new List();
}
}
}
}
///
/// 保存
///
public void Save()
{
try
{
if (!System.IO.Directory.Exists(BasePath))
System.IO.Directory.CreateDirectory(BasePath);
string path = System.IO.Path.Combine(FlyLayout.BasePath, "graphcustom.json");
string json = Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
File.WriteAllText(path, json);
}
catch
{
}
}
///
///
///
public event PropertyChangedEventHandler PropertyChanged;
}
///
/// 控件基类
///
public class FlyComponent : INotifyPropertyChanged
{
///
/// 全局唯一ID
///
public int ID { get; set; }
///
/// 模块的类名全称
///
public string Module { get; set; }
///
/// 容器名称
///
public string ServiceContainerName { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
public override string ToString()
{
return Module;
}
}
///
///
///
public class GraphComponent : INotifyPropertyChanged
{
///
/// 编号
///
public int ID { get; set; }
public System.Drawing.Rectangle Rect { get; set; } = new System.Drawing.Rectangle(0, 0, 1, 1);
public event PropertyChangedEventHandler PropertyChanged;
}
///
/// 图表区 tabitem
///
public class GraphTabItem:INotifyPropertyChanged
{
///
/// 图表
///
public List Graphs { get; set; } = new List();
///
/// 列数量
///
public int ColumnCount { get; set; } = 1;
///
/// 行数量
///
public int RowCount { get; set; } = 3;
///
/// 每行定义, 当为auto时,为true
///
public List RowDefinitions { get; set; } = new List();
///
/// 每列定义, 当为auto时,为true
///
public List ColumnDefinitions { get; set; } = new List();
///
/// 标题
///
public string Header { get; set; } = "Test";
public event PropertyChangedEventHandler PropertyChanged;
}
///
/// 设备页面
///
public class GageTabItem:INotifyPropertyChanged
{
///
/// 标题
///
public string Title { get; set; }
///
/// 容器名称
///
public string ServiceContainerName { get; set; }
///
/// 设置目录 图标
///
public List MenuItems { get; set; } = new List();
///
/// 动态区 控件组
///
public List DynAreaItems { get; set; } = new List();
///
/// 图表区,tabitem
///
public List Items { get; set; } = new List();
///
/// 根据配置 最后生成的 TabControl
///
[JsonIgnore]
public TabControl TabControl;
///
/// 全部组件
///
public List Components { get; set; } = new List();
public event PropertyChangedEventHandler PropertyChanged;
}
}