版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
XXX(設(shè)計)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,"錯誤的用戶名或密碼", Toast.LENGTH_SHORT).show(); } super.handleMessage(msg); } }; logButton.setOnClickListener(newView.OnClickListener(){//登錄點(diǎn)擊 @Override publicvoidonClick(Viewv){ //TODOAuto-generatedmethodstub try{ proDialog=ProgressDialog.show(loginActivity.this,"請稍候", "正在登陸...",true,true); ThreadloginThread=newThread(newLoginFailureHandler()); loginThread.start();//子線程開啟 }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();//登錄失敗返回錯誤標(biāo)志位 Bundlebundle=newBundle(); bundle.putBoolean("isNetError",loginState); message.setData(bundle); loginHandler.sendMessage(message); } } } publicstaticbooleanisNetWorkAvailable(Contextcontext){//檢測網(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ù)訂請求 if(savebandwith()){ try{ proDialog=ProgressDialog.show(setbandwith.this,"請稍候", "正在提交...",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è)置開始時間的控件 starttime(); break; caseR.id.eTime://點(diǎn)擊設(shè)置終止時間的控件 endtime(); break; caseR.id.ngbandwith://點(diǎn)擊設(shè)置保證帶寬的控件 showDialoggbw(); break; caseR.id.nmbandwith://點(diǎn)擊設(shè)置最大帶寬的控件 showDialogmbw(); break; default: break; } }privatebooleansavebandwith(){//將帶寬信息存入本地數(shù)據(jù)庫中 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è)置有沖突!",Toast.LENGTH_LONG).show(); //showInfo("時間范圍設(shè)置有沖突!"); } }else{ Toast.makeText(setbandwith.this,"終止時間必須大于起始時間!",Toast.LENGTH_LONG).show(); //showInfo("終止時間必須大于起始時間!"); } 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ù)器錯誤的標(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ù)庫 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,"請稍候", "正在提交...",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)識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ù)庫Intentintent=newIntent();intent.putExtra("top_time",dadaInfoString);setResult(RESULT_CODE,intent);finish();showInfo("資源不足,為您分配合理帶寬值!");deleteDialog.dismiss();}}}//子線程中將刪除的標(biāo)志位及每一條帶寬信息的唯一標(biāo)識發(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)識dao.delete(deleteBandwidthvo.getBandwidthID());//刪除SQLite數(shù)據(jù)庫中相應(yīng)的帶寬信息Intentintent=newIntent();intent.putExtra("top_time",dadaInfoString);setResult(RESULT_CODE,intent);finish();showInfo("刪除成功!");deleteDialog.dismiss();}elseif(deleteState.equals("fail")){//獲取刪除失敗的標(biāo)識Messagemessage=newMessage();Bundlebundle=newBundle();bundle.putBoolean("isNetError",false);message.setData(bundle);deleteHandler.sendMessage(message);}}}查詢歷史數(shù)據(jù)//精確查詢某一具體時間點(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. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024會計從業(yè)人員繼續(xù)學(xué)習(xí)考試
- 軍訓(xùn)的收獲與感悟200字左右
- 齊魯工業(yè)大學(xué)《版面編排設(shè)計》2023-2024學(xué)年第一學(xué)期期末試卷
- 南京信息工程大學(xué)《語言與數(shù)據(jù)可視化》2021-2022學(xué)年期末試卷
- 齊魯工業(yè)大學(xué)《產(chǎn)品模型制作》2022-2023學(xué)年期末試卷
- 光伏電站建設(shè)合同書
- 修車服務(wù)合同模板
- 城市高端住宅開發(fā)項目協(xié)議范本
- 農(nóng)藥制造過程質(zhì)量控制方法考核試卷
- 制糖業(yè)的品牌管理與市場推廣考核試卷
- 22G101-1與16G101-1的圖集差異
- 《針織學(xué)》期末考試試卷附答案
- 特種設(shè)備使用登記表(范本)
- (完整版)5以內(nèi)的加減法(可直接打印)
- 智能物流-完整版課件(全)
- 新疆準(zhǔn)東經(jīng)濟(jì)技術(shù)開發(fā)區(qū)西部固廢處置場項目環(huán)評報告書
- GB∕T 36008-2018 機(jī)器人與機(jī)器人裝備 協(xié)作機(jī)器人
- (新版)保衛(wèi)管理員考試題庫(含答案)
- 信貸法律基礎(chǔ)知識培訓(xùn)講座PPT
- TCECA-G 0171-2022 零碳工廠評價規(guī)范
- 光與色的世界(課件)
評論
0/150
提交評論