版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
XXX(設(shè)計(jì))I附錄用戶登錄publicclassloginActivityextendsActivity{ privateEditTextnumText;//輸入用戶名編輯框 privateEditTextpswdText;//輸入密碼編輯框 privateHandlerloginHandler;//信息處理機(jī) privateProgressDialogproDialog;//進(jìn)度條 @Override publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.login); numText=(EditText)this.findViewById(R.id.num); pswdText=(EditText)this.findViewById(R.id.pswd); ButtonlogButton=(Button)this.findViewById(R.id.login); loginHandler=newHandler(){//消息處理機(jī)制,主線程控制界面更新 @Override publicvoidhandleMessage(Messagemsg){ Bundlebundle=msg.getData(); booleanloginResult=(Boolean)bundle.get("isNetError");//獲取登陸失敗標(biāo)志位 if(proDialog!=null){ proDialog.dismiss(); } booleanisNet=isNetWorkAvailable(loginActivity.this); if(!isNet){ Toast.makeText(loginActivity.this,"當(dāng)前網(wǎng)絡(luò)不可用", Toast.LENGTH_SHORT).show(); } if(!loginResult){ Toast.makeText(loginActivity.this,"錯(cuò)誤的用戶名或密碼", Toast.LENGTH_SHORT).show(); } super.handleMessage(msg); } }; logButton.setOnClickListener(newView.OnClickListener(){//登錄點(diǎn)擊 @Override publicvoidonClick(Viewv){ //TODOAuto-generatedmethodstub try{ proDialog=ProgressDialog.show(loginActivity.this,"請(qǐng)稍候", "正在登陸...",true,true); ThreadloginThread=newThread(newLoginFailureHandler()); loginThread.start();//子線程開(kāi)啟 }catch(Exceptione){ } } }); } privateclassLoginFailureHandlerimplementsRunnable{ @Override publicvoidrun(){ Stringnum=numText.getText().toString(); Stringpswd=pswdText.getText().toString(); Map<String,String>params=newHashMap<String,String>(); params.put("usernum",num); params.put("pswd",pswd); booleanloginState=HttpUtils.sendPostMessage(params,"utf-8"); if(loginState){ Intentintent=newIntent(loginActivity.this, CalendarActivity.class);//登錄成功實(shí)現(xiàn)界面跳轉(zhuǎn)intent.putExtra("user",num); startActivity(intent); proDialog.dismiss(); }else{ Messagemessage=newMessage();//登錄失敗返回錯(cuò)誤標(biāo)志位 Bundlebundle=newBundle(); bundle.putBoolean("isNetError",loginState); message.setData(bundle); loginHandler.sendMessage(message); } } } publicstaticbooleanisNetWorkAvailable(Contextcontext){//檢測(cè)網(wǎng)絡(luò)是否連接 ConnectivityManagercm=(ConnectivityManager)context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfoinfo=cm.getActiveNetworkInfo(); returninfo!=null&&info.isConnected(); }}帶寬信息預(yù)訂@Override publicvoidonClick(Viewv){ switch(v.getId()){ caseR.id.sure://點(diǎn)擊提交按鈕,提交預(yù)訂請(qǐng)求 if(savebandwith()){ try{ proDialog=ProgressDialog.show(setbandwith.this,"請(qǐng)稍候", "正在提交...",true,true); ThreadbookThread=newThread(newbookHandler()); bookThread.start(); }catch(Exceptione){} }else{} break; caseR.id.quit://點(diǎn)擊返回按鈕,返回到帶寬信息顯示界面 setbandwith.this.finish(); break; caseR.id.sTime://點(diǎn)擊設(shè)置開(kāi)始時(shí)間的控件 starttime(); break; caseR.id.eTime://點(diǎn)擊設(shè)置終止時(shí)間的控件 endtime(); break; caseR.id.ngbandwith://點(diǎn)擊設(shè)置保證帶寬的控件 showDialoggbw(); break; caseR.id.nmbandwith://點(diǎn)擊設(shè)置最大帶寬的控件 showDialogmbw(); break; default: break; } }privatebooleansavebandwith(){//將帶寬信息存入本地?cái)?shù)據(jù)庫(kù)中 if(ehour==0&&eminute==0){ ehour=24; eminute=0; } shour0=String.valueOf(shour); sminute0=String.valueOf(sminute); ehour0=String.valueOf(ehour); eminute0=String.valueOf(eminute); if(shour<10){ shour0="0"+shour; } if(sminute<10){ sminute0="0"+sminute; } if(ehour<10){ ehour0="0"+ehour; } if(eminute<10){ eminute0="0"+eminute; } start=shour*60+sminute; end=ehour*60+eminute; if(start<end){ scheduleIDs=dao.getBandwithByTagDate( Integer.parseInt(dadaInfoString[0]), Integer.parseInt(dadaInfoString[1]), Integer.parseInt(dadaInfoString[2])); if(scheduleIDs!=null&&scheduleIDs.length>0){ if(insertTag(shour,sminute,ehour,eminute)){ tag=true; } } if(scheduleIDs.length==0||tag){ setbandwithvo=newSetBandwithVO(); setbandwithvo.setBandwithDate(toptime); setbandwithvo.setYearmonthday(ymd); setbandwithvo.setStarttime(shour0+":"+sminute0); setbandwithvo.setEndtime(ehour0+":"+eminute0); setbandwithvo.setShour(shour); setbandwithvo.setSminute(sminute); setbandwithvo.setEhour(ehour); setbandwithvo.setEminute(eminute); setbandwithvo.setGbandwith(Integer.parseInt(gbandwith.getText() .toString())); setbandwithvo.setMbandwith(Integer.parseInt(mbandwith.getText() .toString())); bandwithID=dao.save(setbandwithvo); setScheduleDateTag(yearString,monthString,dayString, bandwithID); flag=true; deleteBandwithvo=dao.getBandwithByID(this,bandwithID); }else{ Toast.makeText(setbandwith.this,"時(shí)間范圍設(shè)置有沖突!",Toast.LENGTH_LONG).show(); //showInfo("時(shí)間范圍設(shè)置有沖突!"); } }else{ Toast.makeText(setbandwith.this,"終止時(shí)間必須大于起始時(shí)間!",Toast.LENGTH_LONG).show(); //showInfo("終止時(shí)間必須大于起始時(shí)間!"); } returnflag; }//子線程中將帶寬信息數(shù)據(jù)打包成json格式傳遞給服務(wù)器privateclassbookHandlerimplementsRunnable{ @Override publicvoidrun(){ JSONObjectClientKey=newJSONObject(); JSONObjectparams=newJSONObject(); try{ ClientKey.put("action","book");//發(fā)送預(yù)訂的標(biāo)志位 ClientKey.put("title",user); ClientKey.put("start",setbandwithvo.getYearmonthday()+"" +setbandwithvo.getStarttime()); ClientKey.put("end",setbandwithvo.getYearmonthday()+"" +setbandwithvo.getEndtime()); ClientKey.put("usrGB", String.valueOf(setbandwithvo.getGbandwith())); ClientKey.put("usrMB", String.valueOf(setbandwithvo.getMbandwith())); ClientKey.put("bandwithID",String.valueOf(bandwithID)); params.put("calendar_json",ClientKey); }catch(JSONExceptione){ e.printStackTrace(); } StringsetState=jsonHttpUtils.sendbwPostMessage(params,"utf-8"); System.out.println("setState-->>"+setState); if(setState.equals("setsuccess")){//接收預(yù)訂成功的標(biāo)志,返回帶寬顯示界面 Intentintent=newIntent(); intent.putExtra("top_time",dadaInfoString); setResult(RESULT_CODE,intent); finish(); proDialog.dismiss(); }elseif(setState.equals("fail")){//接收連接服務(wù)器錯(cuò)誤的標(biāo)志 Messagemessage=newMessage(); Bundlebundle=newBundle(); bundle.putBoolean("isNetError",false); message.setData(bundle); loginHandler.sendMessage(message); }else{//資源不足預(yù)訂失敗,從服務(wù)器返回為用戶分配的合理帶寬值 try{ JSONObjectjsonObject=newJSONObject(setState); System.out.println("jsonObject-->>"+jsonObject); updateGB=jsonObject.getString("usrGB"); updateMB=jsonObject.getString("usrMB"); }catch(JSONExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } updatevo=newSetBandwithVO(); updatevo.setBandwithDate(toptime); updatevo.setYearmonthday(ymd); updatevo.setStarttime(shour0+":"+sminute0); updatevo.setEndtime(ehour0+":"+eminute0); updatevo.setShour(shour); updatevo.setSminute(sminute); updatevo.setEhour(ehour); updatevo.setEminute(eminute); updatevo.setGbandwith(Integer.parseInt(updateGB)); updatevo.setMbandwith(Integer.parseInt(updateMB)); dao.update(bandwithID,updatevo);//以json數(shù)據(jù)格式接收數(shù)據(jù)并更新數(shù)據(jù)庫(kù) Intentintent=newIntent(); intent.putExtra("top_time",dadaInfoString); setResult(RESULT_CODE,intent); finish(); showInfo("資源不足,為您分配合理帶寬值!"); proDialog.dismiss(); } } }帶寬信息修改和刪除@OverridepublicvoidonClick(Viewv){switch(v.getId()){caseR.id.delete://點(diǎn)擊刪除按鈕,刪除已預(yù)訂帶寬信息dialog();break;caseR.id.update://點(diǎn)擊更新按鈕,修改已預(yù)訂帶寬信息if(updatebandwith()){try{deleteDialog=ProgressDialog.show(UpdateDelBandwith.this,"請(qǐng)稍候", "正在提交...",true,true);ThreadupdateThread=newThread(newupdateHandler());updateThread.start();}catch(Exceptione){}}break;//子線程中將要修改的帶寬信息數(shù)據(jù)打包成json格式傳遞給服務(wù)器privateclassupdateHandlerimplementsRunnable{@Overridepublicvoidrun(){JSONObjectClientKey=newJSONObject();//json數(shù)據(jù)JSONObjectparams=newJSONObject();try{ClientKey.put("action","update");ClientKey.put("title",user);ClientKey.put("start",updateBandwithvo.getYearmonthday()+"" +updateBandwithvo.getStarttime());ClientKey.put("end",updateBandwithvo.getYearmonthday()+"" +updateBandwithvo.getEndtime());ClientKey.put("usrGB",String.valueOf(updateBandwithvo.getGbandwith()));ClientKey.put("usrMB",String.valueOf(updateBandwithvo.getMbandwith()));ClientKey.put("bandwithID",id);params.put("calendar_json",ClientKey);}catch(JSONExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace();}//將json格式數(shù)據(jù)發(fā)送到服務(wù)器StringupdateState=jsonHttpUtils.sendbwPostMessage(params,"utf-8");if(updateState.equals("updatesuccess")){/獲取修改成功的標(biāo)識(shí)Intentintent=newIntent();intent.putExtra("top_time",dadaInfoString);setResult(RESULT_CODE,intent);finish();showInfo("更新成功!");deleteDialog.dismiss();
}elseif(updateState.equals("fail")){//獲取與服務(wù)器連接失敗的標(biāo)志Messagemessage=newMessage();Bundlebundle=newBundle();bundle.putBoolean("isNetError",false);message.setData(bundle);deleteHandler.sendMessage(message);}else{try{//資源不足修改失敗,從服務(wù)器返回為用戶分配的合理帶寬值JSONObjectjsonObject=newJSONObject(updateState);updateGB=jsonObject.getString("usrGB");updateMB=jsonObject.getString("usrMB");}catch(JSONExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}servicebackvo=newSetBandwithVO();servicebackvo.setBandwithDate(toptime);servicebackvo.setYearmonthday(ymd);servicebackvo.setStarttime(shour0+":"+sminute0);servicebackvo.setEndtime(ehour0+":"+eminute0);servicebackvo.setShour(shour);servicebackvo.setSminute(sminute);servicebackvo.setEhour(ehour);servicebackvo.setEminute(eminute);servicebackvo.setGbandwith(Integer.parseInt(updateGB));servicebackvo.setMbandwith(Integer.parseInt(updateMB));dao.update(id,servicebackvo);//以json數(shù)據(jù)格式接收數(shù)據(jù)并更新數(shù)據(jù)庫(kù)Intentintent=newIntent();intent.putExtra("top_time",dadaInfoString);setResult(RESULT_CODE,intent);finish();showInfo("資源不足,為您分配合理帶寬值!");deleteDialog.dismiss();}}}//子線程中將刪除的標(biāo)志位及每一條帶寬信息的唯一標(biāo)識(shí)發(fā)送到服務(wù)器privateclassdeleteHandlerimplementsRunnable{@Overridepublicvoidrun(){JSONObjectClientKey=newJSONObject();JSONObjectparams=newJSONObject();try{ClientKey.put("action","delete");//發(fā)送刪除的標(biāo)志位ClientKey.put("id",id);params.put("calendar_json",ClientKey);}catch(JSONExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}//將json格式數(shù)據(jù)發(fā)送到服務(wù)器StringdeleteState=jsonHttpUtils.sendbwPostMessage(params,"utf-8");if(deleteState.equals("deletesuccess")){/獲取刪除成功的標(biāo)識(shí)dao.delete(deleteBandwidthvo.getBandwidthID());//刪除SQLite數(shù)據(jù)庫(kù)中相應(yīng)的帶寬信息Intentintent=newIntent();intent.putExtra("top_time",dadaInfoString);setResult(RESULT_CODE,intent);finish();showInfo("刪除成功!");deleteDialog.dismiss();}elseif(deleteState.equals("fail")){//獲取刪除失敗的標(biāo)識(shí)Messagemessage=newMessage();Bundlebundle=newBundle();bundle.putBoolean("isNetError",false);message.setData(bundle);deleteHandler.sendMessage(message);}}}查詢歷史數(shù)據(jù)//精確查詢某一具體時(shí)間點(diǎn)的帶寬信息publicbooleangetbandwith(){gbwResult=gbwDefault;mbwResult=mbwDefault;dao=newSetBandwithDAO(this);scheduleIDs=dao.getBandwithByTagDate(yearInt,monthInt,dayInt);//獲取查詢?nèi)掌诘乃衖dLog.v("bandid","帶寬idverbose"+scheduleIDs);if(scheduleIDs!=null&&scheduleIDs.length>0){SetBandwithDAOdao=newSetBandwithDAO(this);shour=newint[scheduleIDs.length];sminute=newint[scheduleIDs.length];shtom=newint[scheduleIDs.length];ehour=newint[scheduleIDs.length];eminute=newint[scheduleIDs.length];ehtom=newint[scheduleIDs.length];for(inti=0;i<scheduleIDs.length;i++){setBandwithvo=dao.getBandwithByID(this,Integer.parseInt(scheduleIDs[i]));list.add(setBandwithvo);//將要查詢?nèi)掌诘乃幸杨A(yù)訂記錄存在list中shour[i]=setBandwithvo.getShour();sminute[i]=setBandwithvo.getSminute();shtom[i]=shour[i]*60+sminute[i];ehour[i]=setBandwithvo.getEhour();eminute[i]=setBandwithvo.getEminute();ehtom[i]=ehour[i]*60+eminute[i];}for(inti=0;i<list.size();i++){if((hour*60+minute)>=shtom[i]&&(hour*60+minute)<ehtom[i]){gbwResult=list.get(i).getGbandwith();//獲取查詢到的保證帶寬mbwResult=list.get(i).getMbandwith();//獲取查詢到的最大帶寬br
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 五年級(jí)數(shù)學(xué)(小數(shù)除法)計(jì)算題專(zhuān)項(xiàng)練習(xí)及答案匯編
- 二零二五年生態(tài)旅游項(xiàng)目代建服務(wù)協(xié)議3篇
- 二零二五年度車(chē)位使用權(quán)轉(zhuǎn)讓及車(chē)位租賃與車(chē)位管理合同模板6篇
- 2025年外研銜接版九年級(jí)生物下冊(cè)階段測(cè)試試卷含答案
- 墻體廣告合同范本
- 租房訂金協(xié)議書(shū)范本
- 個(gè)人財(cái)產(chǎn)轉(zhuǎn)讓合同協(xié)議范本
- 學(xué)生公寓租用合同
- 個(gè)人協(xié)議書(shū)范本
- 2025年華師大版七年級(jí)地理上冊(cè)月考試卷含答案
- 《黃河頌》示范公開(kāi)課教學(xué)PPT課件【統(tǒng)編人教版七年級(jí)語(yǔ)文下冊(cè)】
- TSEESA 010-2022 零碳園區(qū)創(chuàng)建與評(píng)價(jià)技術(shù)規(guī)范
- GB/T 19867.5-2008電阻焊焊接工藝規(guī)程
- 2023年市場(chǎng)部主管年終工作總結(jié)及明年工作計(jì)劃
- 第三章旅游活動(dòng)的基本要素課件
- 國(guó)有資產(chǎn)出租出借審批表(學(xué)校事業(yè)單位臺(tái)賬記錄表)
- 安全生產(chǎn)風(fēng)險(xiǎn)分級(jí)管控實(shí)施細(xì)則
- 30第七章-農(nóng)村社會(huì)治理課件
- 考研考博-英語(yǔ)-東北石油大學(xué)考試押題三合一+答案詳解1
- 出國(guó)學(xué)生英文成績(jī)單模板
- 植物細(xì)胞中氨基酸轉(zhuǎn)運(yùn)蛋白的一些已知或未知的功能
評(píng)論
0/150
提交評(píng)論