Advertisement
Guest User

AddEmployee

a guest
Apr 25th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. package example.uuj.employeerecords;
  2.  
  3. import android.app.DialogFragment;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import android.widget.EditText;
  10. import android.widget.TextView;
  11. import android.widget.Toast;
  12.  
  13.  
  14. public class AddEmployee extends AppCompatActivity
  15. {
  16. // Declare Variables
  17. DatabaseHelper db;
  18. private Button btnAdd;
  19. private TextView displayDate;
  20. private EditText name, address, town, postcode, contactnumber, email, jobtitle, salary;
  21.  
  22. @Override
  23. protected void onCreate(Bundle savedInstanceState)
  24. {
  25. super.onCreate(savedInstanceState);
  26. setContentView(R.layout.activity_add_employee);
  27.  
  28. // Call database helper
  29. db = new DatabaseHelper(this);
  30.  
  31. // Initialise the edit texts and buttons
  32. btnAdd = (Button) findViewById(R.id.btnAddEmployee );
  33. displayDate = (TextView) findViewById( R.id.txtdisplaydate );
  34. name = (EditText) findViewById( R.id.txtName );
  35. address = (EditText) findViewById( R.id.txtAddress );
  36. town = (EditText) findViewById( R.id.txtTown );
  37. postcode = (EditText) findViewById( R.id.txtPostcode );
  38. contactnumber = (EditText) findViewById( R.id.txtContactNumber );
  39. email = (EditText) findViewById( R.id.txtEmail );
  40. jobtitle = (EditText) findViewById( R.id.txtJobTitle );
  41. salary = (EditText) findViewById( R.id.txtSalary );
  42.  
  43. AddData();
  44. }
  45.  
  46. public void onClickDate(View view)
  47. {
  48. DialogFragment newFragment = new DatePickerFragment();
  49. newFragment.show( getFragmentManager(), "Date Picker" );
  50. }
  51.  
  52. // Method to add data to the database
  53. public void AddData() {
  54. btnAdd.setOnClickListener(
  55. new View.OnClickListener() {
  56. @Override
  57. public void onClick(View v)
  58. {
  59. boolean isDataInserted = db.addData(
  60. name.getText().toString(),
  61. displayDate.getText().toString(),
  62. address.getText().toString(),
  63. town.getText().toString(),
  64. postcode.getText().toString(),
  65. contactnumber.getText().toString(),
  66. email.getText().toString(),
  67. jobtitle.getText().toString(),
  68. salary.getText().toString() );
  69.  
  70. // If statement to display message if either data is inserted or not
  71. if(isDataInserted == true)
  72. Toast.makeText(AddEmployee.this,"Data Inserted",Toast.LENGTH_LONG).show();
  73. else
  74. Toast.makeText(AddEmployee.this,"Data not Inserted",Toast.LENGTH_LONG).show();
  75. }
  76. }
  77. );
  78. }
  79.  
  80. // Method for cancel button
  81. public void onClickCancel(View view)
  82. {
  83. // Create cancel button
  84. Button cancel= (Button) findViewById( R.id.btncancel );
  85. cancel.setOnClickListener( new View.OnClickListener()
  86. {
  87. @Override
  88. public void onClick(View view)
  89. {
  90. Intent intent_cancel = new Intent( AddEmployee.this, EmployeeHomePage.class );
  91. startActivity( intent_cancel );
  92. finish();
  93. }
  94. });
  95. }
  96.  
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement