//Editar o aluguer selecionado private void btnEditarAluguer_Click(object sender, EventArgs e) { Alugueres aluguerSelecionado = (Alugueres)lbxAluguer.SelectedItem; Add_Edit_Aluguer(); if (valorpassou == true && kmspassou == true && dataCerta == true) { aluguerSelecionado.Kms = tbxKms.Text; aluguerSelecionado.Valor = double.Parse(tbxValor.Text); aluguerSelecionado.DataInicio = dtpEntrega.Value; aluguerSelecionado.DataFim = dtpRececao.Value; AtualizarListaAluguer(); dadosGuardados = false; lbxAluguer.ClearSelected(); tbxValor.Clear(); tbxKms.Clear(); dtpEntrega.Value = DateTime.Now; dtpRececao.Value = DateTime.Now; } valorpassou = false; kmspassou = false; dataCerta = true; }
//Mostra as informações do aluguer private void ButtonInformacoesAluguer_Click(object sender, EventArgs e) { Clientes clienteSelecionado = (Clientes)lbxClientes.SelectedItem; Alugueres aluguerSelecionado = (Alugueres)lbxAluguer.SelectedItem; if (clienteSelecionado == null || aluguerSelecionado == null) { return; } Form_AluguerInformacoes informacoes = new Form_AluguerInformacoes(clienteSelecionado, aluguerSelecionado); informacoes.Show(); }
//Elimina o aluguer selecionado private void BtnEliminarAluguer_Click(object sender, EventArgs e) { Alugueres aluguerSelecionado = (Alugueres)lbxAluguer.SelectedItem; if (aluguerSelecionado == null) { MessageBox.Show("Selecione um aluguer para o poder eliminar", "Aluguer não selecionado", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } StandLocalDB.Aluguer.Remove(aluguerSelecionado); AtualizarListaAluguer(); dadosGuardados = false; }
//Verifica qual o aluguer selecionado private void lbxAluguer_SelectedIndexChanged(object sender, EventArgs e) { Alugueres aluguerSelecionado = (Alugueres)lbxAluguer.SelectedItem; if (aluguerSelecionado == null) { btnEditarAluguer.Enabled = false; btnEliminarAluguer.Enabled = false; return; } btnEditarAluguer.Enabled = true; btnEliminarAluguer.Enabled = true; btnInfAluguer.Enabled = true; tbxKms.Text = aluguerSelecionado.Kms; tbxValor.Text = aluguerSelecionado.Valor.ToString(); dtpEntrega.Value = aluguerSelecionado.DataInicio; }
//Adiciona um novo aluguer ao cliente selecionado private void btnAddAluguer_Click(object sender, EventArgs e) { Clientes clienteSelecionado = (Clientes)lbxClientes.SelectedItem; CarrosAluguer carroAluguerSelecionado = lbxCarrosAluguer.SelectedItem as CarrosAluguer; if (clienteSelecionado == null || carroAluguerSelecionado == null) { MessageBox.Show("Selecione o cliente e o carro antes de adicionar o aluguer", "Aluguer Errado", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Add_Edit_Aluguer(); if (valorpassou == true && kmspassou == true && dataCerta == true) { Alugueres aluguerTemp = new Alugueres { DataInicio = dtpEntrega.Value.Date, DataFim = dtpRececao.Value.Date, Valor = double.Parse(tbxValor.Text), Kms = tbxKms.Text, CarroAluguer = carroAluguerSelecionado, Cliente = clienteSelecionado, ClienteIdCliente = clienteSelecionado.IdCliente, }; StandLocalDB.Clientes.Find(clienteSelecionado.IdCliente).Aluguer.Add(aluguerTemp); AtualizarListaAluguer(); dadosGuardados = false; lbxAluguer.ClearSelected(); tbxValor.Clear(); tbxKms.Clear(); dtpEntrega.Value = DateTime.Now; dtpRececao.Value = DateTime.Now; } valorpassou = false; kmspassou = false; dataCerta = true; }
//Imprime a fatura do aluguer selecionado na gestão de alugueres public void AluguerUnico(Clientes clienteSelecionado, Alugueres AluguerSelecionado) { SaveFileDialog save = new SaveFileDialog(); save.InitialDirectory = @"C:/"; save.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; save.FileName = "Alugueres feito ao cliente " + clienteSelecionado.Nome; save.DefaultExt = ".txt"; if (save.ShowDialog() != DialogResult.OK) { return; } Stream caminhoFiceiro = save.OpenFile(); StreamWriter sw = new StreamWriter(caminhoFiceiro); sw.WriteLine("StandLocal - Qualquer serviço tem um preço."); sw.WriteLine(" "); sw.WriteLine(" "); sw.WriteLine("Nome: " + clienteSelecionado.Nome); sw.WriteLine("___________________________________________________"); sw.WriteLine("Nif: " + clienteSelecionado.NIF); sw.WriteLine("___________________________________________________"); sw.WriteLine(" "); sw.WriteLine(" "); sw.WriteLine("___________________________________________________"); sw.WriteLine("Carro: "); sw.WriteLine("Marca: " + AluguerSelecionado.CarroAluguer.Marca + " Modelo: " + AluguerSelecionado.CarroAluguer.Modelo); sw.WriteLine("Matricula: " + AluguerSelecionado.CarroAluguer.Matricula + " Tipo de Combustivel: " + AluguerSelecionado.CarroAluguer.Combustivel); sw.WriteLine(" "); sw.WriteLine(" "); sw.WriteLine("Kilometros do Carro antes do Aluguer: " + AluguerSelecionado.Kms); sw.WriteLine("Valor do Aluguer: " + AluguerSelecionado.Valor + "€"); sw.WriteLine("Aluguer Inicializado no dia: " + AluguerSelecionado.DataInicio.ToString("dd-MM-yy")); sw.WriteLine("Aluguer finalizado no dia: " + AluguerSelecionado.DataFim.ToString("dd-MM-yy")); sw.WriteLine("___________________________________________________"); sw.Close(); MessageBox.Show("Dados guadados com sucesso!"); }
//Mostra as informações relacionadas com o aluguer public Form_AluguerInformacoes(object clienteSelecionado, object aluguerSelecionado) { InitializeComponent(); cliente = clienteSelecionado as Clientes; aluguer = aluguerSelecionado as Alugueres; carro = aluguer.CarroAluguer; lblNomeCliente.Text = cliente.Nome; lblCombustivel.Text = carro.Combustivel; lblContactoCliente.Text = cliente.Contacto; lblDtaEntrega.Text = aluguer.DataFim.ToString("dd-MM-yy"); lblEstado.Text = carro.Estado; lblMarca.Text = carro.Marca; lblMatricula.Text = carro.Matricula; lblModelo.Text = carro.Modelo; lblMoradaCliente.Text = cliente.Morada; lblNifCliente.Text = cliente.NIF; lblNumChassis.Text = carro.NumeroChassis; lblNumKms.Text = aluguer.Kms; lblValor.Text = aluguer.Valor.ToString(); lblDataInicio.Text = aluguer.DataInicio.ToString("dd-MM-yy"); }