Advertisement
Guest User

Untitled

a guest
Jan 29th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.44 KB | None | 0 0
  1. package com.TPK.SistemPendataanPelalatan;
  2.  
  3.  
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7.  
  8. import android.app.Activity;
  9. import android.content.Intent;
  10. import android.os.Bundle;
  11. import android.view.Menu;
  12. import android.view.MenuItem;
  13. import android.view.View;
  14. import android.widget.Button;
  15. import android.widget.EditText;
  16. import android.widget.TextView;
  17.  
  18.  
  19.  
  20. public class MainActivity extends Activity {
  21.  
  22. TextView ket;
  23. EditText id_user,pass;
  24. Button btnlogin;
  25.  
  26.  
  27.  
  28. @Override
  29. protected void onCreate(Bundle savedInstanceState) {
  30. super.onCreate(savedInstanceState);
  31. setContentView(R.layout.activity_login);
  32.  
  33. //deklarasi input dan output
  34.  
  35. ket =(TextView) findViewById(R.id.warning_login);
  36. id_user = (EditText) findViewById(R.id.singup_id);
  37. pass = (EditText) findViewById(R.id.input_pass);
  38. btnlogin = (Button) findViewById(R.id.login);
  39.  
  40.  
  41. // event tombol ditekan
  42. btnlogin.setOnClickListener(new View.OnClickListener() {
  43. @Override
  44. public void onClick(View view) {
  45.  
  46. String id=id_user.getText().toString();
  47. String pw=pass.getText().toString();
  48.  
  49. int salah=0;//hitung jumlah kesalahan
  50. try {
  51. Class.forName("com.mysql.jdbc.Driver");
  52. } catch (ClassNotFoundException e1) {
  53. // TODO Auto-generated catch block
  54. e1.printStackTrace();
  55. }
  56.  
  57. try {
  58.  
  59. Statement st=(Statement)hubung.GetConnection().createStatement();
  60.  
  61. if(id_user.getText().toString().isEmpty()||pass.getText().toString().isEmpty()){
  62. ket.setText("ID dan Password Harus di Isi!");
  63. }else{
  64. ResultSet rs=st.executeQuery("select * from user where id='"+id+"'and password='"+pw+"'");
  65. if(rs.next()){
  66. //kalo sukses masuk
  67. ket.setText("Selamat Datang ...");
  68. String nama=rs.getString(1);
  69. if(rs.getString(5)=="1"){//ADMIN
  70. Intent i = new Intent(MainActivity.this, activity_user_admin.class);
  71. i.putExtra("nama", nama);//passing nama ke activity user admin
  72. startActivity(i);
  73. st.close();
  74. }else if(rs.getString(5)=="2"){//SUPERVISOR
  75. Intent i = new Intent(MainActivity.this, activity_user_super.class);
  76. i.putExtra("nama", nama);//passing nama ke activity user super
  77. startActivity(i);
  78. st.close();
  79. }else if(rs.getString(5)=="3"){//TEKNISI
  80. Intent i = new Intent(MainActivity.this, activity_user_teknisi.class);
  81. i.putExtra("nama", nama);//passing nama ke activity user teknisi
  82. startActivity(i);
  83. st.close();
  84. }
  85. }
  86. else {
  87. ket.setText("ID atau Password Salah !");
  88. salah++;
  89. if(salah>3){
  90. salah=0;
  91. ket.setText("Silahkan Lapor Admin");
  92. }
  93.  
  94. }
  95. }
  96.  
  97. } catch (SQLException e) {
  98. // TODO Auto-generated catch block
  99. ket.setText(e.toString());
  100. }
  101. }
  102. });
  103. }
  104.  
  105.  
  106. @Override
  107. public boolean onCreateOptionsMenu(Menu menu) {
  108. // Inflate the menu; this adds items to the action bar if it is present.
  109. getMenuInflater().inflate(R.menu.main, menu);
  110. return true;
  111. }
  112.  
  113. @Override
  114. public boolean onOptionsItemSelected(MenuItem item) {
  115. // Handle action bar item clicks here. The action bar will
  116. // automatically handle clicks on the Home/Up button, so long
  117. // as you specify a parent activity in AndroidManifest.xml.
  118. int id = item.getItemId();
  119. if (id == R.id.action_settings) {
  120. return true;
  121. }
  122. return super.onOptionsItemSelected(item);
  123. }
  124.  
  125. }
  126.  
  127. package com.TPK.SistemPendataanPelalatan;
  128. import java.sql.*;
  129.  
  130. public class hubung {
  131. private static Connection kon;
  132. public static Connection GetConnection() throws SQLException{
  133. if(kon==null){
  134. kon = DriverManager.getConnection("jdbc:mysql://10.11.1.232:3306/tpk_peralatan","root","");
  135. }
  136. return kon;
  137.  
  138. }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement