datagridview1表一列作为別一个datagridview2表查询条件,单击datagridview1单元格显示datagridview2表数据

时间:2024-03-29 19:45:28


datagridview1表一列作为別一个datagridview2表查询条件,单击datagridview1单元格显示datagridview2表数据datagridview1表一列作为別一个datagridview2表查询条件,单击datagridview1单元格显示datagridview2表数据using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace datagridview表一列作为別一个表查询条件
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void data()
        {
            dataGridView1.Columns[0].HeaderText = "选择";//改列名称
            dataGridView1.Columns[1].HeaderText = "订单编号"; //改列名称
            dataGridView1.Columns[2].HeaderText = "订单日期";//改列名称
            dataGridView1.Columns[3].HeaderText = "专卖店"; //改列名称
            dataGridView1.Columns[4].HeaderText = "客户名称";//改列名称
            dataGridView1.Columns[5].HeaderText = "销售员"; //改列名称
            dataGridView1.Columns[6].HeaderText = "定制产品情况";//改列名称
            dataGridView1.Columns[7].HeaderText = "总金额"; //改列名称
            dataGridView1.Columns[8].HeaderText = "付款情况";//改列名称
            dataGridView1.Columns[9].HeaderText = "付款日期"; //改列名称
            dataGridView1.Columns[10].HeaderText = "送货日期";//改列名称
            dataGridView1.Columns[11].HeaderText = "出货状态"; //改列名称
            dataGridView1.Columns[12].HeaderText = "操作员";//改列名称
            dataGridView1.Columns[13].HeaderText = "操作日期"; //改列名称
            dataGridView1.Columns[14].HeaderText = "客户电话";//改列名称
            dataGridView1.Columns[15].HeaderText = "销售电话"; //改列名称
            dataGridView1.Columns[16].HeaderText = "送货地址";//改列名称
            dataGridView1.Columns[17].HeaderText = "备注"; //改列名称

            dataGridView2.Columns[0].HeaderText = "选择";//改列名称
            dataGridView2.Columns[1].HeaderText = "订单编号"; //改列名称
            dataGridView2.Columns[1].HeaderText = "商品编号"; //改列名称
            dataGridView2.Columns[2].HeaderText = "商品名称";//改列名称
            dataGridView2.Columns[3].HeaderText = "产品颜色"; //改列名称
            dataGridView2.Columns[4].HeaderText = "产品规格";//改列名称
            dataGridView2.Columns[5].HeaderText = "单位"; //改列名称
            dataGridView2.Columns[6].HeaderText = "数量";//改列名称
            dataGridView2.Columns[7].HeaderText = "单价"; //改列名称
            dataGridView2.Columns[8].HeaderText = "金额";//改列名称
            dataGridView2.Columns[9].HeaderText = "已出库数"; //改列名称
            dataGridView2.Columns[10].HeaderText = "待出库数";//改列名称
            dataGridView2.Columns[11].HeaderText = "销售员"; //改列名称
            dataGridView2.Columns[12].HeaderText = "订单日期";//改列名称
            dataGridView2.Columns[13].HeaderText = "送货日期"; //改列名称
            dataGridView2.Columns[14].HeaderText = "税率";//改列名称
            dataGridView2.Columns[15].HeaderText = "含税单价"; //改列名称
            dataGridView2.Columns[16].HeaderText = "含税金额";//改列名称
            dataGridView2.Columns[17].HeaderText = "生产批次"; //改列名称
            dataGridView2.Columns[18].HeaderText = "备注"; //改列名称
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“orderManagementSystemDataSet1.FinishedDetailOrderGoods”中。您可以根据需要移动或删除它。
            this.finishedDetailOrderGoodsTableAdapter.Fill(this.orderManagementSystemDataSet1.FinishedDetailOrderGoods);
            // TODO: 这行代码将数据加载到表“orderManagementSystemDataSet.SalesOrderSheet”中。您可以根据需要移动或删除它。
            this.salesOrderSheetTableAdapter.Fill(this.orderManagementSystemDataSet.SalesOrderSheet);
            data();
        }
        SqlConnection conn;
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int rowindex = e.RowIndex;
            string aa1 = Convert.ToString(dataGridView1[1, dataGridView1.CurrentCell.RowIndex].Value).Trim();

            try
            {

                conn = new SqlConnection("server=WINDOWS-CBBU2E6;database=OrderManagementSystem;Uid = sa; Pwd = 123");
                SqlCommand cmd = new SqlCommand("select * from dbo.FinishedDetailOrderGoods  where OrderID='" + aa1 + "'", conn);
                SqlDataAdapter sda = new SqlDataAdapter();
                sda.SelectCommand = cmd;
                DataSet ds = new DataSet();
                sda.Fill(ds, "dbo.FinishedDetailOrderGoods");
                dataGridView2.DataSource = ds.Tables["dbo.FinishedDetailOrderGoods"];

            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message, "软件提示");
                throw ex;
            }
   
        }
    }
}