package com.example.map;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.map.database.ClassDBHelper;
import com.example.map.enity.Class_demo;

public class DeleteClasses extends AppCompatActivity implements View.OnClickListener{
    Button close_activity;//关闭按钮
    Button delete_activity;//删除按钮
    //    Spinner selected_time;//选择上课时间
//    Spinner selected_day;//选择哪天上课
    EditText subject;//科目
    EditText teacher;//老师名字
    private ClassDBHelper mHelper;

    public final String DB_NAME = "class.db";
    public final String TABLE_NAME = "class_table";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.deleteclass);

        delete_activity=findViewById(R.id.delete_activity);
//        selected_time=findViewById(R.id.delete_selected_time);
//        selected_day=findViewById(R.id.delete_selected_day);
        subject=findViewById(R.id.delete_subject);
        teacher=findViewById(R.id.delete_teacher);
        //当点击dialog之外完成此activity
        setFinishOnTouchOutside (true);

        //关闭按钮操作
        close_activity=(Button) findViewById(R.id.close_activity);
        close_activity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                DeleteClasses.this.finish();
            }
        });

        findViewById(R.id.delete_subject).setOnClickListener(this);
        findViewById(R.id.delete_teacher).setOnClickListener(this);
        findViewById(R.id.delete_activity).setOnClickListener(this);
    }

    protected void onStart() {
        super.onStart();
        // 获得数据库帮助器的实例
        mHelper = ClassDBHelper.getInstance(this);
        // 打开数据库帮助器的读写连接
        mHelper.openWriteLink();
        mHelper.openReadLink();
    }
    public void onClick(View v) {
        String subject_=subject.getText().toString().trim();
        String teacher_=teacher.getText().toString().trim();
//        String time = selected_time.getSelectedItem().toString();
//        String day = selected_day.getSelectedItem().toString();
        Class_demo classes = null;
        switch (v.getId()){

            case R.id.close_activity:
                Intent intent = new Intent(DeleteClasses.this, ClassTable.class);//跳转到注册界面
                startActivity(intent);
                finish();
                break;

            case R.id.delete_activity:
                classes=new Class_demo(subject_,teacher_);
                if (mHelper.delete(classes) > 0) {
                    Toast.makeText(this, "课表删除成功", Toast.LENGTH_SHORT).show();
                }
                break;
        }
    }
}