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.
93 lines
2.7 KiB
93 lines
2.7 KiB
package hunnu.sj.raise_money;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import android.os.Handler;
|
|
import android.os.Message;
|
|
import android.view.View;
|
|
import android.widget.EditText;
|
|
|
|
|
|
import hunnu.sj.raise_money.DataBase.UserService;
|
|
|
|
public class SignInActivity extends AppCompatActivity {
|
|
public static final String IS_SIGNIN = "is.user.sign.in";
|
|
public static final int SEND = 0;
|
|
EditText usnm;
|
|
EditText pswd;
|
|
User user;
|
|
Handler mHandler = new Handler(){
|
|
int flag = -1;
|
|
@Override
|
|
public void handleMessage(@NonNull Message msg) {
|
|
super.handleMessage(msg);
|
|
String txt;
|
|
switch (msg.what){
|
|
case 0:
|
|
flag = 0;
|
|
txt = (String) msg.obj;
|
|
usnm.setError(txt);
|
|
break;
|
|
case 1:
|
|
flag = 1;
|
|
txt = (String) msg.obj;
|
|
pswd.setError(txt);
|
|
break;
|
|
}
|
|
|
|
}
|
|
};
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.activity_signin);
|
|
}
|
|
|
|
public void user_commit(View view){
|
|
usnm = findViewById(R.id.user_name);
|
|
pswd = findViewById(R.id.pass_word);
|
|
new LoginThread().start();
|
|
}
|
|
|
|
public void onToRegister(View view){
|
|
Intent intent = new Intent(this,RegiteActivity.class);
|
|
startActivity(intent);
|
|
}
|
|
|
|
class LoginThread extends Thread{
|
|
@Override
|
|
public void run() {
|
|
int flag = -1;
|
|
String name = usnm.getText().toString();
|
|
String pasd = pswd.getText().toString();
|
|
UserService uService = new UserService();
|
|
flag = uService.login(name,pasd);
|
|
Message message = mHandler.obtainMessage();
|
|
if(flag==0){
|
|
message.what = 0;
|
|
message.obj = "用户名不存在";
|
|
mHandler.sendMessage(message);
|
|
}else if(flag==1){
|
|
message.what = 1;
|
|
message.obj = "密码错误";
|
|
mHandler.sendMessage(message);
|
|
}else{
|
|
User user = new User();
|
|
user.setName(name);
|
|
user.setPasd(pasd);
|
|
String role = uService.getRole(name);
|
|
user.setRole(role);
|
|
Bundle bundle = new Bundle();
|
|
bundle.putSerializable("user",user);
|
|
Intent intent =new Intent(SignInActivity.this,MainActivity.class);
|
|
intent.putExtras(bundle);
|
|
startActivity(intent);
|
|
finish();
|
|
}
|
|
}
|
|
}
|
|
}
|