版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Android实训报告院系:计算机与信息工程学院班级:10级软件技术(1)班学号:姓名:
无线点餐系统需求分析餐饮传统的点菜方式是纯人工操作,由服务员记录顾客点的菜,在具体工作中容易出现以下问题:手写单据字迹潦草从而导致上错菜、传菜分单出错现象严重、加菜和查账程序较繁琐。处理特殊口味有遗漏和偏差、客人催菜遗忘现象较频繁、计算账单易出错、不方便人员管理等等。正因如此,无线点餐模式应运而生。它不仅可以有效地提高餐饮业的工作效率,更可以规范服务体系,提高整体服务质量和管理水平,并为规模化经营提供了坚实的技术基础。我们生活在一个充斥着数字技术的世界里,数字技术几乎侵入到我们生活的每个细节。点餐系统在使用上不及Wi-Fi点餐系统便利:服务员依然使用手持终端为顾客点餐,当消费者点完餐后,服务员将存储在手持终端内的点餐信息,对准布置在餐厅各个位置的红外接收端进行发射,接收端会将点餐信息通过网线传送到前台计算机。前台计算机会对点餐信息进行分类处理,然后将点餐信息分别发送给收银台和厨房。
一登录模块一(1)(1)登录模块Android客户端实现首先,为了提高系统的安全性,要想使用该系统必须进行系统登录。其次,每个点餐信息中都要用到登录用户信息,这样可以做到责任分明,工作严谨。登录的基本流程是:通过用户输入的用户名称和用户密码,到后台数据库做查询,如果有该用户则进入系统,否则提示用户输入错误。创建一个Android工程,名称为“WirelessOrder_Client”。在工程的res\layout目录下,创建一个名称为“login_system.xml“的布局文件。
创建一个名称为”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); //设置标题 setTitle("掌中宝无线订餐系统-用户登录"); //设置当前Activity界面布局 setContentView(R.layout.login_system); //通过findViewById方法实例化组件 cancelBtn=(Button)findViewById(R.id.cancelButton); //通过findViewById方法实例化组件 loginBtn=(Button)findViewById(R.id.loginButton); //通过findViewById方法实例化组件 userEditText=(EditText)findViewById(R.id.userEditText); //通过findViewById方法实例化组件 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("用户名称或者密码错误,请重新输入!"); } } } }); } //登录方法 privatebooleanlogin(){ //获得用户名称 Stringusername=userEditText.getText().toString(); //获得密码 Stringpwd=pwdEditText.getText().toString(); //获得登录结果 Stringresult=query(username,pwd); if(result!=null&&result.equals("0")){ returnfalse; }else{ saveUserMsg(result); returntrue; } } //将用户信息保存到配置文件 privatevoidsaveUserMsg(Stringmsg){ //用户编号 Stringid=""; //用户名称 Stringname=""; //获得信息数组 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(); } //验证方法 privatebooleanvalidate(){ Stringusername=userEditText.getText().toString(); if(username.equals("")){ showDialog("用户名称是必填项!"); returnfalse; } Stringpwd=pwdEditText.getText().toString(); if(pwd.equals("")){ showDialog("用户密码是必填项!"); 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(); } //根据用户名称密码查询 privateStringquery(Stringaccount,Stringpassword){ //查询参数 StringqueryString="account="+account+"&password="+password; //url Stringurl=HttpUtil.BASE_URL+"servlet/LoginServlet?"+queryString; //查询返回结果 returnHttpUtil.queryStringForPost(url);}}为了实现登录功能,Android需要通过网络访问后台的数据库进行查询。Android访问网络的实现方法很多,如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{ //基础URL publicstaticfinalStringBASE_URL=":8888/WirelessOrder_Server/"; //获得Get请求对象request publicstaticHttpGetgetHttpGet(Stringurl){ HttpGetrequest=newHttpGet(url); returnrequest; } //获得Post请求对象request publicstaticHttpPostgetHttpPost(Stringurl){ HttpPostrequest=newHttpPost(url); returnrequest; } //根据请求获得响应对象response publicstaticHttpResponsegetHttpResponse(HttpGetrequest)throwsClientProtocolException,IOException{ HttpResponseresponse=newDefaultHttpClient().execute(request); returnresponse; } //根据请求获得响应对象response publicstaticHttpResponsegetHttpResponse(HttpPostrequest)throwsClientProtocolException,IOException{ HttpResponseresponse=newDefaultHttpClient().execute(request); returnresponse; } //发送Post请求,获得响应查询结果 publicstaticStringqueryStringForPost(Stringurl){ //根据url获得HttpPost对象 HttpPostrequest=HttpUtil.getHttpPost(url); Stringresult=null; try{ //获得响应对象 HttpResponseresponse=HttpUtil.getHttpResponse(request); //判断是否请求成功 if(response.getStatusLine().getStatusCode()==200){ //获得响应 result=EntityUtils.toString(response.getEntity()); returnresult; } }catch(ClientProtocolExceptione){ e.printStackTrace(); result="网络异常!"; returnresult; }catch(IOExceptione){ e.printStackTrace(); result="网络异常!"; returnresult; }returnnull;} //获得响应查询结果 publicstaticStringqueryStringForPost(HttpPostrequest){ Stringresult=null; try{ //获得响应对象 HttpResponseresponse=HttpUtil.getHttpResponse(request); //判断是否请求成功 if(response.getStatusLine().getStatusCode()==200){ //获得响应 result=EntityUtils.toString(response.getEntity()); returnresult; } }catch(ClientProtocolExceptione){ e.printStackTrace(); result="网络异常!"; returnresult; }catch(IOExceptione){ e.printStackTrace(); result="网络异常!"; returnresult; }returnnull;} //发送Get请求,获得响应查询结果 publicstaticStringqueryStringForGet(Stringurl){ //获得HttpGet对象 HttpGetrequest=HttpUtil.getHttpGet(url); Stringresult=null; try{ //获得响应对象 HttpResponseresponse=HttpUtil.getHttpResponse(request); //判断是否请求成功 if(response.getStatusLine().getStatusCode()==200){ //获得响应 result=EntityUtils.toString(response.getEntity()); returnresult; } }catch(ClientProtocolExceptione){ e.printStackTrace(); result="网络异常!"; returnresult; }catch(IOExceptione){ e.printStackTrace(); result="网络异常!"; returnresult; }returnnull;}程序运行结果如下:一(2)登录模块服务器端实现后台的服务器实现采用JDBC访问后台数据库,Servlet响应HttpRequest请求,并返会响应结果。为了完成该功能我们需要安装MySQL数据库并配置Tomcat服务器,这部分内容将不再赘述。DBUtil工具类内容如下所示。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; }}创建UserDao接口实现类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实现类*/publicclassUserDaoImplimplementsUserDao{ /** *通过用户名称和密码登录,登录成功返回User对象,登录失败返回null */ publicUserlogin(Stringaccount,Stringpassword){ //查询SQL语句 Stringsql="selectid,account,password,name,permission,remark"+ "fromuserTbl"+ "whereaccount=?andpassword=?"; //数据库连接工具类 DBUtilutil=newDBUtil(); //获得连接 Connectionconn=util.openConnection(); try{ //获得预定义语句 PreparedStatementpstmt=conn.prepareStatement(sql); //设置查询参数 pstmt.setString(1,account); pstmt.setString(2,password); //执行查询 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()); }}创建LoginServlet类响应请应。类通过request.getParameter()方法获得请求参数,调用UserDaoImpl的login()方法,并根据登录结果返回响应结果信息。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(); //»ñµÃ¿Í»§¶ËÇëÇó²ÎÊý Stringusername=request.getParameter("account"); Stringpassword=request.getParameter("password"); Useru=dao.login(username,password); if(u!=null){ //ÏìÓ¦¿Í»§¶ËÄÚÈÝ£¬µÇ¼³É¹¦ 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)程序主菜单实现用户成功登陆之后便可以进入系统主菜单界面了。主菜单是通一个GridView来展示的。创建一个名称为”MainMenuActivity”的Activity,在onCreate()方法中设置Activity界面标题和布局,实例化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("ÕÆÖб¦ÎÞÏ߶©²Íϵͳ-Ö÷²Ëµ¥");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;}//ͼƬ×ÊÔ´Êý×é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(); //Æô¶¯¶©²Í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ÖлñµÃEditTextʵÀý 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("ÕæµÄÒª»»×ÀλÂð£¿") .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(){ //ʵÀý»¯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Êý¾Ý Listitems=newArrayList(); for(inti=0;i<nl.getLength();i++){ //×Àλ±àºÅ 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("ÕæµÄÒª²¢×ÀÂð£¿") .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(); //²éѯ²ÎÊý 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("ÕæµÄÒªÍ˳öϵͳÂð£¿") .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(); }}程序运行结果如下一(4)点餐功能客户端实现进入程序主菜单之后,单击“点菜”项便进入了点菜操作界面。点采功能是本项目中最为复杂的一个功能,它的操作过程分为三个步骤:开桌,点菜,下单。创建一个名为“OrderActivity”的Activity,该Activity继承Activity,在OrderActivity顶部声明使用到的实例,在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{ //×ÀºÅÏÂÀÁбí privateSpinnertableNoSpinner; //¿ª×À¡¢µã²ËºÍϵ¥°´Å¥ privateButtonorderBtn,addBtn,startBtn; //ÈËÊý±à¼¿ò privateEditTextpersonNumEt; //µã²ËÁбí privateListViewlv; //¿ª×ÀÉú³ÉµÄ¶©µ¥Id privateStringorderId; //µã²ËÁбíÖа󶨵ÄÊý¾Ý privateListdata=newArrayList(); //µã²ËÁбíÖоßÌåµÄÊý¾ÝÏî privateMapmap; //ListViewµÄAdapter privateSimpleAdaptersa; //ListViewÖÐÏÔʾµÄÊý¾ÝÏî privateString[]from={"id","name","num","price","remark"}; //ÒýÓõÄTextViewDrawableID privateint[]to=newint[5]; @Override protectedvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); //ΪActivityÉèÖýçÃæ²¼¾Ö setContentView(R.layout.order); //ʵÀý»¯Spinner tableNoSpinner=(Spinner)findViewById(R.id.tableNoSpinner); //Ϊ×ÀºÅÏÂÀÁбíSpinner°ó¶¨Êý¾Ý setTableAdapter(); //ʵÀý»¯¿ª×À°´Å¥ startBtn=(Button)findViewById(R.id.startButton02); //Ϊ¿ª×À°´Å¥Ìí¼Ó¼àÌýÆ÷ startBtn.setOnClickListener(startListener); //ʵÀý»¯µã²Ë°´Å¥ addBtn=(Button)findViewById(R.id.addMealButton01); //Ϊµã²Ë°´Å¥Ìí¼Ó¼àÌýÆ÷ addBtn.setOnClickListener(addListener); //ʵÀý»¯Ïµ¥°´Å¥ orderBtn=(Button)findViewById(R.id.orderButton02); //Ϊϵ¥°´Å¥Ìí¼Ó¼àÌýÆ÷ orderBtn.setOnClickListener(orderListener); //ʵÀý»¯ÈËÊý±à¼¿ò personNumEt=(EditText)findViewById(R.id.personNumEditText02); //ʵÀý»¯ListView lv=(ListView)findViewById(R.id.orderDetailListView01); //Ϊµã²ËÁбíListView°ó¶¨Êý¾Ý setMenusAdapter(); } //Ϊµã²ËÁбíListView°ó¶¨Êý¾Ý privatevoidsetMenusAdapter(){ //ÏÔʾµã²ËÏîµÄTextViewÒýÓà 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; //ʵÀý»¯µã²ËÁбíListViewAdapter sa=newSimpleAdapter(this,data,R.layout.listview,from,to); //ΪListView°ó¶¨Êý¾Ý lv.setAdapter(sa); } //Ϊ×ÀºÅÏÂÀÁбíSpinner°ó¶¨Êý¾Ý privatevoidsetTableAdapter(){ //·ÃÎʱ¾µØSQLiteÊý¾Ý¿âÖÐ×ÀºÅ±íµÄUri Uriuri=Uri.parse("content://vider.TABLES/table"); //ҪѡÔñ×ÀºÅ±íÖеÄÁÐ String[]projection={"_id","num","description"}; //²éѯ·Å»ØÓαê Cursorc=managedQuery(uri,projection,null,null,null); //ʵÀý»¯×ÀºÅÏÂÀÁбíSpinnerµÄAdapter SimpleCursorAdapteradapter2=newSimpleCursorAdapter(this, android.R.layout.simple_spinner_item,c, newString[]{"_id"},newint[]{android.R.id.text1}); //Ϊ×ÀºÅSpinner°ó¶¨Êý¾Ý tableNoSpinner.setAdapter(adapter2); } //¿ª×À¼àÌýÆ÷ privateOnClickListenerstartListener=newOnClickListener(){ @Override publicvoidonClick(Viewv){ Datedate=newDate(); SimpleDateFormatsdf=newSimpleDateFormat("yy:mm:ddhh:MM"); //¿ª×Àʱ¼ä StringorderTime=sdf.format(date); //¿ª×ÀÓû§£¬´ÓµÇ½ÅäÖÃÎļþÖлñµÃ SharedPreferencespres=getSharedPreferences("user_msg", MODE_WORLD_READABLE); StringuserId=pres.getString("id",""); //×ÀºÅ TextViewtv=(TextView)tableNoSpinner.getSelectedView(); StringtableId=tv.getText().toString(); //ÈËÊý StringpersonNum=personNumEt.getText().toString(); //ÇëÇó²ÎÊýÁбí List<NameValuePair>params=newArrayList<NameValuePair>(); //Ìí¼ÓÇëÇó²ÎÊý 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(); } //ÇëÇó·þÎñÆ÷url Stringurl=HttpUtil.BASE_URL+"servlet/StartTableServlet"; //»ñµÃÇëÇó¶ÔÏóHttpPost HttpPostrequest=HttpUtil.getHttpPost(url); //ÉèÖòéѯ²ÎÊý request.setEntity(entity1); //»ñµÃÏìÓ¦½á¹û Stringresult=HttpUtil.queryStringForPost(request); //½«¿ª×ÀÉú³ÉµÄ¶©µ¥Id£¬¸³Öµ¸øÈ«¾ÖorderId orderId=result; Toast. makeText(OrderActivity.this,result,Toast.LENGTH_LONG).show(); } }; //Ìí²Ë¼àÌýÆ÷ privateOnClickListeneraddListener=newOnClickListener(){ @Override publicvoidonClick(Viewv){ //µ÷Óõã²Ë·½·¨ addMeal(); } }; //Ìí²Ë·½·¨ privatevoidaddMeal(){ //»ñµÃLayoutInflaterʵÀý LayoutInflaterinflater=LayoutInflater.from(this); //ʵÀý»¯ÔÚµ¯³ö¶Ô»°¿òÖÐÌí¼ÓµÄÊÓͼ finalViewv=inflater.inflate(R.layout.order_detail,null); //»ñµÃÊÓͼÖеÄSpinner¶ÔÏ󣬲˵¥ÏÂÀÁбí finalSpinnermenuSpinner=(Spinner)v.findViewById(R.id.menuSpinner); //»ñµÃÊÓͼÖеÄEditText¶ÔÏó,ÊýÁ¿ EditTextnumEt=(EditText)v.findViewById(R.id.numEditText); //»ñµÃÊÓͼÖеÄEditTextʵÀý£¬±¸×¢ EditTextremarkEt=(EditText)v.findViewById(R.id.add_remarkEditText); //·ÃÎʱ¾µØSQLiteÊý¾Ý¿âÖÐMenuTbl±íµÄUri Uriuri=Uri.parse("content://vider.MENUS/menu1"); //²éѯÁÐ String[]projection={"_id","name","price"}; //»ñµÃContentResolverʵÀý ContentResolvercr=getContentResolver(); //²éѯ·Å»ØÓαê Cursorc=cr.query(uri,projection,null,null,nul
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 《肠内肠外营养护理》课件
- 2025粉刷劳务承包合同
- 乡村公路维护施工协议
- 水表配件维护水电班组施工合同
- 2024年木方板材节能减排技术应用合同范本2篇
- 文物保护捐赠协议
- 城市供水工程总承包协议
- 生态园水系治理工程协议
- 水利枢纽护坡桩施工合同
- 婚礼活动场地租赁协议
- 人教版数学二年级上册《表内乘法(一)》整理和复习
- 可填充颜色的地图(世界、中国、各省份)课件
- 物质的量浓度-总结
- 皮带纵向撕裂保护
- 220KV高压线防护方案
- et200故障安全模块操作说明
- 邮件分拣PLC控制系统设计
- CNC车间工作总结
- 白杨礼赞默写
- 《机电控制系统分析与设计》课程大作业之一――基于MATLAB
- 跟阿铭学Linux课后练习题答案
评论
0/150
提交评论