吴昊品工程级别软件项目 Round 2 —— 餐饮管理系统(C#)

此为一个标准的应用类的DBMS系统(数据库管理系统),正 如达芬奇的老师所说:不同的鸡蛋就有不同的画法,DBMS系统也是一样的,其应用在不同的场景,就会有不同的实现方式,有些甚至不仅仅是功能和UI的变 换,而是整个数据结构的变换,比如,考虑到数据之间的伸缩性的松紧程度的不同,其实现中可以采用由一些数组组成的结构体,或者是链表来实现,后者的伸缩性 更强(数据结构之间也不是完全对立的,比如,也可以使用游标数组来实现链表的功能)。

 

一.   背景

  机器人炒菜是全自动的,但是,即使是所有的事情都由机器人来处理,还是需要人来负责收银以及处理机器的一切异常(处理器可能会因为湿度,温度等原因发生一些不可预料的故障)。为了提高员工结账,管理客户的效率,我想到了这一套系统,平台为Windows XP,开发组件包括Visual Studio2010+Microsoft SQL Server 2005,用到的语言是C#,主要是考虑到C#的界面美观,并且,在之后可能会有一些联网的扩展,用C#的可扩展性和可维护性均较强。

 

二.   数据库表格规划

  经分析,主要由以下六个E-R实体图组成,结合公司的实际,我会做出一些修改,tb的意思是table(表单),分别为商品信息(tb_food),顾客 消费信息(tb_GuestFood),桌台信息(tb_Room),职员信息(tb_Waiter),用户信息(tb_User),商品类别信息 (tb_foodtype),下面一一介绍其主键以及其它的属性(主键必须唯一地标识这个元素):

 

  商品信息:主键为编号(ID),然后是类别编号(Foodty),商品代号(foodnum),商品名(foodname),商品价格(foodprice)。

商品类别信息:主键为类别编号(ID),然后是类别名(foodtype)。

顾 客的消费信息:主键为编号(ID),然后是商品代号(foodnum),商品名(foodname),消费数量(foodsum),商品价格 (foodallprice),开单人(waitername),备注(beizhu),消费桌台(zhuotai),消费时间(datatime)。

桌 台信息:主键为编号(ID),然后是名称(Roomname)(设置名称主要是考虑到酒店里面有一些专有名称的房间),简称(RoomJC),包间费 (RoomBJF),位置(RoomWZ),状态(RoomZT)(状态主要是区分这个桌台是否被人所占用),类型(RoomType)(比如大厅,包房 等),备注(RoomBZ)(比如一些重要的预定信息),其他信息(RoomQT),顾客姓名(GuestName),开台时间 (zhangdanDate),顾客人数(Num),开单人(WaiterName)。

用户信息:主键为编号(ID),然后是登录名(UserName),密码(UserPwd),权限(power)。

职 员信息:主键为系统编号(ID),然后是名字(WaiterName),CardNum(身份证号),职员编号(WaiterNum)(这个职员在公司的 编号,比如华中科技大学Dian团队的每一个队员就有一个唯一的编号,这样可以方便管理),性别(Sex),年龄(Age),电话(Tel)。


三.   项目的具体模块分析以及与炒菜机器人的结合

(1) 实现人机交互,界面美观,信息灵活,数据库安全可靠(用的是SQL Server),操作简单。

(2) 具备餐厅顾客的开台,点菜,加菜,账目查询和结账的功能,并且集员工的管理于一体(必要的时候可以将员工的财务管理系统和餐饮管理系统合二为一)。

(3) 能够对顾客的消费历史记录进行查询。

(4) 在后期可以考虑和机器人的处理器的联网,这样,便可以在客户点菜的同时将菜谱输入进机器人的程序中,方便了一体化的操作。

 

四。构成模块(这里以结构图的方式展现菜单(menu)的功能)构成模块

限于位置原因,后面四个子菜单的信息在此列出:

(1)           系统维护——权限管理,系统备份,系统恢复。

(2)           系统设置——口令设置,锁定系统。

(3)           帮助——关于。

(4)           退出——退出系统。

 

五.   软件初体验

点 开软件,首先映入眼帘的是注册登录系统,我在这里设置了三个权限(power属性),以区分不同的人员:超级管理员(拥有最高的权限),经理(不能维护系 统,但可以查看基础信息),普通职员(连查看基础信息的权利也被剥夺了)。该注册登录系统的界面以及大致的实现代码如下:

(吴昊注释:这样的注册登录系统不仅仅在DBMS系统中存在,在网站的后台中,甚至是操作系统的外层中都是非常普遍的,用的技术大同小异——例如Linux中的Shell外壳)

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlClient;

namespace MrCy

{

    public partial class Login : Form //窗体结构

    {

        public Login()

        {

            InitializeComponent();//初始化

        }

 

 

 

        private void Form1_Load(object sender, EventArgs e)

        {

            txtName.Focus();//设置焦点到txtName

        }

 

 

        private void txtPwd_KeyPress(object sender, KeyPressEventArgs e)

        {

            if (e.KeyChar == 13)

            {

                btnSubmit_Click(sender, e);

            }

        }

//这里设计了一个特别的功能,你点击回车的时候,可以直接跳过Enter,有点类似于QQ的快捷键ctrl+Enter。

        private void btnSubmit_Click(object sender, EventArgs e)

        {

            if (txtName.Text == "")//如果用户名为空

            {

                MessageBox.Show(“请输入用户名”,“警告”, MessageBoxButtons.OK, MessageBoxIcon.Warning);

            }

            else

            {

                if (txtPwd.Text == "")//如果密码为空

                {

                    MessageBox.Show(“请输入密码”,“警告”, MessageBoxButtons.OK, MessageBoxIcon.Warning);

                }

                else

                {

                    SqlConnection conn = BaseClass.DBConn.CyCon();

                    conn.Open();

                    SqlCommand cmd = new SqlCommand("select count(*) from tb_User where UserName='" + txtName.Text + "' and UserPwd='" + txtPwd.Text + "'", conn);

                    int i = Convert.ToInt32(cmd.ExecuteScalar());

                    if (i > 0)

                    {

                        cmd = new SqlCommand("select * from tb_User where UserName='" + txtName.Text + "'", conn);

                        SqlDataReader sdr = cmd.ExecuteReader();

                        sdr.Read();

                        string UserPower = sdr["power"].ToString().Trim();

                        conn.Close();

                        Main main = new Main();

                        main.power = UserPower;//这里以数字设置了power

                        main.Names = txtName.Text;

                        main.Times = DateTime.Now.ToShortDateString();

                        main.Show();

                        this.Hide();

                    }

                    else

                    {

                        MessageBox.Show("用户名或密码错误");

                    }

                }

            }

        }

 

        private void btnConcel_Click(object sender, EventArgs e)

        {

            if (MessageBox.Show("确定退出系统吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.OK)

            {

                Application.Exit();

            }

        }

    }

}

  之后我们便进入了主界面,如图所示,每一个桌台有如下两个状态可供选择,一个是待用状态,一个是使用状态,有点类似QQ游戏里面的桌位占用。下面的状态栏中有用户名和权限的信息。

源代码如下:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlClient;

namespace MrCy

{

    public partial class Main : Form

    {

        public Main()

        {

            InitializeComponent();

        }

        public SqlDataReader sdr;

        public string power;

        public string Names;

        public string Times;

        private void frmMain_Load(object sender, EventArgs e)

        {

//这里根据具体的权限处理权限信息

                switch (power)

                {

                    case "0": toolStripStatusLabel13.Text = "超级管理员"; break;

                    case "1": toolStripStatusLabel13.Text = "经理"; break;

                    case "2": toolStripStatusLabel13.Text = "一般用户"; break;

                }

            toolStripStatusLabel10.Text = Names;

            toolStripStatusLabel16.Text = Times;

            if (power == "2")

            {

                系统维护SToolStripMenuItem.Enabled = false;

                基础信息MToolStripMenuItem.Enabled = false;

            }

            if (power == "1")

            {

                系统维护SToolStripMenuItem.Enabled = false;

            }

           

        }

//对使用和待用状态的不同处理,主要是对桌台点击鼠标右键时,对应的某些选项进行了加灰色处理。(点击鼠标右键时对应的内容如下)

(图为桌子在使用状态下的点击结果)

 private void AddItems(string rzt)

        {

            if (rzt == "使用")

            {

                lvDesk.Items.Add(sdr["RoomName"].ToString(), 1);

            }

            else

            {

                lvDesk.Items.Add(sdr["RoomName"].ToString(), 0);

            }

        }

 

 

        private void 开台ToolStripMenuItem_Click(object sender, EventArgs e)

        {

            if (lvDesk.SelectedItems.Count != 0)

            {

 

                string names = lvDesk.SelectedItems[0].SubItems[0].Text;

                Open openroom = new Open();

                openroom.name = names;

                openroom.ShowDialog();

            }

            else

            {

                MessageBox.Show("请选择桌台");

            }

        }

 

        private void frmMain_Activated(object sender, EventArgs e)

        {

            lvDesk.Items.Clear();

            SqlConnection conn = BaseClass.DBConn.CyCon();

            conn.Open();

            SqlCommand cmd = new SqlCommand("select * from tb_Room", conn);

            sdr = cmd.ExecuteReader();

            while (sdr.Read())

            {

                string zt = sdr["RoomZT"].ToString().Trim();

                AddItems(zt);

            }

            conn.Close();

        }

        private void 点菜ToolStripMenuItem_Click(object sender, EventArgs e)

        {

            if (lvDesk.SelectedItems.Count != 0)

            {

                string names = lvDesk.SelectedItems[0].SubItems[0].Text;

                DC dc = new DC();

                dc.RName = names;

                dc.ShowDialog();

            }

            else

            {

                MessageBox.Show("请选择桌台");

            }

        }

 

        private void 消费查询ToolStripMenuItem_Click(object sender, EventArgs e)

        {

            if (lvDesk.SelectedItems.Count != 0)

            {

                string names = lvDesk.SelectedItems[0].SubItems[0].Text;

                Serch serch = new Serch();

                serch.RName = names;

                serch.ShowDialog();

            }

            else

            {

                MessageBox.Show("请选择桌台");

            }

        }

        private void 结账ToolStripMenuItem_Click(object sender, EventArgs e)

        {

            if (lvDesk.SelectedItems.Count != 0)

            {

                string names = lvDesk.SelectedItems[0].SubItems[0].Text;

                JZ jz = new JZ();

                jz.Rname = names;

                jz.ShowDialog();

            }

            else

            {

                MessageBox.Show("请选择桌台");

            }

 

        }

//这里是具体的对加灰的处理

        private void lvDesk_DoubleClick(object sender, EventArgs e)

        {

            Details details = new Details();

            details.TableName = lvDesk.SelectedItems[0].SubItems[0].Text;

            details.ShowDialog();

        }

        private void lvDesk_Click(object sender, EventArgs e)

        {

            string names = lvDesk.SelectedItems[0].SubItems[0].Text;

            SqlConnection conn = BaseClass.DBConn.CyCon();

            conn.Open();

            SqlCommand cmd = new SqlCommand("select * from tb_Room where RoomName='" + names + "'", conn);

            SqlDataReader sdr = cmd.ExecuteReader();

            sdr.Read();

            string zt = sdr["RoomZT"].ToString().Trim();

            sdr.Close();

            if (zt == "使用")

            {

                this.contextMenuStrip1.Items[0].Enabled = false;

                this.contextMenuStrip1.Items[1].Enabled = true;

                this.contextMenuStrip1.Items[3].Enabled = true;

                this.contextMenuStrip1.Items[5].Enabled = true;

                this.contextMenuStrip1.Items[6].Enabled = true;

            }

            if (zt == "待用")

            {

                this.contextMenuStrip1.Items[0].Enabled = true;

                this.contextMenuStrip1.Items[1].Enabled = false;

                this.contextMenuStrip1.Items[3].Enabled = false;

                this.contextMenuStrip1.Items[5].Enabled = false;

                this.contextMenuStrip1.Items[6].Enabled = false;

            }

            conn.Close();

        }

 

        private void 取消开台toolStripMenuItem_Click(object sender, EventArgs e)

        {

            if (lvDesk.SelectedItems.Count != 0)

            {

                string names = lvDesk.SelectedItems[0].SubItems[0].Text;

                SqlConnection conn = BaseClass.DBConn.CyCon();

                conn.Open();

                SqlCommand cmd = new SqlCommand("update tb_Room set RoomZT='待用',Num=0 where RoomName='" + names + "'", conn);

                cmd.ExecuteNonQuery();

                cmd = new SqlCommand("delete from tb_GuestFood where zhuotai='" + names + "'", conn);

                cmd.ExecuteNonQuery();

                conn.Close();

                frmMain_Activated(sender, e);

            }

            else

            {

                MessageBox.Show("ÇëÑ¡Ôñץ̀");

            }

        }

        private void 桌台信息ToolStripMenuItem1_Click(object sender, EventArgs e)

        {

            Desk desk = new Desk();

            desk.ShowDialog();

        }

 

        private void 职员信息ToolStripMenuItem1_Click(object sender, EventArgs e)

        {

            User users = new User();

            users.ShowDialog();

        }

 

        private void 日历ToolStripMenuItem1_Click(object sender, EventArgs e)

        {

            Calender calender = new Calender();

            calender.ShowDialog();

        }

 

        private void 记事本ToolStripMenuItem1_Click(object sender, EventArgs e)

        {

            System.Diagnostics.Process.Start("notepad.exe");

        }

 

        private void 计算器ToolStripMenuItem1_Click(object sender, EventArgs e)

        {

            System.Diagnostics.Process.Start("calc.exe");

        }

 

        private void 权限管理ToolStripMenuItem1_Click(object sender, EventArgs e)

        {

            QxGl qx = new QxGl();

            qx.ShowDialog();

        }

 

        private void 系统备份ToolStripMenuItem1_Click(object sender, EventArgs e)

        {

            BF bf = new BF();

            bf.ShowDialog();

        }

 

        private void 系统恢复ToolStripMenuItem1_Click(object sender, EventArgs e)

        {

            HF hf = new HF();

            hf.ShowDialog();

        }

 

        private void 口令设置ToolStripMenuItem1_Click(object sender, EventArgs e)

        {

            Pwd pwd = new Pwd();

            pwd.names = Names;

            pwd.ShowDialog();

        }

 

        private void 锁定系统ToolStripMenuItem1_Click(object sender, EventArgs e)

        {

            Lock locksystem = new Lock();

            locksystem.Owner = this;

            locksystem.ShowDialog();

        }

 

        private void 关于ToolStripMenuItem1_Click(object sender, EventArgs e)

        {

            AboutBox1 ab = new AboutBox1();

            ab.ShowDialog();

        }

 

        private void 退出系统ToolStripMenuItem1_Click(object sender, EventArgs e)

        {

            if (MessageBox.Show("È·¶¨Í˳ö±¾ÏµÍ³Âð£¿", "Ìáʾ", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK)

            {

                Application.Exit();

            }

        }

 

        private void 系统维护ToolStripMenuItem_Click(object sender, EventArgs e)

        {

 

        }

    }

}

(图为桌子在待使用状态下的点击结果)

点击开台之后,系统便进入到开台界面:

源代码如下:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlClient;

namespace MrCy

{

    public partial class Open : Form

    {

        public Open()

        {

            InitializeComponent();

        }

 

 

        public string name;

        public SqlConnection conn;

        private void frmOpen_Load(object sender, EventArgs e)

        {

            conn = BaseClass.DBConn.CyCon();

            conn.Open();

            SqlCommand cmd = new SqlCommand("select * from tb_Room",conn);

            SqlDataReader sdr = cmd.ExecuteReader();

            while (sdr.Read())

            {

               cbNum.Items.Add(sdr["RoomName"].ToString().Trim());

            }

            cbNum.SelectedItem= name.Trim();

            sdr.Close();

            cmd = new SqlCommand("select * from tb_Waiter",conn);

            sdr = cmd.ExecuteReader();

            while (sdr.Read())

            {

                cbWaiter.Items.Add(sdr["WaiterName"].ToString().Trim());

            }

            cbWaiter.SelectedIndex = 0;

            sdr.Close();

        }

 

 

 

        private void txtNum_KeyPress(object sender, KeyPressEventArgs e)

        {

            if ((e.KeyChar != 8 && !char.IsDigit(e.KeyChar)) && e.KeyChar != 13)

            {

                MessageBox.Show("请输入数字");//IsDigit函数用来检验

                e.Handled = true;

            }

        }

 

        private void btnSave_Click(object sender, EventArgs e)

        {

            if (txtNum.Text == ""||Convert.ToInt32(txtNum.Text)<=0)

            {

                MessageBox.Show("请输入用餐人数");

            }

            else

            {

                string RoomName = cbNum.SelectedItem.ToString();

                SqlCommand cmd1 = new SqlCommand("update tb_Room set GuestName='" + txtName.Text + "',zhangdanDate='" + dateTimePicker1.Value.ToString() + "',Num='" + Convert.ToInt32(txtNum.Text) + "',WaiterName='" + cbWaiter.SelectedItem.ToString() + "',RoomZT=’使用’ where RoomName='" + name + "'", conn);

                cmd1.ExecuteNonQuery();

                this.Close();

            }

        }

 

        private void btnExit_Click(object sender, EventArgs e)

        {

            this.Close();

        }

    }

}

保存了开台信息之后,便可以进入点菜和加菜环节

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlClient;

namespace MrCy

{

    public partial class DC : Form

    {

        public DC()

        {

            InitializeComponent();//窗体初始化

        }

        public string RName;

        private void frmDC_Load(object sender, EventArgs e)

        {

            this.Text = RName + “点/加菜”;

//这里的逻辑可以根据具体的炒菜机器人进行适当修改

            TreeNode newnode1 = tvFood.Nodes.Add("锅底");

            TreeNode newnode2 = tvFood.Nodes.Add("配菜");

            TreeNode newnode3 = tvFood.Nodes.Add("烟酒");

            TreeNode newnode4 = tvFood.Nodes.Add("主食");

            SqlConnection conn = BaseClass.DBConn.CyCon();

            conn.Open();

            SqlCommand cmd = new SqlCommand("select * from tb_food where foodty='1'", conn);

            SqlDataReader sdr = cmd.ExecuteReader();

            while (sdr.Read())

            {

                newnode1.Nodes.Add(sdr[3].ToString().Trim());

            }

            sdr.Close();

            cmd = new SqlCommand("select * from tb_food where foodty='2'", conn);

            sdr = cmd.ExecuteReader();

            while (sdr.Read())

            {

                newnode2.Nodes.Add(sdr[3].ToString().Trim());

            }

            sdr.Close();

            cmd = new SqlCommand("select * from tb_food where foodty='3'", conn);

            sdr = cmd.ExecuteReader();

            while (sdr.Read())

            {

                newnode3.Nodes.Add(sdr[3].ToString().Trim());

            }

            sdr.Close();

            cmd = new SqlCommand("select * from tb_food where foodty='4'", conn);

            sdr = cmd.ExecuteReader();

            while (sdr.Read())

            {

                newnode4.Nodes.Add(sdr[3].ToString().Trim());

            }

            sdr.Close();

            cmd = new SqlCommand("select * from tb_Waiter",conn);

            sdr = cmd.ExecuteReader();

            while (sdr.Read())

            {

                cbWaiter.Items.Add(sdr["WaiterName"].ToString().Trim());

            }

            cbWaiter.SelectedIndex = 0;

            sdr.Close();

            cmd = new SqlCommand("select RoomZT from tb_Room where RoomName='"+RName+"'",conn);

            string zt = Convert.ToString(cmd.ExecuteScalar());

            if (zt.Trim() == "待用")

            {

                groupBox1.Enabled = false;

                groupBox2.Enabled = false;

                groupBox3.Enabled = false;

                groupBox4.Enabled = false;

            }

            conn.Close();

            GetData();

            tvFood.ExpandAll();

        }

 

        private void treeView1_DoubleClick(object sender, EventArgs e)

        {

            string foodname = tvFood.SelectedNode.Text;

            if (foodname == "锅底" || foodname == "配菜" || foodname == "烟酒" || foodname == "主食")

            {

 

            }

            else

            {

                SqlConnection conn = BaseClass.DBConn.CyCon();

                conn.Open();

                SqlCommand cmd = new SqlCommand("select * from tb_food where foodname='" + foodname + "'", conn);

                SqlDataReader sdr = cmd.ExecuteReader();

                sdr.Read();

                txtNum.Text = sdr["foodnum"].ToString().Trim();

                txtName.Text = foodname;

                txtprice.Text = sdr["foodprice"].ToString().Trim();

                conn.Close();

                if (txtpnum.Text == "")

                {

                    MessageBox.Show("数量不能为空");

                    return;

                }

                else

                {

                    txtallprice.Text = Convert.ToString(Convert.ToInt32(txtprice.Text) * Convert.ToInt32(txtpnum.Text));

                }

            }

        }

 

        private void txtpnum_TextChanged(object sender, EventArgs e)

        {

            if (txtpnum.Text == "")

            {

                MessageBox.Show("数量不能为空");

                return;

            }

            else

            {

                if (Convert.ToInt32(txtpnum.Text) < 1)

                {

                    MessageBox.Show("数量不能为小于1的数字");

                    return;

                }

                else

                {

                    txtallprice.Text = Convert.ToString(Convert.ToInt32(txtprice.Text) * Convert.ToInt32(txtpnum.Text));

                }

            }

        }

        private void GetData()//连数据库

        {

            SqlConnection conn = BaseClass.DBConn.CyCon();

            SqlDataAdapter sda = new SqlDataAdapter("select foodname,foodsum,foodallprice,waitername,beizhu,zhuotai,datatime from tb_GuestFood where zhuotai='" + RName + "'order by ID desc", conn);

            DataSet ds = new DataSet();

            sda.Fill(ds);

            dgvFoods.DataSource = ds.Tables[0];

        }

 

        private void txtpnum_KeyPress(object sender, KeyPressEventArgs e)

        {

            if ((e.KeyChar != 8 && !char.IsDigit(e.KeyChar)) && e.KeyChar != 13)

            {

                MessageBox.Show("请输入数字");

                e.Handled = true;

            }

        }

 

        private void btnDelete_Click(object sender, EventArgs e)

        {

            if (dgvFoods.SelectedRows.Count > 0)

            {

                string names = dgvFoods.SelectedCells[0].Value.ToString();

                SqlConnection conn = BaseClass.DBConn.CyCon();

                conn.Open();

                SqlCommand cmd = new SqlCommand("delete from tb_GuestFood where foodname='" + names + "' and zhuotai='" + RName + "'", conn);

                cmd.ExecuteNonQuery();

                conn.Close();

                GetData();

            }

        }

//这里解决一些按钮的异常

        private void btnSave_Click(object sender, EventArgs e)

        {

            if (txtName.Text == "" || txtNum.Text == ""|| txtprice.Text == "")

            {

                MessageBox.Show("请选择菜系");

                return;

            }

            else

            {

                if (txtpnum.Text == "")

                {

                    MessageBox.Show("数量不能为空");

                    return;

                }

                else

                {

                    if (Convert.ToInt32(txtpnum.Text) <= 0)

                    {

                        MessageBox.Show("消费数量不能小于等于0");

                        return;

                    }

                    else

                    {

                        SqlConnection conn = BaseClass.DBConn.CyCon();

                        conn.Open();

                        SqlCommand cmd = new SqlCommand("insert into tb_GuestFood(foodnum,foodname,foodsum,foodallprice,waitername,beizhu,zhuotai,datatime) values('" + txtNum.Text.Trim() + "','" + txtName.Text.Trim() + "','" + txtpnum.Text.Trim() + "','" + Convert.ToDecimal(txtallprice.Text.Trim()) + "','" + cbWaiter.SelectedItem.ToString() + "','" + txtbz.Text.Trim() + "','" + RName + "','" + DateTime.Now.ToString() + "')", conn);

                        cmd.ExecuteNonQuery();

                        conn.Close();

                        GetData();

                    }

                }

            }

        }

 

        private void btnExit_Click(object sender, EventArgs e)

        {

            this.Close();

        }

 

 

    }

}

在这里,我们暂时缓一下,处理一下数据库的联结问题,因为这里选择的是SQL Server,所以采用如下代码:

using System;

using System.Collections.Generic;

using System.Text;

using System.Data.SqlClient;

namespace MrCy.BaseClass

{

    class DBConn

    {

        public static SqlConnection CyCon()

        {

            return new SqlConnection("server=(local);database=eat;uid=sa;pwd=888888");

        }

    }

}

关于结账,我们有如下的界面:(消费查询暂时有一些问题,是否是同一个界面我暂时也不知道)

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlClient;

namespace MrCy

{

    public partial class JZ : Form

    {

        public JZ()

        {

            InitializeComponent();

        }

        public string Rname;

        public string price;

        public string bjf;

        private void frmJZ_Load(object sender, EventArgs e)

        {

            this.Text = Rname + "结账";

            groupBox1.Text = "当前桌台-" + Rname;

            SqlConnection conn = BaseClass.DBConn.CyCon();

            SqlDataAdapter sda = new SqlDataAdapter("select foodname,foodsum,foodallprice,waitername,beizhu,zhuotai,datatime from tb_GuestFood where zhuotai='" + Rname + "'order by ID desc", conn);

            DataSet ds = new DataSet();

            sda.Fill(ds);

            dgvRecord.DataSource = ds.Tables[0];

            conn.Open();

            SqlCommand cmd = new SqlCommand("select sum(foodallprice) from tb_GuestFood where zhuotai='" + Rname + "'", conn);

            price = Convert.ToString(cmd.ExecuteScalar());

            if (price == "")

            {

                lblprice.Text = "0";

                btnJZ.Enabled = false;

            }

            else

            {

                cmd = new SqlCommand("select RoomBJF from tb_Room where RoomName='"+Rname+"'", conn);

                bjf = cmd.ExecuteScalar().ToString();

//这里涉及了一个打折的优惠活动,可以根据公司内部的具体优惠活动进行打折处理。

                if (bjf == "0")

                {

                    btnJZ.Enabled = true;

                    lblprice.Text = price + "*95%"+"+"+bjf+"=" + (Convert.ToDecimal(Convert.ToDouble(price) * Convert.ToDouble(0.95))).ToString("C");

                }

                else

                {

                    btnJZ.Enabled = true;

                    lblprice.Text = price + "*95%"+"+"+bjf+"=" + (Convert.ToDecimal(Convert.ToDouble(price) * Convert.ToDouble(0.95)) + Convert.ToDecimal(bjf)).ToString("C");

                }

                conn.Close();

            }

        }

 

        private void txtmoney_KeyPress(object sender, KeyPressEventArgs e)

        {

            if ((e.KeyChar != 8 && !char.IsDigit(e.KeyChar)) && e.KeyChar != 13)

            {

                MessageBox.Show("请输入数字");

                e.Handled = true;

            }

        }

 

        private void txtmoney_TextChanged(object sender, EventArgs e)

        {

            if (price == "")

            {

                lbl0.Text = "0";

            }

            else

            {

                if (txtmoney.Text == "")

                {

                    txtmoney.Text = "0";

                    lbl0.Text = "0";

                }

                else

                {

                    lbl0.Text = Convert.ToDecimal(Convert.ToDouble(txtmoney.Text.Trim()) - Convert.ToDouble(price) * Convert.ToDouble(0.95) - Convert.ToDouble(bjf)).ToString("C");

                }

            }

        }

        private void btnJZ_Click(object sender, EventArgs e)

        {

            if (txtmoney.Text == ""||lbl0.Text=="0")

            {

                MessageBox.Show("请先结账");

                return;

            }

            else

            {

                if (lbl0.Text.Substring(1, 1) == "-")

                {

                    MessageBox.Show("金额不足");

                    return;

                }

                else

                {

                    SqlConnection conn = BaseClass.DBConn.CyCon();

                    conn.Open();

                    SqlCommand cmd = new SqlCommand("delete from tb_GuestFood where zhuotai='" + Rname + "'", conn);

                    cmd.ExecuteNonQuery();

                    cmd = new SqlCommand("update tb_Room set RoomZT='待用',Num=0,WaiterName='' where RoomName='" + Rname + "'", conn);

//结账之后。桌台的状态重新恢复为待用

                    cmd.ExecuteNonQuery();

                    conn.Close();

                    this.Close();

 

                }

            }

        }

 

posted on 2013-02-28 17:22  吴昊系列  阅读(1069)  评论(0编辑  收藏  举报

导航