Sunday 30 October 2011

RegistrationActivity.java for registration which uses file validate.java


package com.OfficeDepot;

import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class RegistrationActivity extends Activity {

EditText password, firstname, lastname, email, phone, confirm_password;
int[] flag;

private Button finish;

// Back Button

private Button back;
private TextView top_text;
AlertDialog alertDialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.registration);

top_text = (TextView) findViewById(R.id.top_text);
top_text.setText("Registration");

back = (Button) findViewById(R.id.back);

confirm_password = (EditText) findViewById(R.id.edit_confirmpassword);
password = (EditText) findViewById(R.id.edit_password);
firstname = (EditText) findViewById(R.id.edit_firstname);
lastname = (EditText) findViewById(R.id.edit_lastname);
email = (EditText) findViewById(R.id.edit_email);
phone = (EditText) findViewById(R.id.edit_phone);

finish = (Button) findViewById(R.id.send);

flag = new int[6];
for (int i = 0; i < 6; i++) {
flag[i] = 0;
}
alertDialog = new AlertDialog.Builder(
RegistrationActivity.this).create();
alertDialog.setTitle("");

finish.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

if (Validate.Check_Lengh(firstname)) {

alertDialog.setMessage("Enter FirstName.");
alertDialog.setButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {

// here you can add functions

}
});
alertDialog.show();
} else {
flag[0] = 1;
if (Validate.Check_Lengh(lastname)) {

alertDialog.setMessage("Enter LastName.");
alertDialog.setButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {

// here you can add
// functions

}
});
alertDialog.show();
} else {
flag[1] = 1;
if (Validate.Check_Lengh(email)) {

alertDialog.setMessage("Enter Email.");
alertDialog.setButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int which) {

// here you can
// add functions

}
});
alertDialog.show();
} else {
if (Validate.checkEmail(email) == false) {
alertDialog.setMessage("Enter Valid Email.");
alertDialog.setButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int which) {

// here
// you
// can
// add
// functions

}
});
alertDialog.show();

} else {
Log.v("log_tag", "Else not proper");
flag[2] = 1;
if (Validate.Check_Lengh(phone)) {

alertDialog.setMessage("Enter Phone.");
alertDialog
.setButton(
"OK",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int which) {

// here
// you
// can
// add
// functions

}
});
alertDialog.show();
} else {
if (phone.getText().toString().length() != 10) {

alertDialog
.setMessage("Enter Valid Phone.");
alertDialog
.setButton(
"OK",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int which) {

// here
// you
// can
// add
// functions

}
});
alertDialog.show();
} else {

if (phone.getText().toString()
.contains("-")
|| phone.getText().toString()
.contains("+")
|| phone.getText().toString()
.contains("*")
|| phone.getText().toString()
.contains("#")
|| phone.getText().toString()
.contains("/")) {

alertDialog
.setMessage("Enter Valid Phone.");
alertDialog
.setButton(
"OK",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int which) {

// here
// you
// can
// add
// functions

}
});
alertDialog.show();
} else {
flag[3] = 1;
if (Validate.Check_Lengh(password)) {

//
alertDialog
.setMessage("Enter Password");
alertDialog
.setButton(
"OK",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int which) {

}
});
alertDialog.show();

}

else {

if (password.getText()
.toString().length() < 6) {
alertDialog
.setMessage("Password must be 6 characters long");
alertDialog
.setButton(
"OK",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int which) {

// here
// you
// can
// add
// functions

}
});
alertDialog.show();

}

else {
flag[4] = 1;
if (Validate
.Check_Lengh(confirm_password)) {

alertDialog
.setMessage("Enter Password again to confirm");
alertDialog
.setButton(
"OK",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int which) {

}
});
alertDialog.show();

} else {

if (confirm_password
.getText()
.toString()
.length() < 6) {
alertDialog
.setMessage("Password must be 6 characters long");
alertDialog
.setButton(
"OK",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int which) {

// here
// you
// can
// add
// functions

}
});
alertDialog.show();
} else if (!(confirm_password
.getText()
.toString()
.equals(password
.getText()
.toString()))) {
alertDialog
.setMessage("Enter the Same Password Again ");
alertDialog
.setButton(
"OK",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int which) {

// here
// you
// can
// add
// functions

}
});
alertDialog.show();

} else {
flag[5] = 1;

}
}
}
}
}
}
}
}
}
}
}
if (flag[5] == 1) {
Log.e("log_tag", "All Data Final");
doRegistration();

}

}

});

}

public void doRegistration() {

PropertyInfo p[] = new PropertyInfo[7];
p[0] = new PropertyInfo();

p[0].type = PropertyInfo.STRING_CLASS;
p[0].setName("FirstName");
p[0].setValue(firstname.getText().toString());

p[1] = new PropertyInfo();

p[1].type = PropertyInfo.STRING_CLASS;
p[1].setName("LastName");
p[1].setValue(lastname.getText().toString());

p[2] = new PropertyInfo();

p[2].type = PropertyInfo.STRING_CLASS;
p[2].setName("Email");
p[2].setValue(email.getText().toString());

p[3] = new PropertyInfo();

p[3].type = PropertyInfo.STRING_CLASS;
p[3].setName("Phone");
p[3].setValue(phone.getText().toString());

p[4] = new PropertyInfo();

p[4].type = PropertyInfo.STRING_CLASS;
p[4].setName("Password");
p[4].setValue(password.getText().toString());

p[5] = new PropertyInfo();

p[5].type = PropertyInfo.STRING_CLASS;
p[5].setName("StoreID");
p[5].setValue(15);
p[6] = new PropertyInfo();

p[6].type = PropertyInfo.INTEGER_CLASS;
p[6].setName("Mode");
p[6].setValue(1);

SoapObject Soapresponse = Ksoap
.CallService("Iphone_Registration", 7, p);

// if (Soapresponse != null) {
// SoapObject Soapresult = (SoapObject) Soapresponse.getProperty(0);
// if (Soapresult != null) {
// Dataset = (SoapObject) Soapresult.getProperty(1);
// if (Dataset != null) {
// Table = (SoapObject) Dataset.getProperty(0);
// }
// }
String result = Soapresponse.getProperty("Iphone_RegistrationResult").toString();

//Log.e("soap result", Soapresponse.toString());
alertDialog
.setMessage(""+result);
alertDialog
.setButton(
"OK",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int which) {

// here
// you
// can
// add
// functions

}
});
alertDialog.show();

}

}

No comments:

Post a Comment