コード例 #1
0
        /// <summary>
        /// 查询按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_query_Click(object sender, EventArgs e)
        {
            data_storage.AutoGenerateColumns = false;          //清空datagridview
            data_storage.DataSource          = null;
            data_storage.Rows.Clear();
            string find_type = "";                             //存储查询方式的值
            string find_text = "";                             //存储查询关键字
            string find_sql  = "";                             //根据时间查询的sql条件(根据用户的选择而更改)

            if (com_find_type.Text != "")                      //如果选择查询方式
            {
                if (text_find_name.Text == "")
                {
                    MessageBox.Show("请输入查询关键字");           //判断是否输入查询关键字
                    return;
                }
            }
            find_type = com_find_type.Text;
            find_text = text_find_name.Text;
            if (date_start_time.Text != " " && date_stop_time.Text == " ")     //如果截止时间为空
            {
                find_sql = " and convert(DATETIME,b.operation_time,120)>convert(DATETIME,'" + date_start_time.Text + " 00:00:00',120)";
            }
            if (date_start_time.Text == " " && date_stop_time.Text != " ")     //如果起始时间为空
            {
                find_sql = " and convert(DATETIME,b.operation_time,120)<convert(DATETIME,'" + date_stop_time.Text + " 23:59:59',120)";
            }
            if (date_start_time.Text != " " && date_stop_time.Text != " ")     //如果起始时间和截止时间都不为空
            {
                find_sql = " and convert(DATETIME,b.operation_time,120) BETWEEN convert(DATETIME,'" + date_start_time.Text + " 00:00:00',120) AND convert(DATETIME,'" + date_stop_time.Text + " 23:59:59',120)";
            }
            if (com_find_type.Text == "" && date_start_time.Text == " " && date_stop_time.Text == " ") //如果都为空 则查询全部
            {
                if (com_type_id.Text != "")                                                            //如果操作类型不是空
                {
                    data_storage.DataSource = bb.GetDataset(" where o.id=" + com_type_id.SelectedValue.ToString()).Tables[0];
                    data_storage.ClearSelection();
                    return;
                }
                data_storage.DataSource = bb.GetDataset("").Tables[0];
            }
            else
            {
                if (com_type_id.Text != "")  //如果操作类型不是空
                {
                    data_storage.DataSource = bb.ByCondition(find_type, find_text, find_sql, " where o.id=" + com_type_id.SelectedValue.ToString()).Tables[0];
                    data_storage.ClearSelection();
                    return;
                }
                data_storage.DataSource = bb.ByCondition(find_type, find_text, find_sql, " where 1=1").Tables[0];
            }
            data_storage.ClearSelection();
        }
コード例 #2
0
        /// <summary>
        /// 查询按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_query_Click(object sender, EventArgs e)
        {
            data_storage.AutoGenerateColumns = false;          //重置datagridview并且不清空标题
            data_storage.DataSource          = null;
            data_storage.Rows.Clear();
            string find_type = "";                             //存储查询方式的值
            string find_text = "";                             //存储查询关键字
            string find_sql  = "";                             //根据时间查询的sql条件(根据用户的选择而更改)

            if (com_find_type.Text != "")                      //如果选择查询方式
            {
                if (text_find_name.Text == "")
                {
                    MessageBox.Show("请输入查询关键字");           //判断是否输入查询关键字
                    return;
                }
            }
            find_type = com_find_type.Text;
            find_text = text_find_name.Text;
            if (date_start_time.Text != " " && date_stop_time.Text == " ")     //如果截止时间为空
            {
                find_sql = "convert(DATETIME,b.operation_time,120)>convert(DATETIME,'" + date_start_time.Text + " 00:00:00',120)";
            }
            if (date_start_time.Text == " " && date_stop_time.Text != " ")     //如果起始时间为空
            {
                find_sql = "convert(DATETIME,b.operation_time,120)<convert(DATETIME,'" + date_stop_time.Text + " 23:59:59',120)";
            }
            if (date_start_time.Text != " " && date_stop_time.Text != " ")     //如果起始时间和截止时间都不为空
            {
                find_sql = "convert(DATETIME,b.operation_time,120) BETWEEN convert(DATETIME,'" + date_start_time.Text + " 00:00:00',120) AND convert(DATETIME,'" + date_stop_time.Text + " 23:59:59',120)";
            }
            if (com_find_type.Text == "" && date_start_time.Text == " " && date_stop_time.Text == " ")
            {
                data_storage.DataSource = bb.GetDataset(operation_type).Tables[0];
            }
            else
            {
                data_storage.DataSource = bb.ByCondition(find_type, find_text, find_sql, operation_type).Tables[0];
            }
        }