You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.6 KiB
80 lines
2.6 KiB
package com.example.Cat.activity;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import android.content.Intent;
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
import android.os.Bundle;
|
|
import android.view.View;
|
|
import android.widget.Button;
|
|
import android.widget.EditText;
|
|
import android.widget.Toast;
|
|
|
|
import com.example.Cat.R;
|
|
import com.example.Cat.databaseoperation.User_Database;
|
|
import com.example.Cat.entity.UserInfo;
|
|
|
|
import java.util.List;
|
|
|
|
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
|
|
private Button registerButton, loginButton;
|
|
private EditText usernameText, paswdEdit;
|
|
List<UserInfo> list ;
|
|
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
User_Database user=new User_Database(MainActivity.this);
|
|
SQLiteDatabase sqLiteDatabase=user.getReadableDatabase();
|
|
|
|
setContentView(R.layout.user_login);
|
|
init();
|
|
}
|
|
|
|
private void init() {
|
|
usernameText = findViewById(R.id.username);
|
|
paswdEdit = findViewById(R.id.password);
|
|
loginButton = findViewById(R.id.login);
|
|
loginButton.setOnClickListener(this);
|
|
registerButton = findViewById(R.id.register);
|
|
registerButton.setOnClickListener(this);
|
|
}
|
|
|
|
@Override
|
|
public void onClick(View v) {
|
|
switch (v.getId()) {
|
|
case R.id.register:
|
|
Intent intent = new Intent(MainActivity.this, RegisterActivity.class);
|
|
startActivity(intent);
|
|
break;
|
|
case R.id.login:
|
|
Verification();
|
|
break;
|
|
}
|
|
}
|
|
|
|
//验证密码是否正确
|
|
public void Verification(){
|
|
//UserInfo info;
|
|
Intent intent = new Intent(MainActivity.this, UserActivity.class);
|
|
//intent.putExtra("username",usernameText.getText().toString());
|
|
User_Database user=new User_Database(MainActivity.this);
|
|
SQLiteDatabase sqLiteDatabase=user.getReadableDatabase();
|
|
UserInfo info=user.queryByName(sqLiteDatabase,usernameText.getText().toString());
|
|
//info=list.get(0);
|
|
if(info!=null){
|
|
intent.putExtra("username",usernameText.getText().toString());
|
|
if(paswdEdit.getText().toString().equals(info.getPaswd())){
|
|
startActivity(intent);
|
|
}
|
|
else{
|
|
Toast.makeText(this, "密码错误!", Toast.LENGTH_SHORT).show();
|
|
}
|
|
}
|
|
else{
|
|
Toast.makeText(this, "用户不存在!", Toast.LENGTH_SHORT).show();
|
|
}
|
|
}
|
|
}
|