综合查询示例

来源:互联网 发布:淘宝联盟提现钱到哪里 编辑:程序博客网 时间:2024/05/05 06:54

 private void clearPart()
        {
            try
            {
                ds.Clear();
               if (flag1)
                {
                    bindingSource1.DataSource = ds.Tables[0];
                    this.bindingNavigator1.BindingSource = bindingSource1;
                    this.dataGridView1.DataSource = bindingSource1;
                }
                else
                {
                    flag1 = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
private void btnQuery_Click(object sender, EventArgs e)  //查询

        {
            clearPart();
            ds = new DataSet();
            ds.Clear();
            try 
            {
                string strY = System.DateTime.Now.ToString("yyyy-MM-dd-HH:mm");
                string Sql = "SELECT DISTINCT OutBound_no,OutputTime,Class,Sequence,OutBounder_no,DeliveryMan_no FROM T_BJ_OutBound ";
                       
                string WhereStr = " Where OutBound_no is not null";
                
                if (OutBound_no.Text.Trim() != string.Empty)
                {
                    WhereStr = WhereStr + " and OutBound_no ='" + OutBound_no.Text.Trim() + "'";
                }
                if (CK_no.Text.Trim() != string.Empty)
                {
                    WhereStr = WhereStr + " and CK_no ='" + CK_no.Text.Trim() + "'";
                }
                if (OutputMode.Text.Trim() != string.Empty)
                {
                    WhereStr = WhereStr + " and OutputMode ='" + OutputMode.Text.Trim() + "'";
                }
                if (Start_Time.Text.Trim() != string.Empty)
                {
                    if (End_Time.Text.Trim() != string.Empty)
                    {
                        WhereStr = WhereStr + " and OutputTime between '" + Start_Time.Text + "' AND  '" + End_Time.Text + "' ";
                    }
                }
                if (Start_Time.Text.Trim() != string.Empty)
                {
                    if (End_Time.Text.Trim() == string.Empty)
                    {
                        WhereStr = WhereStr + " and OutputTime between '" + Start_Time.Text + "' AND  '" + strY + "'";
                    }
                }
                if (Start_Time.Text.Trim() == string.Empty)
                {
                    if (End_Time.Text.Trim() != string.Empty)
                    {
                        string star = "2011-07-15";
                        WhereStr = WhereStr + " and OutputTime between '" + star + "' AND  '" + End_Time.Text + "' ";
                    }
                }
                Sql = Sql + WhereStr;
                conn = new OracleConnection(ConnectionString);
                conn.Open();
                OracleDataAdapter da = new OracleDataAdapter(Sql, conn);
                da.Fill(ds, "T_BJ_OutBound");
                da.Dispose();
                bindingSource1.DataSource = ds.Tables[0];
                this.bindingNavigator1.BindingSource = bindingSource1;
                this.dataGridView1.DataSource = bindingSource1;
               flag2 = true;
                if (ds.Tables[0].Rows.Count == 0)
                 {
                        DetailClearPart();
                        MessageBox.Show("没有符合条件的数据");
                 }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                conn.Close();
                conn.Dispose();
                ds.Dispose();
            }

        }
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            string strSQL = null;
            int rowIndex = e.RowIndex;
            if (rowIndex < 0)
            {
                rowIndex = 0;
            }
            tempOutBound_no = dataGridView1.Rows[rowIndex].Cells[0].Value.ToString();
            //创建一个新连接
            DetailClearPart();
            Detailds.Clear();
            conn = new OracleConnection(ConnectionString);
            try
            {
                strSQL = "SELECT OutBound_no,Spareparts_no,Spareparts_name,TotalNumber,TotalWeight,CK_no,Shelve_no,OutputMode,OutputTime,Class,Sequence,OutBounder_no,DeliveryMan_no,
                    + "Other FROM T_BJ_OutBound Where OutBound_no = '" + tempOutBound_no + "' order by OutBound_no";
                //创建数据提供者 
                OracleDataAdapter DataAdapter = new OracleDataAdapter(strSQL, conn);
                DataAdapter.Fill(Detailds, "T_BJ_OutInfor");  
                DataAdapter.Dispose();
                bindingSource2.DataSource = Detailds.Tables[0];
                this.bindingNavigator2.BindingSource = bindingSource2;
                this.dataGridView2.DataSource = bindingSource2;
                flag2 = true;
                if (Detailds.Tables[0].Rows.Count == 0)
                {
                    MessageBox.Show("没有符合条件的数据!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                conn.Close();
                conn.Dispose();
                Detailds.Dispose();
            }
        }

       private void DetailClearPart()
        {
            try
            {
                Detailds.Clear();
                if (flag3)
                {
                    Detailds.Clear();
                    this.bindingNavigator2.BindingSource = bindingSource2;
                    this.dataGridView2.DataSource = bindingSource2;
                }
                else
                {
                    flag3 = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

原创粉丝点击