package meuPacote;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.*;
public class CadastrarAtendimento
{
private static Connection conn;
private static final String URL = "jdbc:mysql://localhost:3306/Online";
private static final String DRIVER = "com.mysql.jdbc.Driver";
private static final String USUARIO = "root";
private static final String PASSWORD = "123";
public ResultSet rec;
public Statement st;
public String vendedor;
public int atendimento;
public String data;
public String filial;
public String contato;
public String nomeFanta;
public String razaoSoc;
public String cargo;
public String dpto;
public String ramoAtiv;
public String end;
public String num;
public String bairro;
public String cidade;
public String compl;
public String cep;
public String uf;
public String clienteSN;
public String numFunc;
public String telContato;
public String fax;
public String email;
public String site;
public String possui;
public String qual;
public String interesseCli;
public String pricCarac;
public String prodFaz;
public String modelo;
public String valorItem;
public String qtd;
public String total;
public String dtRetorno;
/*public String driver="jdbc:odbc:ProjVendas";*/
// public Connection conn;
public CadastrarAtendimento() throws SQLException
{
abreConexao();
//atualizar();
}
/********* Métodos GET *************/
public String getVendedor()
{
return vendedor;
}
public int getAtendimento()
{
return atendimento;
}
public String data()
{
return data;
}
public String getFilial()
{
return filial;
}
public String getContato()
{
return contato;
}
public String getNomeFanta()
{
return nomeFanta;
}
public String getRazaoSoc()
{
return razaoSoc;
}
public String getCargo()
{
return cargo;
}
public String getDpto()
{
return dpto;
}
public String getRamoAtiv()
{
return ramoAtiv;
}
public String getEnd()
{
return end;
}
public String getNum()
{
return num;
}
public String getBairro()
{
return bairro;
}
public String getCidade()
{
return cidade;
}
public String getCompl()
{
return compl;
}
public String getCep()
{
return cep;
}
public String getUf()
{
return uf;
}
public String getClienteSN()
{
return clienteSN;
}
public String getNumFunc()
{
return numFunc;
}
public String getTelContato()
{
return telContato;
}
public String getFax()
{
return fax;
}
public String getEmail()
{
return email;
}
public String getSite()
{
return site;
}
public String getPossui()
{
return possui;
}
public String getQual()
{
return qual;
}
public String getInteresseCli()
{
return interesseCli;
}
public String getPricCarac()
{
return pricCarac;
}
public String getProdFaz()
{
return prodFaz;
}
public String getModelo()
{
return modelo;
}
public String getValorItem()
{
return valorItem;
}
public String getQtd()
{
return qtd;
}
public String total()
{
return total;
}
public String dtRetorno()
{
return dtRetorno;
}
/********* Métodos SET *************/
public boolean setVendedor(String nome)
{
if(!nome.equals("")|| vendedor.equals(""))
{
this.vendedor=nome;
return true;
}
else
{
return false;
}
}
public boolean setAtendimento(String numero)
{
int n;
try
{
n=Integer.parseInt(numero);
this.atendimento=n;
return true;
}
catch(Exception ex)
{
return false;
}
}
public boolean setData(String data)
{
if(!data.equals("")|| data.equals(""))
{
this.data=data;
return true;
}
else
{
return false;
}
}
public boolean setFilial(String nome)
{
if(!nome.equals("")|| nome.equals(""))
{
this.filial=nome;
return true;
}
else
{
return false;
}
}
public boolean setContato(String s)
{
if(!s.equals("")|| s.equals(""))
{
this.contato=s;
return true;
}
else
{
return false;
}
}
public boolean setNomeFanta(String nome)
{
if(!nome.equals("")|| nome.equals(""))
{
this.nomeFanta=nome;
return true;
}
else
{
JOptionPane.showMessageDialog(null,"Nome deve ser preenchido","Erro",1);
return false;
}
}
public boolean setRazaoSoc(String rs)
{
if(!rs.equals("")|| rs.equals(""))
{
this.razaoSoc=rs;
return true;
}
else
{
return false;
}
}
public boolean setCargo(String c)
{
if(!c.equals("")|| c.equals(""))
{
this.cargo=c;
return true;
}
else
{
return false;
}
}
public boolean setDpto(String nome)
{
if(!nome.equals("")|| nome.equals(""))
{
this.dpto=nome;
return true;
}
else
{
return false;
}
}
public boolean setRamoAtiv(String nome)
{
if(!nome.equals("")|| nome.equals(""))
{
this.ramoAtiv=nome;
return true;
}
else
{
return false;
}
}
public boolean setEnd(String texto)
{
if(!texto.equals("") || texto.equals(""))
{
this.end=texto;
return true;
}
else
{
return false;
}
}
public boolean setNum(String numero)
{
if(!numero.equals("")|| numero.equals(""))
{
this.num=numero;
return true;
}
else
{
return false;
}
}
public boolean setCep(String numero)
{
if(!numero.equals("")|| numero.equals(""))
{
this.cep = numero;
return true;
}
else
{
return false;
}
}
public boolean setBairro(String b)
{
if(!b.equals("")|| b.equals(""))
{
this.bairro=b;
return true;
}
else
{
return false;
}
}
public boolean setCidade(String texto)
{
if(!texto.equals("") || texto.equals(""))
{
this.cidade = texto;
return true;
}
else
{
return false;
}
}
public boolean setCompl(String texto)
{
if(!texto.equals("")|| texto.equals(""))
{
this.compl = texto;
return true;
}
else
{
return false;
}
}
public boolean setUf(String nome)
{
if(!nome.equals("")|| nome.equals(""))
{
this.uf= nome;
return true;
}
else
{
JOptionPane.showMessageDialog(null,"Estado deve ser preenchido","ERRO",1);
return false;
}
}
public boolean setClienteSN(String texto)
{
if (!texto.equals("")|| texto.equals(""))
{
//if((texto.indexOf("'")==-1)||(texto.indexOf('"')==-1)||(texto.indexOf("!")==-1)||(texto.indexOf("@")==-1)||(texto.indexOf("#")==-1)||(texto.indexOf("$")==-1)||(texto.indexOf("%")==-1)||(texto.indexOf("&")==-1)||(texto.indexOf("*")==-1)||(texto.indexOf("(")==-1)||(texto.indexOf(")")==-1)||(texto.indexOf("_")==-1)||(texto.indexOf("-")==-1)||(texto.indexOf("=")==-1)||(texto.indexOf("+")==-1)||(texto.indexOf("§")==-1)||(texto.indexOf("¹")==-1)||(texto.indexOf("²")==-1)||(texto.indexOf("³")==-1)||(texto.indexOf("£")==-1)||(texto.indexOf("¢")==-1)||(texto.indexOf("¬")==-1)||(texto.indexOf("[")==-1)||(texto.indexOf("{")==-1)||(texto.indexOf("ª")==-1)||(texto.indexOf("}")==-1)||(texto.indexOf("]")==-1)||(texto.indexOf("º")==-1)||(texto.indexOf(":")==-1)||(texto.indexOf(";")==-1)||(texto.indexOf(",")==-1)||(texto.indexOf(".")==-1)||(texto.indexOf("<")==-1)||(texto.indexOf(">")==-1)||(texto.indexOf("?")==-1)||(texto.indexOf("/")==-1)||(texto.indexOf("°")==-1)||(texto.indexOf("|")==-1))
this.clienteSN=texto;
return true;
}
else
{
return false;
}
}
public boolean setTelContato(String texto)
{
if(!texto.equals("")|| texto.equals(""))
{
this.telContato = texto;
return true;
}
else
{
return false;
}
}
public boolean setFax(String texto)
{
if(!texto.equals("")|| texto.equals(""))
{
this.fax = texto;
return true;
}
else
{
return false;
}
}
public boolean setNumFunc(String numero)
{
if(!numero.equals("")|| numero.equals(""))
{
this.numFunc=numero;
return true;
}
else
{
return false;
}
}
public boolean setEmail( String texto )
{
if(!texto.equals("")|| texto.equals(""))
{
this.email=texto;
return true;
}
else
{
return false;
}
}
public boolean setSite( String texto )
{
if(!texto.equals("")|| texto.equals(""))
{
this.site=texto;
return true;
}
else
{
return false;
}
}
public boolean setPossui( String texto )
{
if(!texto.equals("")|| texto.equals(""))
{
this.possui=texto;
return true;
}
else
{
return false;
}
}
public boolean setQual( String texto )
{
if(!texto.equals("")|| texto.equals(""))
{
this.qual=texto;
return true;
}
else
{
return false;
}
}
public boolean setInteresseCli( String texto )
{
if(!texto.equals("")|| texto.equals(""))
{
this.interesseCli=texto;
return true;
}
else
{
return false;
}
}
public boolean setPricCarac( String texto )
{
if(!texto.equals("")|| texto.equals(""))
{
this.pricCarac=texto;
return true;
}
else
{
return false;
}
}
public boolean setProdFaz( String texto )
{
if(!texto.equals("")|| texto.equals(""))
{
this.prodFaz=texto;
return true;
}
else
{
return false;
}
}
public boolean setModelo( String texto )
{
if(!texto.equals("")|| texto.equals(""))
{
this.modelo=texto;
return true;
}
else
{
return false;
}
}
public boolean setValorItem( String texto )
{
if(!texto.equals("")|| texto.equals(""))
{
this.valorItem=texto;
return true;
}
else
{
return false;
}
}
public boolean setQtd(String numero)
{
//int n;
if(!numero.equals("")|| numero.equals(""))
{
//n=Integer.parseInt(numero);
this.qtd=numero;
return true;
}
else
{
return false;
}
}
public boolean setTotal( String texto )
{
if(!texto.equals("")|| texto.equals(""))
{
this.total=texto;
return true;
}
else
{
return false;
}
}
public boolean setDtRetorno( String texto )
{
if(!texto.equals("")|| texto.equals(""))
{
this.dtRetorno=texto;
return true;
}
else
{
return false;
}
}
/*********************************FIM DO MÉTODO SET*******************************************************/
/********** MÈTODO ****** G R A V A R ***********************/
public boolean gravar()
{
System.out.println("entrou no gravar");
String sql = "insert into tbAtendimento values ('"+ this.vendedor +"','"+ this.data +"','" + this.filial +"','"+ this.contato +"','"+ this.nomeFanta +"','"+ this.razaoSoc +"','"+ this.cargo +"','"+ this.dpto +"','"+ this.ramoAtiv +"','"+ this.end +"','"+ this.num +"','"+ this.bairro +"','"+ this.cidade +"','"+ this.compl +"','"+ this.cep +"','"+ this.uf +"','"+ this.clienteSN +"', '"+ this.numFunc +"' , '"+ this.telContato +"','"+ this.fax +"','"+ this.email +"','"+ this.site +"','"+ this.possui +"','"+ this.qual +"','"+ this.interesseCli +"','"+ this.pricCarac +"','"+ this.prodFaz +"','"+ this.modelo +"','"+ this.valorItem +"','"+ this.qtd +"' , '"+this.total+"' ,'"+ this.dtRetorno +"')";
System.out.println(sql);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(DRIVER,"","");
PreparedStatement pst = conn.prepareStatement(sql);
pst.executeUpdate();
//conn.close();
return true;
}
catch (SQLException s)
{
if (s.getErrorCode() == 2627)
{
JOptionPane.showMessageDialog(null, "Chave primária duplicada!", "ERRO", 0);
return false;
}
else
{
JOptionPane.showMessageDialog(null, "Erro inexperado.\n Entre em contato com o desenvolvedor e informe este número: " + s.getMessage(), "ERRO", 0);
return false;
}
}
catch(Exception e)
{
e.printStackTrace();
return false;
}
}
public ResultSet Consulta()
{
System.out.println(“Cosultou”);
String sql = “select atendimento,vendedor,data, filial, contato, nomeFanta, razaoSoc, cargo, dpto, ramoAtiv, ende, num, bairro, cidade, compl, cep, uf, clienteSN, numFunc, telContato, fax, email, site, possui, qual, interesseCli, pricCarac, prodFaz, modelo, valorItem,qtd, total, dtRetorno from tbAtendimento order by vendedor”;
System.out.println(“Cosultou 2”);
String driver =“jdbc:odbc:ProjVendas”;
System.out.println(“Cosultou 3”);
try
{
System.out.println(“entrou no try Cosultou”);
Class.forName("com.mysql.jdbc.Driver");
System.out.println("ODBC Cosultou");
Connection conn = DriverManager.getConnection(driver,"","");
System.out.println(" passou no conn Cosultou");
this.st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
System.out.println("Statement Cosultou");
this.rec = this.st.executeQuery(sql);
System.out.println("executou query");
return this.rec;
}
catch (Exception e)
{
return null;
}
}
/**********************************************************/
/*public void conectar()
{
System.out.println("entrou");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection(driver,"","");
System.out.println("conectou");
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"Erro na conexão!","Erro",1);
}
}
*/
public void atualizar()
{
String sql ="select * from tbAtendimento";
try
{
st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rec = st.executeQuery(sql);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,"Erro na atualização!","Erro",1);
}
}
/***************** GERAR MATRICULA *****************
public boolean gerarMat()
{
System.out.println("gerou mat");
int i=0;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
conn = DriverManager.getConnection("jdbc:odbc:ProjVendas","","");
st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rec= st.executeQuery("select matricula from tbAtendimento order by codAt asc");
rec.first();
do
{
i=i+1;
cod=+i;
}while(rec.next());
return true;
}
catch(Exception erro)
{System.out.println("gerou mat ate aki 3");
erro.printStackTrace();
JOptionPane.showMessageDialog(null, "Erro ao gerar matrícula");
return false;
}
}
*************************************************/
/*********************CONSULTAR ESPECIFICA***********************/
public void consultaCampos(String data, String vendedor, String contato)
{
String sql = "select atendimento,vendedor,data, filial, contato, nomeFanta, razaoSoc, cargo, dpto, ramoAtiv, ende, num, bairro, cidade, compl, cep, uf, clienteSN, numFunc, telContato, fax, email, site, possui, qual, interesseCli, pricCarac, prodFaz, modelo, valorItem,qtd, total, dtRetorno from tbAtendimento where vendedor='" + vendedor + "' and contato='" + contato + "' and data='"+ data +"'";
// String driver ="jdbc:odbc:ProjVendas";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(DRIVER,"","");
Statement st = conn.createStatement();
ResultSet rec = st.executeQuery(sql);
rec.next();
vendedor = rec.getString(1);
contato = rec.getString(2);
data = rec.getString(3);
}
catch (Exception e)
{
}
}
/************* Abre conexao *************************************/
public static Connection abreConexao() throws SQLException
{
try
{
System.out.println("Entrou no try");
if (conn == null)
{
System.out.println("Entrou no if");
Class.forName(DRIVER);
System.out.println("passou class for name");
conn = DriverManager.getConnection(URL, USUARIO, PASSWORD);
System.out.println("CONECTOU");
}
return conn;
}
catch (ClassNotFoundException e)
{
throw new SQLException(e.getMessage());
}
}
}
/****************************************************************************/