private void OnSelectExcluir(object sender, EventArgs e) { try { if (mouseLocation.RowIndex >= 0) { int Id = Convert.ToInt32(gridDados.Rows[mouseLocation.RowIndex].Cells[0].Value); DialogResult Excluir = MessageBox.Show("Tem certeza que excluir esta Abastecimento?", "Excluir Abastecimento", MessageBoxButtons.YesNo); if (Excluir == DialogResult.Yes) { Abastecimentos abastecimentos = new Abastecimentos(); abastecimentos.Id = Id; abastecimentos.Delete(); if (abastecimentos.Success) { MessageBox.Show(abastecimentos.Message); LoadList(); } else { throw new Exception("Houver um erro ao excluir o abastecimento. (" + abastecimentos.Message + ")"); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void PreencherDados() { try { Abastecimentos abastecimentos = new Abastecimentos(); abastecimentos.Id = Id; abastecimentos.Get(); dynamic abastecimento = abastecimentos.Results[0]; timeData.Text = abastecimento.Data; textCupom.Text = abastecimentos.Cupom; combPosto.SelectedValue = abastecimento.Posto; combCombustivel.SelectedValue = abastecimento.Combustivel; combVeiculo.SelectedValue = abastecimento.Veiculo; combMotorista.SelectedValue = abastecimento.Motorista; textHodometro.Text = Convert.ToString(abastecimento.Hodometro); combStatus.SelectedValue = abastecimento.Status; textLitros.Text = Converter.ToQuantidade(abastecimento.Litros); textValor.Text = Converter.ToReais(abastecimento.Valor); textTotal.Text = Converter.ToReais(abastecimento.Total); } catch (Exception e) { MessageBox.Show("Houve um erro ao preencher os dados (" + e.Message + ")."); } }
private void LoadList() { try { List <dynamic> ListaCombustiveis = Listas.Combustiveis; List <dynamic> ListaStatus = Listas.AbastecimentosStatus; Abastecimentos abastecimentos = new Abastecimentos(); abastecimentos.GetAll(); ListaDados = abastecimentos.Results; gridDados.Rows.Clear(); foreach (dynamic abastecimento in ListaDados) { string combustivel = ListaCombustiveis.Find(find => Convert.ToInt32(find.Value) == Convert.ToInt32(abastecimento.Combustivel)).Text; string status = ListaStatus.Find(find => Convert.ToInt32(find.Value) == Convert.ToInt32(abastecimento.Status)).Text; gridDados.Rows.Add( abastecimento.Id, abastecimento.Data, abastecimento.Placa, abastecimento.Posto, combustivel, abastecimento.Litros, "R$ " + (abastecimento.Valor + " (R$ " + abastecimento.Total + ")"), abastecimento.Hodometro, status ); } } catch (Exception e) { MessageBox.Show("Houver um erro ao carregar a lista. (" + e.Message + ")"); } }
private void OnEnviar(object sender, EventArgs e) { try { Validate Validate = new Validate(this, ErrorProvider); Validate.AddRule(timeData, "Data", "required|date:dd/MM/yyyy HH:mm"); Validate.AddRule(textCupom, "Cupom", "max:20"); Validate.AddRule(combPosto, "Posto", "required|numeric|max:11"); Validate.AddRule(combCombustivel, "Combustivel", "required|numeric|exact:1"); Validate.AddRule(combVeiculo, "Veiculo", "numeric|max:11"); Validate.AddRule(combMotorista, "Motorista", "numeric|max:11"); Validate.AddRule(textHodometro, "Hodômetro", "numeric|max:22"); Validate.AddRule(combStatus, "Status", "required|numeric|max:22"); Validate.AddRule(textLitros, "Litros", "required|quantidade|max:11"); Validate.AddRule(textValor, "Valor", "required|reais|max:11"); Validate.AddRule(textTotal, "Total", "required|reais|max:11"); Validate.Validation(); if (Validate.IsValid()) { Abastecimentos abastecimentos = new Abastecimentos(); decimal total = (Convert.ToDecimal(textValor.Text) * Convert.ToDecimal(textLitros.Text)); abastecimentos.Data = timeData.Text; abastecimentos.Cupom = textCupom.Text; abastecimentos.Posto = combPosto.SelectedValue; abastecimentos.Combustivel = combCombustivel.SelectedValue; abastecimentos.Veiculo = combVeiculo.SelectedValue; abastecimentos.Motorista = combMotorista.SelectedValue; abastecimentos.Hodometro = textHodometro.Text; abastecimentos.Status = combStatus.SelectedValue; abastecimentos.Litros = Converter.ToDecimal(textLitros.Text, true); abastecimentos.Valor = Converter.ToDecimal(textValor.Text, true); abastecimentos.Total = Converter.ToDecimal(textTotal.Text, true); if (Id > 0) { abastecimentos.Id = Convert.ToInt32(Id); abastecimentos.Update(); } else { abastecimentos.Create(); } if (abastecimentos.Success) { DialogResult SuccessBox = MessageBox.Show(abastecimentos.Message, "CADASTRADO"); if (SuccessBox == DialogResult.OK) { if (fmPrincipal != null) { fmPrincipal.AtivarForm(new TMSForms.List.FormAbastecimentos(fmPrincipal)); } else { Close(); } } } else { throw new Exception("Houve um erro ao salvar o abastecimento (" + abastecimentos.Message + ")"); } } else { Validate.ErrorProviderShow(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }