Advertisement
Guest User

Untitled

a guest
Apr 25th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. EditText editText,editText1,;
  2. Database mydb;
  3. SQLiteDatabase db;
  4. @Override
  5. protected void onCreate(Bundle savedInstanceState) {
  6. super.onCreate(savedInstanceState);
  7. setContentView(R.layout.activity_main);
  8.  
  9. mydb = new Database(this);
  10. db = mydb.getWritableDatabase();
  11. }
  12. public void loginPage(View v) {
  13. editText = (EditText) findViewById(R.id.username);
  14. editText1 = (EditText) findViewById(R.id.pasword);
  15. String username = editText.getText().toString();
  16. String password = editText1.getText().toString();
  17.  
  18. if (username.equals("")) {
  19. editText.setError("Pls Enter UserName");
  20. } else if (password.equals(""))
  21. {
  22. editText1.setError("pls enter password");
  23. }
  24. try
  25. {
  26. StringBuffer sb = new StringBuffer();
  27. String query = "select * from Users";
  28. Cursor c = db.rawQuery(query,null);
  29. boolean res = c.moveToFirst();
  30. if (res)
  31. {
  32. do {
  33. username = c.getString(0);
  34. sb.append(username);
  35. }
  36. while (c.moveToNext());
  37. }
  38. else
  39. {
  40. Toast.makeText(MainActivity.this, "Wrong credentials", Toast.LENGTH_SHORT).show();
  41. }
  42. String data = sb.toString();
  43. Intent i = new Intent(this,WelcomeActivity.class);
  44. i.putExtra("k1",data);
  45. startActivity(i);
  46. }catch (Exception e)
  47. {
  48. Log.e("ReadDataException",""+e);
  49. }
  50.  
  51. }
  52. public void signupPage(View v)
  53. {
  54. Intent i = new Intent(this,SignupActivity.class);
  55. startActivity(i);
  56. }
  57.  
  58. Database mydb;
  59. SQLiteDatabase db;
  60. String Gender = "";
  61.  
  62. @Override
  63. protected void onCreate(Bundle savedInstanceState) {
  64. super.onCreate(savedInstanceState);
  65. setContentView(R.layout.signuppage);
  66.  
  67. mydb = new Database(this);
  68. db = mydb.getWritableDatabase();
  69. }
  70. public void createAccount(View v)
  71. {
  72. editText2 = (EditText)findViewById(R.id.username);
  73. editText3 = (EditText)findViewById(R.id.passwordd);
  74. editText4 = (EditText)findViewById(R.id.cnfrmpassword);
  75. editText5 = (EditText)findViewById(R.id.emailaddress);
  76. editText6 = (EditText)findViewById(R.id.phone);
  77. RadioGroup rg = (RadioGroup)findViewById(R.id.radio);
  78. final int id = rg.getCheckedRadioButtonId();
  79. final RadioButton rb1 = (RadioButton)findViewById(id);
  80. final RadioButton rb2 = (RadioButton)findViewById(id);
  81. String username = editText2.getText().toString();
  82. String password = editText3.getText().toString();
  83. String cnfmpasswrd = editText4.getText().toString();
  84. String email = editText5.getText().toString();
  85. String phone = editText6.getText().toString();
  86.  
  87. rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
  88. @Override
  89. public void onCheckedChanged(RadioGroup group, int checkedId) {
  90. switch (id)
  91. {
  92. case R.id.male:
  93. {
  94. if (rb1.isChecked())
  95. {
  96. Gender ="Male";
  97. }
  98. }
  99. break;
  100. case R.id.female:
  101. {
  102. if (rb2.isChecked())
  103. {
  104. Gender = "Female";
  105. }
  106. }
  107. }
  108. }
  109. });
  110. if (username.equals(""))
  111. {
  112. editText2.setError("pls enter name");
  113. }
  114. else if (password.equals(""))
  115. {
  116. editText3.setError("pls fill fileds");
  117. }
  118. else if (!password.equals(cnfmpasswrd))
  119. {
  120. editText4.setError("Does not match passwords");
  121. }
  122. else if (email.equals(""))
  123. {
  124. editText5.setError("pls enter email address");
  125. }
  126. else if (phone.equals(""))
  127. {
  128. editText6.setText("pls enter valid number");
  129. }
  130. String query = "insert into Users values('"+username+"',"+password+","+email+","+phone+","+Gender+")";
  131. try
  132. {
  133. db.execSQL(query);
  134. AlertDialog.Builder ab = new AlertDialog.Builder(this);
  135. ab.setMessage("Account Created Succesfully");
  136. ab.show();
  137. setContentView(R.layout.activity_main);
  138. }
  139. catch(Exception e)
  140. {
  141. Log.e("InsertionException",""+e);
  142. }
  143. editText2.setText("");
  144. editText3.setText("");
  145. editText4.setText("");
  146. editText5.setText("");
  147. editText6.setText("");
  148. }
  149.  
  150. public static final String DBNAME = "anil";
  151. public static final int VERSION = 1;
  152. public Database(Context c)
  153. {
  154. super(c,DBNAME,null,VERSION);
  155. }
  156. @Override
  157. public void onCreate(SQLiteDatabase db)
  158. {
  159. try
  160. {
  161. String query = "create table Users(Username TEXT,Password TEXT,Email TEXT,PhoneNumber INTEGER,Gender TEXT)";
  162. db.execSQL(query);
  163. }catch (Exception e)
  164. {
  165. Log.e("TableCreationException",""+e);
  166. }
  167. }
  168. @Override
  169. public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  170.  
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement