예제 #1
0
        public List <VehicleIdentity> VidGrabLine(string Condition)
        {
            string QueryLine = ("SELECT * FROM " + ViDTab + " WHERE ");

            QueryLine += (Condition + ";");

            MySqlCommand LookUpData = new MySqlCommand(QueryLine, DBconnect);

            List <VehicleIdentity> TempIDL = new List <VehicleIdentity>();

            LookUpData.Connection.Open();

            MySqlDataReader RecordData;

            RecordData = LookUpData.ExecuteReader();

            while (RecordData.Read())
            {
                VehicleIdentity TempID = new VehicleIdentity();
                TempID.ViD      = RecordData.GetString(0);
                TempID.Vtype    = RecordData.GetInt32(1);
                TempID.BornAt   = DateTime.Parse(RecordData.GetString(2));
                TempID.BornLink = new LinkID(RecordData.GetString(3));
                if (!RecordData.IsDBNull(4))
                {
                    TempID.Routename = RecordData.GetString(4);
                }
                if (!RecordData.IsDBNull(5))
                {
                    TempID.Origin = RecordData.GetInt32(5);
                }
                if (!RecordData.IsDBNull(6))
                {
                    TempID.Destination = RecordData.GetInt32(6);
                }
                TempID.Tag          = RecordData.GetInt32(7);
                TempID.BornStage    = RecordData.GetInt32(8);
                TempID.BornScenario = RecordData.GetInt32(9);
                TempID.Obsolete     = RecordData.GetBoolean(10);

                if (!RecordData.IsDBNull(11))
                {
                    TempID.MagicNumbers = RecordData.GetString(11);
                }

                TempIDL.Add(TempID);
            }

            RecordData.Close();
            LookUpData.Connection.Close();

            return(TempIDL);
        }
예제 #2
0
        //Function for adding data
        public void AddStep(int StageNumber, int ScenarioNumber)
        {
            try
            {
                foreach (ReadEventsFile.FileData VehiclesBorn in REF.Fdata)
                {
                    VehicleIdentity TempID = new VehicleIdentity();
                    ViDincriment();
                    TempID.ViD          = IDno.ToString("00000");
                    TempID.Tag          = VehiclesBorn.Tag;
                    TempID.Vtype        = VehiclesBorn.Vtype;
                    TempID.BornAt       = VehiclesBorn.AtTime;
                    TempID.BornLink     = VehiclesBorn.OnLink;
                    TempID.BornStage    = StageNumber;
                    TempID.BornScenario = ScenarioNumber;
                    //Destination data are not available, to be added later
                    //Origin data only available in OD

                    if (RouteMethod.Equals("OD"))
                    {
                        TempID.Origin = GetOriginZone(VehiclesBorn.OnLink);
                    }

                    PDB.ViDAddLine(TempID.MakeDBLine());
                }



                foreach (ReadSnapshotFile.FileData SnapShot in RSF.Fdata)
                {
                    string DBcondition = "ABC";

                    if (RouteMethod.Equals("OD"))
                    {
                        //DBcondition = ("BornTime = '" + SnapShot.BornTime.TimeOfDay.ToString() + "' AND Origin = " + SnapShot.Origin + " AND VehicleType = " + SnapShot.Vtype);//+ " AND Obsolete = '0' AND (BornStage < " + StageNumber + " OR BornScenario = " + ScenarioNumber + ")");
                        DBcondition = ("BornTime = '" + SnapShot.BornTime.TimeOfDay.ToString() + "' AND Origin = " + SnapShot.Origin + " AND VehicleType = " + SnapShot.Vtype + " AND Obsolete = '0' AND (BornStage < " + StageNumber + " OR BornScenario = " + ScenarioNumber + ")");
                    }
                    else if (RouteMethod.Equals("Paths"))
                    {
                        LinkID FirstLink = FirstLinkinRoute(SnapShot);
                        DBcondition = ("BornTime = '" + SnapShot.BornTime.TimeOfDay.ToString() + "' AND BornLink = '" + FirstLink.MakeString() + "' AND VehicleType = " + SnapShot.Vtype + " AND Obsolete = '0' AND (BornStage < " + StageNumber + " OR BornScenario = " + ScenarioNumber + ")");
                    }

                    List <VehicleIdentity> TempIDL = new List <VehicleIdentity>();
                    TempIDL = PDB.VidGrabLine(DBcondition);
                    VehicleIdentity TempID = new VehicleIdentity();

                    if (TempIDL.Count == 1)
                    {
                        TempID = TempIDL[0];
                    }
                    else if (TempIDL.Count > 1)
                    {
                        try
                        {
                            if (RouteMethod.Equals("OD"))
                            {
                                //DBcondition = ("BornTime = '" + SnapShot.BornTime.TimeOfDay.ToString() + "' AND Origin = " + SnapShot.Origin + " AND VehicleType = " + SnapShot.Vtype);//+ " AND Obsolete = '0' AND (BornStage < " + StageNumber + " OR BornScenario = " + ScenarioNumber + ")");
                                DBcondition = ("BornTime = '" + SnapShot.BornTime.TimeOfDay.ToString() + "' AND Origin = " + SnapShot.Origin + " AND VehicleType = " + SnapShot.Vtype + " AND MagicNumbers = '" + SnapShot.MagicNumbers + "'" + " AND Obsolete = '0' AND (BornStage < " + StageNumber + " OR BornScenario = " + ScenarioNumber + ")");
                            }
                            else if (RouteMethod.Equals("Paths"))
                            {
                                LinkID FirstLink = FirstLinkinRoute(SnapShot);
                                DBcondition = ("BornTime = '" + SnapShot.BornTime.TimeOfDay.ToString() + "' AND BornLink = '" + FirstLink.MakeString() + "' AND VehicleType = " + SnapShot.Vtype + " AND Obsolete = '0' AND (BornStage < " + StageNumber + " OR BornScenario = " + ScenarioNumber + ")");
                            }
                            List <VehicleIdentity> TempIDL2 = PDB.VidGrabLine(DBcondition);
                            if (TempIDL2.Count == 0)
                            {
                                throw new Exception();
                            }
                            else if (TempIDL2.Count == 1)
                            {
                                TempID = TempIDL2[0];
                            }
                            else
                            {
                                Console.WriteLine("Something weird is going on");
                            }
                        }
                        catch (Exception e)
                        {
                            if (RouteMethod.Equals("OD"))
                            {
                                //DBcondition = ("BornTime = '" + SnapShot.BornTime.TimeOfDay.ToString() + "' AND Origin = " + SnapShot.Origin + " AND VehicleType = " + SnapShot.Vtype);//+ " AND Obsolete = '0' AND (BornStage < " + StageNumber + " OR BornScenario = " + ScenarioNumber + ")");
                                DBcondition = ("BornTime = '" + SnapShot.BornTime.TimeOfDay.ToString() + "' AND Origin = " + SnapShot.Origin + " AND VehicleType = " + SnapShot.Vtype + " AND ISNULL(MagicNumbers)" + " AND Obsolete = '0' AND (BornStage < " + StageNumber + " OR BornScenario = " + ScenarioNumber + ")");
                            }
                            else if (RouteMethod.Equals("Paths"))
                            {
                                LinkID FirstLink = FirstLinkinRoute(SnapShot);
                                DBcondition = ("BornTime = '" + SnapShot.BornTime.TimeOfDay.ToString() + "' AND BornLink = '" + FirstLink.MakeString() + "' AND VehicleType = " + SnapShot.Vtype + " AND Obsolete = '0' AND (BornStage < " + StageNumber + " OR BornScenario = " + ScenarioNumber + ")");
                            }
                            List <VehicleIdentity> TempIDL3 = PDB.VidGrabLine(DBcondition);

                            if (TempIDL3.Count == 0)
                            {
                                Console.WriteLine("Something weird is going on again");
                            }

                            TempID = TempIDL3[(TempIDL3.Count - 1)];
                            TempID.MagicNumbers = SnapShot.MagicNumbers;
                            PDB.ViDAddLine(TempID.MakeDBLine());
                        }
                    }
                    else if (TempIDL.Count == 0)
                    {
                        Console.WriteLine("What is happenning here?");
                    }


                    if (TempID.ViD.Equals("NoID"))
                    {
                        //throw new Exception("Error: Unique vehicle ID was not assigned to vehicle from snapshot");
                        Console.WriteLine("Vehicle id is unassigned");
                    }

                    if (RouteMethod.Equals("OD"))
                    {
                        if (TempID.Destination == 511)
                        {
                            TempID.Destination = SnapShot.Destination;
                            PDB.ViDAddLine(TempID.MakeDBLine());
                        }
                    }
                    else if (RouteMethod.Equals("Paths"))
                    {
                        if (TempID.Routename.Equals("NULL"))
                        {
                            TempID.Routename = SnapShot.RouteName;
                            PDB.ViDAddLine(TempID.MakeDBLine());
                        }
                    }
                    VehiclePosition TempDat = new VehiclePosition();
                    TempDat.ViD      = TempID.ViD;
                    TempDat.OnLink   = SnapShot.OnLink;
                    TempDat.AtTime   = SnapShot.AtTime;
                    TempDat.LinkDist = SnapShot.LinkDist;
                    TempDat.Vspeed   = SnapShot.Vspeed;
                    double[] Position = LinkToCartesian(SnapShot.OnLink, SnapShot.LinkDist);
                    TempDat.X          = Position[0];
                    TempDat.Y          = Position[1];
                    TempDat.Z          = Position[2];
                    TempDat.InStage    = StageNumber;
                    TempDat.InScenario = ScenarioNumber;

                    PDB.VposAddLine(TempDat.MakeDBLine());
                    //CollatedData.Add(TempDat);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }