Ejemplo n.º 1
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count != 0)
            {
                Kafic z = new Kafic();
                z = (Kafic)dataGridView1.CurrentRow.DataBoundItem;
                DialogResult dlg = MessageBox.Show("Da li ste sigurni da zelite da izmenite Opstinu?\nPromene su trajne!",
                                                   "Obavestenje!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (dlg == DialogResult.Yes)
                {
                    var connectionString = "mongodb://localhost/?safe=true";
                    var server           = MongoServer.Create(connectionString);
                    var db = server.GetDatabase("TouristGuide");


                    var collection = db.GetCollection <Kafic>("kafici");

                    collection.Remove(Query.EQ("_id", z.Id));
                    MessageBox.Show("Uspeno je obrisano!");
                }
                else
                {
                    return;
                }
            }
            else
            {
                MessageBox.Show("Selektujte opstinu!", "Greska!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            var connectionString = "mongodb://localhost/?safe=true";
            var server           = MongoServer.Create(connectionString);
            var db = server.GetDatabase("TouristGuide");

            if (textBox1.Text == "" && textBox2.Text == "" && textBox3.Text == "" && textBox4.Text == "" && textBox5.Text == "")

            {
                MessageBox.Show("Niste popunili sva polja!");
            }
            else
            {
                if (comboBox1.SelectedIndex == -1)
                {
                    MessageBox.Show("Izaberite opstinu! Ukoliko ne postoji morate je napraviti!");
                    return;
                }
                var   collection = db.GetCollection <Kafic>("kafici");
                Kafic k          = new Kafic();
                k.Ime        = textBox1.Text;
                k.Vlasnik    = textBox2.Text;
                k.Adresa     = textBox3.Text;
                k.RadnoVreme = textBox4.Text;
                k.Tip        = textBox5.Text;

                collection.Insert(k);
                k.Opstina = new MongoDBRef("opstine", opstine[comboBox1.SelectedIndex].Id);
                collection.Save(k);
                opstine[comboBox1.SelectedIndex].Kafici.Add(new MongoDBRef("kafici", k.Id));
                azurirajOpstinu(opstine);
                MessageBox.Show("Kafic je uspesno dodat!");
                this.Close();
            }
        }
Ejemplo n.º 3
0
        private void dataGridView1_DoubleClick(object sender, EventArgs e)
        {
            var connectionString = "mongodb://localhost/?safe=true";
            var server           = MongoServer.Create(connectionString);
            var db = server.GetDatabase("TouristGuide");

            Kafic u = (Kafic)dataGridView1.CurrentRow.DataBoundItem;
            // var ustanoveCollection = db.GetCollection<Ustanova>("ustanove");
            var opstine = db.GetCollection <Opstina>("opstine");

            MongoCursor <Opstina> ops = opstine.FindAll();

            String opstinica = "";

            foreach (Opstina o in ops)
            {
                if (o.Id == u.Opstina.Id)
                {
                    opstinica = o.Naziv;
                }
            }
            MessageBox.Show(u.Tip + " se nalazi u opstini: " + opstinica);
        }