public Transport(Masina masina, Sofer sofer, String denumire, Oras oras) { this.Masina = masina; this.Sofer = sofer; this.DenumireIncarcatura = denumire; this.Oras = oras; }
private void btnAdaugaMasina_Click(object sender, EventArgs e) { // Adauga o noua entitate de tip Masina Masina masina = new Masina(tbDenumire.Text, tbNumarMasina.Text); //OLD: listaMasini.Add(masina); //Inserare in baza de date TransportContext DbCtx = new TransportContext(); DbCtx.Masini.Add(masina); //Commit tranzactie DbCtx.SaveChanges(); FormularGestiune gestiune = new FormularGestiune(); gestiune.Show(); this.Hide(); }
private void btnAdaugaTransport_Click(object sender, EventArgs e) { Masina masina = null; Sofer sofer = null; if (lvMasina.SelectedItems.Count != 0) { List <Masina> masini = new TransportContext().Masini.ToList(); masina = masini.ElementAt(lvMasina.SelectedIndices[0]); } if (lvSofer.SelectedItems.Count != 0) { List <Sofer> soferi = new TransportContext().Soferi.ToList(); sofer = soferi.ElementAt(lvSofer.SelectedIndices[0]); } String denumire = tbDenumire.Text; Transport transport = new Transport(); transport.Sofer = sofer; if (masina == null || sofer == null || denumire == null) { MessageBox.Show("Selectati toate campurile!"); } if (String.Equals(cbOras.Text, "BUCURESTI")) { transport.Oras = Oras.BUCURESTI; } else if (String.Equals(cbOras.Text, "CONSTANTA")) { transport.Oras = Oras.CONSTANTA; } else if (String.Equals(cbOras.Text, "PITESTI")) { transport.Oras = Oras.PITESTI; } else if (String.Equals(cbOras.Text, "PLOIESTI")) { transport.Oras = Oras.PLOIESTI; } else if (String.Equals(cbOras.Text, "TARGOVISTE")) { transport.Oras = Oras.TARGOVISTE; } else if (String.Equals(cbOras.Text, "VALCEA")) { transport.Oras = Oras.VALCEA; } transport.Masina = masina; transport.DenumireIncarcatura = denumire; TransportContext ctx = new TransportContext(); ctx.Entry(transport.Masina).State = Microsoft.EntityFrameworkCore.EntityState.Modified; ctx.Entry(transport.Sofer).State = Microsoft.EntityFrameworkCore.EntityState.Modified; ctx.Transporturi.Add(transport); ctx.SaveChanges(); FormularGestiune gestiune = new FormularGestiune(); gestiune.Show(); this.Hide(); }