package com.example.ourhomework1.activities;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.ourhomework1.MainActivity;
import com.example.ourhomework1.R;
import com.example.ourhomework1.dao.UserDao;
import com.example.ourhomework1.pojo.Student;
import com.example.ourhomework1.utils.CommonUtils;

public class addStudentActivity extends AppCompatActivity implements View.OnClickListener {

private Button btn_submit;
private EditText et_id, et_name, et_phone, et_studentClass, et_password;
private Handler mainHandler;
private UserDao userDao;


@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_student);

mainHandler = new Handler(getMainLooper());
userDao = new UserDao();

btn_submit = findViewById(R.id.btn_submit);

et_id = findViewById(R.id.et_id);
et_name = findViewById(R.id.et_name);
et_phone = findViewById(R.id.et_phone);
et_studentClass = findViewById(R.id.et_studentClass);
et_password = findViewById(R.id.et_password);

btn_submit.setOnClickListener(this);

}


@Override
public void onClick(View v) {
if (v.getId() == R.id.btn_submit) {
String stringid = et_id.getText().toString().trim();
int id = Integer.parseInt(stringid);
String name = et_name.getText().toString().trim();
String phone = et_phone.getText().toString().trim();
String studentClass = et_studentClass.getText().toString().trim();
String password = et_password.getText().toString().trim();

new Thread(new Runnable() {
@Override
public void run() {
Student student = new Student(id, name, phone, studentClass, password);
int iRow = 0;
iRow = userDao.addStudent(student);
Intent intent = new Intent(addStudentActivity.this, addRecordActivity.class);
Bundle bundle = new Bundle();
bundle.putString("id", stringid);
intent.putExtras(bundle);
startActivity(intent);

if (iRow > 0) {
mainHandler.post(new Runnable() {
@Override
public void run() {
CommonUtils.showShortMsg(addStudentActivity.this, "注册成功");
}
});
} else {
mainHandler.post(new Runnable() {
@Override
public void run() {
CommonUtils.showShortMsg(addStudentActivity.this, "注册失败");
Intent intent = new Intent(addStudentActivity.this, addStudentActivity.class);
startActivity(intent);
}
});
}
}

}).start();
}

}

//执行查询用户数量的方法


@Override
public void onPointerCaptureChanged(boolean hasCapture) {
super.onPointerCaptureChanged(hasCapture);
}
}
posted on 2025-01-06 15:37    阅读(7)  评论(0)    收藏  举报