You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

207 lines
5.2 KiB
C#

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; }
/// <summary>
/// 表头下划线格式
/// </summary>
[JsonProperty(PropertyName = "line")]
public LineStyle LineStyle { get; set; }
}
[Serializable]
[JsonObject(MemberSerialization.OptIn)]
public class GridXTemplate
{
private List<GridColumn> columns = null;
private Dictionary<int , GridRowTemplate> rows = null;
private Dictionary<string , List<VariableItem>> _dataSource;
public GridXTemplate(Dictionary<string , List<VariableItem>> dataSource)
{
this._dataSource = dataSource;
this.DataSourceKey = "默认数据源";
this.columns = new List<GridColumn>();
this.rows = new Dictionary<int , GridRowTemplate>();
}
/// <summary>
/// 数据源
/// </summary>
[JsonIgnore]
public Dictionary<string , List<VariableItem>> DataSource
{
get
{
return this._dataSource;
}
set
{
this._dataSource = value;
}
}
[JsonProperty(PropertyName = "data")]
public string DataSourceKey { get; set; }
/// <summary>
/// 列集合
/// </summary>
[JsonProperty(PropertyName = "columns")]
public List<GridColumn> Columns
{
get
{
return this.columns;
}
}
/// <summary>
/// 是否包含合计行
/// </summary>
[JsonProperty(PropertyName = "contains")]
public bool ContainsTotalRow { get; set; }
/// <summary>
/// 是否输出打印合计行
/// </summary>
[JsonProperty(PropertyName = "output")]
public bool OutputTotalRow { get; set; }
/// <summary>
/// 超出打印字符长度,独占一行
/// </summary>
[JsonProperty(PropertyName = "newline")]
public bool AllowNewLine { get; set; }
/// <summary>
/// 如果记录集为空不打印
/// </summary>
[JsonProperty(PropertyName = "empty")]
public bool NotAllowEmpty { get; set; }
/// <summary>
/// 行模版
/// </summary>
[JsonProperty(PropertyName = "rows")]
public Dictionary<int , GridRowTemplate> RowTemplates
{
get
{
return this.rows;
}
}
/// <summary>
/// 禁止打印表头
/// </summary>
[JsonProperty(PropertyName = "header")]
public bool NotAllowHeader { get; set; } = false;
/// <summary>
/// 表头采用正常字体打印
/// </summary>
[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<GridRowTemplate>
{
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<GridColumn>
{
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;
}
}
}