예제 #1
0
        private List <Model.Table> GetSQLTableList(DataSet ds)
        {
            DataTable          dt     = ds.Tables[0];
            List <Model.Table> lTable = new List <Model.Table>();

            foreach (DataRow r in dt.Rows)
            {
                Model.Field model    = GetField(r);
                bool        hasTable = false;
                foreach (Model.Table modelTable in lTable)
                {
                    if (model.TableName == modelTable.Fields[0].TableName)
                    {
                        modelTable.Fields.Add(model);
                        hasTable = true;
                        break;
                    }
                }
                if (!hasTable)
                {
                    Model.Table newTable = new Model.Table();
                    newTable.Name = model.TableName;
                    List <Model.Field> lFields = new List <Model.Field>();
                    lFields.Add(model);
                    newTable.Fields = lFields;
                    lTable.Add(newTable);
                }
            }

            foreach (Model.Table table in lTable)
            {
                table.Fields.Sort();
            }
            return(lTable);
        }
예제 #2
0
        /// <summary>
        /// 取得主键
        /// </summary>
        public static Model.Field GetKeyField(Model.Table table, out bool HasIdentifierField)
        {
            List <Model.Field> l = table.Fields;

            Model.Field IdentifierRow = null;
            HasIdentifierField = false;
            foreach (Model.Field model in l)
            {
                if (model.IsIdentifier)
                {
                    IdentifierRow      = model;
                    HasIdentifierField = true;
                    break;
                }
            }
            if (IdentifierRow == null)
            {
                foreach (Model.Field model in l)
                {
                    if (model.IsKeyField)
                    {
                        IdentifierRow = model;
                        break;
                    }
                }
            }
            if (IdentifierRow == null)
            {
                IdentifierRow = l[0];
            }
            return(IdentifierRow);
        }
예제 #3
0
        private List <Model.Table> GetSQLTableList(DataSet ds)
        {
            DataTable          dt     = ds.Tables[0];
            List <Model.Table> tables = new List <Model.Table>();

            foreach (DataRow r in dt.Rows)
            {
                Model.Field field           = GetField(r);
                string      parentTableName = SchemaHelper.GetString(r["TableName"]);

                bool hasTable = false;
                foreach (Model.Table modelTable in tables)
                {
                    if (parentTableName == modelTable.Name)
                    {
                        modelTable.AddField(field);
                        hasTable = true;
                        break;
                    }
                }
                if (!hasTable)
                {
                    Model.Table newTable = new Model.Table();
                    newTable.Name = parentTableName;
                    newTable.AddField(field);
                    tables.Add(newTable);
                }
            }

            foreach (Model.Table table in tables)
            {
                table.Fields.Sort();
            }
            return(tables);
        }
예제 #4
0
 public FieldGetterGenerator(Model.Field field)
 {
     this.field = new Field(field);
     field.Type.Accept(this);
     Debug.Assert(this.body != null);
     Debug.Assert(this.declaration != null);
 }
예제 #5
0
        private static Model.Field GetAccessField(string connectionString, string tbName, DataRow r)
        {
            Model.Field model = new Model.Field();
            model.AllowNull    = CommonHelper.GetBool(r["IS_NULLABLE"]);
            model.DefaultValue = CommonHelper.GetString(r["COLUMN_DEFAULT"]);
            model.FieldDescn   = CommonHelper.GetString(r["DESCRIPTION"]);
            model.FieldLength  = CommonHelper.GetInt(r["CHARACTER_MAXIMUM_LENGTH"]);
            model.FieldName    = CommonHelper.GetString(r["COLUMN_NAME"]);
            model.FieldNumber  = CommonHelper.GetInt(r["ORDINAL_POSITION"]);
            model.FieldSize    = CommonHelper.GetInt(r["CHARACTER_OCTET_LENGTH"]);
            model.SetFieldType(Convert.ToInt32(r["DATA_TYPE"]));

            DataTable dtPrimanyKey = GetDbSchema(connectionString, OleDbSchemaGuid.Primary_Keys, null);

            foreach (DataRow rp in dtPrimanyKey.Rows)
            {
                if (rp[2].ToString() == tbName && rp[3].ToString() == model.FieldName)
                {
                    model.IsKeyField   = true;
                    model.IsIdentifier = true; //由于无法获取标识,这里把主键就当成标识
                }
            }

            model.TableName = CommonHelper.GetString(r["TABLE_NAME"]);
            return(model);
        }
예제 #6
0
        internal void UpdateBoard(Model.GameBoard game)
        {
            Console.Clear();
            int nRows = game.Height;
            int nCols = game.Width;

            Model.Field current        = game.Origin;
            Model.Field neighbourBelow = current.FieldBelow;

            for (int r = 0; r < nRows; r++)
            {
                for (int c = 0; c < nCols; c++)
                {
                    Console.Write(current.ToChar());
                    current = current.FieldToRight;
                }
                current = neighbourBelow;
                if (neighbourBelow != null)
                {
                    neighbourBelow = current.FieldBelow;
                }
                Console.WriteLine();
            }
            Console.WriteLine();
            Console.WriteLine("------------------------------------------");
            Console.WriteLine("------ > gebruik de toetsen 1 t/m 5 ------");
            Console.WriteLine("- Jouw score:    " + game.TotalScore.ToString() + "   ---------------------");
        }
예제 #7
0
        private static Model.Table GetTable(DBUtility.DBHelper dbHelper, string dbName, DataRow rTable)
        {
            string tableName = rTable[0].ToString();

            Model.Table table = new Model.Table();
            table.Name = tableName;

            // 对每个表取字段属性
            DataSet dsColumns = dbHelper.ExecuteQuery(CommandType.Text,
                                                      string.Format("select * from COLUMNS where TABLE_SCHEMA='{0}' and TABLE_NAME='{1}'", dbName, tableName),
                                                      null);

            foreach (DataRow rField in dsColumns.Tables[0].Rows)
            {
                Model.Field field = new Model.Field();
                field.IsIdentifier = rField["EXTRA"].ToString().ToLower() == "auto_increment";
                field.IsKeyField   = rField["COLUMN_KEY"].ToString().ToLower() == "pri";
                field.AllowNull    = rField["IS_NULLABLE"].ToString().ToLower() == "yes";

                field.MySqlTypeString = SchemeHelper.GetString(rField["DATA_TYPE"]);
                field.DefaultValue    = SchemeHelper.GetString(rField["COLUMN_DEFAULT"]);
                field.FieldDescn      = SchemeHelper.GetString(rField["COLUMN_COMMENT"]);
                field.FieldLength     = SchemeHelper.GetLong(rField["CHARACTER_MAXIMUM_LENGTH"]);
                field.FieldName       = SchemeHelper.GetString(rField["COLUMN_NAME"]);
                field.FieldNumber     = SchemeHelper.GetInt(rField["ORDINAL_POSITION"]);
                table.Fields.Add(field);
            }
            return(table);
        }
예제 #8
0
        public static List <Model.Table> GetTableList(DataSet ds)
        {
            DataTable          dt     = ds.Tables[0];
            List <Model.Table> lTable = new List <Model.Table>();

            foreach (DataRow r in dt.Rows)
            {
                Model.Field model = GetField(r);
                foreach (Model.Table modelTable in lTable)
                {
                    if (model.TableName == modelTable.Fields[0].TableName)
                    {
                        modelTable.Fields.Add(model);
                    }
                    else
                    {
                        Model.Table newTable = new Model.Table();
                        newTable.Name = model.TableName;
                        newTable.Fields.Add(model);
                    }
                }
                //lTable.Add(model);
            }
            return(lTable);
        }
예제 #9
0
        private Model.Field GetField(string connectionString, string tbName, DataRow r)
        {
            Model.Field model = new Model.Field();
            model.AllowNull       = SchemeHelper.GetBool(r["IS_NULLABLE"]);
            model.DefaultValue    = SchemeHelper.GetString(r["COLUMN_DEFAULT"]);
            model.FieldDescn      = SchemeHelper.GetString(r["DESCRIPTION"]);
            model.FieldLength     = SchemeHelper.GetInt(r["CHARACTER_MAXIMUM_LENGTH"]);
            model.FieldName       = SchemeHelper.GetString(r["COLUMN_NAME"]);
            model.FieldNumber     = SchemeHelper.GetInt(r["ORDINAL_POSITION"]);
            model.FieldSize       = SchemeHelper.GetInt(r["CHARACTER_OCTET_LENGTH"]);
            model.OleDbTypeString = SchemeHelper.GetString(r["DATA_TYPE"]);
            model.IsIdentifier    = SchemeHelper.GetInt(r["COLUMN_FLAGS"]) == 90;

            DataTable dtPrimanyKey = GetDbSchema(connectionString, OleDbSchemaGuid.Primary_Keys, null);

            foreach (DataRow rp in dtPrimanyKey.Rows)
            {
                if (rp[2].ToString() == tbName && rp[3].ToString() == model.FieldName)
                {
                    model.IsKeyField = true;
                }
            }

            model.TableName = SchemeHelper.GetString(r["TABLE_NAME"]);
            return(model);
        }
예제 #10
0
        private uint GetCaptureSize(Model.Field field)
        {
            var byte_aligned_offset  = GetFieldByteOffset(field);
            var minimum_capture_size = field.Offset - byte_aligned_offset + field.SizeInBits();
            var capture_type_width   = (uint)Math.Max(Math.Pow(2, Math.Ceiling(Math.Log(minimum_capture_size) / Math.Log(2))), 8);

            return(capture_type_width);
        }
예제 #11
0
 public Pawn(Ellipse image, Model.Field startLocation, int playerNumber)
 {
     this.startLocation = startLocation;
     this.currentLocation = startLocation;
     this.startLocation.Pawn = this;
     this.image = image;
     this.playerNumber = playerNumber;
 }
예제 #12
0
        //Place the barricade pawn on a certain location.
        public void setLocation(Model.Field location)
        {
            image.SetValue(Grid.ColumnProperty, location.X);
            image.SetValue(Grid.RowProperty, location.Y);

            currentLocation.Barricade = null;
            currentLocation = location;
            location.Barricade = this;
        }
예제 #13
0
        internal Field(Model.Field modelField, PropertyMatcherViewModel viewModel, ConnectionDirection direction)
        {
            ModelField = modelField;
            ViewModel  = viewModel;
            Direction  = direction;

            _selectionStatus = SelectionStatus.NotSelected;
            Disconnect       = new DisconnectCommand(this);
        }
예제 #14
0
 public FullScreenForm(Model.Field field)
 {
     InitializeComponent();
     Field                 = field;
     FormBorderStyle       = FormBorderStyle.None;
     WindowState           = FormWindowState.Maximized;
     KeyDown              += OnKeyDown;
     skglControl1.KeyDown += OnKeyDown;
 }
예제 #15
0
        private void GenerateField(Model.Field field, uint indent)
        {
            FieldGetterGenerator getterGenerator = new FieldGetterGenerator(field);

            write_indented(indent, getterGenerator.GetDeclaration());
            write_indented(indent, "{");
            write_indented(indent + 1, String.Join(Environment.NewLine, getterGenerator.GetBody()));
            write_indented(indent, "}");
        }
예제 #16
0
파일: Xlsx.cs 프로젝트: DNCarroll/bxl
        void SetHeader(bool withHeaders, List <Model.Field> fields, Cell c, string cellValue)
        {
            var field = new Model.Field {
                ColumnIndex          = fields.Count,
                FieldName            = withHeaders ? cellValue : $"field{fields.Count + 1}",
                ExcelColumnReference = Regex.Replace(c.CellReference, "\\d", "")
            };

            fields.Add(field);
        }
예제 #17
0
 /// <summary>
 /// 判断一个字段是不是Char类型的(包括char,nchar,nvarchar,varchar)
 /// </summary>
 /// <param name="field"></param>
 /// <returns></returns>
 public static bool IsCharClassType(Model.Field field)
 {
     if (field.FieldType == Model.DataType.charType || field.FieldType == Model.DataType.ncharType || field.FieldType == Model.DataType.nvarcharType || field.FieldType == Model.DataType.varcharType)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #18
0
 /// <summary>
 /// 判断一个字段是不是Int类型的(包括bigint,int,smallint,tinyint)
 /// </summary>
 /// <param name="field"></param>
 /// <returns></returns>
 public static bool IsIntClassType(Model.Field field)
 {
     if (field.FieldType == Model.DataType.bigintType || field.FieldType == Model.DataType.intType || field.FieldType == Model.DataType.smallintType || field.FieldType == Model.DataType.tinyintType)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #19
0
 /// <summary>
 /// 判断一个字段是不是DataTime类型的(包括datetime,smalldatetime)
 /// </summary>
 /// <param name="field"></param>
 /// <returns></returns>
 public static bool IsDataTimeClassType(Model.Field field)
 {
     if (field.FieldType == Model.DataType.datetimeType || field.FieldType == Model.DataType.smalldatetimeType)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #20
0
 /// <summary>
 /// 是否要在Add方法中加入该参数
 /// DAL层和存储过程中均要用此判断
 /// </summary>
 public static bool ShouldBeParameter(Model.Table table, Model.Field field)
 {
     if (!field.IsIdentifier && (string.IsNullOrEmpty(field.DefaultValue)))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #21
0
        // コンストラクター
        internal Field(OfficeLineArt.LineArt lineArt, Model.Field fieldModel, Color color)
            : base(lineArt, fieldModel, color)
        {
            this.Excel = ((LineArt)this.LineArt).Application;

            var       wb = this.Excel.Workbooks.Add();
            Worksheet ws = wb.Worksheets[1];

            this.Cell              = ws.Cells[1, "A"];
            this.Cell.RowHeight   *= 25;
            this.Cell.ColumnWidth *= 10;
        }
예제 #22
0
        public static List <Model.Field> GetList(DataSet ds)
        {
            DataTable          dt = ds.Tables[0];
            List <Model.Field> l  = new List <Model.Field>();

            foreach (DataRow r in dt.Rows)
            {
                Model.Field model = GetField(r);
                l.Add(model);
            }
            return(l);
        }
예제 #23
0
 /// <summary>
 /// 是否需要在参数中加字段长度(如果长度超过8000,视为text型,无需加长度)
 /// </summary>
 public static bool ShouldAddLength(Model.Field field)
 {
     if ((field.DbType == DbType.AnsiString || field.DbType == DbType.AnsiStringFixedLength ||
          field.DbType == DbType.String || field.DbType == DbType.StringFixedLength) &&
         field.FieldLength <= 8000)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #24
0
 /// <summary>
 /// 增加一个DbParameter
 /// </summary>
 private static void AddInDbParameter(StringBuilder code, Model.Database db, Model.Field field, Model.CodeStyle style)
 {
     // 对于DateTime类型要特殊处理(针对Access的问题)
     if (field.DbType == DbType.DateTime)
     {
         AppendFormatLine(code, 4, "{0}.CreateInDbParameter(\"{1}\", DbType.{2}, model.{3}),",
                          style.DBHelperName, field.SqlStoreProcedureParameter, DbType.String, field.FieldName);
     }
     else
     {
         AppendFormatLine(code, 4, "{0}.CreateInDbParameter(\"{1}\", DbType.{2}, model.{3}),",
                          style.DBHelperName, field.SqlStoreProcedureParameter, field.DbType, field.FieldName);
     }
 }
예제 #25
0
        public Database GetSchema(string connectionString, Model.DatabaseTypes type)
        {
            Model.Database database = new Model.Database();
            database.ConnString = connectionString;
            database.Type       = type;

            //获取所有表
            DataTable dtAllTable = GetDbSchema(database.ConnString, OleDbSchemaGuid.Tables, new object[] { null, null, null, "table" });

            foreach (DataRow rt in dtAllTable.Rows)
            {
                Model.Table table = new Model.Table();
                table.Name = rt["TABLE_NAME"].ToString();
                DataTable dtColumns = GetDbSchema(database.ConnString, OleDbSchemaGuid.Columns, new object[] { null, null, table.Name });
                foreach (DataRow rc in dtColumns.Rows)
                {
                    Model.Field field = GetField(database.ConnString, table.Name, rc);
                    table.AddField(field);
                }
                table.Fields.Sort();
                database.AddTable(table);
            }

            //获取所有视图
            DataTable dtAllView = GetDbSchema(database.ConnString, OleDbSchemaGuid.Views, null);

            foreach (DataRow rv in dtAllView.Rows)
            {
                Model.Table view = new Model.Table();
                view.Name = rv["TABLE_NAME"].ToString();
                DataTable dtColumns = GetDbSchema(database.ConnString, OleDbSchemaGuid.Columns, new object[] { null, null, view.Name });
                foreach (DataRow rc in dtColumns.Rows)
                {
                    Model.Field field = GetField(database.ConnString, view.Name, rc);
                    view.AddField(field);
                }
                view.Fields.Sort();
                database.AddView(view);
            }

            //获取所有存储过程
            DataTable dtAllStoreProcedure = GetDbSchema(database.ConnString, OleDbSchemaGuid.Procedures, null);

            foreach (DataRow rsp in dtAllStoreProcedure.Rows)
            {
                database.StoreProcedures.Add(rsp["PROCEDURE_NAME"].ToString());
            }
            return(database);
        }
예제 #26
0
 private Model.Field GetField(DataRow r)
 {
     Model.Field model = new Model.Field();
     model.AllowNull    = SchemaHelper.GetBool(r["AllowNull"]);
     model.DefaultValue = SchemaHelper.GetString(r["DefaultValue"]);
     model.Descn        = SchemaHelper.GetString(r["FieldDescn"]);
     model.Length       = SchemaHelper.GetInt(r["FieldLength"]);
     model.Name         = SchemaHelper.GetString(r["FieldName"]);
     model.Pos          = SchemaHelper.GetInt(r["FieldNumber"]);
     model.Size         = SchemaHelper.GetInt(r["FieldSize"]);
     model.FieldType    = SchemaHelper.GetString(r["FieldType"]);
     model.IsId         = SchemaHelper.GetBool(r["IsId"]);
     model.IsKey        = SchemaHelper.GetBool(r["IsKey"]);
     return(model);
 }
예제 #27
0
 private Model.Field GetField(DataRow r)
 {
     Model.Field model = new Model.Field();
     model.AllowNull    = SchemaHelper.GetBool(r["AllowNull"]);
     model.DefaultValue = SchemaHelper.GetString(r["DefaultValue"]);
     model.Descn        = SchemaHelper.GetString(r["FieldDescn"]);
     model.Length       = SchemaHelper.GetInt(r["FieldLength"]);
     model.Name         = SchemaHelper.GetString(r["FieldName"]);
     model.Position     = SchemaHelper.GetInt(r["FieldNumber"]);
     model.Size         = SchemaHelper.GetInt(r["FieldSize"]);
     model.SetDbType(Model.DatabaseTypes.Sql2000, SchemaHelper.GetString(r["FieldType"]));
     model.IsIdentifier = SchemaHelper.GetBool(r["IsIdentifier"]);
     model.IsKeyField   = SchemaHelper.GetBool(r["IsKeyField"]);
     return(model);
 }
예제 #28
0
        /// <summary>
        /// 判断一个字段是不是String类型的(包括Xml,String,StringFixedLength,AnsiString,AnsiStringFixedLength)
        /// </summary>
        public static bool IsStringDbType(Model.Field field)
        {
            switch (field.DbType)
            {
            case DbType.Xml:
            case DbType.String:
            case DbType.StringFixedLength:
            case DbType.AnsiString:
            case DbType.AnsiStringFixedLength:
                return(true);

            default:
                return(false);
            }
        }
예제 #29
0
 private static Model.Field GetSQLField(DataRow r)
 {
     Model.Field model = new Model.Field();
     model.AllowNull    = CommonHelper.GetBool(r["AllowNull"]);
     model.DefaultValue = CommonHelper.GetString(r["DefaultValue"]);
     model.FieldDescn   = CommonHelper.GetString(r["FieldDescn"]);
     model.FieldLength  = CommonHelper.GetInt(r["FieldLength"]);
     model.FieldName    = CommonHelper.GetString(r["FieldName"]);
     model.FieldNumber  = CommonHelper.GetInt(r["FieldNumber"]);
     model.FieldSize    = CommonHelper.GetInt(r["FieldSize"]);
     model.SetFieldType(r["FieldType"].ToString());
     model.IsIdentifier = CommonHelper.GetBool(r["IsIdentifier"]);
     model.IsKeyField   = CommonHelper.GetBool(r["IsKeyField"]);
     model.TableName    = CommonHelper.GetString(r["TableName"]);
     return(model);
 }
예제 #30
0
 private Model.Field GetField(DataRow r)
 {
     Model.Field model = new Model.Field();
     model.AllowNull     = SchemeHelper.GetBool(r["AllowNull"]);
     model.DefaultValue  = SchemeHelper.GetString(r["DefaultValue"]);
     model.FieldDescn    = SchemeHelper.GetString(r["FieldDescn"]);
     model.FieldLength   = SchemeHelper.GetInt(r["FieldLength"]);
     model.FieldName     = SchemeHelper.GetString(r["FieldName"]);
     model.FieldNumber   = SchemeHelper.GetInt(r["FieldNumber"]);
     model.FieldSize     = SchemeHelper.GetInt(r["FieldSize"]);
     model.SqlTypeString = SchemeHelper.GetString(r["FieldType"]);
     model.IsIdentifier  = SchemeHelper.GetBool(r["IsIdentifier"]);
     model.IsKeyField    = SchemeHelper.GetBool(r["IsKeyField"]);
     model.TableName     = SchemeHelper.GetString(r["TableName"]);
     return(model);
 }
예제 #31
0
        /// <summary>
        /// Draws a graphic representation of a Field entity
        /// </summary>
        /// <param name="field">the Field entity to be drawn</param>
        /// <returns>the representation of the provided Field entity</returns>
        public static string Draw(Model.Field field)
        {
            var sb = new StringBuilder();

            for (var i = 0; i < field.Cells.GetLength(0); i++)
            {
                for (var j = 0; j < field.Cells.GetLength(0); j++)
                {
                    var cell = field.Cells[i, j];
                    sb.Append(Draw(cell));
                }
                sb.Append("\n");
            }

            return(sb.ToString());
        }
예제 #32
0
        /// <summary>
        /// 判断一个字段是不是Int类型的(包括bigint,int,smallint,tinyint)
        /// </summary>
        public static bool IsIntDbType(Model.Field field)
        {
            switch (field.DbType)
            {
            case DbType.Int16:
            case DbType.Int32:
            case DbType.Int64:
            case DbType.UInt16:
            case DbType.UInt32:
            case DbType.UInt64:
                return(true);

            default:
                return(false);
            }
        }
예제 #33
0
        //Convert a 2d String array map to a map of linked fields.
        public Model.Field[,] convertMap(String[,] stringMap, int width, int height)
        {
            iRows = height;
            iColumns = width;

            fields = new Model.Field[iColumns,iRows];

            for (int iRow = 0; iRow < iRows; iRow++)
            {
                for (int iColumn = 0; iColumn < iColumns; iColumn++)
                {
                    switch (stringMap[iRow,iColumn])
                    {
                        case "f":
                            fields[iColumn, iRow] = new Model.Finish();
                            break;
                        case "#":
                            fields[iColumn, iRow] = new Model.Barricade();
                            break;
                        case "o":
                            fields[iColumn, iRow] = new Model.Field();
                            break;
                        case "|":
                            fields[iColumn, iRow] = new Model.LineField();
                            break;
                        case "s":
                            fields[iColumn, iRow] = new Model.SafeSpot();
                            break;
                        case "r":
                            fields[iColumn, iRow] = new Model.RedBase();
                            break;
                        case "R":
                            redStart = new Model.RedStart();
                            fields[iColumn, iRow] = redStart;
                            break;
                        case "g":
                            fields[iColumn, iRow] = new Model.GreenBase();
                            break;
                        case "G":
                            greenStart = new Model.GreenStart();
                            fields[iColumn, iRow] = greenStart;
                            break;
                        case "y":
                            fields[iColumn, iRow] = new Model.YellowBase();
                            break;
                        case "Y":
                            yellowStart = new Model.YellowStart();
                            fields[iColumn, iRow] = yellowStart;
                            break;
                        case "b":
                            fields[iColumn, iRow] = new Model.BlueBase();
                            break;
                        case "B":
                            blueStart = new Model.BlueStart();
                            fields[iColumn, iRow] = blueStart;
                            break;
                        default:
                            break;
                    }

                    if(fields[iColumn, iRow] is Model.Field)
                    {
                        fields[iColumn, iRow].X = iColumn;
                        fields[iColumn, iRow].Y = iRow;
                    }

                }
            }

            createLinks();

            return fields;
        }
예제 #34
0
 public BarricadePawn(Rectangle image, Model.Field startLocation)
 {
     this.currentLocation = startLocation;
     this.currentLocation.Barricade = this;
     this.image = image;
 }
예제 #35
0
        //Functions
        public static void Read(string domain, MainController mainController)
        {
            string[] lines = System.IO.File.ReadAllLines(domain);
            string[,] characters = new string[lines[0].Length, lines.Length];

            int numLines = lines.Length;
            int numChars = 0;

            for (int i = 0; i < numLines; i++) //making a 2 dimensional array of characters
            {
                Debug.WriteLine("");
                string[] line = lines[i].ToCharArray().Select( c => c.ToString()).ToArray(); //string array van losse characters
                if (numChars == 0)
                    numChars = line.Length;
                for (int j = 0; j < numChars; j++)
                {
                    characters[j, i] = line[j];
                    Debug.Write(line[j]);
                }
            }

            Debug.WriteLine("");

            Model.Field[,] fields = new Model.Field[(numLines + 1) / 2, (numChars / 4) - 1];

            mainController.MakeGrid((numLines + 1) / 2, (numChars / 4) - 1);

            for (int i = 0; i < numLines; i++)
            {
                if (i % 2 == 0) //only parse even lines, uneven lines are all connector lines.
                {
                    int returnTo = 0;
                    int.TryParse(characters[0, i], out returnTo);

                    bool barricadeAllowed = false;
                    if (characters[1, i] == "B")
                    {
                        barricadeAllowed = true;
                    }

                    for (int j = 1; j < numChars / 4; j++)
                    {
                        Model.Field exitN = null;
                        Model.Field exitW = null;

                        if (i != 0)
                        {
                            if (characters[(j * 4) + 1, i - 1] == "|")
                            {
                                Debug.WriteLine("ExitN found");
                                if (characters[(j * 4) + 1, i - 2] == "|") //Removing the need for linking fields. Only works for vertical long links!
                                {
                                    Debug.WriteLine("EXITN 1 extra up!");
                                    exitN = fields[j - 1, (i / 2) - 2];
                                }
                                else
                                {
                                    exitN = fields[j - 1, (i / 2) - 1];
                                }
                                mainController.DrawField("LinkUp", j - 1, (i / 2));
                            }
                        }

                        if (j > 1)
                        {
                            if (characters[(j * 4) - 1, i] == "-")
                            {
                                Debug.WriteLine("ExitW found");
                                exitW = fields[j - 2, (i/2)];
                                mainController.DrawField("LinkLeft", j - 1, (i / 2));
                            }
                        }

                        switch (characters[(j * 4), i]) //vakjes aanmaken.
                        {
                            case "<":
                                if (characters[(j * 4) + 1, i] == " ") //goal
                                {
                                    Model.GoalField goalField = new Model.GoalField(exitN, null, null, exitW, j - 1, (i / 2));
                                    fields[j - 1, (i / 2)] = goalField;
                                    mainController.DrawField("GoalField", j - 1, (i / 2));
                                    goalField.finishGame += mainController.FinishGame;
                                    break;
                                }
                                int numForest;
                                if (int.TryParse(characters[(j * 4) + 1, i], out numForest)) //forest
                                {
                                    fields[j - 1, (i / 2)] = new Model.Forest(exitN, null, null, exitW, numForest, j - 1, (i / 2));
                                    mainController.DrawField("Forest", j - 1, (i / 2));
                                    mainController.RegisterForest((Model.Forest)fields[j - 1, (i / 2)]);
                                    break;
                                }
                                //else startfield
                                fields[j - 1, (i / 2)] = new Model.StartField(exitN, null, null, exitW, characters[(j * 4) + 1, i], j - 1, (i / 2));
                                mainController.RegisterStartField((Model.StartField)fields[j - 1, (i / 2)]);
                                mainController.DrawField("StartField", j - 1, (i / 2));
                                break;
                            case "(":
                                fields[j - 1, (i / 2)] = new Model.Field(exitN, null, null, exitW, barricadeAllowed, returnTo, j - 1, (i / 2));
                                mainController.DrawField("Field", j - 1, (i / 2));
                                break;
                            case "[":
                                fields[j - 1, (i / 2)] = new Model.BarricadeField(exitN, null, null, exitW, barricadeAllowed, returnTo, j - 1, (i / 2));
                                mainController.DrawField("BarricadeField", j - 1, (i / 2));
                                break;
                            case "{":
                                fields[j - 1, (i / 2)] = new Model.SafeField(exitN, null, null, exitW, barricadeAllowed, returnTo, j - 1, (i / 2));
                                mainController.DrawField("SafeField", j - 1, (i / 2));
                                break;
                            case " ":
                                if (characters[(j * 4) + 1, i] == "|")
                                {
                                    mainController.DrawField("LinkField", j - 1, (i / 2));
                                }
                                break;
                        }

                        if (fields[j - 1, (i / 2)] != null)
                        {
                            fields[j - 1, (i / 2)].broadcastMove += mainController.BroadcastMove;
                        }

                        switch (characters[(j * 4) + 1, i])
                        {
                            case "*":
                                mainController.MakeBarricade(fields[j - 1, (i / 2)]);
                                break;
                            case "R":
                            case "Y":
                            case "G":
                            case "B":
                                mainController.MakePawn(characters[(j * 4) + 1, i], fields[j - 1, (i / 2)]);
                                break;
                        }
                    }
                }
            }

            mainController.DrawAllMovables();
        }
        private Model.Field CreateField(SPField listField)
        {
            Model.Field field;

            switch (listField.Type)
            {
                case SPFieldType.Choice:
                    field = new Model.FieldChoice
                    {
                        Choices = ((SPFieldChoice)listField).Choices.Cast<string>().ToList()
                    };
                    break;
                case SPFieldType.MultiChoice:
                    field = new Model.FieldChoice
                    {
                        Choices = ((SPFieldMultiChoice)listField).Choices.Cast<string>().ToList()
                    };
                    break;

                case SPFieldType.DateTime:
                    field = new Model.FieldDateTime { DateOnly = ((SPFieldDateTime)listField).DisplayFormat == SPDateTimeFieldFormatType.DateOnly };
                    break;

                case SPFieldType.Lookup:
                    field = new Model.FieldLookup {AllowMultivalue = ((SPFieldLookup)listField).AllowMultipleValues};
                    break;

                default:
                    field = new Model.Field();
                    break;
            }

            field.Id = listField.Id;
            field.IsHidden = listField.Hidden;
            field.IsReadonly = listField.ReadOnlyField;
            field.Title = listField.Title;
            field.InternalName = listField.InternalName;
            field.Group = listField.Group;
            field.Type = (Model.FieldType)listField.Type;

            return field;
        }