using System; using System.Collections.Generic; using System.Linq; using System.Text; using Newtonsoft.Json; namespace POSV.Printer { [Serializable] [JsonObject(MemberSerialization.OptIn)] public class GridXParameter { [JsonProperty(PropertyName = "template")] public GridXTemplate Template { get; set; } [JsonProperty(PropertyName = "font")] public FontStyle FontStyle { get; set; } [JsonProperty(PropertyName = "align")] public AlignStyle AlignStyle { get; set; } /// /// 表头下划线格式 /// [JsonProperty(PropertyName = "line")] public LineStyle LineStyle { get; set; } } [Serializable] [JsonObject(MemberSerialization.OptIn)] public class GridXTemplate { private List columns = null; private Dictionary rows = null; private Dictionary> _dataSource; public GridXTemplate(Dictionary> dataSource) { this._dataSource = dataSource; this.DataSourceKey = "默认数据源"; this.columns = new List(); this.rows = new Dictionary(); } /// /// 数据源 /// [JsonIgnore] public Dictionary> DataSource { get { return this._dataSource; } set { this._dataSource = value; } } [JsonProperty(PropertyName = "data")] public string DataSourceKey { get; set; } /// /// 列集合 /// [JsonProperty(PropertyName = "columns")] public List Columns { get { return this.columns; } } /// /// 是否包含合计行 /// [JsonProperty(PropertyName = "contains")] public bool ContainsTotalRow { get; set; } /// /// 是否输出打印合计行 /// [JsonProperty(PropertyName = "output")] public bool OutputTotalRow { get; set; } /// /// 超出打印字符长度,独占一行 /// [JsonProperty(PropertyName = "newline")] public bool AllowNewLine { get; set; } /// /// 如果记录集为空不打印 /// [JsonProperty(PropertyName = "empty")] public bool NotAllowEmpty { get; set; } /// /// 行模版 /// [JsonProperty(PropertyName = "rows")] public Dictionary RowTemplates { get { return this.rows; } } /// /// 禁止打印表头 /// [JsonProperty(PropertyName = "header")] public bool NotAllowHeader { get; set; } = false; /// /// 表头采用正常字体打印 /// [JsonProperty(PropertyName = "headerFont")] public bool HeaderFontStyle { get; set; } = false; public override string ToString() { return JSON.Serialize(this); } } [Serializable] [JsonObject(MemberSerialization.OptIn)] public class GridRowTemplate : IEquatable { public GridRowTemplate(string name , string content , int width) { this.Name = name; this.Content = content; this.Width = width; } [JsonProperty(PropertyName = "name")] public string Name { get; set; } [JsonProperty(PropertyName = "content")] public string Content { get; set; } [JsonProperty(PropertyName = "width")] public int Width { get; set; } public bool Equals(GridRowTemplate other) { if (other == null) { return false; } return this.Content.Equals(other.Content) && this.Width == other.Width; } } [Serializable] [JsonObject(MemberSerialization.OptIn)] public class GridColumn : IEquatable { public GridColumn(int index , string name , int width , int length) { this.Index = index; this.Name = name; this.Width = width; this.Length = length; } [JsonProperty(PropertyName = "index")] public int Index { get; set; } [JsonProperty(PropertyName = "name")] public string Name { get; set; } [JsonProperty(PropertyName = "width")] public int Width { get; set; } [JsonProperty(PropertyName = "length")] public int Length { get; set; } public bool Equals(GridColumn other) { if (other == null) { return false; } return this.Name.Equals(other.Name) && this.Width == other.Width; } } }