Example #1
0
        //从文件中加载数据,文件格式与Save函数相同
        public void Load(string fileName)
        {
            //清除原来的数据
            this.cells.Clear();
            this.columns.Clear();
            this.rows.Clear();
            this.selectedCells.Clear();
            this.sqls.Clear();
            if (fileName == "" || fileName == null) return;
            StreamReader sw = new StreamReader(fileName, Encoding.Default, false);

            string jsonText = sw.ReadToEnd();

            // JsonObject json;
            var json = (JObject)JsonConvert.DeserializeObject(jsonText);

            //读出所有sql语句
            JArray array = (JArray)json["sqls"];
            foreach (JObject obj in array)
            {
                Sql sql = new Sql()
                {
                    Name = (string)obj["name"],
                    Content = (string)obj["sql"]
                };
                this.sqls.Add(sql);
            }

            //左表头内容表达式
            LeftValue = (string)json["leftsql"];
            //左表头内容表达式
            HeadValue = (string)json["headsql"];

            //读出所有列
            int i = 0;
            array = (JArray)json["columns"];
            foreach (JObject obj in array)
            {
                Column column = new Column()
                {
                    Width = (int)obj["width"],
                    Number = i++
                };
                this.columns.Add(column);
            }

            //读出所有行
            i = 0;
            array = (JArray)json["rows"];
            foreach (JObject obj in array)
            {
                Row row = new Row()
                {
                    Height = (int)obj["height"],
                    Type = (string)obj["type"],
                    Number = i++
                };
                this.rows.Add(row);
            }

            this.headCells.Clear();
            this.leftCells.Clear();
            this.mainCells.Clear();

            //读出所有单元格
            array = (JArray)json["cells"];
            foreach (JObject obj in array)
            {
                Cell cell = new Cell()
                {
                    Row = (int)obj["row"],
                    RowSpan = (int)obj["rowspan"],
                    ColumnSpan = (int)obj["columnspan"],
                    Column = (int)obj["column"],
                    Content = (string)obj["content"],
                    location = (string)obj["location"],
                    Height = (int)obj["height"],
                };
                this.cells.Add(cell);

                //根据单元格类型,把单元格添加到对应队列中
                string type = (string)obj["type"];
                if (type == "head")
                {
                    headCells.Add(cell);
                }
                else if (type == "left")
                {
                    leftCells.Add(cell);
                }
                else if (type == "main")
                {
                    mainCells.Add(cell);
                }
                else if (type == "bottom")
                {
                    bottomCells.Add(cell);
                }
                if (type == "headchange")
                {
                    headchangeCells.Add(cell);
                }
            }

            this.Layout();
        }
Example #2
0
 //新增一条sql语句
 public void AddSql()
 {
     Sql sql = new Sql() { Name="", Content="" };
     this.sqls.Add(sql);
 }