コード例 #1
0
        @Override
        public void onClick(View v) {

          Vehicle vehicleDTO = new Vehicle();

          if (TextUtils.isEmpty(editText_closing_kms.getText())) {
            Toast.makeText(getActivity(), "Please enter closing Kms.", Toast.LENGTH_SHORT).show();
            return;
          }
          if (TextUtils.isEmpty(editText_closing_engine_hrs.getText())) {
            Toast.makeText(getActivity(), "Please enter closing engine Hrs.", Toast.LENGTH_SHORT)
                .show();
            return;
          }
          if (TextUtils.isEmpty(editText_fow_hrs.getText())) {
            Toast.makeText(getActivity(), "Please enter forward engine Hrs.", Toast.LENGTH_SHORT)
                .show();
            return;
          }
          if (TextUtils.isEmpty(editText_rev_hrs.getText())) {
            Toast.makeText(getActivity(), "Please enter reverse engine Hrs.", Toast.LENGTH_SHORT)
                .show();
            return;
          }
          if (TextUtils.isEmpty(editText_in_time_date.getText())) {
            Toast.makeText(
                    getActivity(), "Please choose Vehicle In date and time", Toast.LENGTH_SHORT)
                .show();
            return;
          }

          // Take All the strings coming from EditText
          String show_creationDate_text = textView_show_creationDate.getText().toString();

          // String show_creationQuantity_text =
          // textView_show_totalQuantity.getText().toString();

          String dc_no_editText = editText_dc_no.getText().toString();
          String qty_editText = editText_qty.getText().toString();
          String man_pump_editText = editText_man_pump.getText().toString();
          String issued_diesel_editText = editText_diesel_issued.getText().toString();
          String openKms_editText = editText_openkms.getText().toString();
          String startEngineHrs_editText = editText_start_engine_hrs.getText().toString();
          String out_date_time_editText = editText_out_time_date.getText().toString();
          String closingKms_editText = editText_closing_kms.getText().toString();
          String in_date_time_editText = editText_in_time_date.getText().toString();
          String closingEngineHrs_editText = editText_closing_engine_hrs.getText().toString();
          String fow_hrs_editText = editText_fow_hrs.getText().toString();
          String rev_hrs_editText = editText_rev_hrs.getText().toString();

          // Set all the strings in DTO
          vehicleDTO.setVehicleRegistration_rowId(
              vehicle_data_from_context_menu.getVehicleRegistration_rowId());
          vehicleDTO.setDate_for_entered_data(show_creationDate_text);
          // vehicleDTO.setQuantity_for_entered_data(qty_editText);

          vehicleDTO.setDc_no(dc_no_editText);
          vehicleDTO.setQuantity(qty_editText);
          vehicleDTO.setMan_pump(man_pump_editText);
          vehicleDTO.setDiesel_issued(issued_diesel_editText);
          vehicleDTO.setOpen_kms(openKms_editText);
          vehicleDTO.setStart_engine_hrs(startEngineHrs_editText);
          vehicleDTO.setOut_date_time(out_date_time_editText);
          vehicleDTO.setClosing_kms(closingKms_editText);
          vehicleDTO.setClosing_engine_hrs(closingEngineHrs_editText);
          vehicleDTO.setFow_hrs(fow_hrs_editText);
          vehicleDTO.setRev_hrs(rev_hrs_editText);
          vehicleDTO.setIn_date_time(in_date_time_editText);

          // get data from Quantity edit text into text view

          DatabaseOperation_Vehicle databaseOperation =
              DatabaseOperation_Vehicle.getInstance(getActivity());
          if (!flag_checkOut_AlreadyDone && !flag_checkIn_AlreadyDone) {
            // Call the insert API from DatabaseOperation_Vehicle class
            flag_vehicle_management = databaseOperation.createVehicleManagement(vehicleDTO);

            if (flag_vehicle_management) {
              vehicleDTO.setVehicle_no(vehicle_data_from_context_menu.getVehicle_no());
              vehicleDTO.setPlant(vehicle_data_from_context_menu.getPlant());
              vehicleDTO.setTransporter_name(vehicle_data_from_context_menu.getTransporter_name());
              vehicleDTO.setVehicleState("In");
              databaseOperation.updateVehicleRegistration(vehicleDTO);

              Toast.makeText(getActivity(), "CheckIn is processed..", Toast.LENGTH_SHORT).show();
              Fragment detail = new VehicleListingFragment();
              FragmentManager fragmentManager = getFragmentManager();
              fragmentManager.beginTransaction().replace(R.id.content_frame, detail).commit();
            }
          } else {
            // Call the update API from DatabaseOperation_Vehicle class
            int update_result = databaseOperation.updateVehicleManagement(vehicleDTO);
            if (!flag_checkIn_AlreadyDone) {
              if (update_result == 1) {
                vehicleDTO.setVehicle_no(vehicle_data_from_context_menu.getVehicle_no());
                vehicleDTO.setPlant(vehicle_data_from_context_menu.getPlant());
                vehicleDTO.setTransporter_name(
                    vehicle_data_from_context_menu.getTransporter_name());
                vehicleDTO.setVehicleState("In");
                databaseOperation.updateVehicleRegistration(vehicleDTO);

                Toast.makeText(getActivity(), "CheckIn is processed..", Toast.LENGTH_SHORT).show();
                Fragment detail = new VehicleListingFragment();
                FragmentManager fragmentManager = getFragmentManager();
                fragmentManager.beginTransaction().replace(R.id.content_frame, detail).commit();
              }
            } else {
              Toast.makeText(getActivity(), "CheckIn is already done..", Toast.LENGTH_SHORT).show();
            }
          }
        }
コード例 #2
0
        @Override
        public void onClick(View v) {

          Vehicle vehicleDTO = new Vehicle();

          if (TextUtils.isEmpty(editText_dc_no.getText())) {
            Toast.makeText(getActivity(), "Please enter DC No.", Toast.LENGTH_SHORT).show();
            return;
          }
          if (TextUtils.isEmpty(editText_qty.getText())) {
            Toast.makeText(getActivity(), "Please enter Quantity", Toast.LENGTH_SHORT).show();
            return;
          }
          if (TextUtils.isEmpty(editText_man_pump.getText())) {
            Toast.makeText(getActivity(), "Please enter Man/Pump", Toast.LENGTH_SHORT).show();
            return;
          }
          if (TextUtils.isEmpty(editText_diesel_issued.getText())) {
            Toast.makeText(getActivity(), "Please enter issued Diesel", Toast.LENGTH_SHORT).show();
            return;
          }
          if (TextUtils.isEmpty(editText_openkms.getText())) {
            Toast.makeText(getActivity(), "Please enter opening Kms.", Toast.LENGTH_SHORT).show();
            return;
          }
          if (TextUtils.isEmpty(editText_start_engine_hrs.getText())) {
            Toast.makeText(getActivity(), "Please enter starting engine Hrs.", Toast.LENGTH_SHORT)
                .show();
            return;
          }
          if (TextUtils.isEmpty(editText_out_time_date.getText())) {
            Toast.makeText(
                    getActivity(), "Please choose Vehicle Out date and time", Toast.LENGTH_SHORT)
                .show();
            return;
          }

          // Take All the strings coming from EditText
          String show_creationDate_text = textView_show_creationDate.getText().toString();
          // String show_totalQuantity_text =
          // textView_show_totalQuantity.getText().toString();

          String dc_no_editText = editText_dc_no.getText().toString();
          String qty_editText = editText_qty.getText().toString();
          String man_pump_editText = editText_man_pump.getText().toString();
          String issued_diesel_editText = editText_diesel_issued.getText().toString();
          String openKms_editText = editText_openkms.getText().toString();
          String startEngineHrs_editText = editText_start_engine_hrs.getText().toString();
          String out_date_time_editText = editText_out_time_date.getText().toString();
          String closingKms_editText = editText_closing_kms.getText().toString();
          String in_date_time_editText = editText_in_time_date.getText().toString();
          String closingEngineHrs_editText = editText_closing_engine_hrs.getText().toString();
          String fow_hrs_editText = editText_fow_hrs.getText().toString();
          String rev_hrs_editText = editText_rev_hrs.getText().toString();

          // Set all the strings in DTO
          vehicleDTO.setVehicleRegistration_rowId(
              vehicle_data_from_context_menu.getVehicleRegistration_rowId());
          vehicleDTO.setDate_for_entered_data(show_creationDate_text);
          // vehicleDTO.setQuantity_for_entered_data(qty_editText);

          vehicleDTO.setDc_no(dc_no_editText);
          vehicleDTO.setQuantity(qty_editText);
          vehicleDTO.setMan_pump(man_pump_editText);
          vehicleDTO.setDiesel_issued(issued_diesel_editText);
          vehicleDTO.setOpen_kms(openKms_editText);
          vehicleDTO.setStart_engine_hrs(startEngineHrs_editText);
          vehicleDTO.setOut_date_time(out_date_time_editText);
          vehicleDTO.setClosing_kms(closingKms_editText);
          vehicleDTO.setClosing_engine_hrs(closingEngineHrs_editText);
          vehicleDTO.setFow_hrs(fow_hrs_editText);
          vehicleDTO.setRev_hrs(rev_hrs_editText);
          vehicleDTO.setIn_date_time(in_date_time_editText);

          // saveM1(editText_qty.getText().toString());

          PreferenceOperation preferenceOperation = PreferenceOperation.getInstance(getActivity());
          if (!TextUtils.isEmpty(qty_editText)) {
            String lastTotalQuantity = preferenceOperation.getTotalQuantity();
            DateFormat df = new SimpleDateFormat("dd/MM/yy");
            Calendar calobj = Calendar.getInstance();
            String currentDate = df.format(calobj.getTime());
            if (TextUtils.isEmpty(lastTotalQuantity)) {
              preferenceOperation.putTotalQuantity(qty_editText);
              preferenceOperation.putLastUpdatedQuantityDate(currentDate);
            } else {
              Double double1 = Double.parseDouble(lastTotalQuantity);
              Double double2 = Double.parseDouble(qty_editText);
              if (currentDate.equals(preferenceOperation.getLastUpdatedQuantityDate())) {
                Double resultantQuantity = double1 + double2;
                preferenceOperation.putTotalQuantity(resultantQuantity.toString());
              } else {
                preferenceOperation.putTotalQuantity(double2.toString());
              }
              preferenceOperation.putLastUpdatedQuantityDate(currentDate);
            }
          }

          DatabaseOperation_Vehicle databaseOperation =
              DatabaseOperation_Vehicle.getInstance(getActivity());
          if (!flag_checkOut_AlreadyDone && !flag_checkIn_AlreadyDone) {
            // Call the insert API from DatabaseOperation_Vehicle class
            flag_vehicle_management = databaseOperation.createVehicleManagement(vehicleDTO);

            if (flag_vehicle_management) {
              vehicleDTO.setVehicle_no(vehicle_data_from_context_menu.getVehicle_no());
              vehicleDTO.setPlant(vehicle_data_from_context_menu.getPlant());
              vehicleDTO.setTransporter_name(vehicle_data_from_context_menu.getTransporter_name());
              vehicleDTO.setVehicleState("Out");
              databaseOperation.updateVehicleRegistration(vehicleDTO);

              Toast.makeText(getActivity(), "CheckOut is processed..", Toast.LENGTH_SHORT).show();
              Fragment detail = new VehicleListingFragment();
              FragmentManager fragmentManager = getFragmentManager();
              fragmentManager.beginTransaction().replace(R.id.content_frame, detail).commit();
            }
          } else {
            // Call the insert API from DatabaseOperation_Vehicle class
            int update_result = databaseOperation.updateVehicleManagement(vehicleDTO);
            if (!flag_checkOut_AlreadyDone) {
              if (update_result == 1) {
                vehicleDTO.setVehicle_no(vehicle_data_from_context_menu.getVehicle_no());
                vehicleDTO.setPlant(vehicle_data_from_context_menu.getPlant());
                vehicleDTO.setTransporter_name(
                    vehicle_data_from_context_menu.getTransporter_name());
                vehicleDTO.setVehicleState("Out");
                databaseOperation.updateVehicleRegistration(vehicleDTO);

                Toast.makeText(getActivity(), "CheckOut is processed..", Toast.LENGTH_SHORT).show();
                Fragment detail = new VehicleListingFragment();
                FragmentManager fragmentManager = getFragmentManager();
                fragmentManager.beginTransaction().replace(R.id.content_frame, detail).commit();
              }

            } else {
              Toast.makeText(getActivity(), "CheckOut is already done..", Toast.LENGTH_SHORT)
                  .show();
            }
          }
        }