コード例 #1
0
        private void btnTrue_Click(object sender, EventArgs e)
        {
            //validacija
            if ((txtMinut.Text == "") || (cbxTip.Text == "") || (cbxIgrac.Text == ""))
            {
                MessageBox.Show("Niste uneli sva potrebna polja");
                return;
            }

            int minuti = Int32.Parse(txtMinut.Text);

            if (minuti < 1 || minuti > 100)
            {
                MessageBox.Show("Nevalidan minut");
                return;
            }

            var connectionString = "mongodb://localhost/?safe=true";
            var server           = MongoServer.Create(connectionString);
            var db = server.GetDatabase("fudbal");

            var utakmiceColl  = db.GetCollection <Utakmica>("utakmice");
            var igraciColl    = db.GetCollection <Fudbaler>("igraci");
            var dogadjajiColl = db.GetCollection <Dogadjaj>("dogadjaji");

            Fudbaler igrac = cbxIgrac.SelectedItem as Fudbaler;

            MongoDBRef pom1 = new MongoDBRef("igraci", igrac.Id);
            MongoDBRef pom2 = new MongoDBRef("utakmice", U.Id);

            Dogadjaj dog = new Dogadjaj {
                Minut = minuti, Tip = cbxTip.Text, Igrac = pom1, Utakmica = pom2
            };

            dogadjajiColl.Insert(dog);

            U.Dogadjaji.Add(new MongoDBRef("dogadjaji", dog.Id));
            utakmiceColl.Save(U);

            if (cbxTip.Text == "Gol")
            {
                igrac.Broj_gol += 1;
                igraciColl.Save(igrac);
            }

            this.Close();
        }
コード例 #2
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            var connectionString = "mongodb://localhost/?safe=true";
            var server           = MongoServer.Create(connectionString);
            var db = server.GetDatabase("fudbal");

            var utakmiceColl  = db.GetCollection <Utakmica>("utakmice");
            var dogadjajiColl = db.GetCollection <Dogadjaj>("dogadjaji");

            Dogadjaj   d      = dataGridViewDogadjaji.CurrentRow.Tag as Dogadjaj;
            MongoDBRef mdbref = new MongoDBRef("dogadjaji", d.Id);

            U.Dogadjaji.Remove(mdbref);

            utakmiceColl.Save(U);

            dogadjajiColl.Remove(Query.EQ("_id", d.Id));

            UcitajDGVDogadjaji();
        }