protected void btn_editar_Click(object sender, EventArgs e) { ArrayList erros = new ArrayList(); try { lista_credito.Visible = false; Credito_Operações crd_banco = new Credito_Operações(); txtAlerta.Text = ""; if (lista_status.SelectedIndex != 0 || lista_mecanica.SelectedIndex != 0) { if ((Int32.Parse(hf_mecanica.Value) != Int32.Parse(lista_mecanica.SelectedValue.ToString()) || decimal.Parse(hf_valor.Value) != decimal.Parse(valor_compra.Text)) || Int32.Parse(hf_status.Value) != Int32.Parse(lista_status.SelectedValue)) { if (decimal.Parse(valor_compra.Text.Replace(".", ",")) > 0) { ModeloCredito crd = new ModeloCredito(); crd.id_mecanica = Int32.Parse(lista_mecanica.SelectedValue.ToString()); crd.valor_compra = decimal.Parse(valor_compra.Text); crd.id_status = Int32.Parse(lista_status.SelectedValue.ToString()); crd.id_usuario = Credito_Operações.RetornaID(Int32.Parse(hf_credito.Value)); crd.id_credito = Int32.Parse(hf_credito.Value); crd.data_credito = DateTime.Parse(data_credito.Text); if (crd_banco.LimpaCriacao(Int32.Parse(hf_credito.Value), decimal.Parse(hf_valor.Value), Int32.Parse(hf_mecanica.Value)) && crd_banco.UpdateCredito(crd)) { erros.Add("Edição realizada!"); LimpaTudo(); } else { erros.Add("Problemas na Edição do Crédito"); LimpaTudo(); } } else { erros.Add("Valor da compra inválido!\n"); LimpaTudo(); } } else { erros.Add("Esses valores já estão no banco\n"); } } else { erros.Add("Selecione Mecânica e Status"); } } catch (Exception ex) { erros.Add(ex.Message); } finally { if (erros.Count > 0) { ModalAlerta.Visible = true; for (int i = 0; i < erros.Count; i++) { txtAlerta.Text = txtAlerta.Text += erros[i]; } } } }
protected void btn_credito_Click(object sender, EventArgs e) { ArrayList erros = new ArrayList(); try { txtAlerta.Text = ""; ModeloCredito crd = new ModeloCredito(); Credito_Operações crd_banco = new Credito_Operações(); if (data_compra.Text != "" && motivo.Text != "" && nota_fiscal.Text != "" && valor_compra.Text != "" && motivo.Text != "") { var teste = decimal.Parse(valor_compra.Text.Replace(".", ",")); if (!(teste >= 0)) { erros.Add("Valor da Compra não pode ser menor do que zero\n"); } if (DateTime.Parse(data_compra.Text) > DateTime.Parse(data_credito.Text)) { erros.Add("Data de credito nao pode ser menor que data de compra\n"); } if (DateTime.Parse(data_compra.Text) > DateTime.Now) { erros.Add("Data de compra não pode ser maior do que a atual\n"); } if (lista_parceiro.SelectedIndex == 0) { erros.Add("Selecione um parceiro, depois selecione uma mecânica\n"); } if (lista_status.SelectedIndex == 0) { erros.Add("Selecione um Status\n"); } if (teste >= 0 && DateTime.Parse(data_compra.Text) < DateTime.Parse(data_credito.Text) && lista_parceiro.SelectedIndex != 0 && lista_status.SelectedIndex != 0 && DateTime.Parse(data_compra.Text) < DateTime.Now) { crd.id_mecanica = Int32.Parse(lista_mecanica.SelectedValue); crd.id_status = Int32.Parse(lista_status.SelectedValue); crd.motivo = motivo.Text; crd.nota_fiscal = Int32.Parse(nota_fiscal.Text); crd.valor_compra = teste; crd.data_compra = DateTime.Parse(data_compra.Text); crd.data_credito = DateTime.Now; crd.id_usuario = Int32.Parse(id_usuario.Text); int id_credito = 0; int valor_credito = 0; if (crd_banco.FazCredito(crd, ref id_credito, ref valor_credito)) { LimpaCampos(); erros.Add("Crédito inserido com sucesso! ID da Transação: " + id_credito + " Valor Creditado: " + valor_credito); } else { erros.Add("Problemas com a conexão, tente novamente\n"); } } } else { erros.Add("Preencha todos os campos!\n"); } } catch (Exception ex) { erros.Add(ex.Message); } finally { if (erros.Count > 0) { ModalAlerta.Visible = true; for (int i = 0; i < erros.Count; i++) { txtAlerta.Text = txtAlerta.Text += erros[i]; } } } }