版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、Android學(xué)生信息管理系統(tǒng)APP1、 需求分析為了方便的進(jìn)行對(duì)學(xué)生數(shù)據(jù)庫的操作,本app可在android設(shè)備上進(jìn)行對(duì)學(xué)生信息數(shù)據(jù)庫的信息管理功能,具體功能如下:1.對(duì)數(shù)據(jù)庫中所有學(xué)生姓名進(jìn)行顯示,對(duì)各個(gè)條目進(jìn)行點(diǎn)擊可展開具體信息2. 查詢數(shù)據(jù):查詢數(shù)據(jù)是根據(jù)姓名與學(xué)號(hào)兩個(gè)條件進(jìn)行查詢,兩者滿足任一條件則進(jìn)行模糊查詢,兩個(gè)條件同時(shí)滿足則進(jìn)行精確查詢,查詢結(jié)果界面與功能一中相同,以姓名排列,點(diǎn)擊展開所有信息3. 增加數(shù)據(jù):在數(shù)據(jù)庫中增添?xiàng)l目,包括姓名(字符串),學(xué)號(hào)(數(shù)字,主鍵),性別(單選框),年齡(數(shù)字),專業(yè)(字符串)。每個(gè)條目均有誤輸入設(shè)定,且主鍵可檢查重復(fù)性,所有數(shù)據(jù)可檢查完整性,
2、若插入成功則會(huì)顯示一條消息提示成功,若失敗則會(huì)提示檢查主鍵重復(fù)或者數(shù)據(jù)不完整4. 修改數(shù)據(jù):根據(jù)姓名學(xué)號(hào)進(jìn)行精確查找,查找成功后轉(zhuǎn)入修改界面,為了防止漏填與便捷修改界面會(huì)默認(rèn)填充之前的數(shù)據(jù)(除學(xué)號(hào)),修改完畢即可更新,同樣會(huì)檢查數(shù)據(jù)完整性5. 刪除數(shù)據(jù):根據(jù)姓名學(xué)號(hào)進(jìn)行精確查找,查找成功則會(huì)進(jìn)行刪除,并顯示一條刪除成功的提示,若失敗,也會(huì)進(jìn)行提示2、 概念結(jié)構(gòu)設(shè)計(jì) ER圖:3、 邏輯結(jié)構(gòu)設(shè)計(jì)學(xué)生:姓名(字符串)學(xué)號(hào)(數(shù)字,主碼)性別(單選框)年齡(數(shù)字)專業(yè)(字符串)create table student(name TEXT,NO TEXT Primary Key,sex TEXT,prof
3、ession TEXT,age TEXT)4、 具體實(shí)現(xiàn)1.主界面:主界面顯示所有功能,每個(gè)按鈕點(diǎn)擊后,跳轉(zhuǎn)進(jìn)入相應(yīng)功能核心代碼:public class Main extends Activity SQLiteDatabase db;Button btn_search;Button btn_modify;Button btn_add;Button btn_delete;Button btn_quit;Button btn_show;Overrideprotected void onCreate(Bundle savedInstanceState) requestWindowFeature(W
4、indow.FEATURE_NO_TITLE);getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);super.onCreate(savedInstanceState);setContentView(R.layout.layout_main);/打開數(shù)據(jù)庫,若不存在,則創(chuàng)建db = SQLiteDatabase.openOrCreateDatabase(this.get().toString()+/Student.db3, nul
5、l);btn_search = (Button) findViewById(R.id.btn_search);btn_modify = (Button) findViewById(R.id.btn_modify);btn_add = (Button) findViewById(R.id.btn_add);btn_delete = (Button) findViewById(R.id.btn_delete);btn_quit = (Button) findViewById(R.id.btn_quit);btn_show = (Button) findViewById(R.id.Btn_show)
6、;tryCursor cursor = db.rawQuery(select * from student, null);cursor.close();catch(SQLiteException e)db.execSQL(create table student+ (+ name TEXT,+ NO TEXT Primary Key,+ sex TEXT,+ profession TEXT,+ age TEXT+ );/顯示所有數(shù)據(jù)按鈕的功能實(shí)現(xiàn)btn_show.setOnClickListener(new OnClickListener()public void onClick(View s
7、ource) /獲取指針Cursor cursor = db.rawQuery(select * from student, null);/判斷數(shù)據(jù)庫是否不存在任何數(shù)據(jù)if(cursor.moveToFirst() = false)Toast.makeText(Main.this, 不存在記錄, Toast.LENGTH_SHORT).show();elseList p = new ArrayList();List re_name = new ArrayList();List info = new ArrayList();/保存搜索出的所有數(shù)據(jù)for(cursor.moveToFirst()
8、; !cursor.isAfterLast() ; cursor.moveToNext()int nameColume = cursor.getColumnIndex(name);int NOColume = cursor.getColumnIndex(NO);int proColume = cursor.getColumnIndex(profession);int sexColume = cursor.getColumnIndex(sex);int ageColume = cursor.getColumnIndex(age);Student student = new Student();s
9、 = 姓名:+cursor.getString(nameColume);student.NO = 學(xué)號(hào):+cursor.getString(NOColume);student.sex = 性別:+cursor.getString(sexColume);fession = 專業(yè):+cursor.getString(proColume);student.age = 年齡:+cursor.getString(ageColume);p.add(student);String temp = student.MakeString();info.add(temp)
10、;String newname = cursor.getString(nameColume);re_name.add(newname);/對(duì)保存的數(shù)據(jù)進(jìn)行封裝String Cur_name = new Stringre_name.size();Cur_name = re_name.toArray(Cur_name);String Cur_info = new Stringinfo.size();Cur_info = info.toArray(Cur_info);Bundle bundle = new Bundle();bundle.putStringArray(name, Cur_name);
11、Student data = new Student(); = Cur_info;/將封裝的數(shù)據(jù)傳遞給結(jié)果界面的activityIntent intent = new Intent(Main.this,SearchResult.class);intent.putExtras(bundle);intent.putExtra(data, data);startActivity(intent);cursor.close(););/為剩下的按鈕綁定監(jiān)聽器實(shí)現(xiàn)跳轉(zhuǎn)功能btn_search.setOnClickListener(new OnClickListener()public vo
12、id onClick(View source) Intent intent = new Intent(Main.this,Search.class);startActivity(intent););btn_modify.setOnClickListener(new OnClickListener()public void onClick(View source) Intent intent = new Intent(Main.this,Modify.class);startActivity(intent););btn_add.setOnClickListener(new OnClickList
13、ener()public void onClick(View source) Intent intent = new Intent(Main.this,Add.class);startActivity(intent););btn_delete.setOnClickListener(new OnClickListener()public void onClick(View source) Intent intent = new Intent(Main.this,Delete.class);startActivity(intent););btn_quit.setOnClickListener(ne
14、w OnClickListener()public void onClick(View source) db.close();finish(););2. 數(shù)據(jù)顯示界面:按姓名排列,點(diǎn)擊條目展開具體信息核心代碼:public class SearchResult extends ActivitySuppressLint(RtlHardcoded)public void onCreate(Bundle savedInstanceState)requestWindowFeature(Window.FEATURE_NO_TITLE);getWindow().setFlags(WindowManager
15、.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);/獲取傳送來的數(shù)據(jù)super.onCreate(savedInstanceState);setContentView(R.layout.layout_result);final Intent intent = getIntent();BaseExpandableListAdapter adapter = new BaseExpandableListAdapter()/提取數(shù)據(jù)Bundle bundle = intent.getExtras();S
16、tudent mem_data = (Student) getIntent().getExtras().get(data);String people = (String) bundle.getSerializable(name);String data = mem_;public Object getChild(int groupPosition,int childPosition)return datagroupPositionchildPosition;public long getChildId(int groupPosition,int childPosition)
17、return childPosition;public int getChildrenCount(int groupPosition)return datagroupPosition.length;/設(shè)定每個(gè)子選項(xiàng)每行的顯示方式private TextView getTextView()AbsListView.LayoutParams lp = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);TextView textView = new
18、 TextView(SearchResult.this);textView.setLayoutParams(lp);textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);textView.setPadding(36, 0, 0, 0);textView.setTextSize(20);return textView;/設(shè)定每個(gè)子選項(xiàng)顯示內(nèi)容public View getChildView(int groupPosition , int childPosition,boolean isLastChild,View convertV
19、iew,ViewGroup Parent)TextView textView = getTextView();textView.setText( +getChild(groupPosition,childPosition).toString();return textView;public Object getGroup(int groupPosition)return peoplegroupPosition;public int getGroupCount()return people.length;public long getGroupId(int groupPosition)retur
20、n groupPosition;/設(shè)定每個(gè)組選項(xiàng)顯示內(nèi)容public View getGroupView(int groupPosition, boolean isExpanded ,View convertView , ViewGroup parnet)LinearLayout ll = new LinearLayout(SearchResult.this);ll.setOrientation(0);TextView textView = getTextView();textView.setText( +getGroup(groupPosition).toString();ll.addVie
21、w(textView);return ll;ExpandableListView expandListView = (ExpandableListView) findViewById(R.id.list);expandListView.setAdapter(adapter);3. 增添數(shù)據(jù)界面:根據(jù)文本框輸入內(nèi)容進(jìn)行數(shù)據(jù)的插入,且具有完整性和重復(fù)性的判斷,插入成功失敗均會(huì)產(chǎn)生提示核心代碼:public class Add extends Activity SQLiteDatabase db;Button btn_Accept;Button btn_Cancle;TextView ET_name
22、;TextView ET_NO;TextView ET_Pro;TextView ET_Age;RadioGroup rg;String radio_sex = 男;Overrideprotected void onCreate(Bundle savedInstanceState) requestWindowFeature(Window.FEATURE_NO_TITLE);getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);sup
23、er.onCreate(savedInstanceState);setContentView(R.layout.layout_add);db = SQLiteDatabase.openDatabase(this.get().toString()+/Student.db3, null,SQLiteDatabase.OPEN_READWRITE);btn_Accept = (Button) findViewById(R.id.btn_Accept);btn_Cancle = (Button) findViewById(R.id.btn_Cancle);ET_name = (TextView) fi
24、ndViewById(R.id.ET_Add_name);ET_NO = (TextView) findViewById(R.id.ET_Add_NO);ET_Pro = (TextView) findViewById(R.id.ET_Add_Pro);ET_Age = (TextView) findViewById(R.id.ET_Add_Age);rg = (RadioGroup) findViewById(R.id.rg);rg.setOnCheckedChangeListener(new OnCheckedChangeListener()public void onCheckedCha
25、nged(RadioGroup group, int CheckedId)radio_sex = CheckedId = R.id.rad_male ? 男 : 女;);/提交操作btn_Accept.setOnClickListener(new OnClickListener()public void onClick(View source) String name = ET_name.getText().toString();String NO = ET_NO.getText().toString();String sex = radio_sex;String pro = ET_Pro.g
26、etText().toString();String age = ET_Age.getText().toString();/規(guī)范性與完整性判斷try/插入數(shù)據(jù)db.execSQL(insert into student values( ?, ?, ?, ?, ?),new String name, NO, sex, pro, age);/規(guī)范性與完整性判斷catch(SQLiteException e)Toast.makeText(Add.this, 插入數(shù)據(jù)失敗,請(qǐng)檢查數(shù)據(jù)規(guī)范性與學(xué)號(hào)的唯一性, Toast.LENGTH_SHORT).show();return;Toast.makeText
27、(Add.this, 成功插入一條數(shù)據(jù):+n+name+n+NO+n+sex+n+pro+n+age, Toast.LENGTH_SHORT).show(););btn_Cancle.setOnClickListener(new OnClickListener()public void onClick(View source) db.close();finish(););4. 修改數(shù)據(jù)界面:查找界面:對(duì)文本框內(nèi)輸入的數(shù)據(jù)進(jìn)行精確查找,成功后轉(zhuǎn)入修改界面修改界面:文本框內(nèi)默認(rèn)顯示之前的數(shù)據(jù),修改完成點(diǎn)擊確定以文本框內(nèi)的信息對(duì)數(shù)據(jù)進(jìn)行更新核心代碼:查找:btn_Accept.setOnClickL
28、istener(new OnClickListener()public void onClick(View source) String name = ET_Modify_Name.getText().toString();String NO = ET_Modify_No.getText().toString();Cursor cursor = db.rawQuery(select * from student where + name=? + and NO=? , new String name, NO);/判斷查找結(jié)果是否為空if(cursor.moveToFirst() = false)
29、Toast.makeText(Modify.this, 記錄不存在, Toast.LENGTH_SHORT).show();elseString mem_name = null;String mem_No = null;String mem_profession = null;String mem_sex = null;String mem_age = null;/保存所有數(shù)據(jù)for(cursor.moveToFirst() ; !cursor.isAfterLast() ; cursor.moveToNext()int nameColume = cursor.getColumnIndex(n
30、ame);int NoColume = cursor.getColumnIndex(NO);int proColume = cursor.getColumnIndex(profession);int sexColume = cursor.getColumnIndex(sex);int ageColume = cursor.getColumnIndex(age);mem_name = cursor.getString(nameColume);mem_No = cursor.getString(NoColume);mem_profession = cursor.getString(proColum
31、e);mem_sex = cursor.getString(sexColume);mem_age = cursor.getString(ageColume);/封裝所有數(shù)據(jù)Bundle bundle = new Bundle();bundle.putString(name, mem_name);bundle.putString(No, mem_No);bundle.putString(profession, mem_profession);bundle.putString(sex, mem_sex);bundle.putString(age, mem_age);/傳遞數(shù)據(jù)Intent inte
32、nt = new Intent(Modify.this,ModifyResult.class);intent.putExtras(bundle);startActivity(intent);cursor.close(););btn_Cancle.setOnClickListener(new OnClickListener()public void onClick(View source) / TODO Auto-generated method stubdb.close();finish(););修改:public class ModifyResult extends ActivitySQLi
33、teDatabase db;Button btn_accept;Button btn_cancle;TextView TextView_ModifyResult_No;EditText ET_ModifyResult_Name;EditText ET_ModifyResult_pro;EditText ET_ModifyResult_age;RadioGroup rg;String radio_sex;protected void onCreate(Bundle savedInstanceState)super.onCreate(savedInstanceState);setContentVi
34、ew(R.layout.layout_modifyresult);/獲取數(shù)據(jù)final Intent intent = getIntent();Bundle bundle = intent.getExtras();db = SQLiteDatabase.openDatabase(this.get().toString()+/Student.db3, null,SQLiteDatabase.OPEN_READWRITE);btn_accept = (Button) findViewById(R.id.btn_modifyresult_accept);btn_cancle = (Button) f
35、indViewById(R.id.btn_modifyresult_cancle);TextView_ModifyResult_No = (TextView) findViewById(R.id.TextView_ModifyResult_No);ET_ModifyResult_Name = (EditText) findViewById(R.id.ET_ModifyResult_Name);ET_ModifyResult_pro = (EditText) findViewById(R.id.ET_ModifyResult_pro);ET_ModifyResult_age = (EditTex
36、t) findViewById(R.id.ET_ModifyResult_age);rg = (RadioGroup) findViewById(R.id.modify_rg);/設(shè)定默認(rèn)數(shù)據(jù)String name = bundle.getString(name);final String No = bundle.getString(No);String pro = bundle.getString(profession);String age = bundle.getString(age);radio_sex = bundle.getString(sex);TextView_ModifyRe
37、sult_No.setText(No);ET_ModifyResult_Name.setText(name);ET_ModifyResult_pro.setText(pro);ET_ModifyResult_age.setText(age);rg.setOnCheckedChangeListener(new OnCheckedChangeListener()public void onCheckedChanged(RadioGroup group, int CheckedId)radio_sex = CheckedId = R.id.rad_male ? 男 : 女;);btn_accept.
38、setOnClickListener(new OnClickListener()public void onClick(View source) String new_name = ET_ModifyResult_Name.getText().toString();String new_profession = ET_ModifyResult_pro.getText().toString();String new_age = ET_ModifyResult_age.getText().toString();String new_sex = radio_sex;/更新數(shù)據(jù)trydb.execSQ
39、L(UPDATE student + SET name=? ,NO=? ,sex=? ,profession=? ,age=? + WHERE NO=?,new String new_name , No , new_sex , new_profession , new_age , No);catch(SQLiteException e)Toast.makeText(ModifyResult.this, 更新數(shù)據(jù)失敗, Toast.LENGTH_SHORT).show();return;Toast.makeText(ModifyResult.this, 更新數(shù)據(jù)成功, Toast.LENGTH_
40、SHORT).show();finish(););btn_cancle.setOnClickListener(new OnClickListener()public void onClick(View source) db.close();finish(););5. 查找數(shù)據(jù)界面:對(duì)文本框內(nèi)的數(shù)據(jù)進(jìn)行模糊查詢,查詢成功則跳轉(zhuǎn)只查詢結(jié)果界面,查詢失敗則產(chǎn)生相應(yīng)提示核心代碼:public class Search extends Activity SQLiteDatabase db;Button btn_Accept;Button btn_Cancle;EditText ET_name;EditT
41、ext ET_NO;Overrideprotected void onCreate(Bundle savedInstanceState) requestWindowFeature(Window.FEATURE_NO_TITLE);getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);super.onCreate(savedInstanceState);setContentView(R.layout.layout_search);db
42、 = SQLiteDatabase.openDatabase(this.get().toString()+/Student.db3, null,SQLiteDatabase.OPEN_READWRITE);btn_Accept = (Button) findViewById(R.id.btn_Accept);btn_Cancle = (Button) findViewById(R.id.btn_Cancle);ET_name = (EditText) findViewById(R.id.ET_Search_name);ET_NO = (EditText) findViewById(R.id.E
43、T_Search_NO);btn_Accept.setOnClickListener(new OnClickListener()public void onClick(View source) String name = ET_name.getText().toString();String NO = ET_NO.getText().toString();/獲取指針Cursor cursor = db.rawQuery(select * from student where + name=? /+ or + name=?+ or NO=? /+ or + NO=?, new String na
44、me, NO);/檢驗(yàn)查找是否為空if(cursor.moveToFirst() = false)Toast.makeText(Search.this, 記錄不存在, Toast.LENGTH_SHORT).show();elseToast.makeText(Search.this, 成功, Toast.LENGTH_SHORT).show();/return;List p = new ArrayList();List re_name = new ArrayList();List info = new ArrayList();/保存數(shù)據(jù)for(cursor.moveToFirst() ; !c
45、ursor.isAfterLast() ; cursor.moveToNext()int nameColume = cursor.getColumnIndex(name);int NOColume = cursor.getColumnIndex(NO);int proColume = cursor.getColumnIndex(profession);int sexColume = cursor.getColumnIndex(sex);int ageColume = cursor.getColumnIndex(age);Student student = new Student();stude
46、 = 姓名:+cursor.getString(nameColume);student.NO = 學(xué)號(hào):+cursor.getString(NOColume);student.sex = 性別:+cursor.getString(sexColume);fession = 專業(yè):+cursor.getString(proColume);student.age = 年齡:+cursor.getString(ageColume);p.add(student);String temp = student.MakeString();info.add(temp);Str
47、ing newname = cursor.getString(nameColume);re_name.add(newname);/封裝數(shù)據(jù)String Cur_name = new Stringre_name.size();Cur_name = re_name.toArray(Cur_name);String Cur_info = new Stringinfo.size();Cur_info = info.toArray(Cur_info);Bundle bundle = new Bundle();bundle.putStringArray(name, Cur_name);Student data = new Student(); = Cur_info;/傳遞數(shù)據(jù)Intent intent = new Inten
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 美容院美容師聘用合同
- 互聯(lián)網(wǎng)企業(yè)知識(shí)產(chǎn)權(quán)保護(hù)
- 體育場(chǎng)館地彈門安裝協(xié)議
- 運(yùn)輸賓館安全運(yùn)輸指南
- 供應(yīng)鏈效率末尾淘汰制管理辦法
- 政府會(huì)議出行服務(wù)合同
- 劇院停車場(chǎng)運(yùn)營(yíng)辦法
- 化工項(xiàng)目招投標(biāo)風(fēng)險(xiǎn)防控
- 4S汽車店消防泵房施工協(xié)議
- 會(huì)議中心隔音墻施工協(xié)議
- 第二章作物需水量和灌溉用水量
- 深圳航空飛行品質(zhì)監(jiān)控系統(tǒng)(FOQA)需求規(guī)格說明書 V2.0
- 消防員培訓(xùn)匯總課件
- 帶強(qiáng)調(diào)事項(xiàng)段的保留意見的審計(jì)報(bào)告參考格式1400字
- 婦聯(lián)婚姻家庭矛盾糾紛化解工作匯報(bào)總結(jié)報(bào)告4篇
- 六年級(jí)數(shù)學(xué)老師家長(zhǎng)會(huì)課件PPT
- 非計(jì)劃性拔管的應(yīng)急預(yù)案
- 幼兒園課件:時(shí)鐘國(guó)王
- 湘美版高中美術(shù)-《變化中的審美》課件
- WSET二級(jí)及考試習(xí)題集錦
- 醫(yī)藥招商策略
評(píng)論
0/150
提交評(píng)論