private void button1_Click(object sender, EventArgs e) { int broj_selektovanih = this.listBox1.SelectedItems.Count; if (broj_selektovanih == 0) { MessageBox.Show("Niste selektovali agenciju kojoj pripada!"); return; } string z = this.listBox1.SelectedItem.ToString(); char[] param = { ' ' }; string[] rez = z.Split(param); int p = Convert.ToInt32(rez[0]); try { ISession s = DataLayer.GetSession(); Fashion_Show.Entiteti.Agencijski_Maneken am = s.Load <Fashion_Show.Entiteti.Agencijski_Maneken>(ID_AManekena); //IQuery q = s.CreateQuery("select a.PripadaAgeciji from Agencijski_Maneken as a where a.ID = ? "); // q.SetInt32(0, ID_AManekena); // Agencija stara_agencija = q.UniqueResult<Agencija>(); Agencija stara_agencija = am.PripadaAgeciji; stara_agencija.AManekeni.Remove(am); Fashion_Show.Entiteti.Agencija agencija = s.Load <Fashion_Show.Entiteti.Agencija>(p); am.Maticni_Broj = Convert.ToInt64(this.textBox2.Text); am.Licno_Ime = this.textBox3.Text; am.Prezime = this.textBox4.Text; am.Datum_Rodjenja = Convert.ToDateTime(this.textBox5.Text); am.Pol = this.textBox1.Text; am.Boja_Kose = this.textBox6.Text; am.Boja_Ociju = this.textBox7.Text; am.Visina = Convert.ToInt32(this.textBox8.Text); am.Tezina = Convert.ToInt32(this.textBox9.Text); am.Konfekcijski_Broj = Convert.ToInt32(this.textBox10.Text); am.PripadaAgeciji = agencija; s.SaveOrUpdate(am); agencija.AManekeni.Add(am); s.SaveOrUpdate(agencija); s.Flush(); s.Close(); MessageBox.Show("Azurirali ste stavku idite na prikaz agencijskih manekena za refresh!"); Close(); } catch (Exception ec) { MessageBox.Show(ec.Message); } }
private void Kreirajbutton_Click(object sender, EventArgs e) { int broj_selektovanih = this.listBox2.SelectedItems.Count; if (broj_selektovanih == 0) { MessageBox.Show("Niste selektovali agenciju kojoj pripada!"); return; } string z = this.listBox2.SelectedItem.ToString(); char[] param = { ' ' }; string[] rez = z.Split(param); int p = Convert.ToInt32(rez[0]); try { ISession s = DataLayer.GetSession(); Fashion_Show.Entiteti.Agencija agencija = s.Load <Fashion_Show.Entiteti.Agencija>(p);//agencija kojoj pripada Agencijski_Maneken amaneken = new Agencijski_Maneken(); amaneken.Maticni_Broj = Convert.ToInt64(this.textBox2.Text); amaneken.Licno_Ime = this.textBox3.Text; amaneken.Prezime = this.textBox4.Text; amaneken.Datum_Rodjenja = Convert.ToDateTime(this.textBox5.Text); amaneken.Pol = this.textBox1.Text; amaneken.Boja_Kose = this.textBox6.Text; amaneken.Boja_Ociju = this.textBox7.Text; amaneken.Visina = Convert.ToInt32(this.textBox8.Text); amaneken.Tezina = Convert.ToInt32(this.textBox9.Text); amaneken.Konfekcijski_Broj = Convert.ToInt32(this.textBox10.Text); amaneken.PripadaAgeciji = agencija; s.Save(amaneken); agencija.AManekeni.Add(amaneken); s.SaveOrUpdate(agencija); s.Flush(); s.Close(); MessageBox.Show("Stavka uspesno dodata"); this.Prikazbutton.PerformClick(); } catch (Exception ec) { MessageBox.Show(ec.Message); } }
private void cmdRead_Click(object sender, EventArgs e)//ucitavanje podataka o agenciji// { try { ISession s = DataLayer.GetSession(); //Ucitavaju se podaci o agenciji za zadatim brojem Fashion_Show.Entiteti.Agencija a = s.Load <Fashion_Show.Entiteti.Agencija>(201); MessageBox.Show(a.PIB + " " + a.Naziv + " " + a.Datum_Osnivanja + " " + a.Sediste + " " + a.Tip); s.Close(); } catch (Exception ec) { MessageBox.Show(ec.Message); } }
private void button3_Click(object sender, EventArgs e) { try { ISession s = DataLayer.GetSession(); Fashion_Show.Entiteti.Agencija agencija = s.Load <Fashion_Show.Entiteti.Agencija>(ID_Agencije); agencija.PIB = Convert.ToInt32(this.textBox2.Text); agencija.Naziv = this.textBox3.Text; agencija.Datum_Osnivanja = Convert.ToDateTime(this.textBox4.Text); agencija.Sediste = this.textBox5.Text; s.SaveOrUpdate(agencija); s.Flush(); s.Close(); MessageBox.Show("Azurirali ste stavku idite na listu agencija za refresh"); Close(); } catch (Exception ec) { MessageBox.Show(ec.Message); } }
private void cmdOneToMany_Click(object sender, EventArgs e)//Agenciji pripada bar 1 Agencijski_maneken// { try { ISession s = DataLayer.GetSession(); //Ucitavaju se podaci o agenciji sa zadatim brojem Fashion_Show.Entiteti.Agencija p = s.Load <Fashion_Show.Entiteti.Agencija>(203); foreach (Agencijski_Maneken o in p.AManekeni) { MessageBox.Show(o.Licno_Ime + " " + o.Prezime); } s.Close(); } catch (Exception ec) { MessageBox.Show(ec.Message); } }
private void Obrisi_Agencijubutton_Click(object sender, EventArgs e)//moze da brise i agen. manekena koji je i kreator { int broj_selektovanih = this.listBox1.SelectedItems.Count; if (broj_selektovanih == 0) { MessageBox.Show("Niste selektovali agenciju za brisanje"); return; } string z = this.listBox1.SelectedItem.ToString();// vadi ID agencije char[] param = { ' ' }; string[] rez = z.Split(param); int p = Convert.ToInt32(rez[0]); try { ISession s = DataLayer.GetSession(); Fashion_Show.Entiteti.Agencija agencija = s.Load <Fashion_Show.Entiteti.Agencija>(p); // da li agencija ima agen manekena koji je i kreator //brise agen manekena agencije koji je samo a maneken IQuery q = s.CreateQuery("select a.AManekeni from Agencija as a where a.ID = ? "); q.SetInt32(0, p); IList <Agencijski_Maneken> amanekeni = q.List <Agencijski_Maneken>(); IQuery q2 = s.CreateQuery("from Kreator"); IList <Kreator> kreatori = q2.List <Kreator>(); foreach (Agencijski_Maneken am in amanekeni) { foreach (Kreator k in kreatori) { if (am.ID == k.ID) { IQuery q3 = s.CreateQuery("delete from Kreator k where k.ID = ?"); q3.SetInt32(0, k.ID); q3.ExecuteUpdate(); } } } bool inter = true; if (agencija.GetType() == typeof(Internacionalna_Agencija)) { inter = true; } else if (agencija.GetType() == typeof(Domaca_Agencija)) { inter = false; } s.Delete(agencija); s.Flush(); s.Close(); if (inter) { this.button2.PerformClick(); } else { this.Prikazbutton.PerformClick(); } MessageBox.Show("Uspesno brisanje stavke"); } catch (Exception ec) { MessageBox.Show(ec.Message); } }