Ejemplo n.º 1
0
        private bool Equal(Type type, FilterOptions filter, DataRow row)
        {
            var value1 = (IComparable)row[filter.Column];
            var value2 = (IComparable)Convert.ChangeType(filter.Value, type, CultureInfo.InvariantCulture);

            if (value1.CompareTo(value2) == 0)
                return true;

            return false;
        }
Ejemplo n.º 2
0
        private bool AndNot(Type type, FilterOptions filter, DataRow row)
        {
            var typeCode = Type.GetTypeCode(type);

            if (typeCode == TypeCode.Byte || typeCode == TypeCode.UInt16 || typeCode == TypeCode.UInt32 || typeCode == TypeCode.UInt64)
            {
                if (((ulong)Convert.ChangeType(row[filter.Col], typeof(ulong), CultureInfo.InvariantCulture) & Convert.ToUInt64(filter.Val, CultureInfo.InvariantCulture)) == 0)
                    return true;

                return false;
            }
            else if (typeCode == TypeCode.SByte || typeCode == TypeCode.Int16 || typeCode == TypeCode.Int32 || typeCode == TypeCode.Int64)
            {
                if (((long)Convert.ChangeType(row[filter.Col], typeof(long), CultureInfo.InvariantCulture) & Convert.ToInt64(filter.Val, CultureInfo.InvariantCulture)) == 0)
                    return true;

                return false;
            }
            else
                return false;
        }
Ejemplo n.º 3
0
        private void SyncFilters()
        {
            m_filters.Clear();

            var delimiter = new char[] { ' ' };

            for (var i = 0; i < listBox1.Items.Count; ++i)
            {
                string filter = (string)listBox1.Items[i];
                var args = filter.Split(delimiter, 3);
                if (args.Length != 3)
                    throw new ArgumentException("We got a trouble!");

                m_filters[i] = new FilterOptions(args[0], args[1], args[2]);
            }
        }
Ejemplo n.º 4
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBox2.Text))
            {
                MessageBox.Show("Enter something first!");
                textBox2.Focus();
                return;
            }

            var fi = new FilterOptions((string)listBox2.SelectedItem, (ComparisonType)comboBox3.SelectedItem, textBox2.Text);

            var dt = m_mainForm.DataTable;
            var col = dt.Columns[fi.Column];

            try
            {
                if (col.DataType.IsPrimitive && col.DataType != typeof(float) && col.DataType != typeof(double))
                    if (fi.Value.StartsWith("0x", true, CultureInfo.InvariantCulture))
                        fi.Value = Convert.ToUInt64(fi.Value, 16).ToString(CultureInfo.InvariantCulture);

                Convert.ChangeType(fi.Value, col.DataType, CultureInfo.InvariantCulture);
            }
            catch
            {
                MessageBox.Show("Invalid filter!");
                return;
            }

            listBox1.Items.Add(fi);
        }
Ejemplo n.º 5
0
        private bool Contains(FilterOptions filter, DataRow row)
        {
            if (checkBox2.Checked)
            {
                if (row.Field<string>(filter.Column).ToUpperInvariant().Contains(filter.Value.ToUpperInvariant()))
                    return true;

                return false;
            }
            else
            {
                if (row.Field<string>(filter.Column).Contains(filter.Value))
                    return true;

                return false;
            }
        }
Ejemplo n.º 6
0
        private bool EndsWith(FilterOptions filter, DataRow row)
        {
            if (row.Field<string>(filter.Column).EndsWith(filter.Value, checkBox2.Checked ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal))
                return true;

            return false;
        }