码迷,mamicode.com
首页 > 其他好文 > 详细

课程设计报告

时间:2019-12-06 13:35:11      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:uri   userinfo   一个数据库   vat   The   wro   upd   logo   ++   

基于Android的移动点餐系统设计与实现

1.系统需求分析

1.1用例分析

Uml图如图1.1所示

 

   

                          1.1

 

 

1.2数据逻辑模型

移动点餐系统E-r图如图1.2所示

 

                         1.2

2系统总体设计

系统总体设计图如图1.3所示

     

                        1.3

 

 

在使用移动点餐系统的时候是要求先注册的,按照提示输入用户名,密码,电话,地址方可进行注册,在注册成功之后就可以进行登录,登录后就可以使用图上功能。自行进行点餐环节或外卖环节,进入点餐界面或外卖界面进行菜品的选择,完毕后进行提交。还可对订单信息和个人信息进行查询。

 

3系统数据库设计

根据前面E-r图设计出实现系统功能所需要的数据库表的结构,并以表格的形式列出每一个数据库表的表结构,即字段名、类型、长度、小数位数、是否主键、索引、是否允许为空、说明等。

                        Dish(菜品表)

字段名

数据类型

长度

主键

索引

外键

可空

说明

Id

Varcha

10

 

菜品id

Name

Char

10

 

菜品名

Imgname

Varchar

10

 

菜品图像名

Price

Varchar

10

 

菜品价格

 

4系统详细设计

 

 

 

 

1

注册

用户名,密码,电话,地址

向数据库中插入一个新的管理员用户

成功则转到登录页面失败则转到添加页面

2  2

 

登录

用户名和密码

根据输入用户名从数据库中找一个同名的用户并且进行密码比对

成功则跳转到操作页面,失败就转到登录页面

 3

   

点餐和外卖

进入界面即可

 

进行点餐

 

提交

 

 

 

 

 

5系统实现(关键代码)

5.1注册界面

通过输入用户名,密码,电话,地址进行注册。

 

 

 Xml代码

<TextView

        android:id="@+id/textView1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_gravity="center_horizontal"

        android:layout_marginTop="30dp"

        android:text="用户注册"

        android:textSize="25sp" />

 

    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content" 

        android:layout_margin="10dp"

        android:orientation="horizontal">

        <TextView

            android:id="@+id/textView2"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginLeft="30dp"

            android:text="用 户 名:" />

        <EditText

            android:id="@+id/etRegisterUserId"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginRight="30dp"

            android:ems="30" >

            <requestFocus />

        </EditText>

    </LinearLayout>

 

    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content" 

        android:layout_margin="10dp"

        android:orientation="horizontal">

        <TextView

            android:id="@+id/textView3"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginLeft="30dp"

            android:text="用户密码:" />

 

        <EditText

            android:id="@+id/etRegisterUserPsword"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginRight="30dp"

            android:ems="30"

            android:inputType="textPassword" >

 

            <requestFocus />

        </EditText>

    </LinearLayout>

 

    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content" 

        android:layout_margin="10dp"

        android:orientation="horizontal">

        <TextView

            android:id="@+id/textView4"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginLeft="30dp"

            android:text="确认密码:" />

 

        <EditText

            android:id="@+id/etRegisterUserAffirmPsword"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginRight="30dp"

            android:ems="30"

            android:inputType="textPassword" >

 

            <requestFocus />

        </EditText>

    </LinearLayout>

 

    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content" 

        android:layout_margin="10dp"

        android:orientation="horizontal">

        <TextView

            android:id="@+id/textView5"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginLeft="30dp"

            android:text="电话号码:" />

 

        <EditText

            android:id="@+id/etRegisterUserMobilePhone"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginRight="30dp"

            android:ems="30"

            android:inputType="phone" >

 

            <requestFocus />

        </EditText>

    </LinearLayout>

        

    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content" 

        android:layout_margin="10dp"

        android:orientation="horizontal">

        <TextView

            android:id="@+id/textView6"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginLeft="30dp"

            android:text="送餐地址:" />

        <EditText

            android:id="@+id/etRegisterUserAddress"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginRight="30dp"

            android:ems="30" >

            <requestFocus />

        </EditText>

    </LinearLayout>

    

    <LinearLayout

        android:layout_width="wrap_content"

        android:layout_height="wrap_content" 

        android:layout_marginTop="10dp"

        android:layout_gravity="center"

        android:orientation="horizontal">

        <Button

            android:id="@+id/btnRegister"

            android:layout_width="100dp"

            android:layout_height="wrap_content"

            android:text=" 注  册 " />

        <Button

            android:id="@+id/btnCancel"

            android:layout_width="100dp"

            android:layout_height="wrap_content"

            android:layout_marginLeft="30dp"

            android:text=" 取  消 " />

    </LinearLayout>

    </LinearLayout>

Java代码

package edu.cqut.MobileOrderFood;

import android.net.Uri;

import android.os.Bundle;

import android.app.Activity;

import android.content.Intent;

import android.view.Menu;

import android.view.View;

import android.widget.*;

public class RegisterActivity extends Activity {

public EditText metId, metPsword, metAffirmPsword, metPhone, metAddress;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_register);

 

metId = (EditText)findViewById(R.id.etRegisterUserId);

metPsword = (EditText)findViewById(R.id.etRegisterUserPsword);

metAffirmPsword = (EditText)findViewById(R.id.etRegisterUserAffirmPsword);

metPhone = (EditText)findViewById(R.id.etRegisterUserMobilePhone);

metAddress = (EditText)findViewById(R.id.etRegisterUserAddress);

Button btnOK = (Button)findViewById(R.id.btnRegister);

Button btnCancel = (Button)findViewById(R.id.btnCancel);

 

Button.OnClickListener mybtnListener = new Button.OnClickListener()

{

@Override

public void onClick(View v) {

switch (v.getId())

{

case R.id.btnCancel:

finish();

break;

case R.id.btnRegister:

String strPsword = metPsword.getText().toString();

String strAffirmPsword = metAffirmPsword.getText().toString();

if (strPsword.equals(strAffirmPsword))

{

 

Uri info = Uri.parse("用户注册信息");

Intent intentUserInfo = new Intent(null, info);

intentUserInfo.putExtra("user", metId.getText().toString());

intentUserInfo.putExtra("password", metPsword.getText().toString());

intentUserInfo.putExtra("phone", metPhone.getText().toString());

intentUserInfo.putExtra("address", metAddress.getText().toString());

setResult(RESULT_OK, intentUserInfo);

finish();

}

else

{

Toast.makeText(RegisterActivity.this,

"两次密码输入不一致,请重新输入密码!", Toast.LENGTH_LONG).show();

//清空密码输入框

metPsword.setText("");

metAffirmPsword.setText("");

//让密码输入框获得焦点

metPsword.setFocusable(true);

metPsword.setFocusableInTouchMode(true);

metPsword.requestFocus();

}

}

 

}

};

 

btnOK.setOnClickListener(mybtnListener);

btnCancel.setOnClickListener(mybtnListener);

}

 

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.register, menu);

return true;

}

}

5.2登录界面

注册后输入正确的用户名,密码,进行登录。

       

         

 Xml代码

 <LinearLayout

        android:layout_width="wrap_content"

        android:layout_height="wrap_content" 

        android:layout_margin="5dp"

        android:layout_gravity="center_horizontal"

        android:orientation="horizontal">

        <TextView

            android:id="@+id/textView2"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="用  户  名:" />

        <EditText

            android:id="@+id/etLoginUserId"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:ems="8" >

            <requestFocus />

        </EditText>

</LinearLayout>

<LinearLayout

        android:layout_width="wrap_content"

        android:layout_height="wrap_content" 

        android:layout_margin="5dp"

        android:layout_gravity="center_horizontal"

        android:orientation="horizontal">

        <TextView

            android:id="@+id/textView3"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="用户密码:" />

        <EditText

            android:id="@+id/etLoginUserPswrod"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:ems="8"

            android:inputType="textPassword">

        </EditText>

</LinearLayout>

<LinearLayout

        android:layout_width="wrap_content"

        android:layout_height="wrap_content" 

android:layout_gravity="center_horizontal"

        android:orientation="horizontal">

        <Button

            android:id="@+id/btnRegister"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_weight="1"

            android:text="注  册 " />

        <Button

            android:id="@+id/btnlogin"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_weight="1"

            android:text="登  录 " />

        <Button

            android:id="@+id/btnCancel"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_weight="1"

            android:text="取  消 " />

    </LinearLayout>

</LinearLayout>

 

 

Java代码

package edu.cqut.MobileOrderFood;

 

import android.app.Dialog;

import android.content.Context;

import android.view.View;

import android.widget.*;

 

public class LoginDialog extends Dialog

{

public enum ButtonID {BUTTON_NONE, BUTTON_OK, BUTTON_CANCEL, BUTTON_REGISTER};

public String mUserId=null; //用户名

public String mPsword=null; //用户密码

public Boolean mIsHoldUserId=false; //是否记住用户名

public ButtonID mBtnClicked=ButtonID.BUTTON_NONE;//指示哪个按钮被点击

 

public EditText mdtUserId = null;

public Button mbtnLogin=null;

public Button mbtnRegister=null;

 

public LoginDialog(Context context) {

super(context);

setContentView(R.layout.login);

this.setTitle("用户登录");

setCancelable(true);

 

mdtUserId = (EditText)findViewById(R.id.etLoginUserId);

final EditText dtPsword = (EditText)findViewById(R.id.etLoginUserPswrod);

    mbtnLogin = (Button)findViewById(R.id.btnlogin);

Button btnCancel = (Button)findViewById(R.id.btnCancel);

mbtnRegister = (Button)findViewById(R.id.btnRegister);

 

Button.OnClickListener buttonListener=new Button.OnClickListener(){

@Override

public void onClick(View v) {

switch (v.getId()){

case R.id.btnlogin:

mUserId = mdtUserId.getText().toString();

mPsword = dtPsword.getText().toString();

mBtnClicked = ButtonID.BUTTON_OK;

break;

case R.id.btnRegister:

mBtnClicked = ButtonID.BUTTON_REGISTER;

break;

case R.id.btnCancel:

mBtnClicked = ButtonID.BUTTON_CANCEL;

break;

}

dismiss();

}

};

mbtnLogin.setOnClickListener(buttonListener);

btnCancel.setOnClickListener(buttonListener);

mbtnRegister.setOnClickListener(buttonListener);

}

 

//使dtUserId控件显示用户名

public void DisplayUserName(String name)

{

mdtUserId.setText(name);

}

}

5.3点餐界面

 

Xml代码

<TableRow

        android:id="@+id/DishHead"

        android:layout_width="match_parent"

android:layout_height="wrap_content">

<TextView  

android:layout_width="wrap_content"

android:layout_height="wrap_content" 

android:textColor="#000000"

android:textSize="20sp"

android:gravity="center"

android:text="编号"/>

<TextView

    android:layout_height="wrap_content"

    android:layout_width="wrap_content"

    android:textColor="#000000"

    android:textSize="20sp" 

    android:gravity="center"

    android:layout_marginBottom="4dp"

     android:layout_marginLeft="10dp"

     android:layout_weight="2"

    android:text="菜品"/>

<TextView

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:textColor="#000000"

    android:textSize="20sp" 

    android:text="价格"

    android:layout_marginLeft="5dp"

    android:gravity="center"

    android:layout_weight="1"/>

    </TableRow>

    

<ListView

    android:layout_width="fill_parent"   

        android:layout_height="wrap_content"   

        android:id="@+id/ListViewCainpin"  />  

</LinearLayout>

Java代码

package edu.cqut.MobileOrderFood;

 

public class Dish

{

public int mId = -1;     

public String mName;

public int mImage;

public String mImageName;

public float mPrice;

}

 

 

 

6系统测试

本次课设所用的开发环境为
开发技术:SQLITE、Android Application Project
数据库:SQLITE
开发工具:SQLITE、Eclipse

6.1系统测试

  1. 测试app能否在手机或电脑模拟器中正常运行。
  2. 测试数据库能否顺利连接。
  3. 测试注册,登录能否正常进行。
  4. 测试点餐系统能否正常使用。
  5. 测试外卖系统能否正常使用。
  6. 测试个人中心系统能否正常使用。

 

 

 

 

 

 

6.2测试结果

 

App完成后又对其进行了重新的测试,各项功能均正常,测试结果图如下。

 

 

   

 

     

     

 

    

 

 

 

 

 

 

 

 

 

    

 

 

    

 

 

 

 

7.总结

 

经过两个礼拜的学习,研究和开发,终于按时完成了课设。通过这个课设,我认识到理论跟实际还是有很大的差别,对安卓的知识进行了进一步的了解,激发了自己对安卓的兴趣。虽然过程中遇到了很多困难,但是在同学的帮助下一一克服。通过不断的发现问题和解决问题的过程,使自己有了很大的提高,并且得到了宝贵的经验。在以后的学习里,会更加努力,细心。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

附件

  1. 布局文件

 

    <LinearLayout

        android:id="@+id/linearLayout1"

        android:layout_width="match_parent"

        android:layout_height="wrap_content" >

        <ImageView

            android:id="@+id/homeImageView"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:cropToPadding="true"

            android:scaleType="centerCrop"

            android:src="@drawable/diancanlogo" />

    </LinearLayout>

 

    <TableLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:layout_alignLeft="@+id/linearLayout1"

        android:layout_below="@+id/linearLayout1" >

        <TableRow

            android:id="@+id/tableRow1"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content" >

    <ImageButton

        android:id="@+id/imgBtnRest"

        android:layout_height="wrap_content"

        android:layout_weight="1"

        android:layout_marginTop="15dp"

        android:background="@drawable/diancan"/>

    <ImageButton

        android:id="@+id/imgBtnTakeout"

        android:layout_height="wrap_content"

        android:layout_weight="1"

        android:layout_marginTop="15dp"

        android:layout_marginLeft="5dp"

        android:background="@drawable/waimai"/>

        </TableRow>

        <TableRow

            android:id="@+id/tableRow2"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content" >

    <ImageButton

        android:id="@+id/imgBtnUserInfo"

        android:layout_height="wrap_content"

        android:layout_weight="1"

        android:layout_marginTop="5dp"

        android:background="@drawable/gerenzhongxin"/>

    <ImageButton

        android:id="@+id/imgBtnLogin"

        android:layout_height="wrap_content"

        android:layout_weight="1"

        android:layout_marginTop="5dp"

        android:layout_marginLeft="5dp"

        android:visibility="visible"

        android:background="@drawable/denglu"/>

    <ImageButton

        android:id="@+id/imgBtnLogout"

        android:layout_height="wrap_content"

        android:layout_weight="1"

        android:layout_marginTop="5dp"

        android:layout_marginLeft="5dp"

        android:visibility="gone"

        android:background="@drawable/zhuxiao"/>

        </TableRow>

    <ImageButton

        android:id="@+id/imgBtnMyOrderes"

        android:layout_height="wrap_content"

        android:layout_marginTop="5dp"

        android:background="@drawable/wodedingdan"/>

    </TableLayout>

</RelativeLayout>

 

 

    <TableRow

        android:id="@+id/DishHead"

        android:layout_width="match_parent"

android:layout_height="wrap_content">

<TextView  

android:layout_width="wrap_content"

android:layout_height="wrap_content" 

android:textColor="#000000"

android:textSize="20sp"

android:gravity="center"

android:text="编号"/>

<TextView

    android:layout_height="wrap_content"

    android:layout_width="wrap_content"

    android:textColor="#000000"

    android:textSize="20sp" 

    android:gravity="center"

    android:layout_marginBottom="4dp"

     android:layout_marginLeft="10dp"

     android:layout_weight="2"

    android:text="菜品"/>

<TextView

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:textColor="#000000"

    android:textSize="20sp" 

    android:text="价格"

    android:layout_marginLeft="5dp"

    android:gravity="center"

    android:layout_weight="1"/>

    </TableRow>

    

<ListView

    android:layout_width="fill_parent"   

        android:layout_height="wrap_content"   

        android:id="@+id/ListViewCainpin"  />  

</LinearLayout>

 

    <TableRow

        android:id="@+id/OrderedHead"

        android:layout_width="match_parent"

android:layout_height="wrap_content">

<TextView  

android:layout_width="120dp"

android:layout_height="wrap_content" 

android:textColor="#000000"

android:textSize="20sp"

android:gravity="center"

android:text="菜名"/>

<TextView

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:textColor="#000000"

    android:textSize="20sp" 

    android:text="单价"

    android:layout_weight="1"/>

<TextView

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:textColor="#000000"

    android:textSize="20sp" 

    android:text="数量"

    android:layout_weight="1"/>

<TextView

    android:id="@+id/sum"

    android:layout_width="wrap_content" 

android:layout_height="wrap_content"

    android:textColor="#000000"

    android:text="合计"

    android:layout_weight="1"

    android:textSize="20sp" />        

    </TableRow>

    

    <ListView

        android:id="@+id/OrderedListview"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:layout_below="@id/OrderedHead"/>

    

    <TableRow

        android:id="@+id/OrderEnd"

        android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="15dp"

android:layout_below="@id/OrderedListview">

<TextView  

android:layout_width="150dp"

android:layout_height="wrap_content" 

android:textColor="#000000"

android:textSize="20sp"

android:gravity="center"

android:text="总    价"/>

<TextView

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:textSize="20sp" 

    android:layout_weight="1"/>

<TextView

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:textSize="20sp" 

    android:layout_weight="1"/>

<TextView

    android:id="@+id/ordertotalprice"

    android:layout_width="wrap_content" 

android:layout_height="wrap_content"

    android:textColor="#000000"

    android:layout_weight="1"

    android:gravity="center"

    android:textSize="20sp" />        

    </TableRow>

    

    <LinearLayout

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_below="@id/OrderEnd"

        android:layout_centerHorizontal="true"

        android:layout_marginTop="15dp" >       

    <Button

        android:id="@+id/submit_cancel"

        android:layout_width="100dp"

        android:layout_height="wrap_content"

        android:text="取消"/>   

    <Button

        android:id="@+id/submit_ok"

        android:layout_width="100dp"

        android:layout_height="wrap_content"

        android:text="提交"/>  

    </LinearLayout>

 

</RelativeLayout>

              

 

 <TextView

        android:id="@+id/textView1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_gravity="center_horizontal"

        android:layout_marginTop="30dp"

        android:text="用户注册"

        android:textSize="25sp" />

 

    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content" 

        android:layout_margin="10dp"

        android:orientation="horizontal">

        <TextView

            android:id="@+id/textView2"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginLeft="30dp"

            android:text="用  户  名:" />

        <EditText

            android:id="@+id/etRegisterUserId"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginRight="30dp"

            android:ems="30" >

            <requestFocus />

        </EditText>

    </LinearLayout>

 

    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content" 

        android:layout_margin="10dp"

        android:orientation="horizontal">

        <TextView

            android:id="@+id/textView3"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginLeft="30dp"

            android:text="用户密码:" />

 

        <EditText

            android:id="@+id/etRegisterUserPsword"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginRight="30dp"

            android:ems="30"

            android:inputType="textPassword" >

 

            <requestFocus />

        </EditText>

    </LinearLayout>

 

    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content" 

        android:layout_margin="10dp"

        android:orientation="horizontal">

        <TextView

            android:id="@+id/textView4"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginLeft="30dp"

            android:text="确认密码:" />

 

        <EditText

            android:id="@+id/etRegisterUserAffirmPsword"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginRight="30dp"

            android:ems="30"

            android:inputType="textPassword" >

 

            <requestFocus />

        </EditText>

    </LinearLayout>

 

    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content" 

        android:layout_margin="10dp"

        android:orientation="horizontal">

        <TextView

            android:id="@+id/textView5"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginLeft="30dp"

            android:text="电话号码:" />

 

        <EditText

            android:id="@+id/etRegisterUserMobilePhone"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginRight="30dp"

            android:ems="30"

            android:inputType="phone" >

 

            <requestFocus />

        </EditText>

    </LinearLayout>

        

    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content" 

        android:layout_margin="10dp"

        android:orientation="horizontal">

        <TextView

            android:id="@+id/textView6"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginLeft="30dp"

            android:text="送餐地址:" />

        <EditText

            android:id="@+id/etRegisterUserAddress"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginRight="30dp"

            android:ems="30" >

            <requestFocus />

        </EditText>

    </LinearLayout>

    

    <LinearLayout

        android:layout_width="wrap_content"

        android:layout_height="wrap_content" 

        android:layout_marginTop="10dp"

        android:layout_gravity="center"

        android:orientation="horizontal">

        <Button

            android:id="@+id/btnRegister"

            android:layout_width="100dp"

            android:layout_height="wrap_content"

            android:text=" 注  册 " />

        <Button

            android:id="@+id/btnCancel"

            android:layout_width="100dp"

            android:layout_height="wrap_content"

            android:layout_marginLeft="30dp"

            android:text=" 取  消 " />

    </LinearLayout>

    

 

</LinearLayout>

 

  <LinearLayout

        android:orientation="vertical"

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        android:padding="5dp">

        <TabWidget

            android:id="@android:id/tabs"

            android:layout_width="fill_parent"

            android:layout_height="wrap_content">            

        </TabWidget>

 

        <FrameLayout

            android:id="@android:id/tabcontent"

            android:layout_width="fill_parent"

     android:layout_height="fill_parent"

     android:padding="3dp">            

        </FrameLayout>

       </LinearLayout>

</TabHost>

 

    <TextView

        android:id="@+id/textView1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_gravity="center_horizontal"

        android:layout_marginTop="30dp"

        android:text="用户信息"

        android:textSize="25sp" />

 

    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content" 

        android:layout_margin="10dp"

        android:orientation="horizontal">

        <TextView

            android:id="@+id/textView2"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginLeft="30dp"

            android:text="用  户  名:" />

        <TextView

            android:id="@+id/textUserId"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginRight="30dp"

            android:ems="30" >

        </TextView>

    </LinearLayout>

    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content" 

        android:layout_margin="10dp"

        android:orientation="horizontal">

        <TextView

            android:id="@+id/textView3"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginLeft="30dp"

            android:text="登录密码:" />

        <EditText

            android:id="@+id/etLoginPswrod"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginRight="30dp"

            android:ems="30" >

            <requestFocus />

        </EditText>

    </LinearLayout>

    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content" 

        android:layout_margin="10dp"

        android:orientation="horizontal">

        <TextView

            android:id="@+id/textView6"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginLeft="30dp"

            android:text="电话号码:" />

        <EditText

            android:id="@+id/etUserPhone"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginRight="30dp"

            android:ems="30" >

            <requestFocus />

        </EditText>

    </LinearLayout>

     <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content" 

        android:layout_margin="10dp"

        android:orientation="horizontal">

        <TextView

            android:id="@+id/textView7"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginLeft="30dp"

            android:text="送餐地址:" />

        <EditText

            android:id="@+id/etUserAddress"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginRight="30dp"

            android:ems="30" >

            <requestFocus />

        </EditText>

</LinearLayout>

<LinearLayout

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_marginTop="10dp"

        android:layout_gravity="center"

        android:orientation="horizontal" >

        <Button

            android:id="@+id/btnModify"

            android:layout_width="120dp"

            android:layout_height="wrap_content"

 

            android:gravity="center"

            android:text="修改 " />

        <Button

            android:id="@+id/btnReturn"

            android:layout_width="120dp"

            android:layout_height="wrap_content"

android:layout_marginLeft="15dp"

            android:gravity="center"

            android:text="返回" />

</LinearLayout>

</LinearLayout>

 

<LinearLayout

        android:layout_width="wrap_content"

        android:layout_height="wrap_content" 

        android:layout_margin="5dp"

        android:layout_gravity="center_horizontal"

        android:orientation="horizontal">

        <TextView

            android:id="@+id/textView2"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="用  户  名:" />

        <EditText

            android:id="@+id/etLoginUserId"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:ems="8" >

            <requestFocus />

        </EditText>

    </LinearLayout>

 

    <LinearLayout

        android:layout_width="wrap_content"

        android:layout_height="wrap_content" 

        android:layout_margin="5dp"

        android:layout_gravity="center_horizontal"

        android:orientation="horizontal">

        <TextView

            android:id="@+id/textView3"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="用户密码:" />

        <EditText

            android:id="@+id/etLoginUserPswrod"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:ems="8"

            android:inputType="textPassword">

        </EditText>

    </LinearLayout>

 

    <LinearLayout

        android:layout_width="wrap_content"

        android:layout_height="wrap_content" 

android:layout_gravity="center_horizontal"

        android:orientation="horizontal">

        <Button

            android:id="@+id/btnRegister"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_weight="1"

            android:text="注  册 " />

        <Button

            android:id="@+id/btnlogin"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_weight="1"

            android:text="登  录 " />

        <Button

            android:id="@+id/btnCancel"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_weight="1"

            android:text="取  消 " />

    </LinearLayout>

 

</LinearLayout>

 

<LinearLayout   

    android:layout_width="wrap_content"   

    android:layout_height="wrap_content"

    android:layout_gravity="center"

    android:orientation="horizontal">   

<TextView

     android:layout_width="wrap_content"   

     android:layout_height="wrap_content"   

     android:text="数量"/>  

<Button

     android:layout_width="40dp"

     android:layout_height="wrap_content"

     android:id="@+id/btnSub"

     android:text="-"/>

<TextView

     android:layout_width="40dp"

     android:layout_height="wrap_content"

     android:id="@+id/tvOrderNum"

     android:gravity="center"

     android:text="1"/>

<Button

     android:layout_width="30dp"

     android:layout_height="wrap_content"

     android:id="@+id/btnAdd"

     android:text="+"/>       

</LinearLayout>

<LinearLayout   

    android:layout_width="wrap_content"   

    android:layout_height="wrap_content"

    android:layout_gravity="center"

    android:orientation="horizontal">

<Button

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:text="确  定"

    android:id="@+id/order_dialog_ok"/>

<Button

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:text="取  消"

    android:id="@+id/order_dialog_cancel"/>

</LinearLayout>

</LinearLayout>  

  1. Java文件(部分)

1.Dish

package edu.cqut.MobileOrderFood;

public class Dish

{

public int mId = -1;      

public String mName;

public int mImage;

public String mImageName;

public float mPrice;

}

2.Dished

package edu.cqut.MobileOrderFood;

import java.util.ArrayList;

public class Dishes

{

public ArrayList<Dish> mDishes;  

public int GetDishQuantity()

{

return mDishes.size();

}

public Dish GetDishbyIndex(int i)

{

return mDishes.get(i);

}

public Dish GetDishbyName(String dishName)

{

int s = mDishes.size();

for (int i=0; i<s; i++) {

Dish theDish = mDishes.get(i);

if (dishName.equals(theDish.mName)) {

return theDish;

}

}

return null;

}

}

  1. Login

package edu.cqut.MobileOrderFood;

import android.app.Dialog;

import android.content.Context;

import android.view.View;

import android.widget.*;

public class LoginDialog extends Dialog

{

public enum ButtonID {BUTTON_NONE, BUTTON_OK, BUTTON_CANCEL, BUTTON_REGISTER};

public String mUserId=null;

public String mPsword=null;

public Boolean mIsHoldUserId=false;

public ButtonID mBtnClicked=ButtonID.BUTTON_NONE;

public EditText mdtUserId = null;

public Button mbtnLogin=null;

public Button mbtnRegister=null;

public LoginDialog(Context context) {

super(context);

setContentView(R.layout.login);

this.setTitle("用户登录");

setCancelable(true);

 

mdtUserId = (EditText)findViewById(R.id.etLoginUserId);

final EditText dtPsword = (EditText)findViewById(R.id.etLoginUserPswrod);

    mbtnLogin = (Button)findViewById(R.id.btnlogin);

Button btnCancel = (Button)findViewById(R.id.btnCancel);

mbtnRegister = (Button)findViewById(R.id.btnRegister);

 

Button.OnClickListener buttonListener=new Button.OnClickListener(){

@Override

public void onClick(View v) {

switch (v.getId()){

case R.id.btnlogin:

mUserId = mdtUserId.getText().toString();

mPsword = dtPsword.getText().toString();

mBtnClicked = ButtonID.BUTTON_OK;

break;

case R.id.btnRegister:

mBtnClicked = ButtonID.BUTTON_REGISTER;

break;

case R.id.btnCancel:

mBtnClicked = ButtonID.BUTTON_CANCEL;

break;

}

dismiss();

}

};

mbtnLogin.setOnClickListener(buttonListener);

btnCancel.setOnClickListener(buttonListener);

mbtnRegister.setOnClickListener(buttonListener);

}

public void DisplayUserName(String name)

{

mdtUserId.setText(name);

}

}

4.MyApplication

ackage edu.cqut.MobileOrderFood;

import java.util.ArrayList;

import android.app.Application;

import android.content.Context;

public class MyApplication extends Application

{

MyUser g_user;

ShoppingCart g_cart;

ArrayList<Order> g_orders;

// Dishes g_dishes;  

    public String g_ip="";     

    public String g_http_ip="";

    public int g_communiMode = 1;

    public int g_objPort = 35885;

    Context g_context;    

    public DBAdapter g_dbAdepter = null;

String g_imgDishImgPath="Android/data/edu.cqut.mobileorderfood/img";

}

  1. MyUser

package edu.cqut.MobileOrderFood;

public class MyUser

{

    public String mUserid = "";

    public String mSeatname = "";

public String mPassword = "";  

public String mUserphone = "";

    public String mUseraddress = "";

public Boolean mIslogined=false;

}

  1. Order

package edu.cqut.MobileOrderFood;

public class Order

{

public int mId = -1;

public ShoppingCart mOrderItems;

public String mOrderTime;

 

public Order(String userid)

{

mOrderItems = new ShoppingCart(userid);

}

 

6.DBAdapter

private final Context context;

private DBOpenHelper dbOpenHelper;

 

public DBAdapter(Context _context) {

    context = _context;

  }

 public void close() {

  if (db != null){

  db.close();

  db = null;

  }

}

 

  public void open() throws SQLiteException {  

  dbOpenHelper = new DBOpenHelper(context, DB_NAME, null, DB_VERSION);

  try {

  db = dbOpenHelper.getWritableDatabase();

  }

  catch (SQLiteException ex) {

  db = dbOpenHelper.getReadableDatabase();

  }   

}

  

 

  public long insert(Dish dish) {

    ContentValues newValues = new ContentValues();

    newValues.put(KEY_ID, dish.mId);

    newValues.put(KEY_NAME, dish.mName);

    newValues.put(KEY_IMGNAME, dish.mImageName);

    newValues.put(KEY_PRICE, dish.mPrice);

    

    return db.insert(DB_TABLE, null, newValues);

  }

 

 

  public ArrayList<Dish> queryAllData() {  

  Cursor results =  db.query(DB_TABLE, new String[] { KEY_ID, KEY_NAME, KEY_IMGNAME, KEY_PRICE},

  null, null, null, null, null);

  return ConvertToDishes(results);   

  }

  

  public Dish queryOneData(long id) {  

  Cursor results =  db.query(DB_TABLE, new String[] { KEY_ID, KEY_NAME, KEY_IMGNAME,

  KEY_PRICE}, KEY_ID+"="+id, null, null, null, null);

  return ConertToDish(results);   

  }

  

  private Dish ConertToDish(Cursor cursor)

  {

  int resultCounts = cursor.getCount();

  if (resultCounts == 0 || !cursor.moveToFirst()){

  return null;

  }

  Dish theDish = new Dish();

  theDish.mId = cursor.getInt(0);

  theDish.mName = cursor.getString(cursor.getColumnIndex(KEY_NAME));

  theDish.mImageName = cursor.getString(cursor.getColumnIndex(KEY_IMGNAME));

  theDish.mPrice = cursor.getFloat(cursor.getColumnIndex(KEY_PRICE));

 

  return theDish;   

  }

  

  private ArrayList<Dish> ConvertToDishes(Cursor cursor){

  int resultCounts = cursor.getCount();

  if (resultCounts == 0 || !cursor.moveToFirst()){

  return null;

  }

  ArrayList<Dish> dishes = new ArrayList<Dish>();

  for (int i = 0 ; i<resultCounts; i++){

  Dish theDish = new Dish();

  theDish.mId = cursor.getInt(0);

  theDish.mName = cursor.getString(cursor.getColumnIndex(KEY_NAME));

  theDish.mImageName = cursor.getString(cursor.getColumnIndex(KEY_IMGNAME));

  theDish.mPrice = cursor.getFloat(cursor.getColumnIndex(KEY_PRICE));

  dishes.add(theDish);

  

  cursor.moveToNext();

  }   

  return dishes;

  }

  

  public long deleteAllData() {

  return db.delete(DB_TABLE, null, null);

  }

 

  public long deleteOneData(long id) {

  return db.delete(DB_TABLE,  KEY_ID + "=" + id, null);

  }

 

  public long updateOneData(long id , Dish dish){

  ContentValues updateValues = new ContentValues();   

  updateValues.put(KEY_NAME, dish.mName);

  updateValues.put(KEY_IMGNAME, dish.mImageName);

  updateValues.put(KEY_PRICE, dish.mPrice);

  

  return db.update(DB_TABLE, updateValues,  KEY_ID + "=" + id, null);

  }

  

 

  private static class DBOpenHelper extends SQLiteOpenHelper

  {

 

  public DBOpenHelper(Context context, String name, CursorFactory factory, int version) {

    super(context, name, factory, version);

  }

 

  private static final String DB_CREATE = "create table " +

    DB_TABLE + " (" + KEY_ID + " integer primary key, " +

    KEY_NAME+ " text not null, " + KEY_IMGNAME+ " text," + KEY_PRICE + " float);";

 

  @Override

  public void onCreate(SQLiteDatabase _db) {

    _db.execSQL(DB_CREATE);

  }

 

  @Override

  public void onUpgrade(SQLiteDatabase _db, int _oldVersion, int _newVersion) {     

    _db.execSQL("DROP TABLE IF EXISTS " + DB_TABLE);

    onCreate(_db);

  }

}

  

 

    public boolean FillDishTable(ArrayList<Dish> dishes)

    {

     int s = dishes.size();

     for (int i=0; i<s; i++)

     {

     Dish theDish = dishes.get(i);

     if (insert(theDish) == -1)

     return false;

     }

     return true;

    }

    

  

public ArrayList<Map<String, Object>> getDishData()

{

 

ArrayList<Dish> dishes = queryAllData();

ArrayList<Map<String, Object>> fooddata=new ArrayList<Map<String,Object>>();  

 

int s = dishes.size();

for (int i=0; i<s; i++) {

Dish theDish = dishes.get(i);

Map<String, Object> map = new HashMap<String, Object>();

map.put("dishid", theDish.mId);

map.put("image", theDish.mImageName);

map.put("title", theDish.mName);

map.put("price", theDish.mPrice);

fooddata.add(map);

}

return fooddata;

}

 

课程设计报告

标签:uri   userinfo   一个数据库   vat   The   wro   upd   logo   ++   

原文地址:https://www.cnblogs.com/cunhua/p/11994613.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!