void lAddSearchWindow_Closed(object sender, EventArgs e)
        {
            AddSearchWindow lAddSearchWindow = sender as AddSearchWindow;

            if (lAddSearchWindow.DialogResult == true)
            {
                TaxPayerSearchEntity laddTaxPayerSearchEntity = lAddSearchWindow.GetTaxPayerSearchEntity();
                TaxPayerSearchEntitis.Add(laddTaxPayerSearchEntity);
            }
        }
        void lAddSearchWindow_ClosedModify(object sender, EventArgs e)
        {
            AddSearchWindow lAddSearchWindow = sender as AddSearchWindow;

            if (lAddSearchWindow.DialogResult == true)
            {
                TaxPayerSearchEntity laddTaxPayerSearchEntity = lAddSearchWindow.GetTaxPayerSearchEntity();
                //SelectTaxPayerSearchEntity = laddTaxPayerSearchEntity;
                int lIndex = 0;
                foreach (TaxPayerSearchEntity lTaxPayerSearchEntity in TaxPayerSearchEntitis)
                {
                    if (lTaxPayerSearchEntity == SelectTaxPayerSearchEntity)
                    {
                        break;
                    }
                    lIndex++;
                }
                TaxPayerSearchEntitis[lIndex] = laddTaxPayerSearchEntity;

                //TaxPayerSearchEntitis.Add(laddTaxPayerSearchEntity);
            }
        }
 public void SetTaxPayerSearchEntity(TaxPayerSearchEntity aTaxPayerSearchEntity)
 {
     AddSearchWindowViewModel.SetTacPayerSearchEntity(aTaxPayerSearchEntity);
 }
        private EntityQuery<DocumentManager.Web.Model.taxpayer> TaxPayerQuery(EntityQuery<DocumentManager.Web.Model.taxpayer> aQuerable, TaxPayerSearchEntity aTaxPayerSearchEntity)
        {
            EntityQuery<DocumentManager.Web.Model.taxpayer> lQuerable = aQuerable;

            switch (aTaxPayerSearchEntity.TPTaxPayerField)
            {
                case TaxPayerField.CODE:
                    lQuerable = Search(lQuerable, aTaxPayerSearchEntity);
                    break;
                case TaxPayerField.NAME:
                    break;
                case TaxPayerField.TYPE:
                    break;
                case TaxPayerField.PROJECT:
                    break;
                case TaxPayerField.FINISH:
                    break;
                case TaxPayerField.FREE:
                    break;
            }
            return lQuerable;
        }
        private Expression FirstExpression(TaxPayerSearchEntity aTaxPayerSearchEntity)
        {
            Expression filter = Expression.Constant(true);

            Expression left = Expression.Property(Param, typeof(DocumentManager.Web.Model.taxpayer).GetProperty(TaxPayerFieldFieldString.GetString(aTaxPayerSearchEntity.TPTaxPayerField)));
            Expression right = Expression.Constant(null);
            switch (aTaxPayerSearchEntity.TPValueType)
            {
                case ValueType.VALUEBOOLEAN:
                    //right = Expression.Constant(aTaxPayerSearchEntity.ValueBoolean);
                    right = Expression.Constant(aTaxPayerSearchEntity.ValueBoolean, typeof(bool?));
                    break;
                case ValueType.VALUEINT:
                    //right = Expression.Constant(aTaxPayerSearchEntity.ValueInt);
                    right = Expression.Constant(aTaxPayerSearchEntity.ValueInt, typeof(int?));
                    break;
                case ValueType.VALUESTR:
                    right = Expression.Constant(aTaxPayerSearchEntity.ValueStr);
                    break;
            }

            switch (aTaxPayerSearchEntity.TPSearchOperator)
            {
                case SearchOperator.CONTAINS:
                    filter = Expression.Call(Expression.Property(Param, typeof(DocumentManager.Web.Model.taxpayer).GetProperty(TaxPayerFieldFieldString.GetString(aTaxPayerSearchEntity.TPTaxPayerField)))
                        , typeof(string).GetMethod("Contains", new Type[] { typeof(string) })
                        , Expression.Constant(aTaxPayerSearchEntity.ValueStr));
                    //totalExpr = Expression.And(filter, totalExpr);
                    break;
                case SearchOperator.NOTCONTAINS:
                    filter = Expression.Call(Expression.Property(Param, typeof(DocumentManager.Web.Model.taxpayer).GetProperty(TaxPayerFieldFieldString.GetString(aTaxPayerSearchEntity.TPTaxPayerField)))
                        , typeof(string).GetMethod("Contains", new Type[] { typeof(string) })
                        , Expression.Constant(aTaxPayerSearchEntity.ValueStr));
                    filter = Expression.Not(filter);
                    break;
                case SearchOperator.EQUAL:
                    filter = Expression.Equal(left, right);
                    break;
                case SearchOperator.NOEQUAL:
                    filter = Expression.NotEqual(left, right);
                    break;
                case SearchOperator.GREATER:
                    filter = Expression.GreaterThan(left, right);
                    break;
                case SearchOperator.LESS:
                    filter = Expression.LessThan(left, right);
                    break;
                case SearchOperator.GREATEREQUAL:
                    filter = Expression.GreaterThanOrEqual(left, right);
                    break;
                case SearchOperator.LESSEQUAL:
                    filter = Expression.LessThanOrEqual(left, right);
                    break;
            }

            return filter;
        }
        public EntityQuery<DocumentManager.Web.Model.taxpayer> Search(EntityQuery<DocumentManager.Web.Model.taxpayer> aQuerable
                                                                    , TaxPayerSearchEntity aTaxPayerSearchEntity)
        {
            EntityQuery<DocumentManager.Web.Model.taxpayer> lQuerable = aQuerable;

            Expression filter = Expression.Constant(true);
            Expression totalExpr = Expression.Constant(true);

            ParameterExpression lParam = Expression.Parameter(typeof(DocumentManager.Web.Model.taxpayer), "TaxPayer");

            {
               // Expression leftk = Expression.Property(lParam, typeof(DocumentManager.Web.Model.taxpayer).GetProperty("taxpayer_group_id"));
                //Nullable<int> lValue = 0;

                //Expression rightk = Expression.Constant(0);
                //totalExpr = Expression.Equal(leftk, rightk);
            }

            Expression left = Expression.Property(lParam, typeof(DocumentManager.Web.Model.taxpayer).GetProperty(TaxPayerFieldFieldString.GetString(aTaxPayerSearchEntity.TPTaxPayerField)));
            Expression right = Expression.Constant(null);
            switch(aTaxPayerSearchEntity.TPValueType)
            {
                case ValueType.VALUEBOOLEAN:
                    right = Expression.Constant(aTaxPayerSearchEntity.ValueBoolean);
                    break;
                case ValueType.VALUEINT:
                    right = Expression.Constant(aTaxPayerSearchEntity.ValueInt);
                    break;
                case ValueType.VALUESTR:
                    right = Expression.Constant(aTaxPayerSearchEntity.ValueStr);
                    break;
            }

            switch (aTaxPayerSearchEntity.TPSearchOperator)
            {
                case SearchOperator.CONTAINS:
                    filter = Expression.Call( Expression.Property( lParam, typeof(DocumentManager.Web.Model.taxpayer).GetProperty(TaxPayerFieldFieldString.GetString(aTaxPayerSearchEntity.TPTaxPayerField)))
                        , typeof(string).GetMethod("Contains", new Type[] { typeof(string) })
                        , Expression.Constant(aTaxPayerSearchEntity.ValueStr));
                    //totalExpr = Expression.And(filter, totalExpr);
                    break;
                case SearchOperator.NOTCONTAINS:
                    filter = Expression.Call(Expression.Property(lParam, typeof(DocumentManager.Web.Model.taxpayer).GetProperty(TaxPayerFieldFieldString.GetString(aTaxPayerSearchEntity.TPTaxPayerField)))
                        , typeof(string).GetMethod("Contains", new Type[] { typeof(string) })
                        , Expression.Constant(aTaxPayerSearchEntity.ValueStr));
                    filter = Expression.Not(filter);
                    break;
                case SearchOperator.EQUAL:
                    filter = Expression.Equal(left, right);
                    break;
                case SearchOperator.NOEQUAL:
                    filter = Expression.NotEqual(left, right);
                    break;
                case SearchOperator.GREATER:
                    filter = Expression.GreaterThan(left, right);
                    break;
                case SearchOperator.LESS:
                    filter = Expression.LessThan(left, right);
                    break;
                case SearchOperator.GREATEREQUAL:
                    filter = Expression.GreaterThanOrEqual(left, right);
                    break;
                case SearchOperator.LESSEQUAL:
                    filter = Expression.LessThanOrEqual(left, right);
                    break;
            }

            switch (aTaxPayerSearchEntity.TPSearchCondition)
            {
                case SearchCondition.AND:
                    totalExpr = Expression.AndAlso(filter, totalExpr);
                    break;
                case SearchCondition.OR:
                    totalExpr = Expression.OrElse(filter, totalExpr);
                    break;
            }

            //Expression pred = Expression.Lambda(totalExpr, lParam);
            //Expression whereExpression = Expression.Call(typeof(Queryable), "Where", new Type[] { typeof(DocumentManager.Web.Model.taxpayer) }, Expression.Constant(lQuerable), pred);
            //OrderBy部分排序
            //MethodCallExpression orderByCallExpression = Expression.Call(typeof(Queryable), queryCondition.IsDesc ? "OrderByDescending" : "OrderBy", new Type[] { typeof(TestUser), orderEntries[queryCondition.OrderField].OrderType }, whereExpression, Expression.Lambda(Expression.Property(param, orderEntries[queryCondition.OrderField].OrderStr), param));
            //EntityQuery<DocumentManager.Web.Model.taxpayer>()
            //return lQuerable.Query.AsQueryable().Provider.CreateQuery<DocumentManager.Web.Model.taxpayer>(whereExpression);
            //return lQuerable.Query.AsQueryable().Provider.CreateQuery<DocumentManager.Web.Model.taxpayer>(whereExpression);
            return lQuerable.Where((Expression<Func<DocumentManager.Web.Model.taxpayer, bool>>)Expression.Lambda(totalExpr, lParam));
        }
        public EntityQuery <DocumentManager.Web.Model.taxpayer> Search(EntityQuery <DocumentManager.Web.Model.taxpayer> aQuerable
                                                                       , TaxPayerSearchEntity aTaxPayerSearchEntity)
        {
            EntityQuery <DocumentManager.Web.Model.taxpayer> lQuerable = aQuerable;

            Expression filter    = Expression.Constant(true);
            Expression totalExpr = Expression.Constant(true);

            ParameterExpression lParam = Expression.Parameter(typeof(DocumentManager.Web.Model.taxpayer), "TaxPayer");

            {
                // Expression leftk = Expression.Property(lParam, typeof(DocumentManager.Web.Model.taxpayer).GetProperty("taxpayer_group_id"));
                //Nullable<int> lValue = 0;

                //Expression rightk = Expression.Constant(0);
                //totalExpr = Expression.Equal(leftk, rightk);
            }

            Expression left  = Expression.Property(lParam, typeof(DocumentManager.Web.Model.taxpayer).GetProperty(TaxPayerFieldFieldString.GetString(aTaxPayerSearchEntity.TPTaxPayerField)));
            Expression right = Expression.Constant(null);

            switch (aTaxPayerSearchEntity.TPValueType)
            {
            case ValueType.VALUEBOOLEAN:
                right = Expression.Constant(aTaxPayerSearchEntity.ValueBoolean);
                break;

            case ValueType.VALUEINT:
                right = Expression.Constant(aTaxPayerSearchEntity.ValueInt);
                break;

            case ValueType.VALUESTR:
                right = Expression.Constant(aTaxPayerSearchEntity.ValueStr);
                break;
            }

            switch (aTaxPayerSearchEntity.TPSearchOperator)
            {
            case SearchOperator.CONTAINS:
                filter = Expression.Call(Expression.Property(lParam, typeof(DocumentManager.Web.Model.taxpayer).GetProperty(TaxPayerFieldFieldString.GetString(aTaxPayerSearchEntity.TPTaxPayerField)))
                                         , typeof(string).GetMethod("Contains", new Type[] { typeof(string) })
                                         , Expression.Constant(aTaxPayerSearchEntity.ValueStr));
                //totalExpr = Expression.And(filter, totalExpr);
                break;

            case SearchOperator.NOTCONTAINS:
                filter = Expression.Call(Expression.Property(lParam, typeof(DocumentManager.Web.Model.taxpayer).GetProperty(TaxPayerFieldFieldString.GetString(aTaxPayerSearchEntity.TPTaxPayerField)))
                                         , typeof(string).GetMethod("Contains", new Type[] { typeof(string) })
                                         , Expression.Constant(aTaxPayerSearchEntity.ValueStr));
                filter = Expression.Not(filter);
                break;

            case SearchOperator.EQUAL:
                filter = Expression.Equal(left, right);
                break;

            case SearchOperator.NOEQUAL:
                filter = Expression.NotEqual(left, right);
                break;

            case SearchOperator.GREATER:
                filter = Expression.GreaterThan(left, right);
                break;

            case SearchOperator.LESS:
                filter = Expression.LessThan(left, right);
                break;

            case SearchOperator.GREATEREQUAL:
                filter = Expression.GreaterThanOrEqual(left, right);
                break;

            case SearchOperator.LESSEQUAL:
                filter = Expression.LessThanOrEqual(left, right);
                break;
            }

            switch (aTaxPayerSearchEntity.TPSearchCondition)
            {
            case SearchCondition.AND:
                totalExpr = Expression.AndAlso(filter, totalExpr);
                break;

            case SearchCondition.OR:
                totalExpr = Expression.OrElse(filter, totalExpr);
                break;
            }

            //Expression pred = Expression.Lambda(totalExpr, lParam);
            //Expression whereExpression = Expression.Call(typeof(Queryable), "Where", new Type[] { typeof(DocumentManager.Web.Model.taxpayer) }, Expression.Constant(lQuerable), pred);
            //OrderBy部分排序
            //MethodCallExpression orderByCallExpression = Expression.Call(typeof(Queryable), queryCondition.IsDesc ? "OrderByDescending" : "OrderBy", new Type[] { typeof(TestUser), orderEntries[queryCondition.OrderField].OrderType }, whereExpression, Expression.Lambda(Expression.Property(param, orderEntries[queryCondition.OrderField].OrderStr), param));
            //EntityQuery<DocumentManager.Web.Model.taxpayer>()
            //return lQuerable.Query.AsQueryable().Provider.CreateQuery<DocumentManager.Web.Model.taxpayer>(whereExpression);
            //return lQuerable.Query.AsQueryable().Provider.CreateQuery<DocumentManager.Web.Model.taxpayer>(whereExpression);
            return(lQuerable.Where((Expression <Func <DocumentManager.Web.Model.taxpayer, bool> >)Expression.Lambda(totalExpr, lParam)));
        }
        private EntityQuery <DocumentManager.Web.Model.taxpayer> TaxPayerQuery(EntityQuery <DocumentManager.Web.Model.taxpayer> aQuerable, TaxPayerSearchEntity aTaxPayerSearchEntity)
        {
            EntityQuery <DocumentManager.Web.Model.taxpayer> lQuerable = aQuerable;

            switch (aTaxPayerSearchEntity.TPTaxPayerField)
            {
            case TaxPayerField.CODE:
                lQuerable = Search(lQuerable, aTaxPayerSearchEntity);
                break;

            case TaxPayerField.NAME:
                break;

            case TaxPayerField.TYPE:
                break;

            case TaxPayerField.PROJECT:
                break;

            case TaxPayerField.FINISH:
                break;

            case TaxPayerField.FREE:
                break;
            }
            return(lQuerable);
        }
        private Expression CreateExpression(Expression aExpression, TaxPayerSearchEntity aTaxPayerSearchEntity)
        {
            //ParameterExpression lParam = Expression.Parameter(typeof(DocumentManager.Web.Model.taxpayer), "TaxPayer");

            Expression filter = Expression.Constant(true);

            Expression left  = Expression.Property(Param, typeof(DocumentManager.Web.Model.taxpayer).GetProperty(TaxPayerFieldFieldString.GetString(aTaxPayerSearchEntity.TPTaxPayerField)));
            Expression right = Expression.Constant(null);

            switch (aTaxPayerSearchEntity.TPValueType)
            {
            case ValueType.VALUEBOOLEAN:
                //right = Expression.Constant(aTaxPayerSearchEntity.ValueBoolean);
                right = Expression.Constant(aTaxPayerSearchEntity.ValueBoolean, typeof(bool?));
                break;

            case ValueType.VALUEINT:
                //right = Expression.Constant(aTaxPayerSearchEntity.ValueInt);
                right = Expression.Constant(aTaxPayerSearchEntity.ValueInt, typeof(int?));
                break;

            case ValueType.VALUESTR:
                right = Expression.Constant(aTaxPayerSearchEntity.ValueStr);
                break;
            }

            switch (aTaxPayerSearchEntity.TPSearchOperator)
            {
            case SearchOperator.CONTAINS:
                filter = Expression.Call(Expression.Property(Param, typeof(DocumentManager.Web.Model.taxpayer).GetProperty(TaxPayerFieldFieldString.GetString(aTaxPayerSearchEntity.TPTaxPayerField)))
                                         , typeof(string).GetMethod("Contains", new Type[] { typeof(string) })
                                         , Expression.Constant(aTaxPayerSearchEntity.ValueStr));
                //totalExpr = Expression.And(filter, totalExpr);
                break;

            case SearchOperator.NOTCONTAINS:
                filter = Expression.Call(Expression.Property(Param, typeof(DocumentManager.Web.Model.taxpayer).GetProperty(TaxPayerFieldFieldString.GetString(aTaxPayerSearchEntity.TPTaxPayerField)))
                                         , typeof(string).GetMethod("Contains", new Type[] { typeof(string) })
                                         , Expression.Constant(aTaxPayerSearchEntity.ValueStr));
                filter = Expression.Not(filter);
                break;

            case SearchOperator.EQUAL:
                filter = Expression.Equal(left, right);
                break;

            case SearchOperator.NOEQUAL:
                filter = Expression.NotEqual(left, right);
                break;

            case SearchOperator.GREATER:
                filter = Expression.GreaterThan(left, right);
                break;

            case SearchOperator.LESS:
                filter = Expression.LessThan(left, right);
                break;

            case SearchOperator.GREATEREQUAL:
                filter = Expression.GreaterThanOrEqual(left, right);
                break;

            case SearchOperator.LESSEQUAL:
                filter = Expression.LessThanOrEqual(left, right);
                break;
            }

            switch (aTaxPayerSearchEntity.TPSearchCondition)
            {
            case SearchCondition.AND:
                filter = Expression.AndAlso(filter, aExpression);
                break;

            case SearchCondition.OR:
                filter = Expression.OrElse(filter, aExpression);
                break;
            }

            return(filter);
        }
        public void SetTacPayerSearchEntity(TaxPayerSearchEntity aTaxPayerSearchEntity)
        {
            foreach(SearchConditionStruct lSearchConditionStruct in SearchConditionList)
            {
                if(lSearchConditionStruct.Value == aTaxPayerSearchEntity.TPSearchCondition)
                {
                    SelectSearchCondition = lSearchConditionStruct;
                }
            }

            foreach (TaxPayerFieldStruct lTaxPayerFieldStruct in TaxPayerFieldList)
            {
                if (lTaxPayerFieldStruct.Value == aTaxPayerSearchEntity.TPTaxPayerField)
                {
                    SelectTaxPayerField = lTaxPayerFieldStruct;
                }
            }

            foreach (SearchOperatorStruct lSearchOperatorStruct in SearchOperatorList)
            {
                if (lSearchOperatorStruct.Value == aTaxPayerSearchEntity.TPSearchOperator)
                {
                    SelectSearchOperator = lSearchOperatorStruct;
                }
            }

            ValueStr = aTaxPayerSearchEntity.ValueStr;
            ValueInt = aTaxPayerSearchEntity.ValueInt;
            ValueBoolean = aTaxPayerSearchEntity.ValueBoolean;
        }
        public TaxPayerSearchEntity GetTaxPayerSearchEntity()
        {
            TaxPayerSearchEntity lTaxPayerSearchEntity = new TaxPayerSearchEntity();

            if(SelectSearchCondition != null)
            {
                lTaxPayerSearchEntity.TPSearchCondition = SelectSearchCondition.Value;
            }

            if (SelectTaxPayerField != null)
            {
                lTaxPayerSearchEntity.TPTaxPayerField = SelectTaxPayerField.Value;
            }

            if (SelectSearchOperator != null)
            {
                lTaxPayerSearchEntity.TPSearchOperator = SelectSearchOperator.Value;
            }

            lTaxPayerSearchEntity.GroupID = GroupID;
            lTaxPayerSearchEntity.ValueBoolean = ValueBoolean;
            lTaxPayerSearchEntity.ValueInt = ValueInt;
            lTaxPayerSearchEntity.ValueStr = ValueStr;
            lTaxPayerSearchEntity.TaxPayerTypeList = TaxPayerTypeList;
            return lTaxPayerSearchEntity;
        }