private bool LoadEspetaculos(Espetaculos es) { ProjetoCircoEntities db = new ProjetoCircoEntities(); es.NMEspetaculo = txtNMEspetaculo.Text; es.DTEspetaculo = txtDTHR.Text; db.Espetaculos.Add(es); db.SaveChanges(); ListBox.SelectedObjectCollection listaCol = lstCol.SelectedItems; ListBox.SelectedObjectCollection listLocal = lstLocal.SelectedItems; ListBox.SelectedObjectCollection listArtista = lstArtistas.SelectedItems; ListBox.SelectedObjectCollection listaPec = lstPec.SelectedItems; try { foreach (Artistas art in listArtista) { Pagos f = new Pagos { IDArtista = art.Id, IDEspetaculo = es.IDEspetaculo, Pago = null }; db.Pagos.Add(f); } db.SaveChanges(); foreach (Local loc in listLocal) { LocalEspetaculo e = new LocalEspetaculo { IDEspetaculo = es.IDEspetaculo, IDLocal = loc.IDLocal }; db.LocalEspetaculo.Add(e); } db.SaveChanges(); foreach (Peças pe in listaPec) { Figurino f = new Figurino { IDPec = pe.CDPeças, IDEspetaculo = es.IDEspetaculo }; db.Figurino.Add(f); } db.SaveChanges(); }catch (Exception ex) { MessageBox.Show("Erro ao salvar :( " + ex.Message); return(false); } return(true); }
private void btnSalvarEspetaculo_Click(object sender, EventArgs e) { Espetaculos espetaculos = new Espetaculos(); ProjetoCircoEntities db = new ProjetoCircoEntities(); if (LoadEspetaculos(espetaculos)) { MessageBox.Show("Espetaculo salvo com sucesso!", "Mensagem do sistema"); this.Close(); } }
private void lstBuscar_Click(object sender, EventArgs e) { ProjetoCircoEntities db = new ProjetoCircoEntities(); Espetaculos objEspetaculo = (Espetaculos)lstBuscar.SelectedItem; if (objEspetaculo != null) { AtualizarFrmRelatorio(db, objEspetaculo.IDEspetaculo); } }
public void AtualizarFrmRelatorio(ProjetoCircoEntities db, int id) { txtDtEsp.Text = string.Empty; txtNMEsp.Text = string.Empty; lstCol.Items.Clear(); lstArt.Items.Clear(); lstPec.Items.Clear(); lstLocal.Items.Clear(); Espetaculos a = db.Espetaculos.Where(x => x.IDEspetaculo == id).Single(); List <Artistas> lstArtistas = db.Artistas.ToList(); List <Peças> lstPecas = db.Peças.ToList(); txtDtEsp.Text = a.DTEspetaculo; txtNMEsp.Text = a.NMEspetaculo; foreach (LocalEspetaculo n in a.LocalEspetaculo) { var aux = db.Local.Where(x => x.IDLocal == n.IDLocal).Single(); lstLocal.Items.Add(aux); } foreach (Figurino n in a.Figurino) { var aux = db.Peças.Where(x => x.CDPeças == n.IDPec).Single(); lstPec.Items.Add(aux); var aux2 = db.Coleções.Where(x => x.IDColecao == aux.IDColecao).Single(); lstCol.Items.Add(aux2); } foreach (Pagos n in a.Pagos) { var aux = db.Artistas.Where(x => x.Id == n.IDArtista).Single(); lstArt.Items.Add(aux); } var lst = lstCol.Items; }