Esempio n. 1
0
        private static void MakeTableHeader(List <CellFormat> fomatcells,
                                            System.Data.DataTable source,
                                            List <List <SingleCell> > headers,
                                            Soway.Data.DS.Tree.Tree <MatrixHeader> tableHeaders)
        {
            Soway.Data.DS.Tree.ITreeFactory <MatrixHeader, MatrixHeader> fac = new Soway.Data.DS.Tree.ITreeFactory <MatrixHeader, MatrixHeader>(

                (ob1, ob2) =>
            {
                return(Soway.Data.DS.Tree.TeeNodeCompareResult.Child);
            });
            if (fomatcells.Count > 0)
            {
                //按列区分出表格的列
                var sourceTable = source.DefaultView.ToTable(true, fomatcells.Select(p => p.SourceColumn).ToArray());
                //生成列表的树
                foreach (DataRow row in sourceTable.Rows)
                {
                    fac.AddArrayToLeaf(tableHeaders, GetFmtArry(fomatcells, row.ItemArray));
                }

                foreach (var node in tableHeaders)
                {
                    var objs = GetObjsToParent(node);
                    if (fomatcells[node.Level].StaticFormats.Count > 0)
                    {
                        foreach (var staticcell in fomatcells[node.Level].StaticFormats)
                        {
                            objs[node.Level] = staticcell.Name;
                            fac.AddArrayToLeaf(tableHeaders, GetFmtArry(fomatcells, objs, staticcell));
                        }
                    }
                }

                int level = -1;
                List <SingleCell> cells = null;
                foreach (var node in tableHeaders)
                {
                    if (node.Level > level)
                    {
                        level = node.Level;
                        cells = new List <SingleCell>();
                        headers.Add(cells);
                    }
                    var cell = new SingleCell()
                    {
                        Value = node.Data.Value.ToString(),
                        Span  = node.Width
                    };
                    if (node.Data.Value == ReportEmptyValue.Value)
                    {
                        cell.MegerToParent = true;
                    }
                    cells.Add(cell);
                }
            }
        }
        public static void GanTacTu(ref Grid luoi, int kieuluoi, double chisohp, int X, int O)
        {
            Cell o;
            if (kieuluoi == 1)
            {
                o = new SingleCell();
            }
            else
            {
                o = new MultCell();
            }
            Random random = new Random();
            int dem;
            if (o is SingleCell)
            {
                int chieudai = luoi.Hang; int chieurong = luoi.Cot;
                int hang; int cot;
                List<int> list = new List<int>();
                for (int i = 0; i < luoi.Hang; i++)
                {
                    for (int j = 0; j < luoi.Cot; j++)
                    {
                        luoi[i, j] = new SingleCell();
                    }
                }
                dem = 0;
                while (dem < O)
                {
                    hang = random.Next(chieudai);
                    cot = random.Next(chieurong);
                    Agent b = luoi[hang, cot].DemTacTuDon();
                    if (b == null)
                    {
                        luoi[hang, cot].TaoTacTu(new TacTuO(chisohp)); dem++;
                    }

                }
                dem = 0;
                while (dem < X)
                {
                    hang = random.Next(chieudai);
                    cot = random.Next(chieurong);
                    Agent b = luoi[hang, cot].DemTacTuDon();
                    if (b == null)
                    {
                        luoi[hang, cot].TaoTacTu(new TacTuX(chisohp)); dem++;
                    }
                }
            }
            if (o is MultCell)
            {
                for (int i = 0; i < luoi.Hang; i++)
                {
                    for (int j = 0; j < luoi.Cot; j++)
                    {
                        luoi[i, j] = new MultCell();
                    }
                }
                dem = 0;
                while (dem < O)
                {
                    int hang = random.Next(luoi.Hang);
                    int cot = random.Next(luoi.Cot);
                    luoi[hang, cot].TaoTacTu(new TacTuO(chisohp)); dem++;
                }
                dem = 0;
                while (dem < X)
                {
                    int hang = random.Next(luoi.Hang);
                    int cot = random.Next(luoi.Cot);
                    luoi[hang, cot].TaoTacTu(new TacTuX(chisohp)); dem++;
                }
            }
        }