From e37019dd417b803b498e1c1dae7e325daa867794 Mon Sep 17 00:00:00 2001 From: IvanaE Date: Wed, 7 Nov 2018 14:16:54 -0500 Subject: [PATCH] added service exists verification --- .../olympusservices/NewServiceDialogFragment.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/NewServiceDialogFragment.java b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/NewServiceDialogFragment.java index 3e2e5df..88fe37f 100644 --- a/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/NewServiceDialogFragment.java +++ b/OlympusServices/app/src/main/java/com/uottawa/olympus/olympusservices/NewServiceDialogFragment.java @@ -64,7 +64,8 @@ public class NewServiceDialogFragment extends DialogFragment { EditText nameInput = (EditText) ((AlertDialog) dialog).findViewById(R.id.NameInput); EditText rateInput = (EditText) ((AlertDialog) dialog).findViewById(R.id.RateInput); String name = nameInput.getText().toString(); - if (rateInput.getText().toString().length()>0 && name.length()>0 && name.matches("[a-zA-Z]*")){ + DBHelper dbHelper = new DBHelper(getContext()); + if (rateInput.getText().toString().length()>0 && name.length()>0 && name.matches("[a-zA-Z]*")&& dbHelper.findService(name)==null){ Double rate = Double.parseDouble(rateInput.getText().toString()); Bundle args = new Bundle(); args.putString("name", name); @@ -72,9 +73,11 @@ public class NewServiceDialogFragment extends DialogFragment { NewServiceDialogFragment.this.setArguments(args); mListener.onDialogNew(NewServiceDialogFragment.this); } - else{ + else if(!(rateInput.getText().toString().length()>0) || !(name.length()>0)|| !name.matches("[a-zA-Z]*")){ Toast.makeText(getContext(), "Service must have an alphanumeric name and a rate", Toast.LENGTH_LONG).show(); - + } + else{ + Toast.makeText(getContext(), "Service already exists", Toast.LENGTH_LONG).show(); } } })