C# +Sql 实现商品管理系统

功能需求:


C# +Sql 实现商品管理系统

C# +Sql 实现商品管理系统


C# +Sql 实现商品管理系统

添加商品信息

C# +Sql 实现商品管理系统

查询显示商品信息

数据库代码:

create database GoodsManager   /* 创建数据库*/

use GoodsManager

create table Brand(
  Bid int primary key identity(1,1),
  brand varchar(20) not null
)

create table PcInfo(
	id int primary key identity(1,1),
	pcName varchar(50) not null,
	brandId int,
   isReceive int ,
   pcPrice decimal(8,2) not null,
  pcDetail  varchar(200) not null,
  pcRemark varchar(200),
  [timestamp] datetime
)

select * from Brand
select * from PcInfo

insert Pcinfo values('aaa',2,0,4999,'{detail}','{Datetime}')
/*多表查询*/
select *,p.id pid from Brand b,PcInfo p where b.id=p.brandId
C# +Sql 实现商品管理系统

主窗体弹出后面的子窗体

   private void 查询信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ListForm list = new ListForm();
            list.Show();
        }

        private void 增加信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddForm add = new AddForm();
            add.Show();

        }

显示数据:

// 显示
        private void ListForm_Load(object sender, EventArgs e)
        {
            string sql = "select *,p.id pid from Brand b,PcInfo p where b.id=p.brandId";
            this.dataGridView1.AutoGenerateColumns = false;
            this.dataGridView1.DataSource = DBHelper.Select(sql) ;
        }

        // 查询
        private void button1_Click(object sender, EventArgs e)
        {
            string sql = #34;select *,p.id pid from Brand b,PcInfo p where b.id=p.brandId and p.pcName like '%{textBox1.Text}%'";
            this.dataGridView1.AutoGenerateColumns = false;
            this.dataGridView1.DataSource = DBHelper.Select(sql);
        }

        // 删除    联系方式:2250598135
        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string id = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
            string sql = #34;delete PcInfo where id='{id}'";
            if (DBHelper.Update(sql)) {
                MessageBox.Show("删除成功!");
            }
        }

添加商品信息:

 private void AddForm_Load(object sender, EventArgs e)
        {
          // 绑定下拉框
            // TODO: 这行代码将数据加载到表“goodsManagerDataSet.Brand”中。您可以根据需要移动或删除它。
            this.brandTableAdapter.Fill(this.goodsManagerDataSet.Brand);

        }

        // 添加并保存
        private void button1_Click(object sender, EventArgs e)
        {
            string isRec = this.radioButton1.Checked ? "1" : "0";
            string sql = #34;insert Pcinfo values('{txtName.Text}',{comboBox1.SelectedValue.ToString()},{isRec},{txtPrice.Text},'{txtDetail.Text}','{DateTime.Now.ToString("yyyy-MM-dd")}')";
            if (DBHelper.Update(sql)) {
                MessageBox.Show("添加成功!");
                this.Hide();
            }
        }
发表评论
留言与评论(共有 0 条评论) “”
   
验证码:

相关文章

推荐文章