Beispiel #1
0
        /// <summary>
        /// 值比较
        /// </summary>
        private static bool CompareMore(MDataRow row, params TFilter[] filters)
        {
            if (row == null)
            {
                return(false);
            }
            bool result = false;

            MDataCell cell = null, otherCell = null;
            SqlDbType sqlDbType = SqlDbType.Int;
            bool      moreResult = false;
            object    valueA = null, valueB = null;

            foreach (TFilter item in filters)
            {
                if (item._Op == Op.None)
                {
                    moreResult = true;
                }
                else
                {
                    if (item._columnAIndex == -1)
                    {
                        valueA    = item._valueA;
                        sqlDbType = SqlDbType.NVarChar;
                    }
                    else
                    {
                        cell      = row[item._columnAIndex];
                        valueA    = cell.Value;
                        sqlDbType = cell.Struct.SqlType;
                    }
                    if (item._columnBIndex > -1)
                    {
                        otherCell = row[item._columnBIndex];
                        valueB    = otherCell.Value;
                        if (DataType.GetGroup(sqlDbType) != DataType.GetGroup(otherCell.Struct.SqlType))
                        {
                            sqlDbType = SqlDbType.NVarChar;//不同类型的比较,转成字符串比较。
                        }
                    }
                    else
                    {
                        valueB = item._valueB;
                    }
                    switch (item._Op)
                    {
                    case Op.IsNull:
                        moreResult = cell != null && cell.IsNull;
                        break;

                    case Op.IsNotNull:
                        moreResult = cell != null && !cell.IsNull;
                        break;

                    default:
                        if (Convert.ToString(valueA) == "" || Convert.ToString(valueB) == "")    //空格的问题,稍后回来处理。
                        {
                            int a = valueA == null ? 1 : (Convert.ToString(valueA) == "" ? 2 : 3);
                            int b = valueB == null ? 1 : (Convert.ToString(valueB) == "" ? 2 : 3);
                            switch (item._Op)
                            {
                            case Op.Big:
                                moreResult = a > b;
                                break;

                            case Op.Like:
                            case Op.Equal:
                                moreResult = a == b;
                                break;

                            case Op.SmallEqual:
                                moreResult = a <= b;
                                break;

                            case Op.BigEqual:
                                moreResult = a >= b;
                                break;

                            case Op.Small:
                                moreResult = a < b;
                                break;

                            case Op.NotEqual:
                                moreResult = a != b;
                                break;
                                //case Op.In:

                                //    break;
                                //case Op.NotIn:
                                //    break;
                            }
                        }
                        else
                        {
                            moreResult = Compare(sqlDbType, valueA, item._Op, valueB);
                        }
                        break;
                    }
                }
                switch (item._Ao)
                {
                case Ao.And:
                    result = result && moreResult;
                    break;

                case Ao.Or:
                    result = result || moreResult;
                    break;

                default:
                    result = moreResult;
                    break;
                }
            }

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// 多条件下值比较
        /// </summary>
        private static bool CompareMore(MDataRow row, List <TFilter> filters)
        {
            if (row == null)
            {
                return(false);
            }
            bool result = false;

            MDataCell cell = null, otherCell = null;
            SqlDbType sqlDbType = SqlDbType.Int;
            //单个条件比较的结果
            bool   moreResult = false;
            object valueA = null, valueB = null;

            foreach (TFilter item in filters)
            {
                if (item._Op == Op.None || item._columnAIndex == -1)
                {
                    if (item._columnBIndex == -1)
                    {
                        moreResult = Convert.ToString(item._valueA) == Convert.ToString(item._valueB);
                    }
                    else
                    {
                        moreResult = true;//如果条件的列不属于当前表,直接忽略该条件
                    }
                }
                else
                {
                    //if (item._columnAIndex == -1)
                    //{
                    //    moreResult = true;
                    //    continue;
                    //    //valueA = item._valueA;
                    //    //sqlDbType = SqlDbType.NVarChar;
                    //}
                    //else
                    //{
                    cell      = row[item._columnAIndex];
                    valueA    = cell.Value;
                    sqlDbType = cell.Struct.SqlType;
                    //}
                    #region MyRegion
                    if (item._columnBIndex > -1)
                    {
                        otherCell = row[item._columnBIndex];
                        valueB    = otherCell.Value;
                        if (DataType.GetGroup(sqlDbType) != DataType.GetGroup(otherCell.Struct.SqlType))
                        {
                            sqlDbType = SqlDbType.NVarChar;//不同类型的比较,转成字符串比较。
                        }
                    }
                    else
                    {
                        valueB = item._valueB;
                    }
                    switch (item._Op)
                    {
                    case Op.IsNull:
                        moreResult = cell != null && cell.IsNull;
                        break;

                    case Op.IsNotNull:
                        moreResult = cell != null && !cell.IsNull;
                        break;

                    default:
                        if (Convert.ToString(valueA) == "" || Convert.ToString(valueB) == "")    //空格的问题,稍后回来处理。
                        {
                            #region MyRegion
                            int a = valueA == null ? 1 : (Convert.ToString(valueA) == "" ? 2 : 3);
                            int b = valueB == null ? 1 : (Convert.ToString(valueB) == "" ? 2 : 3);
                            switch (item._Op)
                            {
                            case Op.Big:
                                moreResult = a > b;
                                break;

                            case Op.Like:
                            case Op.Equal:
                                moreResult = a == b;
                                break;

                            case Op.SmallEqual:
                                moreResult = a <= b;
                                break;

                            case Op.BigEqual:
                                moreResult = a >= b;
                                break;

                            case Op.Small:
                                moreResult = a < b;
                                break;

                            case Op.NotLike:
                            case Op.NotEqual:
                                moreResult = a != b;
                                break;
                                //case Op.In:

                                //    break;
                                //case Op.NotIn:
                                //    break;
                            }
                            #endregion
                        }
                        else
                        {
                            moreResult = Compare(sqlDbType, valueA, item._Op, valueB);
                        }
                        break;
                    }
                    #endregion
                }
                switch (item._Ao)
                {
                case Ao.And:
                    result = result && moreResult;
                    if (!result)
                    {
                        break;
                    }
                    break;

                case Ao.Or:
                    result = result || moreResult;
                    break;

                default:
                    result = moreResult;
                    break;
                }
            }

            return(result);
        }
Beispiel #3
0
 public new void Insert(int index, MDataRow row)
 {
     base.InsertRange(index, row);
     Columns.InsertRange(index, row.Columns);
 }