コード例 #1
0
        private bool addLocomotiv()
        {
            Locomotiva bs = new Locomotiva();

            bs.Type        = (comboBox1.SelectedItem as VihecalType).name;
            bs.LastCheck   = dateTimePicker1.Value;
            bs.CurrentCond = textBox1.Text;
            int psg;

            if (!int.TryParse(textBox4.Text, out psg))
            {
                return(false);
            }
            bs.MaximumPulingCapacity = psg;

            var trs = TransportModel.GetTransport(bs.Type);

            bs.Transport = new MongoDB.Driver.MongoDBRef("Transport", trs.Id);
            var id = VehicalModel.AddVehical(bs);



            for (int i = 0; i < listBox1.Items.Count; i++)
            {
                VehicalModel.AddVagon(id, (listBox1.Items[i] as Vagon).Id);
            }
            return(true);
        }
コード例 #2
0
        public static void InitVehical()
        {
            var connectionString = "mongodb://localhost/?safe=true";
            var server           = MongoServer.Create(connectionString);
            var db = server.GetDatabase("TransportSystem");


            var collectionV = db.GetCollection <TimeTable>("Vehical");

            Bus v = new Bus()
            {
                CurrentCond = "active", LastCheck = DateTime.Now, NumOfPassengers = 58, Type = "Bus"
            };

            collectionV.Insert(v);
            Locomotiva v1 = new Locomotiva()
            {
                CurrentCond = "active", LastCheck = DateTime.UtcNow, MaximumPulingCapacity = 290.65, Type = "Voz"
            };

            Vagon v2 = new Vagon()
            {
                CurrentCond = "active", LastCheck = DateTime.Now, NumOfPassengers = 30, Type = "Voz"
            };
            Vagon v3 = new Vagon()
            {
                CurrentCond = "error", LastCheck = DateTime.Now, NumOfPassengers = 40, Type = "Voz"
            };

            collectionV.Insert(v2);
            collectionV.Insert(v3);
            v1.Vagons.Add(new MongoDBRef("Vehical", v2.Id));
            v1.Vagons.Add(new MongoDBRef("Vehical", v3.Id));
            collectionV.Insert(v1);

            v2.Logomotiva = new MongoDBRef("Vehical", v1.Id);
            v3.Logomotiva = new MongoDBRef("Vehical", v1.Id);
            collectionV.Save(v2);
            collectionV.Save(v1);
        }