




已閱讀5頁,還剩23頁未讀, 繼續(xù)免費閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領
文檔簡介
Android學生信息管理系統(tǒng)APP1、 需求分析為了方便的進行對學生數(shù)據(jù)庫的操作,本app可在android設備上進行對學生信息數(shù)據(jù)庫的信息管理功能,具體功能如下:1.對數(shù)據(jù)庫中所有學生姓名進行顯示,對各個條目進行點擊可展開具體信息2. 查詢數(shù)據(jù):查詢數(shù)據(jù)是根據(jù)姓名與學號兩個條件進行查詢,兩者滿足任一條件則進行模糊查詢,兩個條件同時滿足則進行精確查詢,查詢結(jié)果界面與功能一中相同,以姓名排列,點擊展開所有信息3. 增加數(shù)據(jù):在數(shù)據(jù)庫中增添條目,包括姓名(字符串),學號(數(shù)字,主鍵),性別(單選框),年齡(數(shù)字),專業(yè)(字符串)。每個條目均有誤輸入設定,且主鍵可檢查重復性,所有數(shù)據(jù)可檢查完整性,若插入成功則會顯示一條消息提示成功,若失敗則會提示檢查主鍵重復或者數(shù)據(jù)不完整4. 修改數(shù)據(jù):根據(jù)姓名學號進行精確查找,查找成功后轉(zhuǎn)入修改界面,為了防止漏填與便捷修改界面會默認填充之前的數(shù)據(jù)(除學號),修改完畢即可更新,同樣會檢查數(shù)據(jù)完整性5. 刪除數(shù)據(jù):根據(jù)姓名學號進行精確查找,查找成功則會進行刪除,并顯示一條刪除成功的提示,若失敗,也會進行提示2、 概念結(jié)構(gòu)設計 ER圖:3、 邏輯結(jié)構(gòu)設計學生:姓名(字符串)學號(數(shù)字,主碼)性別(單選框)年齡(數(shù)字)專業(yè)(字符串)create table student(name TEXT,NO TEXT Primary Key,sex TEXT,profession TEXT,age TEXT)4、 具體實現(xiàn)1.主界面:主界面顯示所有功能,每個按鈕點擊后,跳轉(zhuǎn)進入相應功能核心代碼: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(Window.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.getFilesDir().toString()+/Student.db3, null);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);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ù)按鈕的功能實現(xiàn)btn_show.setOnClickListener(new OnClickListener()public void onClick(View source) /獲取指針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() ; !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(); = 姓名:+cursor.getString(nameColume);student.NO = 學號:+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);String 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ù)傳遞給結(jié)果界面的activityIntent intent = new Intent(Main.this,SearchResult.class);intent.putExtras(bundle);intent.putExtra(data, data);startActivity(intent);cursor.close(););/為剩下的按鈕綁定監(jiān)聽器實現(xiàn)跳轉(zhuǎn)功能btn_search.setOnClickListener(new OnClickListener()public void 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 OnClickListener()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(new OnClickListener()public void onClick(View source) db.close();finish(););2. 數(shù)據(jù)顯示界面:按姓名排列,點擊條目展開具體信息核心代碼:public class SearchResult extends ActivitySuppressLint(RtlHardcoded)public void onCreate(Bundle savedInstanceState)requestWindowFeature(Window.FEATURE_NO_TITLE);getWindow().setFlags(WindowManager.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();Student 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)return childPosition;public int getChildrenCount(int groupPosition)return datagroupPosition.length;/設定每個子選項每行的顯示方式private TextView getTextView()AbsListView.LayoutParams lp = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);TextView textView = new TextView(SearchResult.this);textView.setLayoutParams(lp);textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);textView.setPadding(36, 0, 0, 0);textView.setTextSize(20);return textView;/設定每個子選項顯示內(nèi)容public View getChildView(int groupPosition , int childPosition,boolean isLastChild,View convertView,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)return groupPosition;/設定每個組選項顯示內(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.addView(textView);return ll;ExpandableListView expandListView = (ExpandableListView) findViewById(R.id.list);expandListView.setAdapter(adapter);3. 增添數(shù)據(jù)界面:根據(jù)文本框輸入內(nèi)容進行數(shù)據(jù)的插入,且具有完整性和重復性的判斷,插入成功失敗均會產(chǎn)生提示核心代碼:public class Add extends Activity SQLiteDatabase db;Button btn_Accept;Button btn_Cancle;TextView ET_name;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);super.onCreate(savedInstanceState);setContentView(R.layout.layout_add);db = SQLiteDatabase.openDatabase(this.getFilesDir().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) findViewById(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 onCheckedChanged(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.getText().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ù)失敗,請檢查數(shù)據(jù)規(guī)范性與學號的唯一性, Toast.LENGTH_SHORT).show();return;Toast.makeText(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ù)界面:查找界面:對文本框內(nèi)輸入的數(shù)據(jù)進行精確查找,成功后轉(zhuǎn)入修改界面修改界面:文本框內(nèi)默認顯示之前的數(shù)據(jù),修改完成點擊確定以文本框內(nèi)的信息對數(shù)據(jù)進行更新核心代碼:查找:btn_Accept.setOnClickListener(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)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(name);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(proColume);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 intent = 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 ActivitySQLiteDatabase 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);setContentView(R.layout.layout_modifyresult);/獲取數(shù)據(jù)final Intent intent = getIntent();Bundle bundle = intent.getExtras();db = SQLiteDatabase.openDatabase(this.getFilesDir().toString()+/Student.db3, null,SQLiteDatabase.OPEN_READWRITE);btn_accept = (Button) findViewById(R.id.btn_modifyresult_accept);btn_cancle = (Button) findViewById(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 = (EditText) findViewById(R.id.ET_ModifyResult_age);rg = (RadioGroup) findViewById(R.id.modify_rg);/設定默認數(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_ModifyResult_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.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.execSQL(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_SHORT).show();finish(););btn_cancle.setOnClickListener(new OnClickListener()public void onClick(View source) db.close();finish(););5. 查找數(shù)據(jù)界面:對文本框內(nèi)的數(shù)據(jù)進行模糊查詢,查詢成功則跳轉(zhuǎn)只查詢結(jié)果界面,查詢失敗則產(chǎn)生相應提示核心代碼:public class Search extends Activity SQLiteDatabase db;Button btn_Accept;Button btn_Cancle;EditText ET_name;EditText 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 = SQLiteDatabase.openDatabase(this.getFilesDir().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.ET_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 name, NO);/檢驗查找是否為空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() ; !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(); = 姓名:+cursor.getString(nameColume);student.NO = 學號:+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);String 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_i
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 噴漆臨時工合同范本
- 吊車與電力安裝合同范例
- 破局與重塑:高中物理新課程科學探究實施的深度剖析與路徑探索
- 物聯(lián)網(wǎng)資源共享平臺數(shù)據(jù)建模與實現(xiàn)的深度剖析與實踐探索
- 2024中國建材集團有限公司清華大學校園招聘筆試參考題庫附帶答案詳解
- 2025至2031年中國萊板拖行業(yè)投資前景及策略咨詢研究報告
- 回購股合同范本
- 全案設計代購合同范例
- 品牌加盟轉(zhuǎn)讓合同范本
- 個人投資企業(yè)合同范本
- 2024年山東省濰坊市中考數(shù)學真題試題(含答案及解析)
- 開票稅點自動計算器
- 2024年湖南新課標卷高考生物真題試卷(無答案)
- 2024年江蘇農(nóng)牧科技職業(yè)學院單招職業(yè)適應性測試題庫及參考答案
- 醫(yī)療器械質(zhì)量安全風險會商管理制度
- 降低用藥錯誤發(fā)生率
- 起重機維護保養(yǎng)記錄表
- 焦慮自評量表(SAS)
- 《攝影構(gòu)圖》課件
- 患者轉(zhuǎn)運意外應急預案
- 大學生國防教育教案第四章現(xiàn)代戰(zhàn)爭
評論
0/150
提交評論