Inheritance: IComparable
Beispiel #1
0
 /// <summary>
 /// 加载文件,获得所有需要执行的sql
 /// </summary>
 private void Init()
 {
     string uri = WebClientInfo.BaseAddress + "/" + FileName;
     //根据uri,去后台获取数据
     WebClient client = new WebClient();
     client.DownloadStringCompleted += (o, a) =>
     {
         IsBusy = false;
         if (a.Error != null)
         {
             MessageBox.Show("加载报表文件失败!");
         }
         else
         {
             JsonObject item = JsonValue.Parse(a.Result) as JsonObject;
             //清除原来的数据
             this.Clear();
             //取出所有列定义
             JsonArray columns = item["columns"] as JsonArray;
             foreach (JsonObject obj in columns)
             {
                 int width = obj["width"];
                 Column column = new Column() { Width = width };
                 this.columns.Add(column);
                 //保存列初始化数据
                 this.columns_init.Add(column);
             }
             //主体sql
             JsonArray sqls = item["sqls"] as JsonArray;
             for (int i = 0; i < sqls.Count; i++)
             {
                 JsonObject obj = sqls[i] as JsonObject;
                 string name = obj["name"];
                 BodyDatas bd = new BodyDatas(name, obj["sql"], new ObjectList());
                 TableBodyItems.Add(bd);
             }
             //表头sql
             string headsql="";
             if (item.ContainsKey("headsql")) { headsql = item["headsql"]; }
             if (headsql != "")
             {
                 HasHead = true;
                 TableHeadItems.Name = "head";
                 TableHeadItems.Sql = headsql;
                 TableHeadItems.Value = new ObjectList();
             }
             //左侧sql
             string leftsql = "";
             if (item.ContainsKey("leftsql")) { leftsql = item["leftsql"]; }
             if (leftsql != "")
             {
                 HasLeft = true;
                 TableLeftItems.Name = "left";
                 TableLeftItems.Sql = leftsql;
                 TableLeftItems.Value = new ObjectList();
             }
             //加载所有单元格模板
             InitTemplate(item);
         }
     };
     IsBusy = true;
     client.DownloadStringAsync(new Uri(uri));
 }
Beispiel #2
0
        /// <summary>
        /// 根据表头,重新绘制,如果有表达式则执行表达式
        /// </summary>
        private void UpdateHead()
        {
            if (TableHeadItems.Value.Count == 0 && TableBodyItems.Count == 0) return;
            //绘制有表头变化部分的表头
            if (HasHead)
            {
                //更新表头前,保存初始化列数据
                List<Column> temp_columns = this.columns_init;
                this.columns.Clear();
                //获得表头变化模板包含几列
                Dictionary<string, int> dic = getColumnNumber(headChangeCellTemplate);
                //根据表头sql数据进行复制
                foreach (Cell cell in headCellTemplate)
                {
                    
                    if (cell.Column < dic["min"])
                    {
                        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();
                        if (value == null) { value = copy.Content.Replace("$", ""); }
                        copy.Content = value+"";
                        copy.Row = cell.Row; this.cells.Add(copy);
                        Column column = new Column() { Width = temp_columns[cell.Column].Width };
                        this.columns.Add(column);
                    }
                    //在变化部分的右侧单元格,
                    else if (cell.Column > dic["max"])
                    {
                        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();
                        if (value == null) { value = copy.Content.Replace("$", ""); }
                        copy.Content = value + "";
                        copy.Row = cell.Row;
                        //根据表头变化部分模板复制单元格,横向复制
                        copy.Column = cell.Column + (TableHeadItems.Value.Count - 1) * dic["count"];
                        this.cells.Add(copy);
                        Column column = new Column() { Width = temp_columns[cell.Column].Width };
                        this.columns.Add(column);
                    }
                    else
                    {

                        for (int i = 0; i < TableHeadItems.Value.Count; i++)
                        {
                            Cell copy = cell.copyCell();
                            Program prog = new Program("data." + copy.Content, this, false);
                            Delegate d = prog.Parse(prog.Exp);
                            copy.Delegate = d;
                            object value = copy.Delegate.DynamicInvoke(new object[] { TableHeadItems.Value[i] });
                            if (value == null) { value = copy.Content.Replace("$", ""); }
                            copy.Content = value + "";
                            copy.Row = cell.Row;
                            //根据表头变化部分模板复制单元格,横向复制
                            copy.Column = cell.Column + i * dic["count"];
                            this.cells.Add(copy);
                            //复制列
                            Column column = new Column() { Width = temp_columns[cell.Column].Width };
                            this.columns.Add(column);
                        }
                    }
                }
            }
            //绘制普通表头,执行表达式
            else
            {
                foreach (Cell cell in headCellTemplate)
                {
                    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;
                    this.cells.Add(copy);
                }
            }
            //复制表头行
            this.rows.AddRange(headRowTemplate);
        }
Beispiel #3
0
 /// <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();
 }