Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @WebService(serviceName = "ServicioWebDetalles")
- public class ServicioWebDetalles {
- @WebMethod(operationName = "DetallesArticulo")
- public Articulo DetallesArticulo(@WebParam(name = "cod") String cod) {
- Articulo art = null;
- Conexion con = new Conexion();
- Statement stm = null;
- ResultSet rs = null;
- try {
- stm = con.conectar().createStatement();
- rs = stm.executeQuery("SELECT * FROM articulos WHERE codigo = '" + cod + "'");
- if (rs.next())
- art = new Articulo(cod, rs.getString("nombre"), rs.getString("descripcion"), rs.getInt("cantidad"), rs.getDouble("precio"));
- }
- catch (ClassNotFoundException | SQLException | NullPointerException e){
- System.out.println("servicios.ServicioWebDetalles.DetallesArticulo(): " + e.getMessage());
- }
- return art;
- }
- }
- public class Conexion {
- private Connection con = null;
- public Connection conectar() throws ClassNotFoundException, SQLException {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- String url = "jdbc:mysql://localhost:3306/muebleriabd";
- con = (Connection) DriverManager.getConnection(url, "root", "root");
- }
- catch(ClassNotFoundException | SQLException e){
- System.out.println("BaseDatos.Conexion.conectar(): " + e.getMessage());
- }
- return con;
- }
- public void cerrarConexion() throws SQLException{
- con.close();
- }
- }
- public class MainActivity extends AppCompatActivity {
- private Button btnScan;
- private String url = "http://192.168.1.45:8080/WebServiceMP";
- private String methodName = "ServicioWebDetalles";
- private String nameSpace = "http://servicios/";
- private String soapAction = "http://servicios/ServicioWebDetalles";
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- btnScan = (Button) findViewById(R.id.btn_QR);
- final Activity activity = this;
- btnScan.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- IntentIntegrator integrator = new IntentIntegrator(activity);
- integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
- integrator.setPrompt("Scan");
- integrator.setCameraId(0);
- integrator.setBeepEnabled(false);
- integrator.setBarcodeImageEnabled(false);
- integrator.initiateScan();
- }
- });
- }
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
- if (result != null){
- if (result.getContents() == null){
- Toast.makeText(this, "Cancelado", Toast.LENGTH_LONG).show();
- }
- else {
- // Manejo el resultado del scaneo con result
- String cod = result.getContents();
- SoapObject request = new SoapObject(nameSpace, methodName);
- request.addProperty("codigo", cod);
- SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
- envelope.setOutputSoapObject(request);
- HttpTransportSE transporte = new HttpTransportSE(url);
- try {
- transporte.call(soapAction, envelope);
- SoapObject resultado = (SoapObject) envelope.getResponse();
- Toast.makeText(this, "Llego", Toast.LENGTH_LONG).show();
- } catch (HttpResponseException e) {
- Log.d("CREATION", e.getMessage());
- } catch (XmlPullParserException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- else {
- super.onActivityResult(requestCode, resultCode, data);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement