無線點(diǎn)餐系統(tǒng)的設(shè)計(jì)_第1頁
無線點(diǎn)餐系統(tǒng)的設(shè)計(jì)_第2頁
無線點(diǎn)餐系統(tǒng)的設(shè)計(jì)_第3頁
無線點(diǎn)餐系統(tǒng)的設(shè)計(jì)_第4頁
無線點(diǎn)餐系統(tǒng)的設(shè)計(jì)_第5頁
已閱讀5頁,還剩57頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

Android實(shí)訓(xùn)報(bào)告院系:計(jì)算機(jī)與信息工程學(xué)院班級:10級軟件技術(shù)(1)班學(xué)號:姓名:

無線點(diǎn)餐系統(tǒng)需求分析餐飲傳統(tǒng)的點(diǎn)菜方式是純?nèi)斯げ僮鳎煞?wù)員記錄顧客點(diǎn)的菜,在具體工作中容易出現(xiàn)以下問題:手寫單據(jù)字跡潦草從而導(dǎo)致上錯(cuò)菜、傳菜分單出錯(cuò)現(xiàn)象嚴(yán)重、加菜和查賬程序較繁瑣。處理特殊口味有遺漏和偏差、客人催菜遺忘現(xiàn)象較頻繁、計(jì)算賬單易出錯(cuò)、不方便人員管理等等。正因如此,無線點(diǎn)餐模式應(yīng)運(yùn)而生。它不僅可以有效地提高餐飲業(yè)的工作效率,更可以規(guī)范服務(wù)體系,提高整體服務(wù)質(zhì)量和管理水平,并為規(guī)?;?jīng)營提供了堅(jiān)實(shí)的技術(shù)基礎(chǔ)。我們生活在一個(gè)充斥著數(shù)字技術(shù)的世界里,數(shù)字技術(shù)幾乎侵入到我們生活的每個(gè)細(xì)節(jié)。點(diǎn)餐系統(tǒng)在使用上不及Wi-Fi點(diǎn)餐系統(tǒng)便利:服務(wù)員依然使用手持終端為顧客點(diǎn)餐,當(dāng)消費(fèi)者點(diǎn)完餐后,服務(wù)員將存儲(chǔ)在手持終端內(nèi)的點(diǎn)餐信息,對準(zhǔn)布置在餐廳各個(gè)位置的紅外接收端進(jìn)行發(fā)射,接收端會(huì)將點(diǎn)餐信息通過網(wǎng)線傳送到前臺(tái)計(jì)算機(jī)。前臺(tái)計(jì)算機(jī)會(huì)對點(diǎn)餐信息進(jìn)行分類處理,然后將點(diǎn)餐信息分別發(fā)送給收銀臺(tái)和廚房。

一登錄模塊一(1)(1)登錄模塊Android客戶端實(shí)現(xiàn)首先,為了提高系統(tǒng)的安全性,要想使用該系統(tǒng)必須進(jìn)行系統(tǒng)登錄。其次,每個(gè)點(diǎn)餐信息中都要用到登錄用戶信息,這樣可以做到責(zé)任分明,工作嚴(yán)謹(jǐn)。登錄的基本流程是:通過用戶輸入的用戶名稱和用戶密碼,到后臺(tái)數(shù)據(jù)庫做查詢,如果有該用戶則進(jìn)入系統(tǒng),否則提示用戶輸入錯(cuò)誤。創(chuàng)建一個(gè)Android工程,名稱為“WirelessOrder_Client”。在工程的res\layout目錄下,創(chuàng)建一個(gè)名稱為“l(fā)ogin_system.xml“的布局文件。

創(chuàng)建一個(gè)名稱為”oginActivity”的,Activity,在類的頂部聲明用到的Editatext和Button組件。packagecom.amaker.wlo;importandroid.app.Activity;importandroid.app.AlertDialog;importandroid.content.DialogInterface;importandroid.content.Intent;importandroid.content.SharedPreferences;importandroid.os.Bundle;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.widget.Button;importandroid.widget.EditText;importandroid.widget.Toast;importcom.amaker.util.HttpUtil;publicclassLoginActivityextendsActivity{ //聲明登錄、取消按鈕 privateButtoncancelBtn,loginBtn; //聲明用戶名、密碼輸入框 privateEditTextuserEditText,pwdEditText; @Override publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); //設(shè)置標(biāo)題 setTitle("掌中寶無線訂餐系統(tǒng)-用戶登錄"); //設(shè)置當(dāng)前Activity界面布局 setContentView(R.layout.login_system); //通過findViewById方法實(shí)例化組件 cancelBtn=(Button)findViewById(R.id.cancelButton); //通過findViewById方法實(shí)例化組件 loginBtn=(Button)findViewById(R.id.loginButton); //通過findViewById方法實(shí)例化組件 userEditText=(EditText)findViewById(R.id.userEditText); //通過findViewById方法實(shí)例化組件 pwdEditText=(EditText)findViewById(R.id.pwdEditText); cancelBtn.setOnClickListener(newOnClickListener(){ @Override publicvoidonClick(Viewv){ finish(); } }); loginBtn.setOnClickListener(newOnClickListener(){ @Override publicvoidonClick(Viewv){ if(validate()){ if(login()){ Intentintent=newIntent(LoginActivity.this,MainMenuActivity.class); startActivity(intent); }else{ showDialog("用戶名稱或者密碼錯(cuò)誤,請重新輸入!"); } } } }); } //登錄方法 privatebooleanlogin(){ //獲得用戶名稱 Stringusername=userEditText.getText().toString(); //獲得密碼 Stringpwd=pwdEditText.getText().toString(); //獲得登錄結(jié)果 Stringresult=query(username,pwd); if(result!=null&&result.equals("0")){ returnfalse; }else{ saveUserMsg(result); returntrue; } } //將用戶信息保存到配置文件 privatevoidsaveUserMsg(Stringmsg){ //用戶編號 Stringid=""; //用戶名稱 Stringname=""; //獲得信息數(shù)組 String[]msgs=msg.split(";"); intidx=msgs[0].indexOf("="); id=msgs[0].substring(idx+1); idx=msgs[1].indexOf("="); name=msgs[1].substring(idx+1); //共享信息 SharedPreferencespre=getSharedPreferences("user_msg",MODE_WORLD_WRITEABLE); SharedPreferences.Editoreditor=pre.edit(); editor.putString("id",id); editor.putString("name",name); mit(); } //驗(yàn)證方法 privatebooleanvalidate(){ Stringusername=userEditText.getText().toString(); if(username.equals("")){ showDialog("用戶名稱是必填項(xiàng)!"); returnfalse; } Stringpwd=pwdEditText.getText().toString(); if(pwd.equals("")){ showDialog("用戶密碼是必填項(xiàng)!"); returnfalse; } returntrue; } privatevoidshowDialog(Stringmsg){ AlertDialog.Builderbuilder=newAlertDialog.Builder(this); builder.setMessage(msg) .setCancelable(false) .setPositiveButton("確定",newDialogInterface.OnClickListener(){ publicvoidonClick(DialogInterfacedialog,intid){ } }); AlertDialogalert=builder.create(); alert.show(); } //根據(jù)用戶名稱密碼查詢 privateStringquery(Stringaccount,Stringpassword){ //查詢參數(shù) StringqueryString="account="+account+"&password="+password; //url Stringurl=HttpUtil.BASE_URL+"servlet/LoginServlet?"+queryString; //查詢返回結(jié)果 returnHttpUtil.queryStringForPost(url);}}為了實(shí)現(xiàn)登錄功能,Android需要通過網(wǎng)絡(luò)訪問后臺(tái)的數(shù)據(jù)庫進(jìn)行查詢。Android訪問網(wǎng)絡(luò)的實(shí)現(xiàn)方法很多,如WebService,HTTP,直接使用WebView瀏覽器。packagecom.amaker.util;importjava.io.IOException;importorg.apache.http.HttpResponse;importorg.apache.http.client.ClientProtocolException;importorg.apache.http.client.methods.HttpGet;importorg.apache.http.client.methods.HttpPost;importorg.apache.http.impl.client.DefaultHttpClient;importorg.apache.http.util.EntityUtils;publicclassHttpUtil{ //基礎(chǔ)URL publicstaticfinalStringBASE_URL=":8888/WirelessOrder_Server/"; //獲得Get請求對象request publicstaticHttpGetgetHttpGet(Stringurl){ HttpGetrequest=newHttpGet(url); returnrequest; } //獲得Post請求對象request publicstaticHttpPostgetHttpPost(Stringurl){ HttpPostrequest=newHttpPost(url); returnrequest; } //根據(jù)請求獲得響應(yīng)對象response publicstaticHttpResponsegetHttpResponse(HttpGetrequest)throwsClientProtocolException,IOException{ HttpResponseresponse=newDefaultHttpClient().execute(request); returnresponse; } //根據(jù)請求獲得響應(yīng)對象response publicstaticHttpResponsegetHttpResponse(HttpPostrequest)throwsClientProtocolException,IOException{ HttpResponseresponse=newDefaultHttpClient().execute(request); returnresponse; } //發(fā)送Post請求,獲得響應(yīng)查詢結(jié)果 publicstaticStringqueryStringForPost(Stringurl){ //根據(jù)url獲得HttpPost對象 HttpPostrequest=HttpUtil.getHttpPost(url); Stringresult=null; try{ //獲得響應(yīng)對象 HttpResponseresponse=HttpUtil.getHttpResponse(request); //判斷是否請求成功 if(response.getStatusLine().getStatusCode()==200){ //獲得響應(yīng) result=EntityUtils.toString(response.getEntity()); returnresult; } }catch(ClientProtocolExceptione){ e.printStackTrace(); result="網(wǎng)絡(luò)異常!"; returnresult; }catch(IOExceptione){ e.printStackTrace(); result="網(wǎng)絡(luò)異常!"; returnresult; }returnnull;} //獲得響應(yīng)查詢結(jié)果 publicstaticStringqueryStringForPost(HttpPostrequest){ Stringresult=null; try{ //獲得響應(yīng)對象 HttpResponseresponse=HttpUtil.getHttpResponse(request); //判斷是否請求成功 if(response.getStatusLine().getStatusCode()==200){ //獲得響應(yīng) result=EntityUtils.toString(response.getEntity()); returnresult; } }catch(ClientProtocolExceptione){ e.printStackTrace(); result="網(wǎng)絡(luò)異常!"; returnresult; }catch(IOExceptione){ e.printStackTrace(); result="網(wǎng)絡(luò)異常!"; returnresult; }returnnull;} //發(fā)送Get請求,獲得響應(yīng)查詢結(jié)果 publicstaticStringqueryStringForGet(Stringurl){ //獲得HttpGet對象 HttpGetrequest=HttpUtil.getHttpGet(url); Stringresult=null; try{ //獲得響應(yīng)對象 HttpResponseresponse=HttpUtil.getHttpResponse(request); //判斷是否請求成功 if(response.getStatusLine().getStatusCode()==200){ //獲得響應(yīng) result=EntityUtils.toString(response.getEntity()); returnresult; } }catch(ClientProtocolExceptione){ e.printStackTrace(); result="網(wǎng)絡(luò)異常!"; returnresult; }catch(IOExceptione){ e.printStackTrace(); result="網(wǎng)絡(luò)異常!"; returnresult; }returnnull;}程序運(yùn)行結(jié)果如下:一(2)登錄模塊服務(wù)器端實(shí)現(xiàn)后臺(tái)的服務(wù)器實(shí)現(xiàn)采用JDBC訪問后臺(tái)數(shù)據(jù)庫,Servlet響應(yīng)HttpRequest請求,并返會(huì)響應(yīng)結(jié)果。為了完成該功能我們需要安裝MySQL數(shù)據(jù)庫并配置Tomcat服務(wù)器,這部分內(nèi)容將不再贅述。DBUtil工具類內(nèi)容如下所示。packagecom.amaker.util;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.SQLException;importjava.util.Properties;@authorhz.guopublicclassDBUtil{ publicvoidcloseConn(Connectionconn){ try{ conn.close(); }catch(SQLExceptione){ e.printStackTrace(); } } publicConnectionopenConnection(){ Propertiesprop=newProperties(); Stringdriver=null; Stringurl=null; Stringusername=null; Stringpassword=null; try{ prop.load(this.getClass().getClassLoader().getResourceAsStream( "DBCperties")); driver=prop.getProperty("driver"); url=prop.getProperty("url"); username=prop.getProperty("username"); password=prop.getProperty("password"); Class.forName(driver); returnDriverManager.getConnection(url,username,password); }catch(Exceptione){ e.printStackTrace(); } returnnull; }}創(chuàng)建UserDao接口實(shí)現(xiàn)類UserDaoImpl.packagecom.amaker.dao.impl;importjava.sql.Connection;importjava.sql.PreparedStatement;importjava.sql.ResultSet;importjava.sql.SQLException;importcom.amaker.dao.UserDao;importcom.amaker.entity.User;importcom.amaker.util.DBUtil;/****@author郭宏志*用戶登錄DAO實(shí)現(xiàn)類*/publicclassUserDaoImplimplementsUserDao{ /** *通過用戶名稱和密碼登錄,登錄成功返回User對象,登錄失敗返回null */ publicUserlogin(Stringaccount,Stringpassword){ //查詢SQL語句 Stringsql="selectid,account,password,name,permission,remark"+ "fromuserTbl"+ "whereaccount=?andpassword=?"; //數(shù)據(jù)庫連接工具類 DBUtilutil=newDBUtil(); //獲得連接 Connectionconn=util.openConnection(); try{ //獲得預(yù)定義語句 PreparedStatementpstmt=conn.prepareStatement(sql); //設(shè)置查詢參數(shù) pstmt.setString(1,account); pstmt.setString(2,password); //執(zhí)行查詢 ResultSetrs=pstmt.executeQuery(); //判斷用戶是否存在 if(rs.next()){ //獲得用戶信息 intid=rs.getInt(1); Stringname=rs.getString(4); intpermission=rs.getInt(5); Stringremark=rs.getString(6); //封裝用戶信息 Useru=newUser(); u.setId(id); u.setAccount(account); u.setPassword(password); u.setName(name); u.setPermission(permission); u.setRemark(remark); returnu; } }catch(SQLExceptione){ e.printStackTrace(); }finally{ util.closeConn(conn); } returnnull; } publicstaticvoidmain(String[]args){ UserDaodao=newUserDaoImpl(); Useru=dao.login("admin","123"); System.out.println(u.getAccount()); }}創(chuàng)建LoginServlet類響應(yīng)請應(yīng)。類通過request.getParameter()方法獲得請求參數(shù),調(diào)用UserDaoImpl的login()方法,并根據(jù)登錄結(jié)果返回響應(yīng)結(jié)果信息。packagecom.amaker.servlet;importjava.io.IOException;importjava.io.PrintWriter;importjavax.servlet.ServletException;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importcom.amaker.dao.UserDao;importcom.amaker.dao.impl.UserDaoImpl;importcom.amaker.entity.User;publicclassLoginServletextendsHttpServlet{ publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse) throwsServletException,IOException{ response.setContentType("text/html"); PrintWriterout=response.getWriter(); UserDaodao=newUserDaoImpl(); //??μ??í?§?????ó2?êy Stringusername=request.getParameter("account"); Stringpassword=request.getParameter("password"); Useru=dao.login(username,password); if(u!=null){ //?ìó|?í?§???úèY£?μ???3é1| out.print(build(u)); }else{ out.print("0"); } out.flush(); out.close(); } privateStringbuild(Useru){ StringuserMsg=""; userMsg+="id="+u.getId(); userMsg+=";"; userMsg+="name="+u.getName(); returnuserMsg; } publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse) throwsServletException,IOException{ doGet(request,response); } publicvoidinit()throwsServletException{ } publicLoginServlet(){ super(); } publicvoiddestroy(){ super.destroy(); }}一(3)程序主菜單實(shí)現(xiàn)用戶成功登陸之后便可以進(jìn)入系統(tǒng)主菜單界面了。主菜單是通一個(gè)GridView來展示的。創(chuàng)建一個(gè)名稱為”MainMenuActivity”的Activity,在onCreate()方法中設(shè)置Activity界面標(biāo)題和布局,實(shí)例化GridView組件,為GridView綁定Adapter。packagecom.amaker.wlo;importjava.io.InputStream;import.URL;import.URLConnection;importjava.util.ArrayList;importjava.util.HashMap;importjava.util.List;importjava.util.Map;importjavax.xml.parsers.DocumentBuilder;importjavax.xml.parsers.DocumentBuilderFactory;importorg.w3c.dom.Document;importorg.w3c.dom.NodeList;importandroid.app.Activity;importandroid.app.AlertDialog;importandroid.content.Context;importandroid.content.DialogInterface;importandroid.content.Intent;importandroid.content.SharedPreferences;importandroid.os.Bundle;importandroid.view.LayoutInflater;importandroid.view.View;importandroid.view.ViewGroup;importandroid.view.View.OnClickListener;importandroid.widget.BaseAdapter;importandroid.widget.EditText;importandroid.widget.GridView;importandroid.widget.ImageView;importandroid.widget.SimpleAdapter;importandroid.widget.Spinner;importandroid.widget.SpinnerAdapter;importandroid.widget.TextView;importandroid.widget.Toast;importcom.amaker.util.HttpUtil;publicclassMainMenuActivityextendsActivity{@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setTitle("???D±|?T????2í?μí3-?÷2?μ¥");setContentView(R.layout.main_menu);GridViewgridview=(GridView)findViewById(R.id.gridview);gridview.setAdapter(newImageAdapter(this));}publicclassImageAdapterextendsBaseAdapter{publicImageAdapter(Contextc){mContext=c;}publicintgetCount(){returnmThumbIds.length;}publicObjectgetItem(intposition){returnnull;}publiclonggetItemId(intposition){return0;}publicViewgetView(intposition,ViewconvertView,ViewGroupparent){ImageViewimageView;if(convertView==null){imageView=newImageView(mContext);imageView.setLayoutParams(newGridView.LayoutParams(85,85));imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);imageView.setPadding(8,8,8,8);}else{imageView=(ImageView)convertView;}imageView.setImageResource(mThumbIds[position]);switch(position){ case0: imageView.setOnClickListener(orderLinstener); break; case1: imageView.setOnClickListener(unionTableLinstener); break; case2: imageView.setOnClickListener(changeTableLinstener); break; case3: imageView.setOnClickListener(checkTableLinstener); break; case4: imageView.setOnClickListener(updateLinstener); break; case6: imageView.setOnClickListener(exitLinstener); break; case7: imageView.setOnClickListener(payLinstener); break; default: break; }returnimageView;}//í???×ê?′êy×éprivateInteger[]mThumbIds={R.drawable.diancai,R.drawable.bingtai,R.drawable.zhuantai,R.drawable.chatai,R.drawable.gengxin,R.drawable.shezhi,R.drawable.zhuxiao,R.drawable.jietai};}OnClickListenerupdateLinstener=newOnClickListener(){ @Override publicvoidonClick(Viewv){ Intentintent=newIntent(); //???ˉ?á??Activity intent.setClass(MainMenuActivity.this,UpdateActivity.class); startActivity(intent); } };OnClickListenercheckTableLinstener=newOnClickListener(){ @Override publicvoidonClick(Viewv){ Intentintent=newIntent(); //???ˉ?á??Activity intent.setClass(MainMenuActivity.this,CheckTableActivity.class); startActivity(intent); } };OnClickListenerpayLinstener=newOnClickListener(){ @Override publicvoidonClick(Viewv){ Intentintent=newIntent(); //???ˉ?á??Activity intent.setClass(MainMenuActivity.this,PayActivity.class); startActivity(intent); } };OnClickListenerorderLinstener=newOnClickListener(){ @Override publicvoidonClick(Viewv){ Intentintent=newIntent(); //???ˉ??2íActivity intent.setClass(MainMenuActivity.this,OrderActivity.class); startActivity(intent); } };OnClickListenerexitLinstener=newOnClickListener(){ @Override publicvoidonClick(Viewv){ logout(); } }; OnClickListenerchangeTableLinstener=newOnClickListener(){ @Override publicvoidonClick(Viewv){ changeTable(); } };OnClickListenerunionTableLinstener=newOnClickListener(){ @Override publicvoidonClick(Viewv){ unionTable(); } }; privatevoidchangeTable(){ LayoutInflaterinflater=LayoutInflater.from(this); Viewv=inflater.inflate(R.layout.change_table,null); //′óLinearLayout?D??μ?EditTextêμày finalEditTextet1=(EditText)v.findViewById(R.id.change_table_order_number_EditText); finalEditTextet2=(EditText)v.findViewById(R.id.change_table_no_EditText); AlertDialog.Builderbuilder=newAlertDialog.Builder(this); builder.setMessage("??μ?òa??×à???e£?") .setCancelable(false) .setView(v) .setPositiveButton("è·?¨",newDialogInterface.OnClickListener(){ publicvoidonClick(DialogInterfacedialog,intid){ StringorderId=et1.getText().toString(); StringtableId=et2.getText().toString(); StringqueryString="orderId="+orderId+"&tableId="+tableId; //url Stringurl=HttpUtil.BASE_URL+"servlet/ChangeTableServlet?"+queryString; Stringresult=HttpUtil.queryStringForPost(url); Toast.makeText(MainMenuActivity.this,result,Toast.LENGTH_LONG).show(); } }) .setNegativeButton("è???",newDialogInterface.OnClickListener(){ publicvoidonClick(DialogInterfacedialog,intid){ dialog.cancel(); } }); AlertDialogalert=builder.create(); alert.show(); } privatevoidunionTable(){ //êμày?ˉLayoutInflater LayoutInflaterinflater=LayoutInflater.from(this); Viewv=inflater.inflate(R.layout.union_table,null); finalSpinnerspinner1=(Spinner)v.findViewById(R.id.union_table_Spinner1); finalSpinnerspinner2=(Spinner)v.findViewById(R.id.union_table_Spinner2); StringurlStr=HttpUtil.BASE_URL+"servlet/UnionTableServlet"; try{ URLurl=newURL(urlStr); URLConnectionconn=url.openConnection(); InputStreamin=conn.getInputStream(); DocumentBuilderFactoryfactory=DocumentBuilderFactory .newInstance(); //??μ?DocumentBuilder???ó DocumentBuilderbuilder=factory.newDocumentBuilder(); //??μ?Document???ó Documentdoc=builder.parse(in); NodeListnl=doc.getElementsByTagName("table"); //Spinnerêy?Y Listitems=newArrayList(); for(inti=0;i<nl.getLength();i++){ //×à??±ào? Stringid=doc.getElementsByTagName("id") .item(i).getFirstChild().getNodeValue(); intnum=Integer.parseInt(doc.getElementsByTagName("num") .item(i).getFirstChild().getNodeValue()); Mapdata=newHashMap(); data.put("id",id); items.add(data); } //??μ?SpinnerAdapter SpinnerAdapteras=new SimpleAdapter(this,items, android.R.layout.simple_spinner_item, newString[]{"id"},newint[]{android.R.id.text1}); spinner1.setAdapter(as); spinner2.setAdapter(as); }catch(Exceptione){ e.printStackTrace(); } AlertDialog.Builderbuilder=newAlertDialog.Builder(this); builder.setMessage("??μ?òa2¢×à?e£?") .setCancelable(false) .setView(v) .setPositiveButton("è·?¨",newDialogInterface.OnClickListener(){ publicvoidonClick(DialogInterfacedialog,intid){ TextViewtv1=(TextView)spinner1.getSelectedView(); TextViewtv2=(TextView)spinner2.getSelectedView(); StringtableId1=tv1.getText().toString(); StringtableId2=tv2.getText().toString(); //2é?ˉ2?êy StringqueryString="tableId1="+tableId1+"&tableId2="+tableId2; //url Stringurl=HttpUtil.BASE_URL+"servlet/UnionTableServlet2?"+queryString; Stringresult=HttpUtil.queryStringForPost(url); } }) .setNegativeButton("è???",newDialogInterface.OnClickListener(){ publicvoidonClick(DialogInterfacedialog,intid){ dialog.cancel(); } }); AlertDialogalert=builder.create(); alert.show(); } privatevoidlogout(){ AlertDialog.Builderbuilder=newAlertDialog.Builder(this); builder.setMessage("??μ?òaí?3??μí3?e£?") .setCancelable(false) .setPositiveButton("è·?¨",newDialogInterface.OnClickListener(){ publicvoidonClick(DialogInterfacedialog,intid){ SharedPreferencespres=getSharedPreferences("user_msg",MODE_WORLD_WRITEABLE); SharedPreferences.Editoreditor=pres.edit(); editor.putString("id",""); editor.putString("name",""); Intentintent=newIntent(); intent.setClass(MainMenuActivity.this,LoginActivity.class); startActivity(intent); } }) .setNegativeButton("è???",newDialogInterface.OnClickListener(){ publicvoidonClick(DialogInterfacedialog,intid){ dialog.cancel(); } }); AlertDialogalert=builder.create(); alert.show(); }}程序運(yùn)行結(jié)果如下一(4)點(diǎn)餐功能客戶端實(shí)現(xiàn)進(jìn)入程序主菜單之后,單擊“點(diǎn)菜”項(xiàng)便進(jìn)入了點(diǎn)菜操作界面。點(diǎn)采功能是本項(xiàng)目中最為復(fù)雜的一個(gè)功能,它的操作過程分為三個(gè)步驟:開桌,點(diǎn)菜,下單。創(chuàng)建一個(gè)名為“OrderActivity”的Activity,該Activity繼承Activity,在OrderActivity頂部聲明使用到的實(shí)例,在OnCreate方法中初始化之。packagecom.amaker.wlo;importjava.io.UnsupportedEncodingException;importjava.text.SimpleDateFormat;importjava.util.ArrayList;importjava.util.Date;importjava.util.HashMap;importjava.util.List;importjava.util.Map;importorg.apache.http.NameValuePair;importorg.apache.http.client.entity.UrlEncodedFormEntity;importorg.apache.http.client.methods.HttpPost;importorg.apache.http.message.BasicNameValuePair;importtocol.HTTP;importandroid.app.Activity;importandroid.app.AlertDialog;importandroid.content.ContentResolver;importandroid.content.DialogInterface;importandroid.content.SharedPreferences;importandroid.database.Cursor;import.Uri;importandroid.os.Bundle;importandroid.view.LayoutInflater;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.widget.Button;importandroid.widget.EditText;importandroid.widget.LinearLayout;importandroid.widget.ListView;importandroid.widget.SimpleAdapter;importandroid.widget.SimpleCursorAdapter;importandroid.widget.Spinner;importandroid.widget.TextView;importandroid.widget.Toast;importcom.amaker.util.HttpUtil;publicclassOrderActivityextendsActivity{ //×ào???à-áD±í privateSpinnertableNoSpinner; //?a×à?¢μ?2?oí??μ¥°′?¥ privateButtonorderBtn,addBtn,startBtn; //è?êy±à?-?ò privateEditTextpersonNumEt; //μ?2?áD±í privateListViewlv; //?a×àéú3éμ???μ¥Id privateStringorderId; //μ?2?áD±í?D°ó?¨μ?êy?Y privateListdata=newArrayList(); //μ?2?áD±í?D??ì?μ?êy?Y?? privateMapmap; //ListViewμ?Adapter privateSimpleAdaptersa; //ListView?D??ê?μ?êy?Y?? privateString[]from={"id","name","num","price","remark"}; //òyó?μ?TextViewDrawableID privateint[]to=newint[5]; @Override protectedvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); //?aActivityéè??????2??? setContentView(R.layout.order); //êμày?ˉSpinner tableNoSpinner=(Spinner)findViewById(R.id.tableNoSpinner); //?a×ào???à-áD±íSpinner°ó?¨êy?Y setTableAdapter(); //êμày?ˉ?a×à°′?¥ startBtn=(Button)findViewById(R.id.startButton02); //?a?a×à°′?¥ìí?ó?àìy?÷ startBtn.setOnClickListener(startListener); //êμày?ˉμ?2?°′?¥ addBtn=(Button)findViewById(R.id.addMealButton01); //?aμ?2?°′?¥ìí?ó?àìy?÷ addBtn.setOnClickListener(addListener); //êμày?ˉ??μ¥°′?¥ orderBtn=(Button)findViewById(R.id.orderButton02); //?a??μ¥°′?¥ìí?ó?àìy?÷ orderBtn.setOnClickListener(orderListener); //êμày?ˉè?êy±à?-?ò personNumEt=(EditText)findViewById(R.id.personNumEditText02); //êμày?ˉListView lv=(ListView)findViewById(R.id.orderDetailListView01); //?aμ?2?áD±íListView°ó?¨êy?Y setMenusAdapter(); } //?aμ?2?áD±íListView°ó?¨êy?Y privatevoidsetMenusAdapter(){ //??ê?μ?2???μ?TextViewòyó? to[0]=R.id.id_ListView; to[1]=R._ListView; to[2]=R.id.num_ListView; to[3]=R.id.price_ListView; to[4]=R.id.remark_ListView; //êμày?ˉμ?2?áD±íListViewAdapter sa=newSimpleAdapter(this,data,R.layout.listview,from,to); //?aListView°ó?¨êy?Y lv.setAdapter(sa); } //?a×ào???à-áD±íSpinner°ó?¨êy?Y privatevoidsetTableAdapter(){ //·??ê±?μ?SQLiteêy?Y?a?D×ào?±íμ?Uri Uriuri=Uri.parse("content://vider.TABLES/table"); //òa????×ào?±í?Dμ?áD String[]projection={"_id","num","description"}; //2é?ˉ·???ó?±ê Cursorc=managedQuery(uri,projection,null,null,null); //êμày?ˉ×ào???à-áD±íSpinnerμ?Adapter SimpleCursorAdapteradapter2=newSimpleCursorAdapter(this, android.R.layout.simple_spinner_item,c, newString[]{"_id"},newint[]{android.R.id.text1}); //?a×ào?Spinner°ó?¨êy?Y tableNoSpinner.setAdapter(adapter2); } //?a×à?àìy?÷ privateOnClickListenerstartListener=newOnClickListener(){ @Override publicvoidonClick(Viewv){ Datedate=newDate(); SimpleDateFormatsdf=newSimpleDateFormat("yy:mm:ddhh:MM"); //?a×àê±?? StringorderTime=sdf.format(date); //?a×àó??§£?′óμ??????????t?D??μ? SharedPreferencespres=getSharedPreferences("user_msg", MODE_WORLD_READABLE); StringuserId=pres.getString("id",""); //×ào? TextViewtv=(TextView)tableNoSpinner.getSelectedView(); StringtableId=tv.getText().toString(); //è?êy StringpersonNum=personNumEt.getText().toString(); //???ó2?êyáD±í List<NameValuePair>params=newArrayList<NameValuePair>(); //ìí?ó???ó2?êy params.add(newBasicNameValuePair("orderTime",orderTime)); params.add(newBasicNameValuePair("userId",userId)); params.add(newBasicNameValuePair("tableId",tableId)); params.add(newBasicNameValuePair("personNum",personNum)); UrlEncodedFormEntityentity1=null; try{ entity1=newUrlEncodedFormEntity(params,HTTP.UTF_8); }catch(UnsupportedEncodingExceptione){ e.printStackTrace(); } //???ó·t???÷url Stringurl=HttpUtil.BASE_URL+"servlet/StartTableServlet"; //??μ????ó???óHttpPost HttpPostrequest=HttpUtil.getHttpPost(url); //éè??2é?ˉ2?êy request.setEntity(entity1); //??μ??ìó|?á1? Stringresult=HttpUtil.queryStringForPost(request); //???a×àéú3éμ???μ¥Id£??3?μ??è???orderId orderId=result; Toast. makeText(OrderActivity.this,result,Toast.LENGTH_LONG).show(); } }; //ìí2??àìy?÷ privateOnClickListeneraddListener=newOnClickListener(){ @Override publicvoidonClick(Viewv){ //μ÷ó?μ?2?·?·¨ addMeal(); } }; //ìí2?·?·¨ privatevoidaddMeal(){ //??μ?LayoutInflaterêμày LayoutInflaterinflater=LayoutInflater.from(this); //êμày?ˉ?úμˉ3????°?ò?Dìí?óμ?êóí? finalViewv=inflater.inflate(R.layout.order_detail,null); //??μ?êóí??Dμ?Spinner???ó£?2?μ¥??à-áD±í finalSpinnermenuSpinner=(Spinner)v.findViewById(R.id.menuSpinner); //??μ?êóí??Dμ?EditText???ó,êyá? EditTextnumEt=(EditText)v.findViewById(R.id.numEditText); //??μ?êóí??Dμ?EditTextêμày£?±?×¢ EditTextremarkEt=(EditText)v.findViewById(R.id.add_remarkEditText); //·??ê±?μ?SQLiteêy?Y?a?DMenuTbl±íμ?Uri Uriuri=Uri.parse("content://vider.MENUS/menu1"); //2é?ˉáD String[]projection={"_id","name","price"}; //??μ?ContentResolverêμày ContentResolvercr=getContentResolver(); //2é?ˉ·???ó?±ê Cursorc=cr.query(uri,projection,null,null,nul

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論