SDOAN中面向用户的带宽预订应用软件设计说明书_第1页
SDOAN中面向用户的带宽预订应用软件设计说明书_第2页
SDOAN中面向用户的带宽预订应用软件设计说明书_第3页
SDOAN中面向用户的带宽预订应用软件设计说明书_第4页
SDOAN中面向用户的带宽预订应用软件设计说明书_第5页
已阅读5页,还剩43页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

XXX(设计)I附录用户登录publicclassloginActivityextendsActivity{ privateEditTextnumText;//输入用户名编辑框 privateEditTextpswdText;//输入密码编辑框 privateHandlerloginHandler;//信息处理机 privateProgressDialogproDialog;//进度条 @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(){//消息处理机制,主线程控制界面更新 @Override publicvoidhandleMessage(Messagemsg){ Bundlebundle=msg.getData(); booleanloginResult=(Boolean)bundle.get("isNetError");//获取登陆失败标志位 if(proDialog!=null){ proDialog.dismiss(); } booleanisNet=isNetWorkAvailable(loginActivity.this); if(!isNet){ Toast.makeText(loginActivity.this,"当前网络不可用", Toast.LENGTH_SHORT).show(); } if(!loginResult){ Toast.makeText(loginActivity.this,"错误的用户名或密码", Toast.LENGTH_SHORT).show(); } super.handleMessage(msg); } }; logButton.setOnClickListener(newView.OnClickListener(){//登录点击 @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);//登录成功实现界面跳转intent.putExtra("user",num); startActivity(intent); proDialog.dismiss(); }else{ Messagemessage=newMessage();//登录失败返回错误标志位 Bundlebundle=newBundle(); bundle.putBoolean("isNetError",loginState); message.setData(bundle); loginHandler.sendMessage(message); } } } publicstaticbooleanisNetWorkAvailable(Contextcontext){//检测网络是否连接 ConnectivityManagercm=(ConnectivityManager)context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfoinfo=cm.getActiveNetworkInfo(); returninfo!=null&&info.isConnected(); }}带宽信息预订@Override publicvoidonClick(Viewv){ switch(v.getId()){ caseR.id.sure://点击提交按钮,提交预订请求 if(savebandwith()){ try{ proDialog=ProgressDialog.show(setbandwith.this,"请稍候", "正在提交...",true,true); ThreadbookThread=newThread(newbookHandler()); bookThread.start(); }catch(Exceptione){} }else{} break; caseR.id.quit://点击返回按钮,返回到带宽信息显示界面 setbandwith.this.finish(); break; caseR.id.sTime://点击设置开始时间的控件 starttime(); break; caseR.id.eTime://点击设置终止时间的控件 endtime(); break; caseR.id.ngbandwith://点击设置保证带宽的控件 showDialoggbw(); break; caseR.id.nmbandwith://点击设置最大带宽的控件 showDialogmbw(); break; default: break; } }privatebooleansavebandwith(){//将带宽信息存入本地数据库中 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,"时间范围设置有冲突!",Toast.LENGTH_LONG).show(); //showInfo("时间范围设置有冲突!"); } }else{ Toast.makeText(setbandwith.this,"终止时间必须大于起始时间!",Toast.LENGTH_LONG).show(); //showInfo("终止时间必须大于起始时间!"); } returnflag; }//子线程中将带宽信息数据打包成json格式传递给服务器privateclassbookHandlerimplementsRunnable{ @Override publicvoidrun(){ JSONObjectClientKey=newJSONObject(); JSONObjectparams=newJSONObject(); try{ ClientKey.put("action","book");//发送预订的标志位 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")){//接收预订成功的标志,返回带宽显示界面 Intentintent=newIntent(); intent.putExtra("top_time",dadaInfoString); setResult(RESULT_CODE,intent); finish(); proDialog.dismiss(); }elseif(setState.equals("fail")){//接收连接服务器错误的标志 Messagemessage=newMessage(); Bundlebundle=newBundle(); bundle.putBoolean("isNetError",false); message.setData(bundle); loginHandler.sendMessage(message); }else{//资源不足预订失败,从服务器返回为用户分配的合理带宽值 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数据格式接收数据并更新数据库 Intentintent=newIntent(); intent.putExtra("top_time",dadaInfoString); setResult(RESULT_CODE,intent); finish(); showInfo("资源不足,为您分配合理带宽值!"); proDialog.dismiss(); } } }带宽信息修改和删除@OverridepublicvoidonClick(Viewv){switch(v.getId()){caseR.id.delete://点击删除按钮,删除已预订带宽信息dialog();break;caseR.id.update://点击更新按钮,修改已预订带宽信息if(updatebandwith()){try{deleteDialog=ProgressDialog.show(UpdateDelBandwith.this,"请稍候", "正在提交...",true,true);ThreadupdateThread=newThread(newupdateHandler());updateThread.start();}catch(Exceptione){}}break;//子线程中将要修改的带宽信息数据打包成json格式传递给服务器privateclassupdateHandlerimplementsRunnable{@Overridepublicvoidrun(){JSONObjectClientKey=newJSONObject();//json数据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格式数据发送到服务器StringupdateState=jsonHttpUtils.sendbwPostMessage(params,"utf-8");if(updateState.equals("updatesuccess")){/获取修改成功的标识Intentintent=newIntent();intent.putExtra("top_time",dadaInfoString);setResult(RESULT_CODE,intent);finish();showInfo("更新成功!");deleteDialog.dismiss();

}elseif(updateState.equals("fail")){//获取与服务器连接失败的标志Messagemessage=newMessage();Bundlebundle=newBundle();bundle.putBoolean("isNetError",false);message.setData(bundle);deleteHandler.sendMessage(message);}else{try{//资源不足修改失败,从服务器返回为用户分配的合理带宽值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数据格式接收数据并更新数据库Intentintent=newIntent();intent.putExtra("top_time",dadaInfoString);setResult(RESULT_CODE,intent);finish();showInfo("资源不足,为您分配合理带宽值!");deleteDialog.dismiss();}}}//子线程中将删除的标志位及每一条带宽信息的唯一标识发送到服务器privateclassdeleteHandlerimplementsRunnable{@Overridepublicvoidrun(){JSONObjectClientKey=newJSONObject();JSONObjectparams=newJSONObject();try{ClientKey.put("action","delete");//发送删除的标志位ClientKey.put("id",id);params.put("calendar_json",ClientKey);}catch(JSONExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}//将json格式数据发送到服务器StringdeleteState=jsonHttpUtils.sendbwPostMessage(params,"utf-8");if(deleteState.equals("deletesuccess")){/获取删除成功的标识dao.delete(deleteBandwidthvo.getBandwidthID());//删除SQLite数据库中相应的带宽信息Intentintent=newIntent();intent.putExtra("top_time",dadaInfoString);setResult(RESULT_CODE,intent);finish();showInfo("删除成功!");deleteDialog.dismiss();}elseif(deleteState.equals("fail")){//获取删除失败的标识Messagemessage=newMessage();Bundlebundle=newBundle();bundle.putBoolean("isNetError",false);message.setData(bundle);deleteHandler.sendMessage(message);}}}查询历史数据//精确查询某一具体时间点的带宽信息publicbooleangetbandwith(){gbwResult=gbwDefault;mbwResult=mbwDefault;dao=newSetBandwithDAO(this);scheduleIDs=dao.getBandwithByTagDate(yearInt,monthInt,dayInt);//获取查询日期的所有idLog.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);//将要查询日期的所有已预订记录存在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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论