本文主要是介绍机房座位系统C语言,Android实现机房座位预约系统,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
本文实例为大家分享了Android实现预约系统的具体代码,供大家参考,具体内容如下
这周要去武汉开会,下周项目就得用上,所以,比较紧。加上导师不懂Android开发,只要开会就改需求,/(ㄒoㄒ)/~~反正他说先让学校用着,移动端和服务器的开发就给了两周时间。所以功能实现的比较简单,但代码做的比较容易扩展,都留了接口,后面更新起来也好做一些。通过这个工程,对Struts2的拦截器有了一些新体会。随着项目变大代码量变多,自然而然就会想起用一些设计模式了。不然代码根本没办法看。
整体是4个fragment,每个fragment里都有课程表的布局,课程可以从服务器传过来动态生成。其实很多都可以复用的布局,为了代码结构清晰,都分开写了。不然需要加控制器,调试起来心累。写的不好,还请大家多指教。做的还不完善,弄完以后再传上来。
Application里对数据进行持久化,这么做发现程序变得比较容易控制了。
Application
package com.example.myapplication;
import android.app.Application;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
public class CustomApplication extends Application {
public static final String serverAddress = "http://192.168.1.119";
// public static final String serverAddress = "http://10.187.86.63";
public static final String serverPort = "8080/Person_proj/upload";
// public static final String serverPort = "8000";
private static final String DEFAULT_NAME = "";
private static final String DEFAULT_ID = "-1";
private String name;
private String id;
private String room;
private String myOrder="NULL";
private boolean isLogin = false;
public boolean isLogin() {
SharedPreferences sp = getSharedPreferences("status", MODE_PRIVATE);
return sp.getBoolean("islogin", false);
}
/**
* 0为 未登录
* 1为登录
*/
public void setLogin(boolean isLogin) {
SharedPreferences sp = getSharedPreferences("status", MODE_PRIVATE);
Editor edit = sp.edit();
edit.putBoolean("islogin", isLogin);
edit.commit();
}
private int version;
public int getVersion() {
SharedPreferences sp = getSharedPreferences("status", MODE_PRIVATE);
return sp.getInt("version",0);
}
public void setVersion(int version) {
SharedPreferences sp = getSharedPreferences("status", MODE_PRIVATE);
Editor edit = sp.edit();
edit.putInt("version",version);
edit.commit();
}
public String getMyOrder() {
SharedPreferences sp = getSharedPreferences("status", MODE_PRIVATE);
return sp.getString("order","NULL");
}
public void setMyOrder(String myOrder) {
SharedPreferences sp = getSharedPreferences("status", MODE_PRIVATE);
Editor edit = sp.edit();
edit.putString("order",myOrder);
edit.commit();
}
@Override
public void onCreate() {
super.onCreate();
setName(DEFAULT_NAME); // 初始化全局变量
setId(DEFAULT_ID);
}
public void setName(String name) {
SharedPreferences sp = getSharedPreferences("status", MODE_PRIVATE);
Editor edit = sp.edit();
edit.putString("name", name);
edit.commit();
}
public String getName() {
SharedPreferences sp = getSharedPreferences("status", MODE_PRIVATE);
return sp.getString("name", "none");
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public void setRoom(String room) {
this.room = room;
}
public String getRoom() {
return room;
}
}
做注册时的逻辑判断,onClick事件里:
boolean cancel = false;
View focusView = null;
String id = builder.getUserId().trim();
String password = builder.getPassword().trim();
String passwordConfirm = builder.getPasswordConfirm().trim();
final String username = builder.getUsername().trim();
// Check for a valid password.
if (TextUtils.isEmpty(password)) {
cancel = true;
focusView = builder.getStuPwdEditText();
}
// Check for a valid password.
if (TextUtils.isEmpty(passwordConfirm)) {
cancel = true;
focusView = builder.getStuPwdConfirmEditText();
}
if (!password.equals(passwordConfirm)) {
cancel = true;
focusView = builder.getStuPwdEditText();
}
// Check for a valid Id.
if (TextUtils.isEmpty(id)) {
cancel = true;
focusView = builder.getStuIdEditText();
}
// Check for a valid username.
if (TextUtils.isEmpty(username)) {
cancel = true;
focusView = builder.getStuNameEditText();
}
if(!MatchUtils.match(password)||!MatchUtils.match(passwordConfirm)){
cancel = true;
focusView = builder.getStuPwdEditText();
ToastUtils.MyToast(getApplicationContext(), "密码只能为6位数字!");
}
if (cancel) {
ToastUtils.MyToast(getApplicationContext(), "输入有误,请从新输入!");
focusView.requestFocus();
} else {
//...这里做的网络请求
// TODO signup 提交服务器Get请求
// 符合接口规范
final String url =app.serverAddress+":"+app.serverPort+"?"+"action=signin"+"&"+"username="+username+"&"+"oldpassword="+password;
HttpUtils http = new HttpUtils();
http.send(HttpMethod.GET, url, new RequestCallBack() {
@Override
public void onSuccess(ResponseInfo responseInfo) {
Log.i("tag", "============success============"+responseInfo.result);
ToastUtils.MyToast(getApplicationContext(), responseInfo.result);
if(responseInfo.result.equals("success")){
//注册成功,自动实现登录
app.setLogin(true);
app.setName(username);
//更新UI
Message m = Message.obtain();
m.what=1;
handler.sendMessage(m);
ToastUtils.MyToast(getApplicationContext(), "注册成功,学号:"+username);
}else{
ToastUtils.MyToast(getApplicationContext(), responseInfo.result);
}
dialog.dismiss();
}
@Override
public void onFailure(HttpException error, String msg) {
ToastUtils.MyToast(getApplicationContext(), msg);
dialog.dismiss();
}
});
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
这篇关于机房座位系统C语言,Android实现机房座位预约系统的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!