餐饮管理之结账

结账模块的设计

结账设计的是从开台模块中选择餐桌,连接数据库,选择餐桌的具体点菜信息,算出总价并显示,然后在数据库中添加实付列,找零列。

首先选择餐桌编号,然后点击结账按钮。

代码如下:

pay_name = comboBox1.Text;//选择餐桌编号
            if(pay_name!="")//选择时候的情况
            {
                string strConn = @"Data Source=.;Initial Catalog=Restaurant;Integrated Security=SSPI; ";
                SqlConnection conn = new SqlConnection(strConn);
                conn.Open();//连接数据库

                string sqlcommond = string.Format(@"select * from 具体点菜信息 where 桌台位置 = '" + pay_name + "'and 状态 = '未结账' ");
                SqlCommand cmd = new SqlCommand(sqlcommond, conn);

                //对SQL或存储过程执行后返回的“结果”进行操作
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;

                SqlDataReader dr = cmd.ExecuteReader();

                while (dr.Read())
                {
                    
                    float price = float.Parse(dr["单价"].ToString());
                    int num = Convert.ToInt32(dr["份数"].ToString());
                    int discount = Convert.ToInt32(dr["折扣"].ToString());  //提取出总金额的因数,求积得出总结。
                    sum += price * num * discount;
                }




                conn.Close();            //关闭数据库
                Payment payment = new Payment();  //创建一个新的窗口,
                payment.ShowDialog();
            }
            else
            {
                MessageBox.Show("请选择结账桌台编号!!");
            }

新设计一个新的子窗体,通过在主函数中编写如下代码,获取在结账窗体中得到的总金额。

textBox1.Text = Convert.ToString(Opentable.sum);

结账设计窗口如下,已显示消费的总金额。其中两个textbox控件因为不能去修改,故设计成只读模式。

找零事件中要大量的修改数据库中的餐桌的状态信息。代码如下:

private void button1_Click(object sender, EventArgs e)
        {
            // 实付金额
            float s1 = float.Parse(textBox2.Text);
            // 总金额
            float s2 = float.Parse(textBox1.Text);

            if (s1 < s2)// 防止服务员误操作收取的钱少于总金额
            {
                MessageBox.Show("钱数不够,请确认付款!!");
            
            }
            else
            { 

                string renturn = Convert.ToString(s1 - s2);// 应找零的金额
                textBox3.Text = renturn;


                // 再一次连接数据库
                string strConn = @"Data Source=.;Initial Catalog=Restaurant;Integrated Security=SSPI; ";
                SqlConnection conn = new SqlConnection(strConn);
                conn.Open();   

                //获取开台窗体中的餐桌号,并修改其状态为‘空闲’ ,可再次使用
                int desk = Convert.ToInt32(Opentable.pay_name);
                String sqlcommond1 = string.Format(@"update 桌台信息 set 状态='空闲' where 编号= '" + desk + "' ");
                
                // 操作获取的数据库内容
                SqlCommand cmd1 = new SqlCommand(sqlcommond1, conn);
                SqlDataReader sr1 = cmd1.ExecuteReader();
                sr1.Close();


                //添加找零列,之前写的是 insert into,后来发现添加列也是用update
                string sqlcommond2 = string.Format(@"update 点菜信息 set 找零='" + renturn + "',总价格 ='" + s2 + "',实收 ='" + s1 + "'  where 桌台位置= '" + desk + "' ");
                //String sqlcommond2 = string.Format(@"insert into 点菜信息 set 找零='"+renturn +"' where 编号= '" + desk + "' ");
                SqlCommand cmd2 = new SqlCommand(sqlcommond2, conn);
                SqlDataReader sr2 = cmd2.ExecuteReader();
                sr2.Close();


                //和上面的一样
                string sqlcommond3 = string.Format(@"update 具体点菜信息 set 状态='已结账' where 桌台位置= '" + desk + "' ");
                //String sqlcommond2 = string.Format(@"insert into 点菜信息 set 找零='"+renturn +"' where 编号= '" + desk + "' ");
                SqlCommand cmd3 = new SqlCommand(sqlcommond3, conn);
                SqlDataReader sr3 = cmd3.ExecuteReader();
                sr3.Close();

                string sqlcommondkaitai = string.Format(@"delete from 开台表 where 编号 = '" + desk + "'");
                SqlCommand cmd = new SqlCommand(sqlcommondkaitai, conn);
                SqlDataReader sr = cmd.ExecuteReader();
                sr.Close();

                //注意要将sum 清零!!!!
                Opentable.sum = 0;
            }

        }

最后在完成按钮中关闭窗体,完成结账操作。

this.Close();

 

 

posted @ 2016-05-27 17:45  team_h2s2z  阅读(593)  评论(0编辑  收藏  举报