2018数据库

1.Form1 

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 SCUT2018
{
    public partial class Form1 : Form
    {
        private DB db;

        public Form1()
        {
            InitializeComponent();
            db = new DB();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            tabPage1_Click(sender, e);

        }

        //选项卡改变事件
        private void tabControl1_SelectedChanged(object sender, EventArgs e)
        {
            if (tabControl1.SelectedIndex == 0)
            {
                tabPage1_Click(sender, e);
            }
            else if (tabControl1.SelectedIndex == 1)
            {
                tabPage2_Click(sender, e);
            }
            else if (tabControl1.SelectedIndex == 2)
            {
                tabPage3_Click(sender, e);
            }
        }

        //1查询
        private void tabPage1_Click(object sender, EventArgs e)
        {
            dataGridView1.DataSource = db.getBySql(@"select businessman.busno as 经销商, businessman.busname as 经销商名, [order].good as 商品名称
from businessman, [order]
where businessman.busNo = [order].busNo ");

            DataTable table = db.getBySql("select * from BusinessMan");
            comboBox1.DataSource = table;
            comboBox1.DisplayMember = "busNo";
            comboBox1.ValueMember = "busNo";


            comboBox2.DataSource = table;
            comboBox2.DisplayMember = "busName";
            comboBox2.ValueMember = "busName";

            comboBox3.DataSource = db.getBySql("select * from [Order]");
            comboBox3.DisplayMember = "good";
            comboBox3.ValueMember = "good";
        }
        //2统计
        private void tabPage2_Click(object sender, EventArgs e)
        {
            //(1)按地方统计订单金额:
            dataGridView2.DataSource = db.getBySql(@"select businessman.city as 城市, sum([order].money) as 订单总金额
from businessman, [order]
where businessman.busNo = [order].busNo
group by businessman.city
order by 订单总金额 asc");

            //(2)按经销商统计订单金额(按金额升序排列):
            dataGridView3.DataSource = db.getBySql(@"select businessman.busName as 经销商, sum([order].money) as 订单总金额
from businessman, [order]
where businessman.busNo = [order].busNo
group by businessman.busNo, businessman.busName
order by 订单总金额 asc
");

        }
        //3数据维护
        private void tabPage3_Click(object sender, EventArgs e)
        {
            DataTable table = db.getBySql(@"select * from BusinessMan");
            dataGridView4.DataSource = table;
            dataGridView4.Columns[0].HeaderText = "经销商编号";
            dataGridView4.Columns[1].HeaderText = "经销商名称";
            dataGridView4.Columns[2].HeaderText = "所在城市&#
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值