老师用户的功能实现:更改密码,更改个人信息,还有事给自己班级对于课程名称的学生录入成绩
之前一篇分享过学生的更改密码和个人信息,老师的 *** 作与它相似,这里不重复。
对于录入成绩。需要显示的有那个学生,他的学号是什么,还有他的成绩,因为这些都是不定的,而且是从数据库中读取的,所以需要使用到一个ListVIEw来显示这些数据,ListVIEw的显示需要使用到相关条目和适配器,我的是自定义的适配器,当然大家可以使用SimpleAdapter,这样更简单,不过我只是想试一下自己能否自定义适配器使用而已。
TeacherMainActivity的代码:
public class TeacherMainFrame extends Activity{ private Intent intent; private ListVIEw teachet_ListvIEw; private DataBa@R_301_6892@penHelper helper; private button sure_score; private linearLayout showStudentPartMessage; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.teacher_main_frame); teachet_ListvIEw = (ListVIEw) findVIEwByID(R.ID.teachet_ListvIEw); helper = new DataBa@R_301_6892@penHelper(this); sure_score = (button)findVIEwByID(R.ID.sure_score); showStudentPartMessage = (linearLayout)findVIEwByID(R.ID.showStudentPartMessage); } /** * 统一使用这个点击事件名称管理在老师主界面的各个点击事件按,学生和管理员中也是类似 * @param v */ public voID check_message_teacher(VIEw v) { switch (v.getID()) { case R.ID.change_password_teacher://切换至更改老师密码界面 Intent intentFromTeacher = getIntent(); String teachername = intentFromTeacher .getStringExtra("teachername");//教师号是外码,传递之后用于查询密码表中对于教师号的密码 intent = new Intent(TeacherMainFrame.this,TeacherChangePassword.class); intent.putExtra("teachername",teachername); startActivityForResult(intent,1); break; case R.ID.chekSelfMessage_teacher://切换至更改老师个人信息界面 Intent intentFromTeacher2 = getIntent(); String teachername2 = intentFromTeacher2 .getStringExtra("teachername");//教师号是外码,不能够改变,所以需要在在个人信息中使用一个TextVIEw来显示 intent = new Intent(TeacherMainFrame.this,TeacherMessageActivity.class); intent.putExtra("name",teachername2); startActivity(intent); break; case R.ID.change_green_teacher://给自己班级所教科目的学生入炉成绩 teachet_ListvIEw.setVisibility(VIEw.VISIBLE); sure_score.setVisibility(VIEw.VISIBLE); showStudentPartMessage.setVisibility(VIEw.VISIBLE); change_score_teacher(); break; } } /** * 录入成绩 */ private voID change_score_teacher() { Intent intentFromTeacher = getIntent(); String teachername = intentFromTeacher.getStringExtra("teachername"); sqliteDatabase db = helper.getWritableDatabase(); Cursor cursor = db.rawquery( "select T_Class_name from allteachermessage where Tno=?",new String[] { teachername });//查询教师的个人信息 if (cursor.movetoFirst()) { String T_Class_name = cursor.getString(cursor .getColumnIndex("T_Class_name")); Cursor cursorscore = db .rawquery( "select allstudentmessage.name,allstudentmessage.Sno " + "from allstudentmessage,allteachermessage,dbS_C " + "where allstudentmessage.[classIn]=allteachermessage.T_Class " + "AND dbS_C.s_name=allstudentmessage.Sno " + "AND dbS_C.c_name=allteachermessage.T_Class_name" + " AND allteachermessage.[T_Class_name]=?",new String[] { T_Class_name });//查询老师所教班级对于自己所教科目的学生的学号,姓名两类信息 cursor.close(); List<Map<String,Object>> items = new ArrayList<Map<String,Object>>();//存放自己所教学生的信息的集合 while (cursorscore.movetoNext()) { String S_no = cursorscore.getString(cursorscore .getColumnIndex("allstudentmessage.Sno")); String name = cursorscore.getString(cursorscore .getColumnIndex("allstudentmessage.name")); Map<String,Object> item = new HashMap<String,Object>(); item.put("name",name);//学生的姓名 item.put("S_no",S_no);//学生的学号 item.put("score",0 + "");//学生默认成绩0 items.add(item);//添加到集合汇总 }<pre name="code" >
//SimpleAdapter adapter = new SimpleAdapter(this,items,R.layout.itm_teacher_for_score,new String[]{"name","S_no","score"},new int[]{R.ID.teacher_Sname,R.ID.teacher_Sno,R.ID.teacher_score});<span >//使用系统的适配器</span>TeacherBaseAdapter adapter = new TeacherBaseAdapter(this,R.layout.itm_teacher_for_score);teachet_ListvIEw.setAdapter(adapter);//绑定适配器}}/** * 点击确认按钮的时候发生的事件处理 * @param v */@Suppresslint("ShowToast")public voID sure_score_teacher(VIEw v){Intent intentFromTeacher = getIntent();String teachername = intentFromTeacher.getStringExtra("teachername");String class_name = null;sqliteDatabase db = helper.getReadableDatabase();Cursor cursor = db.rawquery("select T_Class_name from allteachermessage where Tno=?",new String[]{ teachername });if (cursor.movetoFirst()){class_name = cursor.getString(cursor.getColumnIndex("T_Class_name"));}cursor.close();
<span > </span>//遍历ListvIEw,把其中排在item第一二三个位置的textvIEw,edittext的值获得,从而插入数据库中for (int i = 0; i < teachet_ListvIEw.getChildCount(); i++){linearLayout layout = (linearLayout) teachet_ListvIEw.getChildAt(i);// 获得子item的layout// EditText et = (EditText) layout.findVIEwByID(R.ID.et);//// 从layout中获得控件,根据其ID// TextVIEw textVIEw01 = (TextVIEw) layout.getChildAt(0);TextVIEw textVIEw02 = (TextVIEw) layout.getChildAt(1);EditText et = (EditText) layout.getChildAt(2);// String name = textVIEw01.getText().toString();String S_no = textVIEw02.getText().toString();String score = et.getText().toString();Log.i("TeacherMainFrame",S_no + score);db.execsql("UPDATE dbS_C SET score=? WHERE s_name=? AND c_name=?",new Object[]{ score,S_no,class_name });//更新数据库,因为学生之前选课的时候是插入数据库,这里把对应的学生的数据插入到学生--课程表中Toast.makeText(getApplicationContext(),"录入成功",0).show();sure_score.setVisibility(VIEw.GONE);teachet_ListvIEw.setVisibility(VIEw.GONE);showStudentPartMessage.setVisibility(VIEw.GONE);}}protected voID onActivityResult(int requestCode,int resultCode,Intent data){if (1 == requestCode)if (2 == resultCode){String teachername = data.getStringExtra("teachername");intent.putExtra("teachername",teachername);}}private AlertDialog builder = null;public boolean onKeyUp(int keyCode,KeyEvent event){if (keyCode == KeyEvent.KEYCODE_BACK){builder = new AlertDialog.Builder(TeacherMainFrame.this).setTitle("温馨提示:").setMessage("退出本程序?").setPositivebutton("确定",new DialogInterface.OnClickListener(){public voID onClick(DialogInterface dialog,int whichbutton){TeacherMainFrame.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"><span > </span><!--更改密码 --> <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_teacher" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:onClick="check_message_teacher" androID:text="@string/check_self_message" /> </linearLayout><pre name="code" ><span > </span><!--更改个人信息 --><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_teacher" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:onClick="check_message_teacher" androID:text="@string/check_self_message" /> </linearLayout>
<span > </span><!--录入成绩 --><linearLayout androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:orIEntation="horizontal" >
<span > </span><!--显示所有的学生部分信息 --><TextVIEw androID:layout_wIDth="200dp" androID:layout_height="wrap_content" androID:text="@string/change_green_teacher_01" androID:textcolor="#000000" androID:textSize="18sp" />
<span > </span><!--去而录入 --><button androID:ID="@+ID/change_green_teacher" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:onClick="check_message_teacher" androID:text="@string/check_self_message" /> </linearLayout> <linearLayout androID:ID="@+ID/showStudentPartMessage" androID:layout_gravity="left" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:orIEntation="horizontal" androID:visibility="gone" > <TextVIEw androID:text="名字" androID:layout_wIDth="80dp" androID:layout_height="wrap_content" androID:layout_marginleft="30dp"/> <TextVIEw androID:text="学号" androID:layout_wIDth="80dp" androID:layout_height="wrap_content" androID:layout_marginleft="30dp"/> <TextVIEw androID:text="成绩" androID:layout_wIDth="80dp" androID:layout_height="wrap_content"/></linearLayout> <ListVIEw androID:ID="@+ID/teachet_ListvIEw" androID:focusable="true" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" > </ListVIEw> <button androID:ID="@+ID/sure_score" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:onClick="sure_score_teacher" androID:text="确定" androID:visibility="gone" /></linearLayout> 自定义的适配器
public class TeacherBaseAdapter extends BaseAdapter{ List<Map<String,Object>> items;//绑定放入数据 private int resouce;//绑定的数据 private LayoutInflater inflater;//布局填充器 public TeacherBaseAdapter (Context context,List<Map<String,Object>> items,int resouce) { super(); this.items = items; this.resouce = resouce; inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } /** * 得到数据的总数 */ public int getCount() { return items.size(); } /** * */ public Object getItem(int position) { return items.get(position); } public long getItemID(int position) { return position; } @Suppresslint("InflateParams") public VIEw getVIEw(int position,VIEw convertVIEw,VIEwGroup parent) { if(convertVIEw == null) { convertVIEw = inflater.inflate(resouce,null); } TextVIEw name = (TextVIEw) convertVIEw.findVIEwByID(R.ID.teacher_Sname); TextVIEw S_no = (TextVIEw) convertVIEw.findVIEwByID(R.ID.teacher_Sno); final EditText score = (EditText) convertVIEw.findVIEwByID(R.ID.teacher_score); Map<String,Object> item = items.get(position); name.setText((CharSequence) item.get("name")); S_no.setText((CharSequence) item.get("S_no")); score.setText((CharSequence) item.get("score")); return convertVIEw; }}关于老师更改个人信息,需要我们注意的是老师身为一个用户他需要有哪一些信息,我这里定义的有教师号,名字,年龄,性别(使用RadioGroup),所在学院,所教科目,所教班级,然后所教科目使用一个单选的对话框实现,从数据库查询有哪些课程。其他的雨学生用户的 *** 作类似。还有最后一次是关于管理员用户的。下一篇再与大家分享。 总结
以上是内存溢出为你收集整理的SQLite数据库实例四全部内容,希望文章能够帮你解决SQLite数据库实例四所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)