基于C#的商店销售管理系统的设计与实现

本文介绍了一个基于C#的商店销售管理系统的设计与实现,利用面向对象的编程思想,通过Winform创建了包括商品类product在内的功能,支持管理员和用户登录。程序存在一些bug,反映出作者在窗体应用开发上的提升空间。同时,文章中提及了在学校实验室遇到的一些管理规定变化,引发了作者对学校管理制度的不满。
摘要由CSDN通过智能技术生成

一、实验设计思路

Winform的方式实现,充分利用C#的面向对象特性,模拟了十种商品的进货、购买与销售过程,每种商品都有其特定的编号,名称,价格,库存(用类product实现)。登录设置分两种,一种是管理员登录(账号:lczq,密码:lz19951002),第二种是用户登录(账号:customer,密码:customer)。

二、实验设计分析

(1)建立 product 类

class product
{
        //商品编号
        int id;
        public int Id
        {
            get { return id; }
            set { if (value != 0) id = value; }
        }

        //商品名字
        string name;
        public string Name
        {
            get { return name; }
            set { if (value != "") name = value; }
        }

        //商品价格
        double price;
        public double Price
        {
            get { return price; }
            set { if (value >= 0) price = value; }
        }

        //商品数量
        int amount;
        public int Amount
        {
            get { return amount; }
            set { if (value >= 0) amount = value; }
        }

        public product() { }

        public product(int Id, string Name, double Price, int Amount)
        {
            id = Id;
            name = Name;
            price = Price;
            amount = Amount;
        }

        public double sum_price(int number)
        {
            return (double)number * price;
        }
}

(2) 然后分别对管理员和用户进行窗口设计, button textBox 会比较多,这里的设计具体看代码,标有注释。


三、程序流程

源程序提取地址:http://yunpan.cn/cwA3QwSGIUMKH (提取码:7929)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace lczq_weiStore
{
    public partial class Form1 : Form
    {

        int judge = 0;
        bool isOk = false;
        product[] goods = new product[10];
        int[] admin_num = new int[10];
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            init_admin_product();
            init_admin_num();
            this.Text = "Amazon";
        }

        //初始化商品
        void init_admin_product()
        {
            goods[0] = new product(1001, "iphone4", 1699, 40);
            goods[1] = new product(1002, "iphone4s", 1799, 50);
            goods[2] = new product(1003, "iphone5", 2999, 60);
            goods[3] = new product(1004, "iphone5s", 3499, 70);
            goods[4] = new product(1005, "iphone6", 4999, 80);
            goods[5] = new product(1006, "iphone6plus", 5899, 90);
            goods[6] = new product(1007, "MX2", 999, 20);
            goods[7] = new product(1008, "MX3", 1299, 50);
            goods[8] = new product(1009, "MX4", 1799, 60);
            goods[9] = new product(1010, "MX4pro", 2199, 70);

        }

        //初始化操作数组
        void init_admin_num()
        {
            for (int i = 0; i < admin_num.Length; i++) admin_num[i] = 0;
        }

        //登录按钮
        private void button1_Click_1(object sender, EventArgs e)
        {
            string name = UserName.Text;
            string password = PassWord.Text;
            if (name == "lczq" && password == "lz19951002")
            {
                judge = 1;
            }

            if (name == "customer" && password == "customer")
            {
                judge = 2;
            }

            if (judge == 0)
            {
                MessageBox.Show("userName or passWord is wrong!");
                clear_load();
            }

            else if (judge == 1)
            {
                MessageBox.Show("administrator successfully load!");
                change_load(false);
                clear_load();
                get_admin(true);
                get_administrator_in();
            }

            else
            {
                MessageBox.Show("customer successfully load!");
               
                change_load(false);
                clear_load();
                get_customer(true, false);
                get_administrator_in();
                MessageBox.Show("welcome to lczq_weiStore! In our store,there are " + goods[0].Name + " , "
                   + goods[1].Name + " , " + goods[2].Name + " , " + goods[3].Name + " , " + goods[4].Name
                   + " , " + goods[5].Name + " , " + goods[6].Name + " , " + goods[7].Name + " , " + goods[8].Name
                   + " , " + goods[9].Name + " . " + "Wish you have a good shopping day!");

            }

        }

        //取消登录
        private void button2_Click(object sender, EventArgs e)
        {
            clear_load();
        }

        void change_load(bool ok)
        {
            label1.Visible = ok;
            label2.Visible = ok;
            //label3.Visible = ok;
            UserName.Visible = ok;
            PassWord.Visible = ok;
            button1.Visible = ok;
            button2.Visible = ok;
            
        }
        void clear_load()
        {
            UserName.Clear();
            PassWord.Clear();
            UserName.Focus();
        }

        //载入管理员界面
        void get_admin(bool ok)
        {
            label4.Visible = ok;
            label5.Visible = ok;
            label6.Visible = ok;
            label7.Visible = ok;
            label8.Visible = ok;
            textBox1.Visible = ok;
            textBox2.Visible = ok;
            textBox3.Visible = ok;
            textBox4.Visible = ok;
            textBox5.Visible = ok;
            textBox6.Visible = ok;
            textBox7.Visible = ok;
            textBox8.Visible = ok;
            textBox9.Visible = ok;
            textBox10.Visible = ok;
            textBox11.Visible = ok;
            textBox12.Visible = ok;
            textBox13.Visible = ok;
            textBox14.Visible = ok;
            textBox15.Visible = ok;
            textBox16.Visible = ok;
            textBox17.Visible = ok;
            textBox18.Visible = ok;
            textBox19.Visible = ok;
            textBox20.Visible = ok;
            textBox21.Visible = ok;
            textBox22.Visible = ok;
            textBox23.Visible = ok;
            textBox24.Visible = ok;
            t
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值