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 android.widget.TimePicker;


import androidx.appcompat.app.AppCompatActivity;

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

import java.time.LocalDate;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.Calendar;

public class addRecordActivity extends AppCompatActivity implements View.OnClickListener {
private Button btn_submit1, btn_gotoObjective, btn_gotoAnalysis, btn_gotoAllAnalysis;
private EditText et_record;
private TimePicker tp_startTime, tp_endTime;
private UserDao userDao;
private Handler mainHandler;
LocalDate currentDate = LocalDate.now();
DayOfWeek dayOfWeek = currentDate.getDayOfWeek();

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

userDao = new UserDao();
mainHandler = new Handler(getMainLooper());
btn_submit1 = findViewById(R.id.btn_submit1);
btn_gotoObjective = findViewById(R.id.btn_gotoObjective);
btn_gotoAnalysis = findViewById(R.id.btn_gotoAnalysis);
btn_gotoAllAnalysis = findViewById(R.id.btn_gotoAllAnalysis);

tp_startTime = findViewById(R.id.tp_startTime);
tp_endTime = findViewById(R.id.tp_endTime);
et_record = findViewById(R.id.et_record);


btn_submit1.setOnClickListener(this);
btn_gotoObjective.setOnClickListener(this);
btn_gotoAnalysis.setOnClickListener(this);
btn_gotoAllAnalysis.setOnClickListener(this);

}

@Override
public void onClick(View v) {
Bundle bundle = getIntent().getExtras();
String stringId = bundle.getString("id");
int id = Integer.parseInt(stringId);

if (v.getId() == R.id.btn_submit1) {

LocalDate localDate = LocalDate.now();
String date = localDate.toString();
int startTimeHour = tp_startTime.getHour();
int startTimeMinute = tp_startTime.getMinute();
int endTimeHour = tp_endTime.getHour();
int endTimeMinute = tp_endTime.getMinute();
String startTime = String.format("%02d:%02d:00", startTimeHour, startTimeMinute);
String endTime = String.format("%02d:%02d:00", endTimeHour, endTimeMinute);
String record = et_record.getText().toString().trim();


new Thread(new Runnable() {
@Override
public void run() {
Records records = new Records(id, date, startTime, endTime, record);

int iRow = 0;
iRow = userDao.addRecord(records);
if (iRow > 0) {
mainHandler.post(new Runnable() {
@Override
public void run() {
CommonUtils.showShortMsg(addRecordActivity.this, "添加成功");
}
});
} else {
mainHandler.post(new Runnable() {
@Override
public void run() {
CommonUtils.showShortMsg(addRecordActivity.this, "添加失败");
}
});
}
}
}).start();
} else if (v.getId() == R.id.btn_gotoObjective) {

Intent intent = new Intent(addRecordActivity.this, addObjectivesActivity.class);
Bundle bundle1 = new Bundle();
bundle1.putString("id", stringId);
intent.putExtras(bundle1);
startActivity(intent);
} else if (v.getId() == R.id.btn_gotoAnalysis) {
Intent intent = new Intent(addRecordActivity.this, analysisActivity.class);
Bundle bundle1 = new Bundle();
bundle1.putString("id", stringId);
intent.putExtras(bundle1);
startActivity(intent);
} else if (v.getId() == R.id.btn_gotoAllAnalysis) {
Intent intent = new Intent(addRecordActivity.this, AllAnalysisActivity.class);
Bundle bundle1 = new Bundle();
bundle1.putString("id", stringId);
intent.putExtras(bundle1);
startActivity(intent);
}
}


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