parent
8b94bf8ada
commit
8c551b7d7b
@ -0,0 +1,254 @@
|
||||
package edu.hzuapps.androidlabs;
|
||||
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.graphics.Canvas;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class schedule extends AppCompatActivity {
|
||||
private Button informationbutton;
|
||||
private Button buttonadd;
|
||||
private Button buttondelete;
|
||||
MyHelper myHelper;
|
||||
SQLiteDatabase db;
|
||||
Intent intent;
|
||||
Context context =this;
|
||||
String temp;
|
||||
TextView textView;
|
||||
Cursor cursor;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_schedule);
|
||||
informationbutton=findViewById(R.id.information);
|
||||
buttonadd=findViewById(R.id.add);
|
||||
buttondelete=findViewById(R.id.delete);
|
||||
myHelper=new MyHelper(this);
|
||||
db=myHelper.getWritableDatabase();
|
||||
cursor=db.query("courses", null, "weekdayname=? and id=?", new String[]{"1","1"}, null, null, null);
|
||||
cursor.moveToFirst();
|
||||
temp = cursor.getString(2);
|
||||
textView=findViewById(R.id.Monday1);
|
||||
textView.setText(temp);
|
||||
cursor=db.query("courses", null, "weekdayname=? and id=?", new String[]{"1","2"}, null, null, null);
|
||||
cursor.moveToFirst();
|
||||
temp = cursor.getString(2);
|
||||
textView=findViewById(R.id.Monday2);
|
||||
textView.setText(temp);
|
||||
cursor=db.query("courses", null, "weekdayname=? and id=?", new String[]{"1","3"}, null, null, null);
|
||||
cursor.moveToFirst();
|
||||
temp = cursor.getString(2);
|
||||
textView=findViewById(R.id.Monday3);
|
||||
textView.setText(temp);
|
||||
cursor=db.query("courses", null, "weekdayname=? and id=?", new String[]{"1","4"}, null, null, null);
|
||||
cursor.moveToFirst();
|
||||
temp = cursor.getString(2);
|
||||
textView=findViewById(R.id.Monday4);
|
||||
textView.setText(temp);
|
||||
cursor=db.query("courses", null, "weekdayname=? and id=?", new String[]{"2","1"}, null, null, null);
|
||||
cursor.moveToFirst();
|
||||
temp = cursor.getString(2);
|
||||
textView=findViewById(R.id.Tuesday1);
|
||||
textView.setText(temp);
|
||||
cursor=db.query("courses", null, "weekdayname=? and id=?", new String[]{"2","2"}, null, null, null);
|
||||
cursor.moveToFirst();
|
||||
temp = cursor.getString(2);
|
||||
textView=findViewById(R.id.Tuesday2);
|
||||
textView.setText(temp);
|
||||
cursor=db.query("courses", null, "weekdayname=? and id=?", new String[]{"2","4"}, null, null, null);
|
||||
cursor.moveToFirst();
|
||||
temp = cursor.getString(2);
|
||||
textView=findViewById(R.id.Tuesday3);
|
||||
textView.setText(temp);
|
||||
cursor=db.query("courses", null, "weekdayname=? and id=?", new String[]{"2","4"}, null, null, null);
|
||||
cursor.moveToFirst();
|
||||
temp = cursor.getString(2);
|
||||
textView=findViewById(R.id.Tuesday4);
|
||||
textView.setText(temp);
|
||||
cursor=db.query("courses", null, "weekdayname=? and id=?", new String[]{"2","1"}, null, null, null);
|
||||
cursor.moveToFirst();
|
||||
temp = cursor.getString(2);
|
||||
textView=findViewById(R.id.Wednesday1);
|
||||
textView.setText(temp);
|
||||
cursor=db.query("courses", null, "weekdayname=? and id=?", new String[]{"3","2"}, null, null, null);
|
||||
cursor.moveToFirst();
|
||||
temp = cursor.getString(2);
|
||||
textView=findViewById(R.id.Wednesday2);
|
||||
textView.setText(temp);
|
||||
cursor=db.query("courses", null, "weekdayname=? and id=?", new String[]{"3","3"}, null, null, null);
|
||||
cursor.moveToFirst();
|
||||
temp = cursor.getString(2);
|
||||
textView=findViewById(R.id.Wednesday3);
|
||||
textView.setText(temp);
|
||||
cursor=db.query("courses", null, "weekdayname=? and id=?", new String[]{"3","4"}, null, null, null);
|
||||
cursor.moveToFirst();
|
||||
temp = cursor.getString(2);
|
||||
textView=findViewById(R.id.Wednesday4);
|
||||
textView.setText(temp);
|
||||
cursor=db.query("courses", null, "weekdayname=? and id=?", new String[]{"4","1"}, null, null, null);
|
||||
cursor.moveToFirst();
|
||||
temp = cursor.getString(2);
|
||||
textView=findViewById(R.id.Thursday1);
|
||||
textView.setText(temp);
|
||||
cursor=db.query("courses", null, "weekdayname=? and id=?", new String[]{"4","2"}, null, null, null);
|
||||
cursor.moveToFirst();
|
||||
temp = cursor.getString(2);
|
||||
textView=findViewById(R.id.Thursday2);
|
||||
textView.setText(temp);
|
||||
cursor=db.query("courses", null, "weekdayname=? and id=?", new String[]{"4","3"}, null, null, null);
|
||||
cursor.moveToFirst();
|
||||
temp = cursor.getString(2);
|
||||
textView=findViewById(R.id.Thursday3);
|
||||
textView.setText(temp);
|
||||
cursor=db.query("courses", null, "weekdayname=? and id=?", new String[]{"4","4"}, null, null, null);
|
||||
cursor.moveToFirst();
|
||||
temp = cursor.getString(2);
|
||||
textView=findViewById(R.id.Thursday4);
|
||||
textView.setText(temp);
|
||||
cursor=db.query("courses", null, "weekdayname=? and id=?", new String[]{"5","1"}, null, null, null);
|
||||
cursor.moveToFirst();
|
||||
temp = cursor.getString(2);
|
||||
textView=findViewById(R.id.Friday1);
|
||||
textView.setText(temp);
|
||||
cursor=db.query("courses", null, "weekdayname=? and id=?", new String[]{"5","2"}, null, null, null);
|
||||
cursor.moveToFirst();
|
||||
temp = cursor.getString(2);
|
||||
textView=findViewById(R.id.Friday2);
|
||||
textView.setText(temp);
|
||||
cursor=db.query("courses", null, "weekdayname=? and id=?", new String[]{"5","3"}, null, null, null);
|
||||
cursor.moveToFirst();
|
||||
temp = cursor.getString(2);
|
||||
textView=findViewById(R.id.Friday3);
|
||||
textView.setText(temp);
|
||||
cursor=db.query("courses", null, "weekdayname=? and id=?", new String[]{"5","4"}, null, null, null);
|
||||
cursor.moveToFirst();
|
||||
temp = cursor.getString(2);
|
||||
textView=findViewById(R.id.Friday4);
|
||||
textView.setText(temp);
|
||||
buttonadd.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@SuppressLint("ResourceType") AlertDialog dialog = new AlertDialog.Builder(context, R.layout.dailog).create();
|
||||
dialog.setCanceledOnTouchOutside(true);
|
||||
dialog.show();
|
||||
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
|
||||
//窗口的屏幕的位置
|
||||
|
||||
Window win = dialog.getWindow();
|
||||
win.setContentView(R.layout.dailog);
|
||||
win.setLayout(RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT);
|
||||
//窗口的屏幕的位置
|
||||
|
||||
EditText editText1 = (EditText) win.findViewById(R.id.weekdayname);
|
||||
EditText editText2 = (EditText) win.findViewById(R.id.id);
|
||||
EditText editText3 = (EditText) win.findViewById(R.id.coursename);
|
||||
//窗口文本组件
|
||||
|
||||
|
||||
//窗口的 取消按钮 及监视器
|
||||
Button button1 = (Button) win.findViewById(R.id.returnback);
|
||||
button1.setOnClickListener(v1 -> dialog.cancel());
|
||||
|
||||
|
||||
//窗口的 确定按钮 及监视器
|
||||
Button button2 = (Button) win.findViewById(R.id.sure);
|
||||
button2.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String number;
|
||||
TextView textView;
|
||||
String weekdayname=editText1.getText().toString();
|
||||
String id=editText2.getText().toString();
|
||||
String coursename=editText3.getText().toString();
|
||||
if (weekdayname==""){
|
||||
Toast.makeText(schedule.this,"请输入时间",Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
db=myHelper.getWritableDatabase();
|
||||
ContentValues values=new ContentValues();
|
||||
values.put("coursename",coursename);
|
||||
db.update("courses",values,"weekdayname=? and id=?",new String[]{weekdayname,id});
|
||||
Toast.makeText(schedule.this,"课程已添加",Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
buttondelete.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@SuppressLint("ResourceType") AlertDialog dialog = new AlertDialog.Builder(context, R.layout.deletedailog).create();
|
||||
dialog.setCanceledOnTouchOutside(true);
|
||||
dialog.show();
|
||||
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
|
||||
//窗口的屏幕的位置
|
||||
|
||||
Window win = dialog.getWindow();
|
||||
win.setContentView(R.layout.deletedailog);
|
||||
win.setLayout(RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT);
|
||||
//窗口的屏幕的位置
|
||||
|
||||
EditText editText1 = (EditText) win.findViewById(R.id.weekdayname1);
|
||||
EditText editText2 = (EditText) win.findViewById(R.id.id1);
|
||||
//窗口文本组件
|
||||
|
||||
|
||||
//窗口的 取消按钮 及监视器
|
||||
Button button1 = (Button) win.findViewById(R.id.returnback);
|
||||
button1.setOnClickListener(v1 -> dialog.cancel());
|
||||
|
||||
|
||||
//窗口的 确定按钮 及监视器
|
||||
Button button2 = (Button) win.findViewById(R.id.sure);
|
||||
button2.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String number;
|
||||
TextView textView;
|
||||
String weekdayname=editText1.getText().toString();
|
||||
String id=editText2.getText().toString();
|
||||
db=myHelper.getWritableDatabase();
|
||||
ContentValues values=new ContentValues();
|
||||
values.put("coursename", (byte[]) null);
|
||||
db.update("courses",values,"weekdayname=? and id=?",new String[]{weekdayname,id});
|
||||
Toast.makeText(schedule.this,"课程已删除",Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
informationbutton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
intent=new Intent(schedule.this,information.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in new issue