示例#1
0
文件: DAO.cs 项目: aquaphoenix1/TP
        /// <summary>
        /// Загрузка карты
        /// </summary>
        /// <param name="name">Имя карты</param>
        /// <param name="vertexes">Список вершин</param>
        /// <param name="edges">Список дуг</param>
        /// <returns>Изображение карты, список вершин и дуг</returns>
        public static Bitmap LoadMap(string name, out Vertexes vertexes, out Edges edges)
        {
            try
            {
                Bitmap bmp = LoadPicture(name);

                vertexes = new Vertexes();

                var list = GetAll("Vertex", string.Format("Map = '{0}'", name));

                List <List <object> > listTF = DAO.GetAll("TrafficLight", string.Format("Map = '{0}'", name));

                foreach (var vert in list)
                {
                    TrafficLight tf = null;
                    if (!vert[4].ToString().Equals(""))
                    {
                        List <object> l = listTF.First(fl => fl[0].ToString().Equals(vert[4].ToString()) && fl[3].ToString().Equals(vert[3].ToString()));
                        tf = TrafficLight.CreateTrafficLight(long.Parse(l[0].ToString()), int.Parse(l[1].ToString()), int.Parse(l[2].ToString()));
                    }
                    vertexes.AddNoEvent(Vertex.CreateVertex(long.Parse(vert[0].ToString()), int.Parse(vert[1].ToString()), int.Parse(vert[2].ToString()), tf));
                }

                edges = new Edges();

                list = GetAll("Edge", string.Format("Map = '{0}'", name));

                foreach (var edge in list)
                {
                    Vertex      head   = vertexes.GetForId(long.Parse(edge[3].ToString()));
                    Vertex      end    = vertexes.GetForId(long.Parse(edge[4].ToString()));
                    Way.Coating coat   = Way.Coating.GetCoatingByName(edge[6].ToString());
                    Way.Sign    sign   = Way.Sign.GetSignBySpeed(int.Parse(edge[2].ToString()));
                    Way.Police  police = Way.Police.GetPoliceByName(edge[7].ToString());

                    edges.AddNoEvent(Edge.CreateEdge(long.Parse(edge[0].ToString()), head, end, coat, edge[5].ToString(), bool.Parse(edge[1].ToString()), sign, police));
                }

                return(bmp);
            }
            catch
            {
                vertexes = null;
                edges    = null;

                return(null);
            }
        }