示例#1
0
文件: Table.cs 项目: nunch/Crud2
        public void updateColumn(string previousName, Column newColumn, DatabaseXML db)
        {
            Column c2 = new Column {
                Name   = previousName,
                isNull = newColumn.isNull,
                Length = newColumn.Length,
                Type   = newColumn.Type
            };
            List <Index> tmp1 = new List <Index>();

            foreach (Index index in this.Indexes)
            {
                Index tmp_1 = new Index {
                    Name = index.Name
                };
                foreach (string name in index.List)
                {
                    if (name == previousName)
                    {
                        tmp_1.List.Add(newColumn.Name);
                    }
                    else
                    {
                        tmp_1.List.Add(name);
                    }
                }
                tmp1.Add(tmp_1);
            }
            this.Indexes = tmp1;

            List <UniqueKey> tmp5 = new List <UniqueKey>();

            foreach (UniqueKey uk in this.UniqueKeys)
            {
                UniqueKey tmp_1 = new UniqueKey {
                    Name = uk.Name
                };
                foreach (string name in uk.List)
                {
                    if (name == previousName)
                    {
                        tmp_1.List.Add(newColumn.Name);
                    }
                    else
                    {
                        tmp_1.List.Add(name);
                    }
                }
                tmp5.Add(tmp_1);
            }
            this.UniqueKeys = tmp5;

            List <Column> tmp2 = new List <Column>();

            foreach (Column column in this.Columns)
            {
                if (column.Name == previousName)
                {
                    tmp2.Add(newColumn);
                }
                else
                {
                    tmp2.Add(column);
                }
            }
            this.Columns = tmp2;

            List <string> tmp3 = new List <string>();

            foreach (string name in this.PrimaryKey)
            {
                if (name == previousName)
                {
                    tmp3.Add(newColumn.Name);
                }
                else
                {
                    tmp3.Add(name);
                }
            }
            this.PrimaryKey = tmp3;

            List <ForeignKey> tmp4 = new List <ForeignKey>();

            foreach (ForeignKey fk in this.ForeignKeys)
            {
                ForeignKey fk2 = new ForeignKey
                {
                    ExternTableName = fk.ExternTableName,
                    Info            = new List <ForeignKeyInside>()
                };
                foreach (ForeignKeyInside fki in fk.Info)
                {
                    if (fki.ColumnName == previousName)
                    {
                        fk2.Info.Add(new ForeignKeyInside
                        {
                            ColumnName       = newColumn.Name,
                            ExternColumnName = fki.ExternColumnName
                        });
                    }
                    else
                    {
                        fk2.Info.Add(new ForeignKeyInside
                        {
                            ColumnName       = fki.ColumnName,
                            ExternColumnName = fki.ExternColumnName
                        });
                    }
                }
                tmp4.Add(fk2);
            }
            this.ForeignKeys = tmp4;

            foreach (Table table in db.Content)
            {
                if (table.Name != this.Name)
                {
                    bool keep = true;
                    foreach (ForeignKey fk in table.ForeignKeys)
                    {
                        if (keep == true)
                        {
                            if (fk.ExternTableName == this.Name)
                            {
                                foreach (ForeignKeyInside fki in fk.Info)
                                {
                                    if (keep == true)
                                    {
                                        if (fki.ExternColumnName == previousName)
                                        {
                                            c2.Name = fki.ColumnName;
                                            table.updateColumn(c2.Name, c2, db);
                                            keep = false;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
示例#2
0
文件: Table.cs 项目: nunch/Crud2
 public void updateForeignKey(ForeignKey fk)
 {
     this.removeForeignKey(fk.Name);
     this.ForeignKeys.Add(fk);
 }