C#餐饮收银系统

一、引言

餐饮收银系统是一种用于管理餐馆、咖啡厅、快餐店等餐饮业务的计算机化工具。它旨在简化点餐、结账、库存管理等任务,提高运营效率,增强客户体验,同时提供准确的财务记录。C# 餐饮收银系统是一种使用C#编程语言开发的餐饮业务管理软件,具有以下主要功能:

二、需求分析

分析思维导图

三、程序截图

登录

管理员主界面

添加食物界面

服务员订单界面

修改食物详情界面

未完成订单界面

支付成功界面

四、程序说明

管理员账号和密码:admin, admin

服务员账号和密码: test, test

注:可自行注册账号并登录,但是只能注册服务员账号

五、代码

AdminWindows.cs

cs 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Cashier
{
    /// <summary>
    /// AdminWindow.xaml 的交互逻辑
    /// </summary>
    public partial class AdminWindow : Window
    {
        public AdminWindow()
        {
            InitializeComponent();
            frame.Source = new Uri("MenuEditPage.xaml", UriKind.Relative);
        }

        private void textBlock2_Copy_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;
            String choice = btn.Content.ToString();
            switch (choice)
            {
                case "菜单编辑":
                    LoadMenuEditPage();
                    break;
                case "添加食物":
                    LoadAddFoddPage();
                    break;
                case "食物编辑":
                    LoadFoodEditPage();
                    break;
                case "已完成订单":
                    LoadOderCompletedPage();
                    break;
                case "未完成订单":
                    LoadOderNotPage();
                    break;
            }
        }

        private void LoadMenuEditPage()
        {
            frame.Source = new Uri("MenuEditPage.xaml", UriKind.Relative);
        }

        private void LoadAddFoddPage()
        {
            frame.Source = new Uri("AddFoodPage.xaml", UriKind.Relative);
        }

        private void LoadOderCompletedPage()
        {
            frame.Source = new Uri("OderCompletedPage.xaml", UriKind.Relative);
        }

        private void LoadOderNotPage()
        {
            frame.Source = new Uri("OderNotPage.xaml", UriKind.Relative);
        }

        private void LoadFoodEditPage()
        {
            frame.Source = new Uri("FoodEditPage.xaml", UriKind.Relative);
        }
    }
}

AddFoodPage.cs

cs 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using MySql.Data.MySqlClient;
namespace Cashier
{
    /// <summary>
    /// AddFoodPage.xaml 的交互逻辑
    /// </summary>
    ///  
    public partial class AddFoodPage : Page
    {

        private String mysqlConnStr = "server=localhost;User Id=root;password=;Database=canyin";
        public AddFoodPage()
        {
            InitializeComponent();
        }

        private void btn_Click(object sender, RoutedEventArgs e)
        {

            InsertFood();

        }

        private void InsertFood()
        {
            String foodName = foodNameBox.Text.ToString();
            String price = priceBox.Text.ToString();
            String category = categoryBox.Text;

            if(foodName.Equals("") || price.Equals("") || category.Equals(""))
            {
                resultBox.Text = "请将食物信息填写完整";
                return;
            }

            // MessageBox.Show("食物名称是:" + foodName + ", 价格是: " + price + ", 种类是: " + category);
            try
            {
             
                MySqlConnection conn = new MySqlConnection(mysqlConnStr);
                conn.Open();
                String cmd = "insert into food(name, price, category) values('" + foodName + "','" + price + "','" + category + "')";
                MySqlCommand mycmd = new MySqlCommand(cmd, conn);
                if (mycmd.ExecuteNonQuery() > 0)
                {           
                    resultBox.Text = "食品添加成功";
                    foodNameBox.Text = "";
                    priceBox.Text = "";
                    categoryBox.Text = "";
                    conn.Close();
                }
            }
            catch (Exception e)
            {
                resultBox.Text = "食品添加失败" + e.Message;
     
            }
        }

      
    }
}

CommonValue.cs

cs 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cashier
{
    class CommonValue
    {
        public static int EDIT_FOOD_ID = 5;
        public static String mysqlConectString = "server=localhost;User Id=root;password=;Database=canyin";
        public static String USER_NAME;
        public static int FOOD_PAY_ID = 556;
    }
}

MainWindows.cs

cs 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using MySql.Data.MySqlClient;

namespace Cashier
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        //用户账户
        private String user;
        private String password;
        public MainWindow()
        {
            InitializeComponent();
        }

        private void richTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {

        }

        private void textBox_TextChanged(object sender, TextChangedEventArgs e)
        {

        }

        //监听注册按钮
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;
            String choice = btn.Content.ToString();
            switch (choice)
            {
                case "登录":
                    UserLogin();
                    break;
                case "注册":
                    UserRegister();
                    break;
            }
            
        
        }

        private void button1_Click_1(object sender, RoutedEventArgs e)
        {

        }

        private void UserLogin()
        {
            //用户登录的逻辑代码
            user = userBox.Text.ToString();
            password = passwordBox.Text.ToString();
            if(user.Equals(""))
            {
                MessageBox.Show("请输入用户名");
            }
            else if(password.Equals(""))
            {
                MessageBox.Show("请输入密码");
            }
            else
            {
                CheckInfoAndLogin();
            }
        }

        private void UserRegister()
        {
            //跳转到登陆界面
            RegisterWindow register = new RegisterWindow();
            register.Show();
            this.Close();
        }

        //检查用户的数据,如果查询失败则返回密码错误
        private void CheckInfoAndLogin()
        {
            
            try
            {             
                MySqlConnection conn = new MySqlConnection(CommonValue.mysqlConectString);
                conn.Open();
                string cmd = "select * from user where user='" + user + "'";
                MySqlCommand myCmd = new MySqlCommand(cmd, conn);
                MySqlDataReader reader = myCmd.ExecuteReader();
                reader.Read();
                string dbUser = reader["user"].ToString();
                string dbPassword = reader["password"].ToString();
                if (password.Equals(dbPassword) && dbUser.Equals("admin"))
                {
                    OpenAdminWindow();
                    CommonValue.USER_NAME = user;
                }
                else if (password.Equals(dbPassword))
                {
                    OpenWaiterWindow();
                    CommonValue.USER_NAME = user;
                }
                else
                {
                    MessageBox.Show("密码输入错误,请重新输入!");
                }
                conn.Close();
            }
        
            catch(Exception e)
            {
                String msg = e.Message;
                MessageBox.Show("数据库连接错误!" + msg);
            }
          
        }

        //打开管理员窗口
        private void OpenAdminWindow()
        {
            AdminWindow aw = new AdminWindow();
            aw.Show();
            this.Close();
        }

        //打开服务员窗口
        private void OpenWaiterWindow()
        {
            WaiterWindow ww = new WaiterWindow();
            ww.Show();
            this.Close();
        }

    }
}

OderNotPage.cs

cs 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using MySql.Data.MySqlClient;
using System.Data.SqlClient;
using System.Data;

namespace Cashier
{
    /// <summary>
    /// OderNotPage.xaml 的交互逻辑
    /// </summary>
    public partial class OderNotPage : Page
    {
        public OderNotPage()
        {
            InitializeComponent();
            ShowOders();
        }

        private void ShowOders()
        {
            try
            {
                //获取表格
                DataTable data = new DataTable("oder");
                data.Columns.Add(new DataColumn("oder_id", typeof(string)));
                data.Columns.Add(new DataColumn("sum", typeof(string)));

                MySqlConnection conn = new MySqlConnection(CommonValue.mysqlConectString);
                conn.Open();
                string cmd = "select * from oder where complete=0";
                MySqlCommand myCmd = new MySqlCommand(cmd, conn);
                MySqlDataAdapter mda = new MySqlDataAdapter(cmd, conn);
                MySqlDataReader reader = myCmd.ExecuteReader();
                while (reader.Read())
                {

                    string id = reader["oder_id"].ToString();
                    string name = reader["sum"].ToString();

                    data.Rows.Add(id, name);
                }
                listView.DataContext = data.DefaultView;

                conn.Close();

            }
            catch (Exception e)
            {
                MessageBox.Show("查询订单失败:" + e.Message);
            }

        }

        private void button_Click(object sender, RoutedEventArgs e)
        {
            CommonValue.FOOD_PAY_ID = int.Parse(idPayBox.Text.ToString());
            NavigationWindow window = new NavigationWindow();
            window.Source = new Uri("OderDetailPage.xaml", UriKind.Relative);
            window.Show();
        }
    }
}

六、交流与联系

复制代码
q:969060742 文档、完整代码、sql、程序资源
相关推荐
麦麦鸡腿堡1 小时前
Java的单例设计模式-饿汉式
java·开发语言·设计模式
简单点了1 小时前
go前后端项目的启动 、打包和部署
开发语言·后端·golang
爱吃山竹的大肚肚1 小时前
@Valid校验 -(Spring 默认不支持直接校验 List<@Valid Entity>,需用包装类或手动校验。)
java·开发语言
汤姆yu2 小时前
2026版基于python的协同过滤音乐推荐系统
开发语言·python
汤姆yu2 小时前
基于python的电子商务管理系统
开发语言·python
我是大咖2 小时前
C语言-贪吃蛇项目开发工具篇---ncursee库安装
c语言·开发语言
weixin_445476683 小时前
Java并发编程——synchronized的实现原理与应用
java·开发语言·并发·synchronized
加号33 小时前
【C#】获取电脑网卡MAC地址
windows·c#
yi碗汤园3 小时前
【超详细】C#自定义工具类-StringHelper
开发语言·前端·unity·c#·游戏引擎
sali-tec3 小时前
C# 基于halcon的视觉工作流-章49-网面破损
开发语言·图像处理·算法·计算机视觉·c#