private void BOTAOATUALIZAR_Click(object sender, EventArgs e) { OcorrenciaModelo ocorrencia = new OcorrenciaModelo(); Funcoes funcoes = new Funcoes(); if (EDITCODIGOOCORRENCIA.Text != "" && EDITCODIGOOCORRENCIA.Text != null) { ocorrencia.controle = Convert.ToInt32(EDITCODIGOOCORRENCIA.Text); } if (funcoes.ApenasNumeros(EDITDATAOCORRENCIA.Text) != "" && funcoes.ApenasNumeros(EDITDATAOCORRENCIA.Text) != null) { ocorrencia.dataocorrencia = DateTime.Parse(EDITDATAOCORRENCIA.Text, new System.Globalization.CultureInfo("pt-BR")); } ocorrencia.horaocorrencia = EDITHORAOCORRENCIA.Text; ocorrencia.veiculocodigo = Convert.ToInt32(EDITVEICULOCODIGO.Text); ocorrencia.motoristacodigo = Convert.ToInt32(EDITMOTORISTACODIGO.Text); ocorrencia.localocorrencia = EDITLOCALOCORRENCIA.Text; ocorrencia.tipoocorrencia = EDITTIPOOCORRENCIA.Text; OcorrenciaControle controleOcorrencia = new OcorrenciaControle(); controleOcorrencia.alterar(ocorrencia); MessageBox.Show("Ocorencia atualizada com sucesso", "Cadastro Ocorrencia"); limpaTela(); }
public void alterar(OcorrenciaModelo ocorrencia) { try { AbrirConexao(); comando = new MySqlCommand("update ocorrencia set controle =@controle, dataocorrencia =@dataocorrencia, horaocorrencia =@horaocorrencia, veiculocodigo =@veiculocodigo, motoristacodigo =@motoristacodigo, localocorrencia =@localocorrencia, tipoocorrencia =@tipoocorrencia where controle=@controle", conexao); comando.Parameters.AddWithValue("@controle", ocorrencia.controle); if (Convert.ToString(ocorrencia.dataocorrencia) != "01/01/0001 00:00:00") { comando.Parameters.AddWithValue("@dataocorrencia", ocorrencia.dataocorrencia); } else { comando.Parameters.AddWithValue("@dataocorrencia", null); } comando.Parameters.AddWithValue("@horaocorrencia", ocorrencia.horaocorrencia); comando.Parameters.AddWithValue("@veiculocodigo", ocorrencia.veiculocodigo); comando.Parameters.AddWithValue("@motoristacodigo", ocorrencia.motoristacodigo); comando.Parameters.AddWithValue("@localocorrencia", ocorrencia.localocorrencia); comando.Parameters.AddWithValue("@tipoocorrencia", ocorrencia.tipoocorrencia); comando.ExecuteNonQuery(); } catch (Exception erro) { throw erro; } finally { FecharConexao(); } }
public List <OcorrenciaModelo> listLastOcorrencias(int iddivida) { var retorno = new List <OcorrenciaModelo>(); SqlCommand cmd = new SqlCommand(); Conexao conexao = new Conexao(); SqlDataReader dr; cmd.CommandText = "SELECT * FROM OCORRENCIA WHERE OCORRENCIA.IDDIVIDA = @IDDIVIDA"; cmd.Parameters.AddWithValue("@IDDIVIDA", iddivida); try { cmd.Connection = conexao.conectar(); dr = cmd.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { var item = new OcorrenciaModelo(); item.idocorrencia = Convert.ToInt32(dr["IDOCORRENCIA"]); item.conteudo = Convert.ToString(dr["CONTEUDO"]); item.iddivida = Convert.ToInt32(dr["IDDIVIDA"]); item.dataocorrencia = DateTime.Parse(Convert.ToString(dr["DATAOCORRENCIA"])); item.horaOcorrencia = DateTime.Parse(Convert.ToString(dr["HORAOCORRENCIA"])); retorno.Add(item); } } } catch (SqlException ex) { MessageBox.Show(ex.Message); } return(retorno); }
private void BOTAOLOCALIZAR_Click(object sender, EventArgs e) { FocorrenciaLoc ocorrenciaLoc = new FocorrenciaLoc(); ocorrenciaLoc.ShowDialog(); OcorrenciaModelo ocorrencia = new OcorrenciaModelo(); OcorrenciaControle ocorrenciaControle = new OcorrenciaControle(); ocorrencia.controle = int.Parse(ocorrenciaLoc.codigoretornado); if (ocorrenciaLoc.codigoretornado != "" && ocorrenciaLoc.codigoretornado != null) { ocorrencia = ocorrenciaControle.pesquisaOcorrencia(ocorrencia); EDITCODIGOOCORRENCIA.Text = Convert.ToString(ocorrencia.controle); if (ocorrencia.dataocorrencia != DateTime.MinValue) //data nao foi iniciada { DateTime wdata = new DateTime(); wdata = ocorrencia.dataocorrencia; EDITDATAOCORRENCIA.Text = wdata.ToShortDateString(); } EDITHORAOCORRENCIA.Text = ocorrencia.horaocorrencia; EDITVEICULOCODIGO.Text = Convert.ToString(ocorrencia.veiculocodigo); EDITMARCAMODELOCODIGO.Text = Convert.ToString(ocorrencia.motoristacodigo); EDITLOCALOCORRENCIA.Text = ocorrencia.localocorrencia; EDITTIPOOCORRENCIA.Text = ocorrencia.tipoocorrencia; } if (ocorrencia.veiculocodigo > 0) { VeiculoModelo vei = new VeiculoModelo(); vei.codigo = ocorrencia.veiculocodigo; VeiculoControle veiculoControle = new VeiculoControle(); vei = veiculoControle.atualizatela(vei); EDITVEICULOPLACA.Text = vei.placa; EDITVEICULOANOFABRICA.Text = Convert.ToString(vei.anofabrica); EDITVEICULOANOMODELO.Text = Convert.ToString(vei.anomodelo); if (vei.marcamodelocodigo > 0) { MarcamodeloModelo marca = new MarcamodeloModelo(); marca.codigo = vei.marcamodelocodigo; MarcamodeloControle marcaControle = new MarcamodeloControle(); marca = marcaControle.pesquisaMarca(marca); EDITMARCAMODELOCODIGO.Text = Convert.ToString(marca.codigo); EDITMARCAMODELODESCRICAO.Text = marca.descricao; } } if (ocorrencia.motoristacodigo > 0) { MotoristaModelo motorista = new MotoristaModelo(); motorista.codigo = ocorrencia.motoristacodigo; MotoristaControle motoristaControle = new MotoristaControle(); motorista = motoristaControle.atualizatela(motorista); EDITMOTORISTACODIGO.Text = Convert.ToString(motorista.codigo); EDITMOTORISTANOME.Text = motorista.nome; } BOTAONOVO_Click(sender, e); }
public int salvar(OcorrenciaModelo ocorrencia) { MySqlTransaction transacao; try { AbrirConexao(); transacao = conexao.BeginTransaction(); comando = new MySqlCommand("INSERT INTO ocorrencia(controle, dataocorrencia, horaocorrencia, veiculocodigo, motoristacodigo, localocorrencia, tipoocorrencia) VALUES (@controle, @dataocorrencia, @horaocorrencia, @veiculocodigo, @motoristacodigo, @localocorrencia, @tipoocorrencia)", conexao); comando.Parameters.AddWithValue("@controle", ocorrencia.controle); if (Convert.ToString(ocorrencia.dataocorrencia) != "01/01/0001 00:00:00") { comando.Parameters.AddWithValue("@dataocorrencia", ocorrencia.dataocorrencia); } else { comando.Parameters.AddWithValue("@dataocorrencia", null); } comando.Parameters.AddWithValue("@horaocorrencia", ocorrencia.horaocorrencia); comando.Parameters.AddWithValue("@veiculocodigo", ocorrencia.veiculocodigo); comando.Parameters.AddWithValue("@motoristacodigo", ocorrencia.motoristacodigo); comando.Parameters.AddWithValue("@localocorrencia", ocorrencia.localocorrencia); comando.Parameters.AddWithValue("@tipoocorrencia", ocorrencia.tipoocorrencia); comando.ExecuteNonQuery(); MySqlDataReader tabelaDados; comando = new MySqlCommand("SELECT LAST_INSERT_ID() as CONTROLE", conexao); // Executa a consulta tabelaDados = comando.ExecuteReader(); // Verifica se retornou pelo menos um registro int codigogerado = 0; while (tabelaDados.Read()) // Lendo registro { codigogerado = tabelaDados.GetInt32(0); } tabelaDados.Close(); transacao.Commit(); return(codigogerado); } catch (Exception erro) { throw erro; } finally { FecharConexao(); } }
public OcorrenciaModelo pesquisaOcorrencia(OcorrenciaModelo ocorrencia) { try { AbrirConexao(); MySqlDataReader tabelaDados; comando = new MySqlCommand("SELECT * FROM OCORRENCIA WHERE CONTROLE = @CONTROLE", conexao); comando.Parameters.AddWithValue("@controle", ocorrencia.controle); // Executa a consulta tabelaDados = comando.ExecuteReader(); MarcamodeloModelo marca = new MarcamodeloModelo(); while (tabelaDados.Read()) // Lendo registro { if (!tabelaDados.IsDBNull(tabelaDados.GetOrdinal("CONTROLE"))) { ocorrencia.controle = tabelaDados.GetInt32("CONTROLE"); } if (!tabelaDados.IsDBNull(tabelaDados.GetOrdinal("DATAOCORRENCIA"))) { ocorrencia.dataocorrencia = Convert.ToDateTime(tabelaDados.GetString("DATAOCORRENCIA")); } if (!tabelaDados.IsDBNull(tabelaDados.GetOrdinal("HORAOCORRENCIA"))) { ocorrencia.horaocorrencia = tabelaDados.GetString("HORAOCORRENCIA"); } if (!tabelaDados.IsDBNull(tabelaDados.GetOrdinal("VEICULOCODIGO"))) { ocorrencia.veiculocodigo = tabelaDados.GetInt32("VEICULOCODIGO"); } if (!tabelaDados.IsDBNull(tabelaDados.GetOrdinal("MOTORISTACODIGO"))) { ocorrencia.motoristacodigo = tabelaDados.GetInt32("MOTORISTACODIGO"); } if (!tabelaDados.IsDBNull(tabelaDados.GetOrdinal("LOCALOCORRENCIA"))) { ocorrencia.localocorrencia = tabelaDados.GetString("LOCALOCORRENCIA"); } if (!tabelaDados.IsDBNull(tabelaDados.GetOrdinal("TIPOOCORRENCIA"))) { ocorrencia.tipoocorrencia = tabelaDados.GetString("TIPOOCORRENCIA"); } } tabelaDados.Close(); return(ocorrencia); } catch (Exception erro) { throw erro; } finally { FecharConexao(); } }
public void excluir(OcorrenciaModelo ocorrencia) { try { ocorrenciaPersistencia.excluir(ocorrencia); } catch (Exception erro) { throw erro; } }
public void alterar(OcorrenciaModelo ocorrencia) { try { ocorrenciaPersistencia.alterar(ocorrencia); } catch (Exception erro) { throw erro; } }
private void BOTAOPESQUISA_Click(object sender, EventArgs e) { //Dados da tabela cadastro OcorrenciaModelo ocorrencia = new OcorrenciaModelo(); if (COMBOTIPOPESQUISA.Text == "CONTROLE") { ocorrencia.controle = Convert.ToInt32("%" + EDITPESQUISA.Text + "%"); } listaGrid(ocorrencia); }
private void BOTAOEXCLUIR_Click(object sender, EventArgs e) { OcorrenciaModelo ocorrencia = new OcorrenciaModelo(); ocorrencia.controle = Convert.ToInt32(EDITCODIGOOCORRENCIA.Text); OcorrenciaControle ocorrenciaControle = new OcorrenciaControle(); ocorrenciaControle.excluir(ocorrencia); MessageBox.Show("Ocorrencia excluida com sucesso", "Cadastro Ocorrência"); limpaTela(); }
public OcorrenciaModelo pesquisaOcorrencia(OcorrenciaModelo ocorrencia) { try { OcorrenciaModelo ocorrenciaModelo = new OcorrenciaModelo(); ocorrenciaModelo = ocorrenciaPersistencia.pesquisaOcorrencia(ocorrencia); return(ocorrenciaModelo); } catch (Exception erro) { throw erro; } }
public void listaGrid(OcorrenciaModelo ocorrencia) { string strSQL = "SELECT * FROM OCORRENCIA WHERE controle > 0 "; EDITCODIGO.Text = Convert.ToString(ocorrencia.controle); codigoretornado = Convert.ToString(ocorrencia.controle); if (ocorrencia.controle > 0) { strSQL = strSQL + "and controle = @controle"; } /* * if (ocorrencia.dataocorrencia != null) * { * strSQL = strSQL + "and dataocorrencia like @dataocorrencia"; * }*/ objConexao = new MySqlConnection(conexaoBancoDados); objComando = new MySqlCommand(strSQL, objConexao); if (ocorrencia.controle > 0) { objComando.Parameters.AddWithValue("@controle", ocorrencia.controle); } /*if (ocorrencia.dataocorrencia != null) * { * objComando.Parameters.AddWithValue("@dataocorrencia", ocorrencia.dataocorrencia); * }*/ try { MySqlDataAdapter objAdp = new MySqlDataAdapter(objComando); DataTable dtLista = new DataTable(); objAdp.Fill(dtLista); gridOcorrenciaLoc.DataSource = dtLista; } catch (Exception erro) { throw erro; } }
public void excluir(OcorrenciaModelo ocorrencia) { try { AbrirConexao(); comando = new MySqlCommand("DELETE FROM OCORRENCIA WHERE CONTROLE = @CONTROLE", conexao); comando.Parameters.AddWithValue("@controle", ocorrencia.controle); comando.ExecuteNonQuery(); } catch (Exception erro) { throw erro; } finally { FecharConexao(); } }