Advertisement
Guest User

EmployeeHomePage

a guest
Apr 25th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. package example.uuj.employeerecords;
  2.  
  3. import android.app.AlertDialog;
  4. import android.database.Cursor;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import android.widget.EditText;
  10. import android.content.Intent;
  11.  
  12. public class EmployeeHomePage extends AppCompatActivity
  13. {
  14. // Declaring variables
  15. Button btnviewAll;
  16. DatabaseHelper db;
  17.  
  18. @Override
  19. protected void onCreate(Bundle savedInstanceState)
  20. {
  21. super.onCreate( savedInstanceState );
  22. setContentView( R.layout.activity_employee_home_page );
  23.  
  24. // Initialise the button
  25. btnviewAll = (Button)findViewById(R.id.btnviewall);
  26.  
  27. // Call database helper
  28. db = new DatabaseHelper(this);
  29.  
  30. viewAll();
  31. }
  32.  
  33. // Method to open Add Employee activity
  34. public void onClickAddEmployee(View view)
  35. {
  36. // Create Add Employee button
  37. Button addEmployee= (Button) findViewById( R.id.btnAddEmployee );
  38. addEmployee.setOnClickListener( new View.OnClickListener()
  39. {
  40. @Override
  41. public void onClick(View view)
  42. {
  43. Intent intent_cancel = new Intent( EmployeeHomePage.this, AddEmployee.class );
  44. startActivity( intent_cancel );
  45. finish();
  46. }
  47. });
  48. }
  49.  
  50. // Method to view all data from the database
  51. public void viewAll()
  52. {
  53. btnviewAll.setOnClickListener(
  54. new View.OnClickListener() {
  55. @Override
  56. public void onClick(View v) {
  57. Cursor allData = db.getAllData();
  58. if(allData.getCount() == 0)
  59. {
  60. // show message
  61. showMessage("Error","Nothing found");
  62. return;
  63. }
  64.  
  65. StringBuffer buffer = new StringBuffer();
  66. while (allData.moveToNext()) {
  67. buffer.append("ID: "+ allData.getString(0)+"\n");
  68. buffer.append("Name: "+ allData.getString(1)+"\n");
  69. buffer.append("DOB: "+ allData.getString(2)+"\n");
  70. buffer.append("Address: "+ allData.getString(3)+"\n");
  71. buffer.append("Town: "+ allData.getString(4)+"\n");
  72. buffer.append("Postcode: "+ allData.getString(5)+"\n\n");
  73. buffer.append("ContractNumber: "+ allData.getString(6)+"\n");
  74. buffer.append("Email: "+ allData.getString(7)+"\n\n");
  75. buffer.append("JobTitle: "+ allData.getString(8)+"\n");
  76. buffer.append("Salary: "+ allData.getString(9)+"\n\n\n");
  77. }
  78.  
  79. // Show all data
  80. showMessage("Data",buffer.toString());
  81. }
  82. }
  83. );
  84. }
  85.  
  86.  
  87. public void showMessage(String title,String Message)
  88. {
  89. AlertDialog.Builder builder = new AlertDialog.Builder(this);
  90. builder.setCancelable(true);
  91. builder.setTitle(title);
  92. builder.setMessage(Message);
  93. builder.show();
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement