服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - C# - C#实现销售管理系统

C#实现销售管理系统

2022-11-23 11:42Mr&HelloWorld C#

这篇文章主要为大家详细介绍了C#实现销售管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

C#制作简易的的销售管理系统,供大家参考,具体内容如下

1.整体需求

1).具有简易的登录界面
2).能对商品信息进行快速查看、查询、添加、编辑、保存等功能。

2.设计的窗体界面

1).登录界面
2).商品信息的操作界面

3.所需的知识

 1).C#基础语法
 2).ADO.NET数据库

不太清楚的可以去看我主页的文章,都是关于C#基础的知识。

4.具体步骤及代码

1).创建项目

首先打开vs2017,选择“创建项目” ,选择“Windows窗体应用”。详细的操作 可以看我之前写的一些简单项目。

2).添加控件

登录界面和商品信息界面如下:

C#实现销售管理系统

C#实现销售管理系统

可以试着根据图片显示的去添加控件,详情见主页的C#Windows窗体应用设计系列。商品信息界面最上面是一个tool strip 控件。后面会把源码发出来,边参考源码编写可以对C#的设计更加清楚。

3).添加代码

需要添加的代码如下,添加代码的方法见主页的文章介绍。

登录界面:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace EMS
{
    public partial class frmLogin : Form
    {
        BaseClass.BaseInfo baseinfo = new EMS.BaseClass.BaseInfo();
        BaseClass.cPopedom popedom = new EMS.BaseClass.cPopedom();
        public frmLogin()
        {
            InitializeComponent();
        }
 
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtUserName.Text == string.Empty)
            {
                MessageBox.Show("用户名称不能为空!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            DataSet ds = null;
            popedom.SysUser = txtUserName.Text;
            popedom.Password = txtUserPwd.Text;
            ds=baseinfo.Login(popedom);
            if (ds.Tables[0].Rows.Count > 0)
            {
                EMS.BaseInfo.frmStock frm_Stock = new EMS.BaseInfo.frmStock();
                frm_Stock.Show();               
            }
            else
            {
                MessageBox.Show("用户名称或密码不正确!","错误提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
            }
        }
 
        private void txtUserName_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13) //判断是否按下Enter键
                txtUserPwd.Focus();//将鼠标焦点移动到“密码”文本框
        }
 
        private void txtUserPwd_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)//判断是否按下Enter键
                btnLogin.Focus();//将鼠标焦点移动到“登录”按钮
        }
 
        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
 
      
    }
}

商品主界面的代码:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace EMS.BaseInfo
{
    public partial class frmStock : Form
    {
        BaseClass.BaseInfo baseinfo = new EMS.BaseClass.BaseInfo();//创建BaseInfo类的对象
        BaseClass.cStockInfo stockinfo = new EMS.BaseClass.cStockInfo();//创建cStockInfo类的对象
        int G_Int_addOrUpdate = 0;//定义添加/修改操作标识
        public frmStock()
        {
            InitializeComponent();
        }
 
        private void tlBtnAdd_Click(object sender, EventArgs e)
        {
            this.editEnabled();//设置各个控件的可用状态
            this.clearText();//清空文本框
            G_Int_addOrUpdate = 0;//等于0为添加数据
            DataSet ds = null;//创建数据集对象
            string P_Str_newTradeCode = "";//设置库存商品编号为空
            int P_Int_newTradeCode = 0;//初始化商品编号中的数字码
            ds = baseinfo.GetAllStock("tb_stock");//获取库存商品信息
            if (ds.Tables[0].Rows.Count == 0)//判断数据集中是否有值
            {
                txtTradeCode.Text = "T1001";//设置默认商品编号
            }
            else
            {
                P_Str_newTradeCode = Convert.ToString(ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1]["tradecode"]);//获取已经存在的最大编号
                P_Int_newTradeCode = Convert.ToInt32(P_Str_newTradeCode.Substring(1, 4)) + 1;//获取一个最新的数字码
                P_Str_newTradeCode = "T" + P_Int_newTradeCode.ToString();//获取最新商品编号
                txtTradeCode.Text = P_Str_newTradeCode;//将商品编号显示在文本框中
            }
        }
        //设置各按钮的可用状态
        private void editEnabled()
        {
            groupBox1.Enabled = true;
            tlBtnAdd.Enabled = false;
            tlBtnEdit.Enabled = false;
            tlBtnDelete.Enabled = false;
            tlBtnSave.Enabled = true;
            tlBtnCancel.Enabled = true;
        }
        //设置各按钮的可用状态
        private void cancelEnabled()
        {
            groupBox1.Enabled = false;
            tlBtnAdd.Enabled = true;
            tlBtnEdit.Enabled = true;
            tlBtnDelete.Enabled = true;
            tlBtnSave.Enabled = false;
            tlBtnCancel.Enabled = false;
        }
        //清空文本框
        private void clearText()
        {
            txtTradeCode.Text= string.Empty;
            txtFullName.Text = string.Empty;
            txtType.Text = string.Empty;
            txtStandard.Text = string.Empty;
            txtUnit.Text = string.Empty;
            txtProduce.Text = string.Empty;
        }
        //设置DataGridView列标题
        private void SetdgvStockListHeadText()
        {
            dgvStockList.Columns[0].HeaderText = "商品编号";
            dgvStockList.Columns[1].HeaderText = "商品名称";
            dgvStockList.Columns[2].HeaderText = "商品型号";
            dgvStockList.Columns[3].HeaderText = "商品规格";
            dgvStockList.Columns[4].HeaderText = "商品单位";
            dgvStockList.Columns[5].HeaderText = "商品产地";
            dgvStockList.Columns[6].HeaderText = "库存数量";
            dgvStockList.Columns[7].Visible = false;
            dgvStockList.Columns[8].HeaderText = "商品价格(加权平均价格)";
            dgvStockList.Columns[9].Visible = false;
            dgvStockList.Columns[10].HeaderText = "盘点数量";
            dgvStockList.Columns[11].Visible = false;
            dgvStockList.Columns[12].Visible = false;
        }
 
        private void frmStock_Load(object sender, EventArgs e)
        {
            txtTradeCode.ReadOnly = true;//设置商品编号文本框只读
            this.cancelEnabled();//设置各按钮的可用状态
            //显示所有库存商品信息
            dgvStockList.DataSource = baseinfo.GetAllStock("tb_stock").Tables[0].DefaultView;
            this.SetdgvStockListHeadText();//设置DataGridView控件的列标题
        }
 
        private void tlBtnSave_Click(object sender, EventArgs e)
        {
            //判断是添加还是修改数据
            if (G_Int_addOrUpdate == 0)
            {
                try
                {
                    //添加数据
                    stockinfo.TradeCode = txtTradeCode.Text;
                    stockinfo.FullName = txtFullName.Text;
                    stockinfo.TradeType = txtType.Text;
                    stockinfo.Standard = txtStandard.Text;
                    stockinfo.Unit = txtUnit.Text;
                    stockinfo.Produce = txtProduce.Text;
                    //执行添加操作
                    int id = baseinfo.AddStock(stockinfo);
                    MessageBox.Show("新增--库存商品数据--成功!", "成功提示!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message,"错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                //修改数据
                stockinfo.TradeCode = txtTradeCode.Text;
                stockinfo.FullName = txtFullName.Text;
                stockinfo.TradeType = txtType.Text;
                stockinfo.Standard = txtStandard.Text;
                stockinfo.Unit = txtUnit.Text;
                stockinfo.Produce = txtProduce.Text;
                //执行修改操作
                int id = baseinfo.UpdateStock(stockinfo);
                MessageBox.Show("修改--库存商品数据--成功!", "成功提示!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            dgvStockList.DataSource = baseinfo.GetAllStock("tb_stock").Tables[0].DefaultView;//显示最新的库存商品信息
            this.SetdgvStockListHeadText();//设置DataGridView控件列标题
            this.cancelEnabled();//设置各个按钮的可用状态
        }
 
        private void tlBtnEdit_Click(object sender, EventArgs e)
        {
            this.editEnabled();//设置各个按钮的可用状态
            G_Int_addOrUpdate = 1;//等于1为修改数据
        }
 
        private void tlBtnFind_Click(object sender, EventArgs e)
        {
            if (tlCmbStockType.Text == string.Empty)//判断查询类别是否为空
            {
                MessageBox.Show("查询类别不能为空!", "错误提示!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tlCmbStockType.Focus();//使查询类别下拉列表获得鼠标焦点
                return;
            }
            else
            {
                if (tlTxtFindStock.Text.Trim() == string.Empty)//判断查询关键字是否为空
                {
                    //显示所有库存商品信息
                    dgvStockList.DataSource = baseinfo.GetAllStock("tb_stock").Tables[0].DefaultView;
                    this.SetdgvStockListHeadText();//设置DataGridView控件的列标题
                    return;
                }
            }
            DataSet ds = null;//创建DataSet对象
            if (tlCmbStockType.Text == "商品产地") //按商品产地查询
            {
                stockinfo.Produce = tlTxtFindStock.Text;//记录商品产地
                ds = baseinfo.FindStockByProduce(stockinfo, "tb_Stock");//根据商品产地查询商品信息
                dgvStockList.DataSource = ds.Tables[0].DefaultView;//显示查询到的信息
            }
            else//按商品名称查询
            {
                stockinfo.FullName = tlTxtFindStock.Text;//记录商品名称
                ds = baseinfo.FindStockByFullName(stockinfo, "tb_stock");//根据商品名称查询商品信息
                dgvStockList.DataSource = ds.Tables[0].DefaultView;//显示查询到的信息
            }
            this.SetdgvStockListHeadText();//设置DataGridView控件列标题
        }
 
        private void tlBtnDelete_Click(object sender, EventArgs e)
        {
            if (txtTradeCode.Text.Trim() == string.Empty)//判断是否选择了商品编号
            {
                MessageBox.Show("删除--库存商品数据--失败!", "错误提示!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            stockinfo.TradeCode = txtTradeCode.Text;//记录商品编号
            int id = baseinfo.DeleteStock(stockinfo);//执行删除操作
            MessageBox.Show("删除--库存商品数据--成功!", "成功提示!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            dgvStockList.DataSource = baseinfo.GetAllStock("tb_stock").Tables[0].DefaultView;//显示最新的库存商品信息
            this.SetdgvStockListHeadText();//设置DataGridView控件列标题
            this.clearText();//清空文本框
        }
 
        private void tlBtnCancel_Click(object sender, EventArgs e)
        {
            this.cancelEnabled();//设置各个按钮的可用状态
        }
 
        private void dgvStockList_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            txtTradeCode.Text = this.dgvStockList[0, dgvStockList.CurrentCell.RowIndex].Value.ToString();//显示商品编号
            txtFullName.Text = this.dgvStockList[1, dgvStockList.CurrentCell.RowIndex].Value.ToString();//显示商品全称
            txtType.Text = this.dgvStockList[2, dgvStockList.CurrentCell.RowIndex].Value.ToString();//显示商品型号
            txtStandard.Text = this.dgvStockList[3, dgvStockList.CurrentCell.RowIndex].Value.ToString();//显示商品规格
            txtUnit.Text = this.dgvStockList[4, dgvStockList.CurrentCell.RowIndex].Value.ToString();//显示商品单位
            txtProduce.Text = this.dgvStockList[5, dgvStockList.CurrentCell.RowIndex].Value.ToString();//显示商品产地
        }
 
        private void tlBtnExit_Click(object sender, EventArgs e)
        {
            this.Close();//关闭当前窗体
        }
 
        private void dgvStockList_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
 
        }
    }
}

Main.cs

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
 
namespace EMS
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmLogin());
        }
    }
}

需要添加的图片素材在源码文件夹的icon和image文件夹里面,觉得不好看的可以自行查找。
注意,添加代码时要与自己的添加的控件一一对应起来。

4).建立数据库

数据库具体的添加方法在我主页的文章《一起来学C#之数据库》中讲过,在菜单栏中的“项目”-》》“添加新项目”-》》“基于服务的数据库”,具体操作可以看我前面的文章。本次给出的源码有数据库,可以自行修改添加。

C#实现销售管理系统

5).调试运行

根据自己所写的去运行,再对照提供的源码修改错误,运行界面如下。

登录界面:

C#实现销售管理系统

登录账户名:mr 密码:mrsoft,可以根据源码自行修改。

信息界面:

C#实现销售管理系统

写好运行后就可以看到该界面。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/ZhaoProgrammer/article/details/106842399

延伸 · 阅读

精彩推荐
  • C#实例分享C#中Explicit和Implicit用法

    实例分享C#中Explicit和Implicit用法

    本篇文章主要给读者们分享了C#中Explicit和Implicit的用法,对此有需求和兴趣的朋友们一起学习下吧。...

    LamondLu的小窝10552022-02-17
  • C#C#中如何利用正则表达式判断字符

    C#中如何利用正则表达式判断字符

    这篇文章主要介绍了C#中利用正则表达式判断字符的实例代码,非常不错,具有参考借鉴价值,需要的朋友可以参考下...

    C#教程网4412021-12-15
  • C#C#实现在listview中插入图片实例代码

    C#实现在listview中插入图片实例代码

    这篇文章主要介绍了C#实现在listview中插入图片实例代码的相关资料,需要的朋友可以参考下...

    net小伙7312021-12-29
  • C#C#如何使用SHBrowseForFolder导出中文文件夹详解

    C#如何使用SHBrowseForFolder导出中文文件夹详解

    这篇文章主要给大家介绍了关于C#如何使用SHBrowseForFolder导出中文文件夹的相关资料,文中通过示例代码介绍的非常详细,对大家的学习合作工作具有一定的...

    RECT11042022-03-05
  • C#C#实现导出List数据到xml文件的方法【附demo源码下载】

    C#实现导出List数据到xml文件的方法【附demo源码下载】

    这篇文章主要介绍了C#实现导出List数据到xml文件的方法,涉及C#针对list类及xml文件的相关操作技巧,并附带完整demo源码供读者下载参考,需要的朋友可以参考下...

    微wx笑4682021-12-03
  • C#C#正方形图片的绘制方法

    C#正方形图片的绘制方法

    这篇文章主要为大家详细介绍了C#正方形图片的绘制方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...

    薛定谔家的猫12212022-03-02
  • C#C#中的事务用法实例分析

    C#中的事务用法实例分析

    这篇文章主要介绍了C#中的事务用法,以一个简单实例形式分析了C#创建及使用事物的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下...

    yenange12312021-10-27
  • C#使用MSScriptControl 在 C# 中读取json数据的方法

    使用MSScriptControl 在 C# 中读取json数据的方法

    下面小编就为大家带来一篇使用MSScriptControl 在 C# 中读取json数据的方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看...

    C#教程网5572021-12-22