Наследование: IMove, IComparable
Пример #1
0
        //前插一行
        public void InsertRow()
        {
            //当前行之后所有行,行号+1
            for (int i = this.editCell.Row; i < this.rows.Count; i++)
            {
                this.rows[i].Number++;
            }
            //所有当前行之后的单元格,row+1
            foreach (Cell cell in this.cells)
            {
                if (cell.Row >= this.editCell.Row && cell != this.editCell)
                {
                    cell.Row++;
                }
            }

            //生成新单元格
            for (int i = 0; i < this.columns.Count; i++)
            {
                Cell cell = new Cell() { Row = this.editCell.Row, Column = i };
                this.cells.Add(cell);
            }

            //插入新行
            Row row = new Row() { Number = this.editCell.Row, Height = 100 };
            rows.Add(row);

            this.editCell.Row++;
            rows.Sort();
            Layout();
        }
Пример #2
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();
        }
Пример #3
0
        public Table()
        {
            //默认5行5列
            for (int i = 0; i < 5; i++)
            {
                Row row = new Row() { Number = i, Height = 100 };
                rows.Add(row);
            }

            for (int i = 0; i < 5; i++)
            {
                Column column = new Column() { Number = i, Width = 100 };
                columns.Add(column);
            }

            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    Cell cell = new Cell() { Row = i, Column = j };
                    cells.Add(cell);
                }
            }

            //选中第一个单元格进行编辑
            this.editCell = this.cells[0];
        }