温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何用C#实现销售管理系统

发布时间:2021-06-24 13:45:50 来源:亿速云 阅读:330 作者:chen 栏目:开发技术

本篇内容主要讲解“如何用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).添加代码

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

登录界面:

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();         }            } }

商品主界面的代码:

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

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#实现销售管理系统

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

到此,相信大家对“如何用C#实现销售管理系统”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI