Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.TPK.SistemPendataanPelalatan;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- public class MainActivity extends Activity {
- TextView ket;
- EditText id_user,pass;
- Button btnlogin;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_login);
- //deklarasi input dan output
- ket =(TextView) findViewById(R.id.warning_login);
- id_user = (EditText) findViewById(R.id.singup_id);
- pass = (EditText) findViewById(R.id.input_pass);
- btnlogin = (Button) findViewById(R.id.login);
- // event tombol ditekan
- btnlogin.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- String id=id_user.getText().toString();
- String pw=pass.getText().toString();
- int salah=0;//hitung jumlah kesalahan
- try {
- Class.forName("com.mysql.jdbc.Driver");
- } catch (ClassNotFoundException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- try {
- Statement st=(Statement)hubung.GetConnection().createStatement();
- if(id_user.getText().toString().isEmpty()||pass.getText().toString().isEmpty()){
- ket.setText("ID dan Password Harus di Isi!");
- }else{
- ResultSet rs=st.executeQuery("select * from user where id='"+id+"'and password='"+pw+"'");
- if(rs.next()){
- //kalo sukses masuk
- ket.setText("Selamat Datang ...");
- String nama=rs.getString(1);
- if(rs.getString(5)=="1"){//ADMIN
- Intent i = new Intent(MainActivity.this, activity_user_admin.class);
- i.putExtra("nama", nama);//passing nama ke activity user admin
- startActivity(i);
- st.close();
- }else if(rs.getString(5)=="2"){//SUPERVISOR
- Intent i = new Intent(MainActivity.this, activity_user_super.class);
- i.putExtra("nama", nama);//passing nama ke activity user super
- startActivity(i);
- st.close();
- }else if(rs.getString(5)=="3"){//TEKNISI
- Intent i = new Intent(MainActivity.this, activity_user_teknisi.class);
- i.putExtra("nama", nama);//passing nama ke activity user teknisi
- startActivity(i);
- st.close();
- }
- }
- else {
- ket.setText("ID atau Password Salah !");
- salah++;
- if(salah>3){
- salah=0;
- ket.setText("Silahkan Lapor Admin");
- }
- }
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- ket.setText(e.toString());
- }
- }
- });
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- }
- package com.TPK.SistemPendataanPelalatan;
- import java.sql.*;
- public class hubung {
- private static Connection kon;
- public static Connection GetConnection() throws SQLException{
- if(kon==null){
- kon = DriverManager.getConnection("jdbc:mysql://10.11.1.232:3306/tpk_peralatan","root","");
- }
- return kon;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement