Skip to content

Commit

Permalink
hzuapps#5 hzuapps#142 第五次作业
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleUncle committed May 26, 2017
1 parent 92c4fff commit f26db92
Show file tree
Hide file tree
Showing 12 changed files with 368 additions and 460 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package edu.hzuapps.androidlab.homeworks.net1414080903135;
package edu.hzuapp.androidlabs.homeworks.net1414080903135;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.Toast;

import edu.hzuapps.androidlab.R;
import edu.hzuapp.androidlabs.R;

public class Net1414080903135Activity extends AppCompatActivity {

Expand All @@ -12,4 +14,29 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_net1414080903135);
}
//响应按下事件

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
Toast.makeText(this,"按键按下!",Toast.LENGTH_SHORT).show();
return super.onKeyDown(keyCode, event);


}



//响应按松开事件
public boolean onkeyUp (int keyCode, KeyEvent event){
Toast.makeText(this,"按键弹起!",Toast.LENGTH_SHORT).show();
return super.onKeyUp(keyCode,event);
}
//响应触摸事件
/*
public boolean onTouchEvent (int keyCode, KeyEvent event){
float x=event.getX();
float y=event.getY();
Toast.makeText(this, "点击坐标为(“+x+”:"+y+")",Toast.LENGTH_SHORT).show();
return super.onTouchEvent(event);
}*/
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,71 @@
package edu.hzuapp.androidlabs.homeworks.net1414080903135;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Net1414080903135AddObject extends AppCompatActivity {
import edu.hzuapp.androidlabs.R;

public class Net1414080903135AddObject extends AppCompatActivity implements View.OnClickListener {

private EditText ccourse;
private EditText cteacher;
private EditText cperiod;
private EditText ccredit;
private EditText cclassroom;
private WorkDatabaseHelper dbHelper;
private String mcourse;
private String mteacher;
private String mperiod;
private String mcredit;
private String mclassroom;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_net1414080903135_add_object);
dbHelper=new WorkDatabaseHelper(this,"Test.db",null,2);
Button msubmit = (Button) findViewById(R.id.submit);
msubmit.setOnClickListener(this);
ccourse = (EditText) findViewById(R.id.vcourse);
cteacher = (EditText) findViewById(R.id.vteacher);
cperiod = (EditText) findViewById(R.id.vperiod);
ccredit = (EditText) findViewById(R.id.vcredit);
cclassroom = (EditText) findViewById(R.id.vclassroom);
}

public void onClick(View v) {
switch (v.getId()) {
case R.id.submit:
mcourse = ccourse.getText().toString().trim();
mteacher = cteacher.getText().toString().trim();
mperiod = cperiod.getText().toString().trim();
mcredit = ccredit.getText().toString().trim();
mclassroom = cclassroom.getText().toString().trim();

insert(mcourse,mteacher,mperiod,mcredit,mperiod);// 插入课程信息
Intent intent3=new Intent(this,Net1414080903135AddObject.class);
this.finish();
startActivity(intent3);
}

}

public void insert(String mcourse,String mteacher,String mperiod,String mcredit,String mclassroom){
SQLiteDatabase db=dbHelper.getWritableDatabase();
ContentValues values=new ContentValues();
values.put("course",mcourse);
values.put("teacher",mteacher);
values.put("period",mperiod);
values.put("credit",mcredit);
values.put("classroom",mclassroom);
db.insert("work",null,values);
Toast.makeText(this,"成功提交课程",Toast.LENGTH_SHORT).show();
values.clear();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package edu.hzuapp.androidlabs.homeworks.net1414080903135;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import edu.hzuapp.androidlabs.R;

public class Net1414080903135AdminActivity extends AppCompatActivity implements View.OnClickListener{

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_net1414080903135_admin);
Button button = (Button) findViewById(R.id.add);
button.setOnClickListener(this);
Button change1 = (Button) findViewById(R.id.change);
change1.setOnClickListener(this);
}

public void onClick(View v) {
switch (v.getId()) {
case R.id.add:
/*跳转添加课表*/
Intent intent = new Intent(this,Net1414080903135AddObject.class);
startActivity(intent);
/*跳转修改课表*/
case R.id.change:
Intent intento = new Intent(this,Net1414080903135ChangeActivity.class);
startActivity(intento);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,70 @@
package edu.hzuapp.androidlabs.homeworks.net1414080903135;

import android.support.v7.app.AppCompatActivity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import edu.hzuapp.androidlabs.R;

public class Net1414080903135ChangeActivity extends AppCompatActivity {
public class Net1414080903135ChangeActivity extends AppCompatActivity implements View.OnClickListener {

private EditText ccourse;
private EditText cteacher;
private EditText cperiod;
private EditText ccredit;
private EditText cclassroom;
private WorkDatabaseHelper dbHelper;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_net1414080903135_change);
dbHelper=new WorkDatabaseHelper(this,"Test.db",null,2);
Button msubmit = (Button) findViewById(R.id.submit);
msubmit.setOnClickListener(this);
ccourse = (EditText) findViewById(R.id.vcourse);
cteacher = (EditText) findViewById(R.id.vteacher);
cperiod = (EditText) findViewById(R.id.vperiod);
ccredit = (EditText) findViewById(R.id.vcredit);
cclassroom = (EditText) findViewById(R.id.vclassroom);
}

public void onClick(View v) {
switch (v.getId()) {
case R.id.submit:
String mcourse = ccourse.getText().toString().trim();
String mteacher = cteacher.getText().toString().trim();
String mperiod = cperiod.getText().toString().trim();
String mcredit = ccredit.getText().toString().trim();
String mclassroom = cclassroom.getText().toString().trim();

update(mcourse,mteacher,mperiod,mcredit,mclassroom);// 插入课程信息
Intent intent3=new Intent(this,Net1414080903135AddObject.class);
this.finish();
startActivity(intent3);
}

}

public void update(String mcourse,String mteacher,String mperiod,String mcredit,String mclassroom){
SQLiteDatabase db=dbHelper.getWritableDatabase();
ContentValues values=new ContentValues();
values.put("course",mcourse);
values.put("teacher",mteacher);
values.put("period",mperiod);
values.put("credit",mcredit);
values.put("classroom",mclassroom);
db.update("work",values,"teacher=?",new String[]{mteacher});
// int course=db.update("work",values,"period=?",new String[]{mperiod});
// int course=db.update("work",values,"credit=?",new String[]{mcredit});
// int course=db.update("work",values,"classroom=?",new String[]{mclassroom});
Toast.makeText(this,"成功修改课程",Toast.LENGTH_SHORT).show();
values.clear();
}

}
Loading

0 comments on commit f26db92

Please sign in to comment.