コード例 #1
0
  public void agregar_clicked(View view) {
    int s = dbHandler.size();
    if (dia.getText().toString().isEmpty()
        || mes.getText().toString().isEmpty()
        || any.getText().toString().isEmpty()
        || hora.getText().toString().isEmpty()
        || minut.getText().toString().isEmpty()) {
      Toast toast =
          Toast.makeText(getApplicationContext(), " Falten omplir camps", Toast.LENGTH_SHORT);
      toast.show();
    } else {
      int sdia = Integer.parseInt(dia.getText().toString());
      int smes = Integer.parseInt(mes.getText().toString());
      int sany = Integer.parseInt(any.getText().toString());
      int shora = Integer.parseInt(hora.getText().toString());
      int sminut = Integer.parseInt(minut.getText().toString());

      if (s >= 15 && c1.isChecked()) {
        Toast toast =
            Toast.makeText(getApplicationContext(), "EL PARKING ESTÀ PLE", Toast.LENGTH_LONG);
        toast.show();
      } else if (sdia <= 0
          || sdia > 31
          || smes <= 0
          || smes > 12
          || sany < 2016
          || shora < 0
          || shora >= 24
          || sminut < 0
          || sminut > 59) {
        errorInput();
      } else if (matricula.getText().toString().length() < 7
          || matricula.getText().toString().length() > 7) {
        errorInput();
      } else {
        if (c1.isChecked()) {
          Coche coche =
              new Coche(
                  matricula.getText().toString(),
                  sdia,
                  smes,
                  sany,
                  shora,
                  sminut,
                  -1,
                  -1,
                  -1,
                  -1,
                  -1);
          dbHandler.addCoche(coche);
          matU = (matricula.getText().toString());
          diaU = sdia;
          mesU = smes;
          anyU = sany;
          horaU = shora;
          minU = sminut;

          TextView size = (TextView) findViewById(R.id.pll_text);
          s = dbHandler.size();
          String s2 = String.valueOf(s);
          size.setText(s2);

          limpiarcampos();

          Toast toast =
              Toast.makeText(getApplicationContext(), "Afegit correctament!", Toast.LENGTH_SHORT);
          toast.show();
        } else if (c2.isChecked()) {

          Cursor cursor = dbHandler.cocheByMat(matricula.getText().toString());
          if (null != cursor && cursor.moveToFirst()) {
            int edia = Integer.parseInt(cursor.getString(cursor.getColumnIndex("dia")));
            int emes = Integer.parseInt(cursor.getString(cursor.getColumnIndex("mes")));
            int eany = Integer.parseInt(cursor.getString(cursor.getColumnIndex("any")));
            int ehora = Integer.parseInt(cursor.getString(cursor.getColumnIndex("hora")));
            int eminut = Integer.parseInt(cursor.getString(cursor.getColumnIndex("minut")));
            if (edia <= sdia
                && emes <= smes
                && eany <= sany
                && ehora <= shora
                && eminut <= sminut) {
              String mat = cursor.getString(cursor.getColumnIndex("matricula"));
              Coche coche =
                  new Coche(mat, edia, emes, eany, ehora, eminut, sdia, smes, sany, shora, sminut);
              dbHandler.borrarCoche(mat);
              dbHandler.addCoche(coche);
              TextView size = (TextView) findViewById(R.id.pll_text);
              s = dbHandler.size();
              String s2 = String.valueOf(s);
              size.setText(s2);
              double pt =
                  preuTiquet(edia, emes, eany, ehora, eminut, sdia, smes, sany, shora, sminut);
              TextView imp = (TextView) findViewById(R.id.importt_text);
              imp.setText(Double.toString(pt));

              Toast toast =
                  Toast.makeText(getApplicationContext(), "Ha sortit", Toast.LENGTH_SHORT);
              toast.show();

              matU = (matricula.getText().toString());
              diaU = sdia;
              mesU = smes;
              anyU = sany;
              horaU = shora;
              minU = sminut;

            } else {
              Toast toast =
                  Toast.makeText(
                      getApplicationContext(),
                      "El dia de sortida ha de ser posterior al d'entrada",
                      Toast.LENGTH_SHORT);
              toast.show();
            }
          } else {
            Toast toast =
                Toast.makeText(
                    getApplicationContext(),
                    "No està el cotxe aquest al parking",
                    Toast.LENGTH_SHORT);
            toast.show();
          }
        }
      }
    }
  }