C#多条件联合查询,多个文本或者下拉的情况下

  private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                com = comNames.Text.Trim();
                XlName = ComUserName.Text.Trim();
                comUsers = comUser.Text.Trim();
                TxtUlogsS = TxtUlogs.Text.Trim();
                comDs = ComDKQ.Text.Trim();
                SQbase.ReplaceSQLChar(com);
                SQbase.ReplaceSQLChar(XlName);
                SQbase.ReplaceSQLChar(comUsers);
                SQbase.ReplaceSQLChar(TxtUlogsS);
                SQbase.ReplaceSQLChar(Comlogs.Text.Trim());
                if (grid == 1)
                {
                    da1 = DateTime.Parse(dpic1.Value.ToString(dati));
                    da2 = DateTime.Parse(dpic2.Value.ToString(datis));
                    if (da1 >= da2)
                    {
                        MessageBox.Show("开始时间必须小于结束时间", "提示");
                    }
                    else
                    {
                        string sql = string.Format("  where 1=1");

                        if (com == "全部")
                        {
                            sql += string.Format(@"");
                        }
                        else
                        {
                            sql += string.Format(@" and   holderName='" + com + "'");
                        }
                        if (comDs == "全部")
                        {
                            sql += string.Format(@"");
                        }
                        else
                        {
                            sql += string.Format(@" and   Name='" + comDs + "'");
                        }
                        if (CKBox.Checked != true)
                        {
                            sql += string.Format(@" and '" + da2.ToString() + "'>=  g.[OPtime]  and  g.[OPtime]  >='" + da1.ToString() + "'");
                        }
                        else
                        {
                            sql += string.Format(@"");
                        }

                        sql += "  ORDER BY   g.[OPtime] DESC ";

                        DataGdv.DataSource = SKJLS.Cardlogs_Getdate(sql);

                        SQbase.Roswtxt(DataGdv, RoswSTxt);
                    }
                }
                if (grid == 2)
                {

                    da1 = DateTime.Parse(dpic1.Value.ToString(dati));
                    da2 = DateTime.Parse(dpic2.Value.ToString(datis));
                    if (da1 >= da2)
                    {
                        MessageBox.Show("开始时间必须小于结束时间", "提示");
                    }
                    else
                    {
                        string sql = string.Format("  where 1=1");

                        if (comUsers == "全部")
                        {

                            sql += string.Format(@"");
                        }
                        else
                        {

                            sql += string.Format(@"and  ul.[Name] = '" + comUsers + "'");
                        }
                        if (!string.IsNullOrEmpty(TxtUlogsS))
                        {
                            if (TxtUlogsS == "全部")
                            {
                                sql += string.Format(@" and [oEvent] like '%%'");

                            }
                            else
                            {
                                sql += string.Format(@" and [oEvent] like '%" + TxtUlogsS + "%'");

                            }
                        }
                        if (!string.IsNullOrEmpty(Comlogs.Text.Trim()))
                        {
                            if (Comlogs.Text.Trim() == "全部")
                            {
                                sql += string.Format(@"");

                            }
                            else
                            {
                                sql += string.Format(@" and [EventType] like '%" + Comlogs.Text.Trim().ToString() + "%'");

                            }
                        }
                        if (CKBox.Checked != true)
                        {
                            sql += string.Format(@" and ('" + da2.ToString() + "'>OPtime and OPtime>'" + da1.ToString() + "')");
                        }
                        else
                        {
                            sql += string.Format(@"");
                        }
                        sql += " order by  [OPtime] desc";
                        DataGdv.DataSource = YHCZJLS.Userlogs_Getdate(sql);

                        SQbase.Roswtxt(DataGdv, RoswSTxt);
                    }


                }
                if (grid == 3)
                {
                    da1 = DateTime.Parse(dpic1.Value.ToString(dati));
                    da2 = DateTime.Parse(dpic2.Value.ToString(datis));
                    if (da1 >= da2)
                    {
                        MessageBox.Show("开始时间必须小于结束时间", "提示");
                    }
                    else
                    {
                        string sql = "where 1=1";
                        if (!string.IsNullOrEmpty(XlName))
                        {
                            if (XlName == "全部")
                            {

                                sql += string.Format(@"");
                            }
                            else
                            {
                                sql += string.Format(@" and [Name]='" + XlName + "'");
                            }

                        }
                        if (!string.IsNullOrEmpty(com))
                        {

                            if (com == "全部")
                            {

                                sql += string.Format(@"");
                            }
                            else
                            {
                                sql += string.Format(@" and holderName='" + com + "'");
                            }

                        }
                        if (CKBox.Checked != true)
                        {
                            sql += string.Format(@" and '" + da2.ToString() + "'>=OPtime and OPtime >='" + da1.ToString() + "'");
                        }
                        else
                        {
                            sql += string.Format(@"");
                        }
                        sql += string.Format(@" order by  [OPtime] desc ");
                        DataGdv.DataSource = XGJLS.Routelogs_getdate(sql);

                        SQbase.Roswtxt(DataGdv, RoswSTxt);
                    }
                }
                if (grid == 4)
                {
                    da1 = DateTime.Parse(dpic1.Value.ToString(dati));
                    da2 = DateTime.Parse(dpic2.Value.ToString(datis));
                    if (da1 >= da2)
                    {
                        MessageBox.Show("开始时间必须小于结束时间", "提示");
                    }
                    else
                    {
                        string sql = "";
                        if (!string.IsNullOrEmpty(XlName))
                        {
                            if (XlName == "全部")
                            {


                                sql += string.Format(@"");
                            }
                            else
                            {
                                sql += string.Format(@" and [Name]='" + XlName + "'");
                            }

                        }
                        if (!string.IsNullOrEmpty(com))
                        {

                            if (com == "全部")
                            {

                                sql += string.Format(@"");
                            }
                            else
                            {
                                sql += string.Format(@" and  [holderName]='" + com + "'");
                            }

                        }
                        if (CKBox.Checked != true)
                        {
                            sql += string.Format(@" and '" + da2.ToString() + "'>=OPtime and OPtime >='" + da1.ToString() + "'");
                        }
                        else
                        {
                            sql += string.Format(@"");
                        }
                        sql += string.Format(@" order by [RouteLogID],[order]");

                        XGXxShowS(DataGdv, sql);

                        SQbase.Roswtxt(DataGdv, RoswSTxt);
                    }
                }

                if (grid == 5)
                {
                    da1 = DateTime.Parse(dpic1.Value.ToString(dati));
                    da2 = DateTime.Parse(dpic2.Value.ToString(datis));
                    if (da1 >= da2)
                    {
                        MessageBox.Show("开始时间必须小于结束时间", "提示");
                    }
                    else
                    {
                        string sql = "  where [order]=1";
                        if (!string.IsNullOrEmpty(XlName))
                        {
                            if (XlName == "全部")
                            {

                                sql += string.Format(@"");

                            }
                            else
                            {
                                sql += string.Format(@" and t.[Name] ='" + XlName + "'");



                            }
                        }
                        if (!string.IsNullOrEmpty(com))
                        {
                            if (com == "全部")
                            {

                                sql += string.Format(@"");
                            }
                            else
                            {
                                sql += string.Format(@" and [holderName]='" + com + "'");
                            }

                        }
                        if (CKBox.Checked != true)
                        {
                            sql += string.Format(@" and '" + da2.ToString() + "'> NextActioT and  NextActioT>'" + da1.ToString() + "'");
                        }
                        else
                        {
                            sql += string.Format(@"");
                        }

                        sql += string.Format(@"      order by Startuptime,e.[RouteID],[Order]  ");

                        XLXGS(DataGdv, sql);

                        if (!string.IsNullOrEmpty(XlName) && XlName != "全部")
                        {
                            DataTable dtco = new DataTable();

                            dtco = bl.countS(XlName);

                            foreach (DataRow dr in dtco.Rows)
                            {
                                if (dr[0].ToString() != "0")
                                {

                                    DataGdv.Rows[0].Cells[4].Value = dr[0].ToString();

                                }
                                else
                                {

                                    RoswSTxt.Text = "";

                                }
                            }
                        }

                        SQbase.Roswtxt(DataGdv, RoswSTxt);

                    }

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());

            }
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值