Advertisement
Guest User

Untitled

a guest
Apr 9th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. @WebService(serviceName = "ServicioWebDetalles")
  2. public class ServicioWebDetalles {
  3.  
  4.  
  5. @WebMethod(operationName = "DetallesArticulo")
  6. public Articulo DetallesArticulo(@WebParam(name = "cod") String cod) {
  7. Articulo art = null;
  8. Conexion con = new Conexion();
  9. Statement stm = null;
  10. ResultSet rs = null;
  11. try {
  12. stm = con.conectar().createStatement();
  13. rs = stm.executeQuery("SELECT * FROM articulos WHERE codigo = '" + cod + "'");
  14. if (rs.next())
  15. art = new Articulo(cod, rs.getString("nombre"), rs.getString("descripcion"), rs.getInt("cantidad"), rs.getDouble("precio"));
  16. }
  17. catch (ClassNotFoundException | SQLException | NullPointerException e){
  18. System.out.println("servicios.ServicioWebDetalles.DetallesArticulo(): " + e.getMessage());
  19. }
  20. return art;
  21. }
  22. }
  23.  
  24. public class Conexion {
  25.  
  26. private Connection con = null;
  27.  
  28. public Connection conectar() throws ClassNotFoundException, SQLException {
  29. try {
  30. Class.forName("com.mysql.jdbc.Driver");
  31. String url = "jdbc:mysql://localhost:3306/muebleriabd";
  32. con = (Connection) DriverManager.getConnection(url, "root", "root");
  33. }
  34. catch(ClassNotFoundException | SQLException e){
  35. System.out.println("BaseDatos.Conexion.conectar(): " + e.getMessage());
  36. }
  37. return con;
  38. }
  39.  
  40. public void cerrarConexion() throws SQLException{
  41. con.close();
  42. }
  43. }
  44.  
  45. public class MainActivity extends AppCompatActivity {
  46.  
  47. private Button btnScan;
  48. private String url = "http://192.168.1.45:8080/WebServiceMP";
  49. private String methodName = "ServicioWebDetalles";
  50. private String nameSpace = "http://servicios/";
  51. private String soapAction = "http://servicios/ServicioWebDetalles";
  52.  
  53. @Override
  54. protected void onCreate(Bundle savedInstanceState) {
  55. super.onCreate(savedInstanceState);
  56. setContentView(R.layout.activity_main);
  57.  
  58. btnScan = (Button) findViewById(R.id.btn_QR);
  59. final Activity activity = this;
  60. btnScan.setOnClickListener(new View.OnClickListener() {
  61. @Override
  62. public void onClick(View view) {
  63. IntentIntegrator integrator = new IntentIntegrator(activity);
  64. integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
  65. integrator.setPrompt("Scan");
  66. integrator.setCameraId(0);
  67. integrator.setBeepEnabled(false);
  68. integrator.setBarcodeImageEnabled(false);
  69. integrator.initiateScan();
  70. }
  71. });
  72. }
  73.  
  74. @Override
  75. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  76. IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
  77. if (result != null){
  78. if (result.getContents() == null){
  79. Toast.makeText(this, "Cancelado", Toast.LENGTH_LONG).show();
  80. }
  81. else {
  82. // Manejo el resultado del scaneo con result
  83. String cod = result.getContents();
  84.  
  85. SoapObject request = new SoapObject(nameSpace, methodName);
  86. request.addProperty("codigo", cod);
  87. SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
  88. envelope.setOutputSoapObject(request);
  89. HttpTransportSE transporte = new HttpTransportSE(url);
  90. try {
  91. transporte.call(soapAction, envelope);
  92. SoapObject resultado = (SoapObject) envelope.getResponse();
  93. Toast.makeText(this, "Llego", Toast.LENGTH_LONG).show();
  94. } catch (HttpResponseException e) {
  95. Log.d("CREATION", e.getMessage());
  96. } catch (XmlPullParserException e) {
  97. e.printStackTrace();
  98. } catch (IOException e) {
  99. e.printStackTrace();
  100. }
  101. }
  102. }
  103. else {
  104. super.onActivityResult(requestCode, resultCode, data);
  105. }
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement