示例#1
0
        private void btSearch_Click(object sender, System.EventArgs e)
        {
            try
            {
                string filterValue = txtValue.Text.Trim();
                if (filterValue == "")
                {
                    MessageBox.Show("条件为空,请输入条件!", "错误");
                    return;
                }
                if (_mappingDataGrid == null || _mappingDataGrid.DataSource == null)
                {
                    return;
                }
                string filter = "";
                Item   item   = null;
                if (cmbField.Items.Count > 0)
                {
                    item = (Item)cmbField.SelectedItem;
                    FIELDINFO fieldInfo = (FIELDINFO)item.Value;
                    filter += fieldInfo.FieldName.ToString();
                    item    = (Item)cmbOperation.SelectedItem;
                    if (fieldInfo.FieldType == typeof(System.String) || fieldInfo.FieldType == typeof(System.DateTime))
                    {
                        #region 字符串与日期类型
                        switch (item.Value.ToString())
                        {
                        case "Like":
                            filter += " Like '%" + filterValue + "%'";
                            break;

                        case "Not Like":
                            filter += "Not Like '%" + filterValue + "%'";
                            break;

                        case "=":
                            filter += "='" + filterValue + "'";
                            break;

                        case "!=":
                            filter += "<>'" + filterValue + "'";
                            break;

                        case ">":
                            filter += ">'" + filterValue + "'";
                            break;

                        case "<":
                            filter += "<'" + filterValue + "'";
                            break;

                        case ">=":
                            filter += ">='" + filterValue + "'";
                            break;

                        case "<=":
                            filter += "<='" + filterValue + "'";
                            break;

                        case "Null":
                            filter += " is null";
                            break;

                        case "Not Null":
                            filter += " is not null";
                            break;

                        default:
                            filter = "";
                            MessageBox.Show("字段类型与操作符不相匹配!", "错误");
                            break;
                        }
                        #endregion
                    }
                    else
                    {
                        #region 数值类型
                        switch (item.Value.ToString())
                        {
                        case "=":
                            filter += "=" + filterValue;
                            break;

                        case "!=":
                            filter += "<>" + filterValue;
                            break;

                        case ">":
                            filter += ">" + filterValue;
                            break;

                        case "<":
                            filter += "<" + filterValue;
                            break;

                        case ">=":
                            filter += ">=" + filterValue;
                            break;

                        case "<=":
                            filter += "<=" + filterValue;
                            break;

                        case "Null":
                            filter += " is null";
                            break;

                        case "Not Null":
                            filter += " is not null";
                            break;

                        default:
                            filter = "";
                            MessageBox.Show("字段类型与操作符不相匹配!", "错误");
                            break;
                        }
                        #endregion
                    }
                }
                if (filter != "")
                {
                    ((DataView)_mappingDataGrid.DataSource).RowFilter = filter;
                }
            }
            catch (Exception err)
            {
                MessageBox.Show("TrasenClasses\\GeneralControls\\ComboGridSearch\\btSearch_Click():\n" + err.Message, "错误");
            }
        }
示例#2
0
        private void btAdd_Click(object sender, System.EventArgs e)
        {
            string filterValue = txtValue.Text.Trim();

            if (filterValue == "")
            {
                MessageBox.Show("条件为空,请输入条件!", "错误");
                return;
            }
            string filter = "";
            Item   item   = null;

            if (cmbField.Items.Count > 0)
            {
                item = (Item)cmbField.SelectedItem;
                FIELDINFO fieldInfo = (FIELDINFO)item.Value;
                filter += fieldInfo.FieldName;
                item    = (Item)cmbOperation.SelectedItem;
                if (fieldInfo.FieldType == typeof(System.String) || fieldInfo.FieldType == typeof(System.DateTime))
                {
                    #region 字符串与日期类型
                    switch (item.Value.ToString())
                    {
                    case "Like":
                        filter += " Like '%" + filterValue + "%'";
                        break;

                    case "Not Like":
                        filter += "Not Like '%" + filterValue + "%'";
                        break;

                    case "=":
                        filter += "='" + filterValue + "'";
                        break;

                    case "!=":
                        filter += "<>'" + filterValue + "'";
                        break;

                    case ">":
                        filter += ">'" + filterValue + "'";
                        break;

                    case "<":
                        filter += "<'" + filterValue + "'";
                        break;

                    case ">=":
                        filter += ">='" + filterValue + "'";
                        break;

                    case "<=":
                        filter += "<='" + filterValue + "'";
                        break;

                    case "Null":
                        filter += " is null";
                        break;

                    case "Not Null":
                        filter += " is not null";
                        break;

                    default:
                        filter = "";
                        MessageBox.Show("字段类型与操作符不相匹配!", "错误");
                        break;
                    }
                    #endregion
                }
                else
                {
                    #region 数值类型
                    switch (item.Value.ToString())
                    {
                    case "=":
                        filter += "=" + filterValue;
                        break;

                    case "!=":
                        filter += "<>" + filterValue;
                        break;

                    case ">":
                        filter += ">" + filterValue;
                        break;

                    case "<":
                        filter += "<" + filterValue;
                        break;

                    case ">=":
                        filter += ">=" + filterValue;
                        break;

                    case "<=":
                        filter += "<=" + filterValue;
                        break;

                    case "Null":
                        filter += " is null";
                        break;

                    case "Not Null":
                        filter += " is not null";
                        break;

                    default:
                        filter = "";
                        MessageBox.Show("字段类型与操作符不相匹配!", "错误");
                        break;
                    }
                    #endregion
                }
            }
            if (filter != "")
            {
                item = new Item();
                string[] tag = new string[3];
                tag[0] = filter;
                tag[1] = ((Item)cmbLogic.SelectedItem).Value.ToString();
                tag[2] = "";
                string sort = "";
                if (chkSort.Checked)
                {
                    item = (Item)cmbField.SelectedItem;
                    FIELDINFO fieldInfo = (FIELDINFO)item.Value;
                    tag[2] = fieldInfo.FieldName + " " + ((Item)cmbSort.SelectedItem).Value.ToString();
                    if (((Item)cmbSort.SelectedItem).Value.ToString() == "Asc")
                    {
                        sort = "↑";
                    }
                    else
                    {
                        sort = "↓";
                    }
                }
                item.Text  = sort + cmbField.Text + " " + cmbOperation.Text + " " + filterValue + " " + cmbLogic.Text;
                item.Value = tag;
                lstCondition.Items.Add(item);
            }
        }