最后是关于管理员用户的功能实现:更改密码,更改个人信息,查询自己所管理学院的所有老师信息,查询自己管理学院的所有学生信息
前面两个功能与学生的类似,然后还是需要注意的就是管理员用户个人信息表的建立,我的包含:管理员编号,id,年龄,性别,管理学院
这里就不给大家介绍这两个,大家可以看sqlite数据库实例三。
查询自己所管理学院的所有老师信息和学生信息,把他们都在屏幕底部通过添加滚动条显示,不适用新的Activity显示:
代码:
public class ManagerMainFrame extends Activity { private Intent intent; private TextView check_all_student_manager_textview; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.manager_main_frame); check_all_student_manager_textview = (TextView) findViewById(R.id.check_all_student_manager_textview); } /** * 處理各種按鈕事件 * * @param v */ public void check_message_manager(View v) { switch (v.getId()) { // 轉換到改變密碼界面 case R.id.change_password_manager: Intent intentFromManager = getIntent(); String manager_name = intentFromManager .getStringExtra("manager_name"); intent = new Intent(ManagerMainFrame.this,ManagerChangerPassword.class); intent.putExtra("manager_name",manager_name); startActivityForResult(intent,1); break; // 更改自己的信息,轉換到該界面 case R.id.chekSelfMessage_manager: Intent intentFromManager2 = getIntent(); String manager_name2 = intentFromManager2 .getStringExtra("manager_name"); intent = new Intent(ManagerMainFrame.this,ManagerMessageActivity.class); intent.putExtra("name",manager_name2); startActivity(intent); break; // 查看所有學生信息 case R.id.check_all_student_manager: studentMessage(); break; // 查看所有老師信息 case R.id.check_all_teacher_manager: teacherMessage(); break; } } /** * 查看老師信息 */ private void teacherMessage() { // check_all_student_manager_textview.setText(""); Intent intentFromManager = getIntent(); String manager_name = intentFromManager.getStringExtra("manager_name"); sqliteDatabase db = sqliteDatabase.openOrCreateDatabase(getFilesDir() + "/database.db",null); Cursor cursor_step = db.rawQuery( "select control_step from allmanagermessage where Mno=?",new String[] { manager_name }); String step_message = null; if (cursor_step.moveToFirst()) step_message = cursor_step.getString(cursor_step .getColumnIndex("control_step")); cursor_step.close(); StringBuilder sb = new StringBuilder(step_message + "所有老师信息有\n"); Cursor cursor = db .rawQuery( "select allteachermessage.Tno," + "allteachermessage.Tname," + "allteachermessage.Tage," + "allteachermessage.Tsex," + "allteachermessage.T_Class," + "allteachermessage.T_Class_name " + "from allteachermessage,allmanagermessage " + "where allmanagermessage.control_step=allteachermessage.stepIN AND " + "allmanagermessage.control_step=?",new String[] { step_message }); int i = 0; while (cursor.moveToNext() && i < cursor.getCount() / 2) { String Tno = cursor.getString(cursor.getColumnIndex("Tno")); String Tname = cursor.getString(cursor.getColumnIndex("Tname")); String Tage = cursor.getString(cursor.getColumnIndex("Tage")); String Tsex = cursor.getString(cursor.getColumnIndex("Tsex")); String T_Class = cursor.getString(cursor.getColumnIndex("T_Class")); String T_Class_name = cursor.getString(cursor .getColumnIndex("T_Class_name")); sb.append("教师号").append(Tno + ","); sb.append("姓名:").append(Tname + ","); sb.append("年龄:").append(Tage + ","); sb.append("性别").append(Tsex + ","); sb.append("所教班级").append(T_Class + ","); sb.append("所教科目").append(T_Class_name + "\n"); i++; } cursor.close(); check_all_student_manager_textview.setText(sb.toString()); } /** * 查看自己管理學院的所有老師 */ private void studentMessage() { Intent intentFromManager = getIntent(); String manager_name = intentFromManager.getStringExtra("manager_name"); // check_all_student_manager_textview.setText(""); sqliteDatabase db = sqliteDatabase.openOrCreateDatabase(getFilesDir() + "/database.db",null); Cursor cursor_step = db.rawQuery( "select control_step from allmanagermessage where Mno=?",new String[] { manager_name }); String step_message = null; if (cursor_step.moveToFirst()) step_message = cursor_step.getString(cursor_step .getColumnIndex("control_step")); StringBuilder sb = new StringBuilder(step_message + "所有学生的部分信息有\n"); Cursor cursor = db .rawQuery( "select allstudentmessage.Sno," + "allstudentmessage.name," + "allstudentmessage.classIn," + "allstudentmessage.sex " + "from allstudentmessage,allmanagermessage " + "where allstudentmessage.stepIN=allmanagermessage.control_step AND " + "allmanagermessage.control_step=?",new String[] { step_message }); // Log.i("ManagerMainFrame",cursor.getCount()+""); int i = 0; while (cursor.moveToNext() && i < cursor.getCount() / 2) { String sno = cursor.getString(cursor.getColumnIndex("Sno")); String name = cursor.getString(cursor.getColumnIndex("name")); String classIn = cursor.getString(cursor.getColumnIndex("classIn")); String sex = cursor.getString(cursor.getColumnIndex("sex")); sb.append("学号:").append(sno + " ,"); sb.append("姓名:").append(name + ","); sb.append("班级:").append(classIn + ","); sb.append("性别:").append(sex + "\n"); i++; // Log.i("ManagerMainFrame",sno+name+classIn+sex); } check_all_student_manager_textview.setText(sb.toString()); } /** * 用于使用還回來Activity的數據 */ @Override protected void onActivityResult(int requestCode,int resultCode,Intent data) { if (1 == requestCode) if (2 == resultCode) { String manager_name = data.getStringExtra("manager_name"); intent.putExtra("manager_name",manager_name); } } private AlertDialog builder = null; /** * 用于設置退出提示 */ public boolean onKeyUp(int keyCode,KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { builder = new AlertDialog.Builder(ManagerMainFrame.this) .setTitle("温馨提示:") .setMessage("退出本程序?") .setPositiveButton("确定",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int whichButton) { ManagerMainFrame.this.finish(); } }) .setNegativeButton("取消",int whichButton) { builder.dismiss(); } }).show(); } return true; } }主布局文件:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="200dp" android:layout_height="wrap_content" android:text="@string/change_password" android:textColor="#000000" android:textSize="18sp" /> <Button android:id="@+id/change_password_manager" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="check_message_manager" android:text="@string/check_self_message" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="200dp" android:layout_height="wrap_content" android:text="@string/check_self_message_01" android:textColor="#000000" android:textSize="18sp" /> <Button android:id="@+id/chekSelfMessage_manager" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="check_message_manager" android:text="@string/check_self_message" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="200dp" android:layout_height="wrap_content" android:text="@string/check_all_student_manager" android:textColor="#000000" android:textSize="18sp" /> <Button android:id="@+id/check_all_student_manager" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="check_message_manager" android:text="@string/check_self_message" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="200dp" android:layout_height="wrap_content" android:text="@string/check_all_teacher_manager" android:textColor="#000000" android:textSize="18sp" /> <Button android:id="@+id/check_all_teacher_manager" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="check_message_manager" android:text="@string/check_self_message" /> </LinearLayout><pre name="code" class="java"><--!加入有多个数据需要显示,使用滚动条可以实现--><ScrollView android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/check_all_student_manager_textview" android:textSize="16sp" /></ScrollView></LinearLayout>
至此,所有的功能以及全部实现,需要源码可以留言,也可以去 广工数据库课设下载