public void saveInspection() {
    String exception = "";
    if (edtException.getText().toString().length() > 0) {
      exception = edtException.getText().toString();
    }
    if (exception.length() > 200) {
      Toast.makeText(
              getApplicationContext(),
              "Exception must be less then 200 character.",
              Toast.LENGTH_LONG)
          .show();
      return;
    }
    String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
    inspection.deleteRelatedPestsRecords();
    if (isCleanInspection) {
      m_inspectionPests = new ArrayList<InspectionPest>();
      inspection.evidence = "";
    }

    inspection.trap_number = trapscan_info.number;
    inspection.trap_type_id = trapscan_info.trap_type_id;
    int bait = 0, trap = 0;
    if (!spnBaitCondition.getSelectedItem().toString().equalsIgnoreCase("Bait Conditions")) {
      bait = BaitConditionsInfo.getIdByName(spnBaitCondition.getSelectedItem().toString());
    }
    if (!spnTrapCondition.getSelectedItem().toString().equalsIgnoreCase("Trap Conditions")) {
      trap = TrapConditionsInfo.getIdByName(spnTrapCondition.getSelectedItem().toString());
    }
    inspection.bait_condition_id = bait;
    inspection.trap_condition_id = trap;
    currentDateTimeString =
        Utils.Instance()
            .getFormatedDate(
                currentDateTimeString, "MMM dd, yyyy hh:mm:ss a", "yyyy-MM-dd hh:mm a");
    inspection.exception = exception;
    inspection.removed = isRemoved;
    inspection.scanned_on = currentDateTimeString;
    try {
      inspection.save();
    } catch (ActiveRecordException e) {
      e.printStackTrace();
    }

    AddTraps(m_inspectionPests, inspection);
    // if (m_list.size() == 1) {
    // if (m_list.get(0).count == 0 && m_list.get(0).pest_type_id == 0) {
    // m_list = new ArrayList<InspectionPest>();
    // AddTraps(m_list, inspection);
    // } else {
    // AddTraps(m_list, inspection);
    // }
    // } else {
    // }
  }
  public static AttachmentsInfo getPdfFormsByfilename1(String name) {
    try {
      //			List<AttachmentsInfo> lst = FieldworkApplication.Connection().find(
      //					AttachmentsInfo.class,
      //					CamelNotationHelper
      //							.toSQLName("attached_pdf_form_file_name") + "=?",
      //					new String[] { name });
      //			if (lst != null && lst.size() > 0) {
      //				return lst.get(0);
      //			}

      List<AttachmentsInfo> lst = FieldworkApplication.Connection().findAll(AttachmentsInfo.class);
      if (lst != null && lst.size() > 0) {
        for (AttachmentsInfo a : lst) {
          if (a.attached_pdf_form_file_name.equalsIgnoreCase(name)) {
            return a;
          }
        }
      }

    } catch (ActiveRecordException e) {
      e.printStackTrace();
    }
    return null;
  }
Example #3
0
 public static String getValueByName(String name) {
   String value = "";
   try {
     List<StatusInfo> lst = FieldworkApplication.Connection().findAll(StatusInfo.class);
     for (StatusInfo s : lst) {
       if (s.statusName.equalsIgnoreCase(name)) {
         value = s.statusValue;
       }
     }
   } catch (ActiveRecordException e) {
     e.printStackTrace();
   }
   return value;
 }
  public static AttachmentsInfo getPdfFormsByID(int attach_id) {
    try {
      List<AttachmentsInfo> lst = FieldworkApplication.Connection().findAll(AttachmentsInfo.class);
      if (lst != null && lst.size() > 0) {
        for (AttachmentsInfo a : lst) {
          if (a.id == attach_id) {
            return a;
          }
        }
      }

    } catch (ActiveRecordException e) {
      e.printStackTrace();
    }
    return null;
  }
  public static AttachmentsInfo getPdfFormsByfilename(String name) {
    try {
      List<AttachmentsInfo> lst =
          FieldworkApplication.Connection()
              .find(
                  AttachmentsInfo.class,
                  CamelNotationHelper.toSQLName("attached_pdf_form_file_name") + "=?",
                  new String[] {name});
      if (lst != null && lst.size() > 0) {
        return lst.get(0);
      }

    } catch (ActiveRecordException e) {
      e.printStackTrace();
    }
    return null;
  }
  public static ArrayList<AttachmentsInfo> getPdfFormsByWorkerId(int w_id) {

    ArrayList<AttachmentsInfo> m_list = new ArrayList<AttachmentsInfo>();

    try {
      List<AttachmentsInfo> lst =
          FieldworkApplication.Connection()
              .find(
                  AttachmentsInfo.class,
                  CamelNotationHelper.toSQLName("WorkOrderId") + "=?",
                  new String[] {String.valueOf(w_id)});
      if (lst != null && lst.size() > 0) {
        m_list = new ArrayList<AttachmentsInfo>(lst);
      }

    } catch (ActiveRecordException e) {
      e.printStackTrace();
    }
    return m_list;
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.trap_details);
    // info = MainActivity.appointmentInfo;
    Bundle b = getIntent().getExtras();
    if (b != null) {
      appointment_id = b.getInt(Const.Appointment_Id);
      cust_id = b.getInt("CUST_ID");
      barcode = b.getString("BARCODE");
      if (b.containsKey("isFromUnChecked")) {
        isFromUnChecked = b.getBoolean("isFromUnChecked");
      }
    }
    if (appointment_id == 0) {
      appointment_id = Const.app_id;
    }
    if (cust_id == 0) {
      cust_id = Const.customer_id;
    }
    if (barcode.length() == 0) {
      barcode = Const.BarCode;
    }
    action = getSupportActionBar();
    // action.setTitle("Traps Scan Details");
    action.setTitle(
        Html.fromHtml(
            "<font color='"
                + getString(R.string.header_text_color)
                + "'>Traps Scan Details</font>"));
    action.setHomeButtonEnabled(true);
    action.setDisplayHomeAsUpEnabled(true);

    lstMaterial = (ListView) findViewById(R.id.lstMaterialUsages);
    btnSaveTrapData = (Button) findViewById(R.id.btnSaveTrapData);
    btnClean = (Button) findViewById(R.id.btnClean);
    rlEvidence = (RelativeLayout) findViewById(R.id.rlEvidence);
    rlCaptured = (RelativeLayout) findViewById(R.id.rlCaptured);
    llContainer = (LinearLayout) findViewById(R.id.llContainer);
    rlMaterial = (RelativeLayout) findViewById(R.id.rlMaterialUsage);
    txtBarcode = (TextView) findViewById(R.id.txtBarcode);
    txtLocation = (TextView) findViewById(R.id.txtLocation);
    txtBuilding = (TextView) findViewById(R.id.txtBuilding);
    txtFloor = (TextView) findViewById(R.id.txtFloor);
    txtTrapType = (TextView) findViewById(R.id.txtTrapType);
    txtTrapNumber = (TextView) findViewById(R.id.txtNumber);
    txtMessage = (TextView) findViewById(R.id.txtMessage);
    imgClean = (ImageView) findViewById(R.id.imgClean);
    tgbRemoved = (ToggleButton) findViewById(R.id.tgbremoved);
    spnBaitCondition = (Spinner) findViewById(R.id.spnbait_condition_id);
    spnTrapCondition = (Spinner) findViewById(R.id.spntrap_condition_id);
    edtException = (EditText) findViewById(R.id.edtexception);
    txtExceptionCount = (TextView) findViewById(R.id.txtCount);
    btnSaveTrapData.setOnClickListener(this);
    btnClean.setOnClickListener(this);
    rlCaptured.setOnClickListener(this);
    rlEvidence.setOnClickListener(this);
    rlMaterial.setOnClickListener(this);
    trapscan_info = TrapList.Instance().getTrapByBarcodeNdCustomerId(barcode, cust_id);
    inspection = InspectionList.Instance().getInspectionByApp_Id(appointment_id, barcode);
    if (inspection == null) {
      isEdit = false;
      try {
        inspection = FieldworkApplication.Connection().newEntity(InspectionInfo.class);
        inspection.id = -1;
        inspection.barcode = barcode;
        inspection.save();
      } catch (ActiveRecordException e) {
        e.printStackTrace();
      }
    } else {
      isEdit = true;
      m_inspectionPests =
          InspectionPestsList.Instance().getInspectionPestByInspectionId(inspection.id);
      isClean = getIsClean(inspection, m_inspectionPests);
      isCleanInspection = getIsClean(inspection, m_inspectionPests);
      if (isClean) {
        imgClean.setVisibility(View.VISIBLE);
      }
    }
    LoadValues();
    LoadSpinners();
    if (isEdit) {
      loadMaterial();
    }
    tgbRemoved.setOnCheckedChangeListener(
        new OnCheckedChangeListener() {

          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            isRemoved = isChecked;
          }
        });
  };