상속: IComparable
예제 #1
0
파일: Table.cs 프로젝트: DuBin1988/restv2
 /// <summary>
 /// 获得模板
 /// </summary>
 /// <param name="item"></param>
 private void InitTemplate(JsonObject item)
 {
     //取出表头行定义
     JsonArray rows = item["rows"] as JsonArray;
     foreach (JsonObject obj in rows)
     {
         int height = obj["height"];
         string type = obj["type"];
         if (type == "head")
         {
             Row row = new Row() { Height = height };
             this.headRowTemplate.Add(row);
         }
         if (type == "bottom")
         {
             Row row = new Row() { Height = height };
             this.bottomRowTemplate.Add(row);
         }
     }
     //获得模板
     JsonArray cells = item["cells"] as JsonArray;
     foreach (JsonObject obj in cells)
     {
         int row = obj["row"];
         int column = obj["column"];
         string content = obj["content"];
         int rowspan = obj["rowspan"];
         int columnspan = obj["columnspan"];
         string location = obj["location"];
         int height = obj["height"];
         Cell cell = new Cell() { Row = row, Column = column, Content = content, RowSpan = rowspan, ColumnSpan = columnspan, Location = location, Height = height };
         string type = obj["type"];
         //表头
         if (type == "head" || type == "headchange")
         {
             this.headCellTemplate.Add(cell);
         }
         //表头变化部分
         if (type == "headchange")
         {
             this.headChangeCellTemplate.Add(cell);
         }
         //左侧
         if (type == "left")
         {
             Program prog = new Program("data."+cell.Content, this, false);
             Delegate d = prog.Parse(prog.Exp);
             cell.Delegate = d;
             this.leftCellTemplate.Add(cell);
         }
         //主体
         if (type == "main")
         {
             this.bodyCellTemplate.Add(cell);
         }
         //表底
         if (type == "bottom")
         {
             this.bottomCellTemplate.Add(cell);
         }
     }
     //如果表头有变化部分,表头模板根据列号排序
     if (HasHead)
     {
         List<Cell> headCellTemplate_temp = new List<Cell>();
         //表头模板根据列号排序
         for (int i = 0; i < this.headCellTemplate.Count; i++)
         {
             foreach (Cell cell in this.headCellTemplate)
             {
                 if (cell.Column == i)
                 {
                     headCellTemplate_temp.Add(cell);
                     break;
                 }
             }
         }
         this.headCellTemplate.Clear();
         this.headCellTemplate.AddRange(headCellTemplate_temp);
     }
 }
예제 #2
0
파일: Table.cs 프로젝트: DuBin1988/restv2
 /// <summary>
 /// 根据主体数据生成界面
 /// </summary>
 private void UpdateBody()
 {
     if (TableHeadItems.Value.Count == 0 
         && TableLeftItems.Value.Count == 0 
         && TableBodyItems.Count == 0) return;
     //绘制有表头变化,有左侧的主体
     if (HasHead && HasLeft)
     {
         //获得表头变化模板包含几列
         Dictionary<string, int> dic = getColumnNumber(headChangeCellTemplate);
         for (int i = 0; i < TableHeadItems.Value.Count; i++)
         {
             CurrentHead = TableHeadItems.Value[i];
             for (int j = 0; j < TableLeftItems.Value.Count; j++)
             {
                 CurrentLeft = TableLeftItems.Value[j];
                 //画主体
                 foreach (Cell cell in bodyCellTemplate)
                 {
                     Cell copy = cell.copyCell();
                     Program prog = new Program(copy.Content, this, false);
                     Delegate d = prog.Parse(prog.Exp);
                     copy.Delegate = d;
                     object value = copy.Delegate.DynamicInvoke();
                     copy.Content = value + "";
                     copy.Row = cell.Row + j;
                     //单元格在变化部分右侧
                     if (copy.Column > dic["max"]) 
                     { 
                         copy.Column = copy.Column + (TableHeadItems.Value.Count - 1) * dic["count"]; 
                     }
                     else{ copy.Column = cell.Column + i * dic["count"];}
                     this.cells.Add(copy);
                 }
                 
             }
         }
         //根据左侧数据添加行
         foreach (var item in TableLeftItems.Value)
         {
             //根据模板加一行
             Row row = new Row() { Height = bodyCellTemplate[0].Height };
             this.rows.Add(row);
         }
     }
     else if (HasLeft)
     {
         //根据左侧复制主体
         for (int i = 0; i < TableLeftItems.Value.Count; i++)
         {
             CurrentLeft = TableLeftItems.Value[i];
             foreach (Cell cell in bodyCellTemplate)
             {
                 Cell copy = cell.copyCell();
                 Program prog = new Program(copy.Content, this, false);
                 Delegate d = prog.Parse(prog.Exp);
                 copy.Delegate = d;
                 object value = copy.Delegate.DynamicInvoke();
                 copy.Content = value + "";
                 copy.Row = cell.Row + i;
                 copy.Column = cell.Column;
                 this.cells.Add(copy);
             }
             //根据模板加一行
             Row row = new Row() { Height = bodyCellTemplate[0].Height };
             this.rows.Add(row);
         }
     }
     //只有主体部分,没有左侧,没有表头变化部分
     else
     {
         for (int i = 0; i < TableBodyItems[0].Value.Count; i++)
         {
             CurrentMain = TableBodyItems[0].Value[i];
             foreach (Cell cell in bodyCellTemplate)
             {
                 Cell copy = cell.copyCell();
                 Program prog = new Program(copy.Content, this, false);
                 Delegate d = prog.Parse(prog.Exp);
                 copy.Delegate = d;
                 object value = copy.Delegate.DynamicInvoke();
                 copy.Content = value + "";
                 copy.Row = cell.Row + i;
                 this.cells.Add(copy);
             }
             if (bodyCellTemplate.Count != 0)
             {
                 //根据模板加一行
                 Row row = new Row() { Height = bodyCellTemplate[0].Height };
                 this.rows.Add(row);
             }
         }
     }
 }
예제 #3
0
파일: Table.cs 프로젝트: DuBin1988/restv2
 /// <summary>
 /// 把json转成报表对象
 /// </summary>
 /// <param name="json"></param>
 private void jsonToTable(string json)
 {
     this.cells.Clear();
     this.columns.Clear();
     this.rows.Clear();
     JsonObject item = JsonValue.Parse(json) as JsonObject;
     GeneralObject go = new GeneralObject();
     go.FromJson(item);
     //列
     ObjectList ol = go.GetPropertyValue("Column") as ObjectList;
     foreach (GeneralObject one in ol)
     {
         Column c = new Column();
         c.Width = Int32.Parse(one.GetPropertyValue("Width") + "");
         this.columns.Add(c);
     }
     //行
     ol = go.GetPropertyValue("Row") as ObjectList;
     foreach (GeneralObject one in ol)
     {
         Row r = new Row();
         r.Height = Int32.Parse(one.GetPropertyValue("Height")+"");
         this.rows.Add(r);
     }
     //单元格
     ol = go.GetPropertyValue("Cell") as ObjectList;
     foreach (GeneralObject one in ol)
     {
         Cell c = new Cell();
         c.Content = one.GetPropertyValue("Content") + "";
         c.Column = Int32.Parse(one.GetPropertyValue("Column") + "");
         c.ColumnSpan = Int32.Parse(one.GetPropertyValue("ColumnSpan") + "");
         c.Row = Int32.Parse(one.GetPropertyValue("Row") + "");
         c.RowSpan = Int32.Parse(one.GetPropertyValue("RowSpan") + "");
         c.Location = one.GetPropertyValue("Location") + "";
         this.cells.Add(c);
     }
     //绘制报表
     Layout();
 }