private void UcitajDGVDogadjaji() { dataGridViewDogadjaji.Rows.Clear(); dataGridViewDogadjaji.Refresh(); var connectionString = "mongodb://localhost/?safe=true"; var server = MongoServer.Create(connectionString); var db = server.GetDatabase("fudbal"); List <Dogadjaj> listad = new List <Dogadjaj>(); foreach (MongoDBRef dogRef in U.Dogadjaji.ToList()) { Dogadjaj d = db.FetchDBRefAs <Dogadjaj>(dogRef); listad.Add(d); } listad.Sort((x, y) => x.Minut.CompareTo(y.Minut)); foreach (Dogadjaj d in listad) { Fudbaler f = db.FetchDBRefAs <Fudbaler>(d.Igrac); var index = dataGridViewDogadjaji.Rows.Add(); dataGridViewDogadjaji.Rows[index].Cells[0].Value = d.Minut + "' " + d.Tip + " " + f.ToString(); dataGridViewDogadjaji.Rows[index].Tag = d; } }
private void Azuriraj() { var connectionString = "mongodb://localhost/?safe=true"; var server = MongoServer.Create(connectionString); var db = server.GetDatabase("fudbal"); var collection = db.GetCollection <Fudbaler>("igraci"); var query = Query.EQ("_id", UpdateItem.Id); Fudbaler fu = collection.Find(query).Single(); fu.Ime = txbIme.Text; fu.Prezime = txbPrez.Text; fu.Drzava = txbDrzava.Text; fu.God_rodj = Int32.Parse(txbGod.Text); if (fu.Slika != lblSlika.Text) { fu.Slika = upload_image(fu); } collection.Save(fu); this.Close(); }
private void UcitajDGVIgraci() { var connectionString = "mongodb://localhost/?safe=true"; var server = MongoServer.Create(connectionString); var db = server.GetDatabase("fudbal"); List <Fudbaler> listaf = new List <Fudbaler>(); foreach (MongoDBRef fudbalerRef in K.Igraci.ToList()) { Fudbaler f = db.FetchDBRefAs <Fudbaler>(fudbalerRef); listaf.Add(f); } dataGridViewIgraci.DataSource = listaf; dataGridViewIgraci.Columns["id"].Visible = false; dataGridViewIgraci.Columns["Klub"].Visible = false; dataGridViewIgraci.Columns["God_rodj"].Visible = false; dataGridViewIgraci.Columns["Broj_gol"].Visible = false; if (dataGridViewIgraci.Columns.Contains("Slika")) { dataGridViewIgraci.Columns["Slika"].Visible = false; } }
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(); }
private void btnTrue_Click(object sender, EventArgs e) { //validacija if ((txbIme.Text == "") || (txbPrez.Text == "") || (txbDrzava.Text == "") || (txbGod.Text == "")) { MessageBox.Show("Niste uneli sva potrebna polja"); return; } if (UpdateItem != null) { Azuriraj(); return; } var connectionString = "mongodb://localhost/?safe=true"; var server = MongoServer.Create(connectionString); var db = server.GetDatabase("fudbal"); var igraciColl = db.GetCollection <Fudbaler>("igraci"); var kluboviColl = db.GetCollection <Klub>("klubovi"); MongoDBRef pom1 = new MongoDBRef("klubovi", K.Id); Fudbaler fd = new Fudbaler { Ime = txbIme.Text, Prezime = txbPrez.Text, Drzava = txbDrzava.Text, God_rodj = Int32.Parse(txbGod.Text), Klub = pom1, Broj_gol = 0 }; igraciColl.Insert(fd); fd.Slika = upload_image(fd); igraciColl.Save(fd); K.Igraci.Add(new MongoDBRef("igraci", fd.Id)); kluboviColl.Save(K); this.Close(); }
private string upload_image(Fudbaler f) { if (String.IsNullOrEmpty(openFileDialog1.FileName)) { return(null); } string sourceFile = openFileDialog1.FileName; string targetPath = "../../slike/Fudbaleri"; if (!System.IO.Directory.Exists(targetPath)) { System.IO.Directory.CreateDirectory(targetPath); } string fileName = f.Id.ToString() + Path.GetExtension(openFileDialog1.FileName); string destFile = System.IO.Path.Combine(targetPath, fileName); System.IO.File.Copy(sourceFile, destFile, true); return(destFile); }