//Criar um aluguer para o cliente selecionado e põe o carro selecionado em estado aluguer private void buttonAlugar_Click(object sender, EventArgs e) { CarroAluguer carroAluguer = (CarroAluguer)dataGridViewCarrosAluguer.CurrentRow.DataBoundItem; Cliente clienteselected = (Cliente)listBoxClientes.SelectedItem; Aluguer aluguer = new Aluguer { DataInicio = dateTimePicker1.Value, DataFim = dateTimePicker2.Value, ClienteIdCliente = clienteselected.IdCliente, Cliente = clienteselected, CarroAluguer = carroAluguer }; myDB.Aluguers.Add(aluguer); carroAluguer.Estado = "Alugado"; myDB.SaveChanges(); if (MessageBox.Show("Aluguer Criado") == DialogResult.OK) { LerDados(); listBoxAlugueres.DataSource = clienteselected.Aluguers.ToList(); } }
//Criar uma venda para o cliente selecionado private void buttonVender_Click(object sender, EventArgs e) { if (listBoxCliente.SelectedIndex == -1 || listBoxCarrosVenda.SelectedIndex == -1) { return; } FormCriarVenda formCriarVenda = new FormCriarVenda(); Cliente clienteSelecionado = (Cliente)listBoxCliente.SelectedItem; CarroVenda carroVendaSelecionado = (CarroVenda)listBoxCarrosVenda.SelectedItem; if (formCriarVenda.ShowDialog() == DialogResult.OK) { Venda venda = formCriarVenda.Venda; venda.CarroVenda = carroVendaSelecionado; myDb.Vendas.Add(venda); clienteSelecionado.Vendas.Add(venda); listBoxCarrosVenda.ClearSelected(); myDb.SaveChanges(); lerDados(); listBoxVendas.SelectedItem = venda; } }
private void SaveCustomerInfo() { Cliente novoCliente = new Cliente { Nome = textBoxNome.Text, Contacto = textBoxContacto.Text, Morada = textBoxMorada.Text, NIF = Convert.ToInt32(textBoxNIF.Text) }; myDb.Clientes.Add(novoCliente); myDb.SaveChanges(); LerDados(); }
//Adicionar um carro para venda à base de dados private void buttonAdicionar_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(maskedTextBoxNumChassi.Text) || string.IsNullOrEmpty(comboBoxMarca.Text) || string.IsNullOrEmpty(textBoxModelo.Text) || string.IsNullOrEmpty(comboBoxCombustivel.Text)) { return; } string[] extras = listBoxExtras.Items.OfType <string>().ToArray(); string extrasComEnters = ""; foreach (String extra in extras) { extrasComEnters += extra + "\n"; } CarroVenda novoCarroVenda = new CarroVenda { NumeroChassis = maskedTextBoxNumChassi.Text, Marca = comboBoxMarca.Text, Modelo = textBoxModelo.Text, Combustivel = comboBoxCombustivel.Text, Extras = extrasComEnters }; myDb.Carros.Add(novoCarroVenda); myDb.SaveChanges(); MessageBox.Show("Carro adicionado com sucesso para venda", "Criar Venda"); }
//Adiciona um cliente à base de dados private void buttonAdicionar_Click(object sender, EventArgs e) { Cliente novoCliente = new Cliente { Nome = textBoxNome.Text, Contacto = textBoxContacto.Text, Morada = textBoxMorada.Text, NIF = Convert.ToInt32(textBoxNIF.Text) }; myDb.Clientes.Add(novoCliente); myDb.SaveChanges(); Close(); }
//Adiciona um Carro de oficina ao cliente selecionado private void buttonAdicionarCarro_Click(object sender, EventArgs e) { if (listBoxClientes.SelectedIndex == -1) { return; } FormAdicionarCarroOficina formAdicionarCarroOficina = new FormAdicionarCarroOficina(); Cliente clienteSelecionado = new Cliente(); clienteSelecionado = (Cliente)listBoxClientes.SelectedItem; if (formAdicionarCarroOficina.ShowDialog() == DialogResult.OK) { var carroOficina = formAdicionarCarroOficina.CarroOficina; clienteSelecionado.CarroOficinas.Add(carroOficina); listBoxCarros.SelectedItem = carroOficina; myDb.SaveChanges(); LerDados(); } }
private void buttonEditarCarro_Click(object sender, EventArgs e) { CarroVenda bindingCarroVenda = GetCarroVenda(); CarroVenda dbCarroVenda = myDb.Carros.OfType <CarroVenda>().First(); var extras = listBoxExtras.Items.OfType <string>().ToArray(); string extraComEnters = ""; foreach (var extra in extras) { extraComEnters += extra + "\n"; } dbCarroVenda.NumeroChassis = maskedTextBoxNumChassi.Text; dbCarroVenda.Marca = comboBoxMarca.Text; dbCarroVenda.Modelo = comboBoxModelo.Text; dbCarroVenda.Combustivel = comboBoxCombustivel.Text; dbCarroVenda.Extras = extraComEnters; myDb.SaveChanges(); DialogResult = DialogResult.OK; MessageBox.Show("Carro Editado com sucesso", "Carro Editado"); }
//Criar um novo carro de aluguer e colocar todos os campos de volta a branco private void buttonAdicionar_Click(object sender, EventArgs e) { if (maskedTextBoxNumChassi.Text != "" && maskedTextBoxMatricula.Text != "" && comboBoxMarca.Text != "" && textBoxModelo.Text != "" && comboBoxCombustivel.Text != "") { CarroAluguer carroAluguer = new CarroAluguer { NumeroChassis = maskedTextBoxNumChassi.Text, Marca = comboBoxMarca.Text, Modelo = textBoxModelo.Text, Combustivel = comboBoxCombustivel.Text, Matricula = maskedTextBoxMatricula.Text, Estado = "No Stand" }; myDB.Carros.Add(carroAluguer); myDB.SaveChanges(); maskedTextBoxNumChassi.Text = ""; comboBoxMarca.Text = ""; textBoxModelo.Text = ""; comboBoxCombustivel.Text = ""; maskedTextBoxMatricula.Text = ""; } }
//Elimina clientes da base de dados private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e) { myDb.SaveChanges(); LerDados(); }