码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2015-05-20 14:49:51      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:设计   应用程序   面向对象      c#   

一、实验设计思路

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) 然后分别对管理员和用户进行窗口设计,buttontextBox会比较多,这里的设计具体看代码,标有注释。


三、程序流程

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;
            textBox25.Visible = ok;
            textBox26.Visible = ok;
            textBox27.Visible = ok;
            textBox28.Visible = ok;
            textBox29.Visible = ok;
            textBox30.Visible = ok;
            textBox31.Visible = ok;
            textBox32.Visible = ok;
            textBox33.Visible = ok;
            textBox34.Visible = ok;
            textBox35.Visible = ok;
            textBox36.Visible = ok;
            textBox37.Visible = ok;
            textBox38.Visible = ok;
            textBox39.Visible = ok;
            textBox40.Visible = ok;
            textBox41.Visible = ok;
            textBox42.Visible = ok;
            textBox43.Visible = ok; 
            textBox44.Visible = ok;
            textBox45.Visible = ok;
            textBox46.Visible = ok; 
            textBox47.Visible = ok;
            textBox48.Visible = ok;
            textBox49.Visible = ok;
            textBox50.Visible = ok;
            button3.Visible = ok;
            button4.Visible = ok;
            button5.Visible = ok;
            button6.Visible = ok;
            button7.Visible = ok; 
            button8.Visible = ok;
            button9.Visible = ok;
            button10.Visible = ok;
            button11.Visible = ok;
            button12.Visible = ok;
            button13.Visible = ok;
            button14.Visible = ok;
            button15.Visible = ok;
            button16.Visible = ok;
            button17.Visible = ok;
            button18.Visible = ok;
            button19.Visible = ok;
            button20.Visible = ok;
            button21.Visible = ok;
            button22.Visible = ok;
            button23.Visible = ok;
            button24.Visible = ok;
            button25.Visible = ok;

        }

        //管理员登录后载入商品目录
        void get_administrator_in()
        {
            textBox2.Text = Convert.ToString(goods[0].Id);
            textBox12.Text = goods[0].Name;
            textBox22.Text = Convert.ToString(goods[0].Price);
            textBox32.Text = Convert.ToString(goods[0].Amount);
            textBox1.Text = "0";

            textBox3.Text = Convert.ToString(goods[1].Id);
            textBox13.Text = goods[1].Name;
            textBox23.Text = Convert.ToString(goods[1].Price);
            textBox33.Text = Convert.ToString(goods[1].Amount);
            textBox42.Text = "0";

            textBox4.Text = Convert.ToString(goods[2].Id);
            textBox14.Text = goods[2].Name;
            textBox24.Text = Convert.ToString(goods[2].Price);
            textBox34.Text = Convert.ToString(goods[2].Amount);
            textBox43.Text = "0";

            textBox5.Text = Convert.ToString(goods[3].Id);
            textBox15.Text = goods[3].Name;
            textBox25.Text = Convert.ToString(goods[3].Price);
            textBox35.Text = Convert.ToString(goods[3].Amount);
            textBox44.Text = "0";

            textBox6.Text = Convert.ToString(goods[4].Id);
            textBox16.Text = goods[4].Name;
            textBox26.Text = Convert.ToString(goods[4].Price);
            textBox36.Text = Convert.ToString(goods[4].Amount);
            textBox45.Text = "0";

            textBox7.Text = Convert.ToString(goods[5].Id);
            textBox17.Text = goods[5].Name;
            textBox27.Text = Convert.ToString(goods[5].Price);
            textBox37.Text = Convert.ToString(goods[5].Amount);
            textBox46.Text = "0";

            textBox8.Text = Convert.ToString(goods[6].Id);
            textBox18.Text = goods[6].Name;
            textBox28.Text = Convert.ToString(goods[6].Price);
            textBox38.Text = Convert.ToString(goods[6].Amount);
            textBox47.Text = "0";

            textBox9.Text = Convert.ToString(goods[7].Id);
            textBox19.Text = goods[7].Name;
            textBox29.Text = Convert.ToString(goods[7].Price);
            textBox39.Text = Convert.ToString(goods[7].Amount);
            textBox48.Text = "0";

            textBox10.Text = Convert.ToString(goods[8].Id);
            textBox20.Text = goods[8].Name;
            textBox30.Text = Convert.ToString(goods[8].Price);
            textBox40.Text = Convert.ToString(goods[8].Amount);
            textBox49.Text = "0";

            textBox11.Text = Convert.ToString(goods[9].Id);
            textBox21.Text = goods[9].Name;
            textBox31.Text = Convert.ToString(goods[9].Price);
            textBox41.Text = Convert.ToString(goods[9].Amount);
            textBox50.Text = "0";
        }

        //管理员登录后修改的信息保存起来goods[]
        void re_get_administrator_in()
        {
            goods[0].Id = Convert.ToInt32(textBox2.Text);
            goods[0].Name = textBox12.Text;
            goods[0].Price = Convert.ToInt32(textBox22.Text);
            goods[0].Amount = Convert.ToInt32(textBox32.Text);
            textBox1.Text = "0";

            goods[1].Id = Convert.ToInt32(textBox3.Text);
            goods[1].Name = textBox13.Text;
            goods[1].Price = Convert.ToInt32(textBox23.Text);
            goods[1].Amount = Convert.ToInt32(textBox33.Text);
            textBox42.Text = "0";

            goods[2].Id = Convert.ToInt32(textBox4.Text);
            goods[2].Name = textBox14.Text;
            goods[2].Price = Convert.ToInt32(textBox24.Text);
            goods[2].Amount = Convert.ToInt32(textBox34.Text);
            textBox43.Text = "0";

            goods[3].Id = Convert.ToInt32(textBox5.Text);
            goods[3].Name = textBox15.Text;
            goods[3].Price = Convert.ToInt32(textBox25.Text);
            goods[3].Amount = Convert.ToInt32(textBox35.Text);
            textBox44.Text = "0";

            goods[4].Id = Convert.ToInt32(textBox6.Text);
            goods[4].Name = textBox16.Text;
            goods[4].Price = Convert.ToInt32(textBox26.Text);
            goods[4].Amount = Convert.ToInt32(textBox36.Text);
            textBox45.Text = "0";

            goods[5].Id = Convert.ToInt32(textBox7.Text);
            goods[5].Name = textBox17.Text;
            goods[5].Price = Convert.ToInt32(textBox27.Text);
            goods[5].Amount = Convert.ToInt32(textBox37.Text);
            textBox46.Text = "0";

            goods[6].Id = Convert.ToInt32(textBox8.Text);
            goods[6].Name = textBox18.Text;
            goods[6].Price = Convert.ToInt32(textBox28.Text);
            goods[6].Amount = Convert.ToInt32(textBox38.Text);
            textBox47.Text = "0";

            goods[7].Id = Convert.ToInt32(textBox9.Text);
            goods[7].Name = textBox19.Text;
            goods[7].Price = Convert.ToInt32(textBox29.Text);
            goods[7].Amount = Convert.ToInt32(textBox39.Text);
            textBox48.Text = "0";

            goods[8].Id = Convert.ToInt32(textBox10.Text);
            goods[8].Name = textBox20.Text;
            goods[8].Price = Convert.ToInt32(textBox30.Text);
            goods[8].Amount = Convert.ToInt32(textBox40.Text);
            textBox49.Text = "0";

            goods[9].Id = Convert.ToInt32(textBox11.Text);
            goods[9].Name = textBox21.Text;
            goods[9].Price = Convert.ToInt32(textBox31.Text);
            goods[9].Amount = Convert.ToInt32(textBox41.Text);
            textBox50.Text = "0";

            textBox11.Text = Convert.ToString(goods[9].Id);
            textBox21.Text = goods[9].Name;
            textBox31.Text = Convert.ToString(goods[9].Price);
            textBox41.Text = Convert.ToString(goods[9].Amount);
            textBox50.Text = "0";
        }

        //进货数量增减
        private void button3_Click(object sender, EventArgs e)
        {
            if (admin_num[0] > 0) admin_num[0] -= 1;
            textBox1.Text = Convert.ToString(admin_num[0]);
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (admin_num[1] > 0) admin_num[1] -= 1;
            textBox42.Text = Convert.ToString(admin_num[1]);
        }

        private void button7_Click(object sender, EventArgs e)
        {
            if (admin_num[2] > 0) admin_num[2] -= 1;
            textBox43.Text = Convert.ToString(admin_num[2]);
        }

        private void button9_Click(object sender, EventArgs e)
        {
            if (admin_num[3] > 0) admin_num[3] -= 1;
            textBox44.Text = Convert.ToString(admin_num[3]);
        }

        private void button11_Click(object sender, EventArgs e)
        {
            if (admin_num[4] > 0) admin_num[4] -= 1;
            textBox45.Text = Convert.ToString(admin_num[4]);
        }

        private void button13_Click(object sender, EventArgs e)
        {
            if (admin_num[5] > 0) admin_num[5] -= 1;
            textBox46.Text = Convert.ToString(admin_num[5]);
        }

        private void button15_Click(object sender, EventArgs e)
        {
            if (admin_num[6] > 0) admin_num[6] -= 1;
            textBox47.Text = Convert.ToString(admin_num[6]);
        }

        private void button17_Click(object sender, EventArgs e)
        {
            if (admin_num[7] > 0) admin_num[7] -= 1;
            textBox48.Text = Convert.ToString(admin_num[7]);
        }

        private void button19_Click(object sender, EventArgs e)
        {
            if (admin_num[8] > 0) admin_num[8] -= 1;
            textBox49.Text = Convert.ToString(admin_num[8]);
        }

        private void button21_Click(object sender, EventArgs e)
        {
            if (admin_num[9] > 0) admin_num[9] -= 1;
            textBox50.Text = Convert.ToString(admin_num[9]);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            admin_num[0] += 1;
            textBox1.Text = Convert.ToString(admin_num[0]);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            admin_num[1] += 1;
            textBox42.Text = Convert.ToString(admin_num[1]);
        }

        private void button8_Click(object sender, EventArgs e)
        {
            admin_num[2] += 1;
            textBox43.Text = Convert.ToString(admin_num[2]);
        }

        private void button10_Click(object sender, EventArgs e)
        {
            admin_num[3] += 1;
            textBox44.Text = Convert.ToString(admin_num[3]);
        }

        private void button12_Click(object sender, EventArgs e)
        {
            admin_num[4] += 1;
            textBox45.Text = Convert.ToString(admin_num[4]);
        }

        private void button14_Click(object sender, EventArgs e)
        {
            admin_num[5] += 1;
            textBox46.Text = Convert.ToString(admin_num[5]);
        }

        private void button16_Click(object sender, EventArgs e)
        {
            admin_num[6] += 1;
            textBox47.Text = Convert.ToString(admin_num[6]);
        }

        private void button18_Click(object sender, EventArgs e)
        {
            admin_num[7] += 1;
            textBox48.Text = Convert.ToString(admin_num[7]);
        }

        private void button20_Click(object sender, EventArgs e)
        {
            admin_num[8] += 1;
            textBox49.Text = Convert.ToString(admin_num[8]);
        }

        private void button22_Click(object sender, EventArgs e)
        {
            admin_num[9] += 1;
            textBox50.Text = Convert.ToString(admin_num[9]);
        }

        //更新库存
        void update_inventory()
        {
            textBox32.Text = Convert.ToString(goods[0].Amount + admin_num[0]);
            textBox33.Text = Convert.ToString(goods[1].Amount + admin_num[1]);
            textBox34.Text = Convert.ToString(goods[2].Amount + admin_num[2]);
            textBox35.Text = Convert.ToString(goods[3].Amount + admin_num[3]);
            textBox36.Text = Convert.ToString(goods[4].Amount + admin_num[4]);
            textBox37.Text = Convert.ToString(goods[5].Amount + admin_num[5]);
            textBox38.Text = Convert.ToString(goods[6].Amount + admin_num[6]);
            textBox39.Text = Convert.ToString(goods[7].Amount + admin_num[7]);
            textBox40.Text = Convert.ToString(goods[8].Amount + admin_num[8]);
            textBox41.Text = Convert.ToString(goods[9].Amount + admin_num[9]);

        }

        //保存更新
        private void button23_Click(object sender, EventArgs e)
        {
            update_inventory();
            re_get_administrator_in();
            init_admin_num();
        }

        //取消更新
        private void button24_Click(object sender, EventArgs e)
        {
            get_administrator_in();
            init_admin_num();
        }

        //管理员退出登录
        private void button25_Click(object sender, EventArgs e)
        {
            MessageBox.Show("administrator successfully load out!");
            change_load(true);
            get_admin(false);
            clear_load();
        }

        //载入用户界面
        void get_customer(bool ok, bool no)
        {
            label4.Visible = ok;
            label5.Visible = ok;
            label6.Visible = ok;
            label7.Visible = ok;
            label8.Visible = ok;
            textBox1.Visible = ok; textBox1.Enabled = no;
            textBox2.Visible = ok; textBox2.Enabled = no;
            textBox3.Visible = ok; textBox3.Enabled = no;
            textBox4.Visible = ok; textBox4.Enabled = no;
            textBox5.Visible = ok; textBox5.Enabled = no;
            textBox6.Visible = ok; textBox6.Enabled = no;
            textBox7.Visible = ok; textBox7.Enabled = no;
            textBox8.Visible = ok; textBox8.Enabled = no;
            textBox9.Visible = ok; textBox9.Enabled = no;
            textBox10.Visible = ok; textBox10.Enabled = no;
            textBox11.Visible = ok; textBox11.Enabled = no;
            textBox12.Visible = ok; textBox12.Enabled = no;
            textBox13.Visible = ok; textBox13.Enabled = no;
            textBox14.Visible = ok; textBox14.Enabled = no;
            textBox15.Visible = ok; textBox15.Enabled = no;
            textBox16.Visible = ok; textBox16.Enabled = no;
            textBox17.Visible = ok; textBox17.Enabled = no;
            textBox18.Visible = ok; textBox18.Enabled = no;
            textBox19.Visible = ok; textBox19.Enabled = no;
            textBox20.Visible = ok; textBox20.Enabled = no;
            textBox21.Visible = ok; textBox21.Enabled = no;
            textBox22.Visible = ok; textBox22.Enabled = no;
            textBox23.Visible = ok; textBox23.Enabled = no;
            textBox24.Visible = ok; textBox24.Enabled = no;
            textBox25.Visible = ok; textBox25.Enabled = no;
            textBox26.Visible = ok; textBox26.Enabled = no;
            textBox27.Visible = ok; textBox27.Enabled = no;
            textBox28.Visible = ok; textBox28.Enabled = no;
            textBox29.Visible = ok; textBox29.Enabled = no;
            textBox30.Visible = ok; textBox30.Enabled = no;
            textBox31.Visible = ok; textBox31.Enabled = no;
            textBox32.Visible = ok; textBox32.Enabled = no;
            textBox33.Visible = ok; textBox33.Enabled = no;
            textBox34.Visible = ok; textBox34.Enabled = no;
            textBox35.Visible = ok; textBox35.Enabled = no;
            textBox36.Visible = ok; textBox36.Enabled = no;
            textBox37.Visible = ok; textBox37.Enabled = no;
            textBox38.Visible = ok; textBox38.Enabled = no;
            textBox39.Visible = ok; textBox39.Enabled = no;
            textBox40.Visible = ok; textBox40.Enabled = no;
            textBox41.Visible = ok; textBox41.Enabled = no;
            textBox42.Visible = ok; textBox42.Enabled = no;
            textBox43.Visible = ok; textBox43.Enabled = no;
            textBox44.Visible = ok; textBox44.Enabled = no;
            textBox45.Visible = ok; textBox45.Enabled = no;
            textBox46.Visible = ok; textBox46.Enabled = no;
            textBox47.Visible = ok; textBox47.Enabled = no;
            textBox48.Visible = ok; textBox48.Enabled = no;
            textBox49.Visible = ok; textBox49.Enabled = no;
            textBox50.Visible = ok; textBox50.Enabled = no;
            textBox54.Visible = ok;
            totalprice.Visible = ok;
            button3.Visible = no;
            button4.Visible = no;
            button5.Visible = no;
            button6.Visible = no;
            button7.Visible = no;
            button8.Visible = no;
            button9.Visible = no;
            button10.Visible = no;
            button11.Visible = no;
            button12.Visible = no;
            button13.Visible = no;
            button14.Visible = no;
            button15.Visible = no;
            button16.Visible = no;
            button17.Visible = no;
            button18.Visible = no;
            button19.Visible = no;
            button20.Visible = no;
            button21.Visible = no;
            button22.Visible = no;
            button23.Visible = no;
            button24.Visible = no;
            button25.Visible = no;
            button26.Visible = ok;
            button27.Visible = ok;
            button28.Visible = ok;
            button29.Visible = ok;
            button30.Visible = ok;
            button31.Visible = ok;
            button32.Visible = ok;
            button33.Visible = ok;
            button34.Visible = ok;
            button35.Visible = ok;
            button36.Visible = ok;
            button37.Visible = ok;
            button38.Visible = ok;
            button39.Visible = ok;
            button40.Visible = ok;
            button41.Visible = ok;
            button42.Visible = ok;
            button43.Visible = ok;
            button44.Visible = ok;
            button45.Visible = ok;
            button46.Visible = ok;
            button47.Visible = ok;
            button48.Visible = ok;

        }

        //用户减少商品
        void customer_decrease(int pose)
        {
            if (admin_num[pose] > 0)
            {
                admin_num[pose] -= 1;
                double pre_totalprice = Convert.ToDouble(totalprice.Text);
                double now_totalprice = pre_totalprice - goods[pose].Price;
                totalprice.Text = Convert.ToString(now_totalprice);
                goods[pose].Amount += 1;
            }
        }
        private void button26_Click(object sender, EventArgs e)
        {
            customer_decrease(0);
            textBox32.Text = Convert.ToString(goods[0].Amount);
            textBox1.Text = Convert.ToString(admin_num[0]);

        }

        private void button28_Click(object sender, EventArgs e)
        {
            customer_decrease(1);
            textBox33.Text = Convert.ToString(goods[1].Amount);
            textBox42.Text = Convert.ToString(admin_num[1]);

        }

        private void button30_Click(object sender, EventArgs e)
        {
            customer_decrease(2);
            textBox34.Text = Convert.ToString(goods[2].Amount);
            textBox43.Text = Convert.ToString(admin_num[2]);
        }

        private void button32_Click(object sender, EventArgs e)
        {
            customer_decrease(3);
            textBox35.Text = Convert.ToString(goods[3].Amount);
            textBox44.Text = Convert.ToString(admin_num[3]);
        }

        private void button34_Click(object sender, EventArgs e)
        {
            customer_decrease(4);
            textBox36.Text = Convert.ToString(goods[4].Amount);
            textBox45.Text = Convert.ToString(admin_num[4]);
            
        }

        private void button36_Click(object sender, EventArgs e)
        {
            customer_decrease(5);
            textBox37.Text = Convert.ToString(goods[5].Amount);
            textBox46.Text = Convert.ToString(admin_num[5]);
        }

        private void button38_Click(object sender, EventArgs e)
        {
            customer_decrease(6);
            textBox38.Text = Convert.ToString(goods[6].Amount);
            textBox47.Text = Convert.ToString(admin_num[6]);
            
        }

        private void button40_Click(object sender, EventArgs e)
        {
            customer_decrease(7);
            textBox39.Text = Convert.ToString(goods[7].Amount);
            textBox48.Text = Convert.ToString(admin_num[7]);
            
        }

        private void button42_Click(object sender, EventArgs e)
        {
            customer_decrease(8);
            textBox40.Text = Convert.ToString(goods[8].Amount);
            textBox49.Text = Convert.ToString(admin_num[8]);
            
        }

        private void button44_Click(object sender, EventArgs e)
        {
            customer_decrease(9);
            textBox41.Text = Convert.ToString(goods[9].Amount);
            textBox50.Text = Convert.ToString(admin_num[9]);
            
        }


        //用户添加商品
        void customer_increase(int pose)
        {
            if (goods[pose].Amount > 0)
            {
                admin_num[pose] += 1;
                double pre_totalprice = Convert.ToDouble(totalprice.Text);
                double now_totalprice = pre_totalprice + goods[pose].Price;
                totalprice.Text = Convert.ToString(now_totalprice);
                goods[pose].Amount -= 1;
            }
        }
        private void button27_Click(object sender, EventArgs e)
        {
            customer_increase(0);
            textBox32.Text = Convert.ToString(goods[0].Amount);
            textBox1.Text = Convert.ToString(admin_num[0]);
        }

        private void button29_Click(object sender, EventArgs e)
        {
            customer_increase(1);
            textBox33.Text = Convert.ToString(goods[1].Amount);
            textBox42.Text = Convert.ToString(admin_num[1]);
        }

        private void button31_Click(object sender, EventArgs e)
        {
            customer_increase(2);
            textBox34.Text = Convert.ToString(goods[2].Amount);
            textBox43.Text = Convert.ToString(admin_num[2]);
        }

        private void button33_Click(object sender, EventArgs e)
        {
            customer_increase(3);
            textBox35.Text = Convert.ToString(goods[3].Amount);
            textBox44.Text = Convert.ToString(admin_num[3]);
        }

        private void button35_Click(object sender, EventArgs e)
        {
            customer_increase(4);
            textBox36.Text = Convert.ToString(goods[4].Amount);
            textBox45.Text = Convert.ToString(admin_num[4]);
        }

        private void button37_Click(object sender, EventArgs e)
        {
            customer_increase(5);
            textBox37.Text = Convert.ToString(goods[5].Amount);
            textBox46.Text = Convert.ToString(admin_num[5]);
        }

        private void button39_Click(object sender, EventArgs e)
        {
            customer_increase(6);
            textBox38.Text = Convert.ToString(goods[6].Amount);
            textBox47.Text = Convert.ToString(admin_num[6]);
        }

        private void button41_Click(object sender, EventArgs e)
        {
            customer_increase(7);
            textBox39.Text = Convert.ToString(goods[7].Amount);
            textBox48.Text = Convert.ToString(admin_num[7]);
        }

        private void button43_Click(object sender, EventArgs e)
        {
            customer_increase(8);
            textBox40.Text = Convert.ToString(goods[8].Amount);
            textBox49.Text = Convert.ToString(admin_num[8]);
        }

        private void button45_Click(object sender, EventArgs e)
        {
            customer_increase(9);
            textBox41.Text = Convert.ToString(goods[9].Amount);
            textBox50.Text = Convert.ToString(admin_num[9]);
        }


        //用户取消已选择商品
        void customer_cancel()
        {
            for (int i = 0; i < admin_num.Length; i++)
            {
                goods[i].Amount += admin_num[i];
                admin_num[i] = 0;
            }
            textBox32.Text = Convert.ToString(goods[0].Amount);
            textBox33.Text = Convert.ToString(goods[1].Amount);
            textBox34.Text = Convert.ToString(goods[2].Amount);
            textBox35.Text = Convert.ToString(goods[3].Amount);
            textBox36.Text = Convert.ToString(goods[4].Amount);
            textBox37.Text = Convert.ToString(goods[5].Amount);
            textBox38.Text = Convert.ToString(goods[6].Amount);
            textBox39.Text = Convert.ToString(goods[7].Amount);
            textBox40.Text = Convert.ToString(goods[8].Amount);
            textBox41.Text = Convert.ToString(goods[9].Amount);
            textBox1.Text = "0";
            textBox42.Text = "0";
            textBox43.Text = "0";
            textBox44.Text = "0";
            textBox45.Text = "0";
            textBox46.Text = "0";
            textBox47.Text = "0";
            textBox48.Text = "0";
            textBox49.Text = "0";
            textBox50.Text = "0";
            totalprice.Text = "0.0";
        }
        //用户取消操作
        private void button47_Click(object sender, EventArgs e)
        {
            customer_cancel();
        }

        //用户退出登录
        private void button48_Click(object sender, EventArgs e)
        {
            customer_cancel();
            MessageBox.Show("customer successfully load out!");
            change_load(true);
            get_customer(false, false);
            clear_load();
        }

        //载入用户确认商品界面
        void get_shopping_information(bool ok)
        {
            textBox56.Visible = ok;
            textBox57.Visible = ok;
            textBox58.Visible = ok;
            textBox59.Visible = ok;
            textBox60.Visible = ok;
            textBox61.Visible = ok;
            textBox62.Visible = ok;
            textBox63.Visible = ok;
            textBox64.Visible = ok;
            comboBox1.Visible = ok;
            button49.Visible = ok;
            button50.Visible = ok;
            button51.Visible = ok;
        }

        //载入用户已选择商品信息
        void get_shopping_list()
        {
            for (int i = 0; i < admin_num.Length; i++)
            {
                if (admin_num[i] != 0)
                {
                    textBox57.Text += "ID: ";
                    textBox57.Text += Convert.ToString(goods[i].Id);
                    textBox57.Text += " , name: ";
                    textBox57.Text += goods[i].Name;
                    textBox57.Text += " , price: ";
                    textBox57.Text += Convert.ToString(goods[i].Price);
                    textBox57.Text += " , amount: ";
                    textBox57.Text += Convert.ToString(admin_num[i]);
                    textBox57.Text += " , sum_price: ";
                    textBox57.Text += Convert.ToString(goods[i].sum_price(admin_num[i]));
                    textBox57.Text += "\r\n\r\n";
                }
            }
            textBox61.Text = totalprice.Text;
            textBox62.Text = totalprice.Text;
        }

        //折扣信息
        void get_discount()
        {
            comboBox1.Items.Clear();
            comboBox1.Items.Add("Full 1500 minus 100");
            comboBox1.Items.Add("Full 2000 minus 200");
            comboBox1.Items.Add("Overall hit 5% off");
        }

        //折扣选择建议
        void get_discount_advice()
        {
            double sum_price = Convert.ToDouble(totalprice.Text);
            if (sum_price >= 1500 && sum_price < 2000)
            {
                textBox64.Text = "Full 1500 minus 100";
            }

            else if (sum_price >= 2000 && sum_price <= 4000)
            {
                textBox64.Text = "Full 2000 minus 200";
            }

            else
            {
                textBox64.Text = "Overall hit 5% off";
            }
        }

        //确认商品选择按钮
        private void button46_Click(object sender, EventArgs e)
        {
            get_customer(false, false);
            get_shopping_information(true);
            get_shopping_list();
            get_discount();
            get_discount_advice();

        }

        //折扣选择按钮

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            double sum_price = Convert.ToDouble(totalprice.Text);
            double true_price = 0.0;
            int index = comboBox1.SelectedIndex;
            switch (index)
            {
                case 0:
                    if (sum_price >= 1500)
                    {
                        true_price = sum_price - 100;
                        textBox62.Text = Convert.ToString(true_price);
                    }
                    break;

                case 1:
                    if (sum_price >= 2000)
                    {
                        true_price = sum_price - 200;
                        textBox62.Text = Convert.ToString(true_price);
                    }
                    break;

                case 2:
                    true_price = sum_price * 0.95;
                    textBox62.Text = Convert.ToString(true_price);
                    break;

                default: break;
            }
        }

        //用户在确认商品界面直接退出登录
        private void button51_Click(object sender, EventArgs e)
        {
            MessageBox.Show("customer successfully load out!");
            get_shopping_information(false);
            customer_cancel();
            change_load(true);
            isOk = false;
            textBox57.Clear();
            textBox61.Clear();
            textBox62.Clear();
            textBox64.Clear();
        }

        //用户返回上一层
        private void button50_Click(object sender, EventArgs e)
        {
            get_shopping_information(false);
            get_customer(true, false);
            if (isOk == true)
            {
                textBox57.Clear();
                textBox61.Clear();
                textBox62.Clear();
                textBox64.Clear();
                isOk = false;
            }
        }

        //用户确认购买按钮
        private void button49_Click(object sender, EventArgs e)
        {
            MessageBox.Show("thanks for the shopping! this time your consumption is " +
                textBox62.Text + "yuan . welcome you to visit again! ");

            isOk = true;
            for (int i = 0; i < admin_num.Length; i++)
            {
                admin_num[i] = 0;
            }
            textBox1.Text = "0";
            textBox42.Text = "0";
            textBox43.Text = "0";
            textBox44.Text = "0";
            textBox45.Text = "0";
            textBox46.Text = "0";
            textBox47.Text = "0";
            textBox48.Text = "0";
            textBox49.Text = "0";
            textBox50.Text = "0";
            totalprice.Text = "0.0";

        }

    }
}

四、实验总结

写了一天多了,实验自己测了一下,bug还是蛮多的,从中总结出了自己写窗体应用程序时思路不是很清晰,想象力不够啊,代码写得也很冗杂,有待提高。



//over

/*

以下内容与本实验无关

*/

昨天俩老师突然闯进1106,说以后不能在实验室过夜,我想肯定是院长的发的牢骚 。。。

今天在ACM实验室待着待着,突然又闯进来几个老师,说ACM实验室以后也成为公共实验室 ,说我们不能自己带钥匙了,说每天早上八点可以找老师开门,晚上九点四十必须清场,说ACM实验室会装上摄像头监控,说…………

呵、呵、呵、、、、、、

不知道他们在想什么。。。

神烦。越来越觉得华师计算机学院的某些老师,领导就是巨坑,某些管理制度更是令人难以接受。

明天呢,是不是要四个老师继续突然闯进来,然后xxxxoooo一大片让人听到耳朵就不清净的话。

唉唉,算了,不吐槽了,,做好自己的事就好。


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

标签:设计   应用程序   面向对象      c#   

原文地址:http://blog.csdn.net/jhgkjhg_ugtdk77/article/details/45870017

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