public static int Buscar(String placa) { Conexao.Query = $"SELECT V.ID " + $"FROM VEICULO V " + $"WHERE V.PLACA LIKE '{placa}' AND DISPONIVEL = 1"; SqlDataReader dr = Conexao.ExecReader(); int id = 0; if (dr != null) { if (!dr.Read()) { id = 0; } else { id = Int32.Parse(dr[0].ToString()); } } if (!dr.IsClosed) { dr.Close(); } return(id); }
public bool Registrar() { Conexao.Query = $"INSERT INTO VEICULO (CODMODELOVEICULO, CODCLIENTE, PLACA, TIPOVEICULO, DATARESGISTRO, CUSTOMEDIOPKM, ULTIMAALTERA)" + $" VALUES ({codModelo}, {codCliente}, '{placa.ToUpper().Replace("-", "")}', (SELECT ID FROM TIPOVEICULO WHERE NOME LIKE '{tipoVeiculo.ToUpper()}'), GETDATE(), (SELECT CAST({custoMedio.ToString().Replace(",", ".")} AS MONEY) ), GETDATE()); " + $"SELECT SCOPE_IDENTITY() AS ID"; SqlDataReader dr = Conexao.ExecReader(); if (dr.Read()) { id = Int32.Parse(dr[0].ToString()); MessageBox.Show(Form1.container, "Cadastro de Veiculo Realizado com Êxito!.".ToUpper(), "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { throw new Exception(); } dr.Close(); return(true); }
public static String consultaCustoMedio(String placa) { String custo = ""; Conexao.Query = $"SELECT CUSTOMEDIOPKM FROM VEICULO WHERE PLACA LIKE '{placa}'"; SqlDataReader dr = Conexao.ExecReader(); if (dr != null) { if (dr.Read()) { custo = dr[0].ToString(); } } if (!dr.IsClosed) { dr.Close(); } return(custo); }
public static String Buscar(int idVeiculo) { Conexao.Query = $"SELECT V.PLACA, M.NOME " + $"FROM VEICULO V " + $"INNER JOIN MODELOVEICULO M " + $"ON V.CODMODELOVEICULO = M.ID " + $"WHERE V.ID = {idVeiculo} AND DISPONIVEL = 1"; SqlDataReader dr = Conexao.ExecReader(); String nome; if (!dr.Read()) { nome = ""; } else { nome = dr[0].ToString(); } dr.Close(); return(nome); }
public static int Buscar(String nome) { Conexao.Query = $"SELECT ID FROM PESSOA WHERE NOME LIKE '{nome}'"; SqlDataReader dr = Conexao.ExecReader(); int id = 0; if (dr != null) { if (dr.Read()) { id = Int32.Parse(dr[0].ToString()); } else { id = 0; } } if (!dr.IsClosed) { dr.Close(); } return(id); }