コード例 #1
0
        private void button8_Click(object sender, EventArgs e)
        {
            var connectionString = "mongodb://localhost/?safe=true";
            var server           = MongoServer.Create(connectionString);
            var db = server.GetDatabase("kosarka");

            var klubCollection = db.GetCollection <Klub>("klubovi");


            dataGridView1.Rows.Clear();
            dataGridView1.ColumnCount     = 6;
            dataGridView1.Columns[0].Name = "Ime";
            dataGridView1.Columns[1].Name = "Prezime";
            dataGridView1.Columns[2].Name = "Pozicija";
            dataGridView1.Columns[3].Name = "Visina";
            dataGridView1.Columns[4].Name = "Tezina";
            dataGridView1.Columns[5].Name = "Koledz";

            var queryKlub =
                (from klub in klubCollection.AsQueryable <Klub>()
                 where klub.naziv == textBox9.Text
                 select klub).FirstOrDefault();

            if (queryKlub != null)
            {
                foreach (MongoDBRef kosarkasiRef in queryKlub.Kosarkasi.ToList())
                {
                    Kosarkas kosarkas = db.FetchDBRefAs <Kosarkas>(kosarkasiRef);
                    dataGridView1.Rows.Add(kosarkas.ime, kosarkas.prezime, kosarkas.pozicija, kosarkas.visina, kosarkas.tezina, kosarkas.koledz);
                }
            }
        }
コード例 #2
0
        private void button7_Click(object sender, EventArgs e)
        {
            var connectionString = "mongodb://localhost/?safe=true";
            var server           = MongoServer.Create(connectionString);
            var db = server.GetDatabase("kosarka");

            var klubcollection     = db.GetCollection("klubovi");
            var kosarkascollection = db.GetCollection("kosarkasi");

            var queryKlub =
                from klub in klubcollection.AsQueryable <Klub>()
                where klub.naziv == textBox10.Text
                select klub;

            Klub kl = queryKlub.FirstOrDefault();

            var queryKosarkas =
                from kosarkas in kosarkascollection.AsQueryable <Kosarkas>()
                where kosarkas.ime == textBox1.Text && kosarkas.prezime == textBox2.Text
                select kosarkas;

            Kosarkas kos = queryKosarkas.FirstOrDefault();

            if (kl != null && kos != null)
            {
                kos.Klub = new MongoDBRef("klubovi", kl.Id);
                kosarkascollection.Save(kos);

                //
                MongoDBRef aa = new MongoDBRef("kosarkasi", kos.Id);
                kl.Kosarkasi.Add(aa);
                klubcollection.Save(kl);
                //
                MessageBox.Show(textBox1.Text + " " + textBox2.Text + " igra za " + textBox10.Text + ".");

                textBox1.Text  = "";
                textBox2.Text  = "";
                textBox3.Text  = "";
                textBox4.Text  = "";
                textBox5.Text  = "";
                textBox6.Text  = "";
                textBox7.Text  = "";
                textBox10.Text = "";
            }
            else
            {
                MessageBox.Show("Nevalidni podaci!");
                return;
            }
        }
コード例 #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            var connectionString = "mongodb://localhost/?safe=true";
            var server           = MongoServer.Create(connectionString);
            var db = server.GetDatabase("kosarka");

            var collection = db.GetCollection <Kosarkas>("kosarkasi");

            //       string sl = pictureBox1.ImageLocation;

            Image img = pictureBox1.Image;

            byte[] bytes = (byte[])(new ImageConverter()).ConvertTo(img, typeof(byte[]));

            if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "" && textBox5.Text != "" && textBox6.Text != "" && textBox7.Text != "" && img != null)
            {
                Kosarkas kosarkas = new Kosarkas
                {
                    ime         = textBox1.Text,
                    prezime     = textBox2.Text,
                    pozicija    = textBox3.Text,
                    brojnadresu = Convert.ToInt32(textBox4.Text),
                    visina      = Convert.ToInt32(textBox5.Text),
                    tezina      = Convert.ToInt32(textBox6.Text),
                    koledz      = textBox7.Text,
                    slika       = bytes
                };

                collection.Insert(kosarkas);

                MessageBox.Show("Dodat " + textBox1.Text + " " + textBox2.Text + ".");

                textBox1.Text     = "";
                textBox2.Text     = "";
                textBox3.Text     = "";
                textBox4.Text     = "";
                textBox5.Text     = "";
                textBox6.Text     = "";
                textBox7.Text     = "";
                pictureBox1.Image = null;
            }
            else
            {
                MessageBox.Show("Popuni sva polja (ime/prezime/pozicija/broj na dresu/visina/tezina/koledz/slika) !!");
            }
        }