Inheritance: IMove, IComparable
Example #1
0
        //前插一列
        public void InsertColumn()
        {
            //当前列之后所有列,列号+1
            for (int i = this.editCell.Column; i < this.columns.Count; i++)
            {
                this.columns[i].Number++;
            }

            //所有当前列之后的单元格,column+1
            foreach (Cell cell in this.cells)
            {
                if (cell.Column >= this.editCell.Column && cell != this.editCell)
                {
                    cell.Column++;
                }
            }

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

            //插入新列
            Column column = new Column() { Number = this.editCell.Column, Width = 100 };
            this.columns.Add(column);

            this.editCell.Column++;
            this.columns.Sort();
            Layout();
        }
Example #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();
        }
Example #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];
        }