Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package programa_oficial;
- import com.mchange.v2.c3p0.ComboPooledDataSource;
- import java.beans.PropertyVetoException;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.Properties;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /**
- *
- * @author Luis Felipe
- */
- public class DataSource {
- static Connection con;
- private static PreparedStatement pstmt;
- private static Statement stmt;
- public static ResultSet rs;
- private static final String DRIVER = "com.mysql.jdbc.Driver";
- private static final String URL = "jdbc:mysql://sistema-fiado.mysql.uhserver.com/sistema_fiado";
- private static final String user = "arthurdm01";
- private static final String pass = "Passwd.5";
- private static DataSource dataSource;
- private static ComboPooledDataSource cpds;
- static{
- try{
- cpds.setDriverClass(DRIVER);
- cpds.setJdbcUrl(URL);
- cpds.setUser(user);
- cpds.setPassword(pass);
- cpds.setMinPoolSize(100);
- cpds.setMaxPoolSize(1000);
- cpds.setAcquireIncrement(5);
- cpds.setMaxStatements(180);
- } catch (PropertyVetoException ex) {
- Logger.getLogger(DataSource.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- public static DataSource getInstance()
- throws IOException,SQLException,PropertyVetoException{
- if(dataSource == null){
- dataSource = new DataSource();
- return dataSource;
- }else{
- return dataSource;
- }
- }
- public static Connection getConnection() throws SQLException{
- return cpds.getConnection();
- }
- }
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package programa_oficial;
- import Interface.Movimentacao;
- import Interface.Vender_produto;
- import com.mchange.v2.c3p0.ComboPooledDataSource;
- import java.beans.PropertyVetoException;
- import java.io.IOException;
- import java.sql.Connection;
- import java.sql.Date;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JOptionPane;
- import static programa_oficial.Banco.con;
- /**
- *
- * @author Luis Felipe
- */
- public class Controle {
- Banco conex = new Banco();
- public void salvar_Cliente(Cliente cc) throws IOException, PropertyVetoException {
- try {
- PreparedStatement pst = con.prepareStatement("insert into cliente (cpf,email,endereco,id_usuario,nome,telefone) values (?,?,?,?,?,?)");
- pst.setString(1, cc.getCpf());
- pst.setString(2, cc.getEmail());
- pst.setString(3, cc.getEndereco());
- pst.setInt(4, cc.getId_usuario());
- pst.setString(5, cc.getNome());
- pst.setString(6, cc.getTelefone());
- pst.execute();
- JOptionPane.showMessageDialog(null, "Cadastro Realizado");
- } catch (SQLException ex) {
- Logger.getLogger(Controle.class.getName()).log(Level.SEVERE, null, ex);
- JOptionPane.showMessageDialog(null, ex);
- }
- }
- public void salvar_Usuario(Usuario usu) {
- try {
- conex.conectar();
- PreparedStatement pst = conex.con.prepareStatement("insert into usuario (nome,cnpj,email,telefone) values (?,?,?,?)");
- pst.setString(1, usu.getNome());
- pst.setString(2, usu.getCnpj());
- pst.setString(3, usu.getEmail());
- pst.setString(4, usu.getTelefone());
- pst.execute();
- JOptionPane.showMessageDialog(null, "Cadastro Realizado");
- } catch (SQLException ex) {
- Logger.getLogger(Controle.class.getName()).log(Level.SEVERE, null, ex);
- JOptionPane.showMessageDialog(null, ex);
- }
- }
- public void salvar_Funcionario(Funcionario FF) {
- try {
- conex.conectar();
- PreparedStatement pst = conex.con.prepareStatement("insert into funcionario (nome,login,senha) values (?,?,?)");
- pst.setString(1, FF.getNome());
- pst.setString(2, FF.getLogin());
- pst.setString(3, FF.getSenha());
- pst.execute();
- JOptionPane.showMessageDialog(null, "Cadastro Realizado");
- } catch (SQLException ex) {
- Logger.getLogger(Controle.class.getName()).log(Level.SEVERE, null, ex);
- JOptionPane.showMessageDialog(null, ex);
- }
- }
- public void Editar_Clientee(Editar cliente) {
- try {
- conex.conectar();
- PreparedStatement pst = conex.con.prepareStatement("update cliente set nome=?,cpf=?,endereco=?,telefone=? where id ="+ cliente.getId());
- pst.setString(1, cliente.getNome());
- pst.setString(2, cliente.getCpf());
- pst.setString(3, cliente.getEndereco());
- pst.setString(4, cliente.getTelefone());
- // pst.setInt(5, cliente.getId_usuario());
- pst.execute();
- JOptionPane.showMessageDialog(null, "Alteração concluida");
- } catch (SQLException ex) {
- Logger.getLogger(Controle.class.getName()).log(Level.SEVERE, null, ex);
- JOptionPane.showMessageDialog(null, ex);
- }
- }
- public void Deletar_Cliente(Cliente cliente) {
- try {
- conex.conectar();
- PreparedStatement pst = conex.con.prepareStatement("delete from cliente where id ="+ cliente.getId());
- // pst.setInt(5, cliente.getId_usuario());
- pst.execute();
- JOptionPane.showMessageDialog(null, "Cliente excluido");
- } catch (SQLException ex) {
- Logger.getLogger(Controle.class.getName()).log(Level.SEVERE, null, ex);
- JOptionPane.showMessageDialog(null, ex);
- }
- }
- public void Vender_Produto(Venda vender) throws SQLException{
- conex.conectar();
- PreparedStatement pst = conex.con.prepareStatement("insert into venda (data,descricao,em_aberto,id_cliente,id_vendedor,parcelas,total_recebido,valor) values (?,?,?,?,?,?,?,?)");
- java.sql.Date datasql = new java.sql.Date(vender.getData().getTime());
- SimpleDateFormat formata = new SimpleDateFormat("dd/MM/yyyy");
- pst.setDate(1, (Date) datasql);
- pst.setString(2, vender.getDescricao());
- pst.setBoolean(3, vender.isEm_aberto());
- pst.setInt(4, vender.getId_cliente());
- pst.setInt(5, vender.getId_funcionario());
- pst.setFloat(6, vender.getParcelas());
- pst.setFloat(7, vender.getEntrada());
- pst.setFloat(8, vender.getValor());
- pst.execute();
- JOptionPane.showMessageDialog(null, "Venda realizada");
- }
- public void Cadastrar_Funcionario(Funcionario funcionario) throws SQLException{
- Banco.conectar();
- PreparedStatement pst = conex.con.prepareStatement("insert into funcionario (id_usuario,login,nome,senha) values (?,?,?,?)");
- pst.setInt(1,funcionario.getId_usuario() );
- pst.setString(2, funcionario.getLogin());
- pst.setString(3, funcionario.getNome());
- pst.setString(4, funcionario.getSenha());
- pst.execute();
- JOptionPane.showConfirmDialog(null, "Funcionario Cadastrado");
- Banco.desconectar();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement