public override void SetUp()
		{
			base.SetUp();
			_conjunction = Expression.Conjunction();
			_conjunction.Add(Expression.IsNull("Address"))
				.Add(Expression.Between("Count", 5, 10));
		}
Esempio n. 2
0
        internal override WalkedToken Walk(WalkedToken left, WalkedToken right)
        {
            Conjunction crit = new Conjunction();

            crit.Add(left.Criterion);
            crit.Add(right.Criterion);
            return WalkedToken.FromCriterion(crit);
        }
 public static void UpdateDefaultParamValueApp(FrwCompany company)
 {
     FrwParamValue[] paramsValue = FrwParamValue.FindAll(Expression.Eq("objIdCompany", company));
     Conjunction conj = new Conjunction();
     conj.Add(Expression.Not(Expression.In("IdParam", paramsValue.Select(x => x.objIdParam.IdParam).ToArray())));
     conj.Add(Expression.Eq("IsCompanyRequired", true));
     FrwParam[] paramsNew = FrwParam.FindAll(conj);
     string[] paramsNames = paramsNew.Select(x => x.IdParam).ToArray();
     AppParamEnum enumTryParse;
     foreach (string item in paramsNames)
     {
         if (Enum.TryParse<AppParamEnum>(item, out enumTryParse))
             FrwParametersHelper.UpdateDefaultParamValue(enumTryParse, company);
     }
 }
        private bool GetZoomDataByID(object idValue)
        {
            bool hasSearched = false;

            PropertyInfo prop = ZoomConfig.TypeEntity.GetProperty(ZoomConfig.FieldReturnId);
            if (prop != null)
            {
                Type propFieldType = prop.PropertyType;
                if (typeof(KPActiveRecordBase<>).IsSubclassOfRawGeneric(ZoomConfig.TypeEntity))
                {
                    MethodInfo method = ZoomConfig.TypeEntity.GetMethodInheritance("SlicedFindAll", new Type[] { typeof(int), typeof(int), typeof(Order[]), typeof(ICriterion[]) });
                    object zoomReturn = null;
                    if (method != null)
                    {
                        ICriterion filter = null;
                        Order order = null;
                        if (ZoomConfig.KPCriterionFilterDelegate != null)
                            filter = ZoomConfig.KPCriterionFilterDelegate();
                        if (ZoomConfig.KPOrderDelegate != null)
                            order = ZoomConfig.KPOrderDelegate();

                        try
                        {
                            Conjunction conj = new Conjunction();

                            if (FormBaseControl != null 
                                        && !String.IsNullOrWhiteSpace(ZoomConfig.PropertyCompanyEntity)
                                        && !String.IsNullOrWhiteSpace(FormBaseControl.PropertyCompanyEntity) 
                                        && !FormBaseControl.PropertyCompanyEntity.Equals("!")
                                        && !ZoomConfig.PropertyCompanyEntity.Equals("!"))
                            {
                                if (ZoomConfig.TypeEntity != null)
                                {
                                    PropertyInfo propZoomCompany = ZoomConfig.TypeEntity.GetProperty(ZoomConfig.PropertyCompanyEntity);
                                    if (propZoomCompany != null)
                                    {
                                        object dataSource = FormBaseControl.DataSourceAltered;
                                        if (dataSource != null)
                                        {
                                            object company = dataSource.GetType().GetProperty(FormBaseControl.PropertyCompanyEntity).GetValue(dataSource, null);
                                            if (company != null)
                                                conj.Add(Expression.Eq(propZoomCompany.Name, company));
                                        }
                                    }
                                }
                            }

                            ICriterion filterID = Expression.Eq(prop.Name, Convert.ChangeType(idValue, propFieldType));
                            conj.Add(filterID);
                            if (filter != null)
                                conj.Add(filter);

                            zoomReturn = method.Invoke(null, new object[] { 0, 1, order, new ICriterion[] { conj } });
                        }
                        catch
                        { return false; }
                    }

                    if (zoomReturn != null && ((Array)zoomReturn).Length > 0)
                    {
                        zoomReturn = ((Array)zoomReturn).GetValue(0);
                        hasSearched = true;

                        if (HiddenZoomIDField != null)
                            HiddenZoomIDField.Value = idValue.ToString();

                        if (TextBoxZoomField != null)
                        {
                            string propertyValue = String.Empty;
                            if (!String.IsNullOrEmpty(ZoomConfig.DisplaySearchField))
                                propertyValue = ZoomConfig.DisplaySearchField;
                            else
                                propertyValue = ZoomConfig.FieldReturnId;

                            object returnSearch = zoomReturn.GetType().GetProperty(propertyValue).GetValue(zoomReturn, null);
                            if (returnSearch != null)
                            {
                                string oldValue = TextBoxZoomField.Text;
                                TextBoxZoomField.Text = returnSearch.ToString();

                                if (ItemZoom.KPZoomLostFocusDelegate != null)
                                {
                                    if (!oldValue.Equals(TextBoxZoomField.Text, StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        ItemZoom.KPZoomLostFocusDelegate();

                                        if (ItemZoom.IndexTab != null)
                                        {
                                            KPTabControl.SetTabIndex(this.Page, Int32.Parse(ItemZoom.IndexTab.ToString()));
                                        }
                                    }
                                }
                            }
                        }

                        if (!String.IsNullOrWhiteSpace(ZoomConfig.FieldReturnText))
                        {
                            PropertyInfo propField = zoomReturn.GetType().GetProperty(ZoomConfig.FieldReturnText);
                            if (propField == null)
                                throw new KPExceptionSuggestion(String.Format("Não foi encontrado a propriedade '{0}'. Verificar nome da propriedade na Entidade {1}.", ZoomConfig.FieldReturnText, ZoomConfig.TypeEntityNamespace));

                            object labelText = propField.GetValue(zoomReturn, null);
                            if (labelText != null)
                                DescriptionZoomField.Text = labelText.ToString();
                        }
                    }
                }
            }

            return hasSearched;
        }
        private bool GetZoomDataBySearch(string searchValue)
        {
            bool hasSearched = false;

            if (TextBoxZoomField != null && !String.IsNullOrEmpty(searchValue))
            {
                if (!String.IsNullOrEmpty(ZoomConfig.SearchByField))
                {
                    PropertyInfo prop = ZoomConfig.TypeEntity.GetProperty(ZoomConfig.SearchByField);
                    if (prop != null)
                    {
                        Type propFieldType = prop.PropertyType;
                        if (typeof(KPActiveRecordBase<>).IsSubclassOfRawGeneric(ZoomConfig.TypeEntity))
                        {

                            MethodInfo method = ZoomConfig.TypeEntity.GetMethodInheritance("SlicedFindAll", new Type[] { typeof(int), typeof(int), typeof(Order[]), typeof(ICriterion[]) });
                            object zoomSearchReturn = null;
                            if (method != null)
                            {
                                object valueTyped = Convert.ChangeType(searchValue, propFieldType);
                                ICriterion criterionSearch = null;
                                if (valueTyped is String)
                                    criterionSearch = new LikeExpression(ZoomConfig.SearchByField, valueTyped.ToString(), MatchMode.Anywhere);
                                else
                                    criterionSearch = Expression.Eq(ZoomConfig.SearchByField, valueTyped);

                                ICriterion filter = null;
                                Order order = null;
                                if (ZoomConfig.KPCriterionFilterDelegate != null)
                                    filter = ZoomConfig.KPCriterionFilterDelegate();
                                if (ZoomConfig.KPOrderDelegate != null)
                                    order = ZoomConfig.KPOrderDelegate();

                                Conjunction conj = new Conjunction();
                                conj.Add(criterionSearch);
                                if (filter != null)
                                    conj.Add(filter);

                                zoomSearchReturn = method.Invoke(null, new object[] { 0, 2, order, new ICriterion[] { conj } });
                            }

                            if (zoomSearchReturn != null)
                            {
                                if (((Array)zoomSearchReturn).Length == 1)
                                {
                                    hasSearched = true;
                                    foreach (var item in (Array)zoomSearchReturn)
                                    {
                                        object returnID = item.GetType().GetProperty(ZoomConfig.FieldReturnId).GetValue(item, null);
                                        if (returnID != null)
                                            HiddenZoomIDField.Value = returnID.ToString();

                                        if (!String.IsNullOrEmpty(ZoomConfig.DisplaySearchField))
                                        {
                                            object returnSearch = item.GetType().GetProperty(ZoomConfig.DisplaySearchField).GetValue(item, null);
                                            if (returnSearch != null)
                                                TextBoxZoomField.Text = returnSearch.ToString();
                                        }
                                        else
                                        {
                                            TextBoxZoomField.Text = HiddenZoomIDField.Value;
                                        }

                                        object labelText = item.GetType().GetProperty(ZoomConfig.FieldReturnText).GetValue(item, null);
                                        if (labelText != null)
                                            DescriptionZoomField.Text = labelText.ToString();
                                    }
                                }
                                else if (((Array)zoomSearchReturn).Length > 1)
                                {
                                    OpenZoomWindow();
                                }
                            }
                        }
                    }
                }
            }

            return hasSearched;
        }
        private void VisitAndAlsoExpression(BinaryExpression expr)
        {
            criterionStack.Push(new List<ICriterion>());
            Visit(expr.Left);
            Visit(expr.Right);
            var ands = criterionStack.Pop();

            var conjunction = new Conjunction();
            foreach (var crit in ands)
                conjunction.Add(crit);
            CurrentCriterions.Add(conjunction);
        }
        /// <summary>
        /// Método para retorna uma lista de usuários na Grid, selecionando pelo ID do perfil , se não tiver retorna um nova lista.
        /// </summary>
        /// <returns></returns>
        public List<FrwProfileWindow> GetPerfilTela()
        {
            List<FrwProfileWindow> listData = new List<FrwProfileWindow>();
            FrwProfile objProfile = formControl.DataSourceAltered as FrwProfile;
            int IdProfile = objProfile.IdProfile;
            if (IdProfile == 0)
            {
                return new List<FrwProfileWindow>();
            }

            Conjunction conj = new Conjunction();
            conj.Add(Expression.Eq("objIdProfile", new FrwProfile() { IdProfile = IdProfile }));
            conj.Add(Expression.Eq("objIdCompany", objProfile.objIdCompany));

            FrwProfileWindow[] listUserProfile = FrwProfileWindow.FindAll(conj);
            listData.AddRange(listUserProfile);

            return listData;
        }
        private Expression VisitCriterionExpression(Expression expr)
        {
            IEnumerable<ICriterion> criterion = WhereArgumentsVisitor.GetCriterion(_rootCriteria, _session, expr);

            if (criterion.Count() > 0)
            {
                Conjunction conjunction = new Conjunction();
                foreach (ICriterion crit in criterion)
                {
                    conjunction.Add(crit);
                }

                _projections.Add(Projections.Conditional(
                    conjunction,
                    Projections.Constant(true),
                    Projections.Constant(false))
                );
            }

            return expr;
        }
        /// <summary>
        /// Authentication User and Password
        /// </summary>
        /// <param name="login">User login</param>
        /// <param name="password">User password</param>
        /// <returns>return true when success or false when user/login incorrect</returns>
        private static Authenticate Authenticate(string login, string password)
        {
            Authenticate authenticate = null;
            try
            {
                Conjunction conj = new Conjunction();
                conj.Add(Expression.Eq("UserLogin", login).IgnoreCase());
                conj.Add(Expression.Eq("IsAccessAllowed", true));
                FrwUser frwUser = FrwUser.FindOne(conj);

                if (frwUser == null)
                    return authenticate;

                if (KPCryptography.VerifyHash(String.Concat(login.ToLower(), password), KPAlgorithmEnum.MD5, frwUser.UserPassword))
                {
                    conj = new Conjunction();
                    conj.Add(Expression.Eq("objIdUser", frwUser));
                    FrwUserCompany[] userCompany = FrwUserCompany.FindAll(conj);
                    if (userCompany != null && userCompany.Length > 0)
                    {
                        FrwCompany[] companies = userCompany.Select(x => x.objIdCompany).ToArray();
                        FrwCompany companyDefault = companies[0];
                        FrwUserCompany[] userCompanyDefault = userCompany.Where(x => x.IsDefaultCompany == true).ToArray();
                        if (userCompanyDefault != null && userCompanyDefault.Length > 0)
                            companyDefault  = userCompanyDefault[0].objIdCompany;

                        authenticate = new Authenticate(frwUser, true, companies, companyDefault);
                    }
                }
            }
            catch 
            {
                throw;
            }

            return authenticate;
        }
        internal static ComponentPermission[] UserComponentPermissions(FrwUser frwUser)
        {
            List<ComponentPermission> componentPermissionList = new List<ComponentPermission>();

            Conjunction conjUserProfile = new Conjunction();
            conjUserProfile.Add(Expression.Eq("objIdCompany", frwUser.objIdCompany));
            conjUserProfile.Add(Expression.Eq("objIdUser", frwUser));
            FrwUserProfile[] entityUserProfiles = FrwUserProfile.FindAll(conjUserProfile);
            if (entityUserProfiles != null)
            {
                foreach (FrwProfile objIdProfile in entityUserProfiles.Select(x => x.objIdProfile))
                {
                    Conjunction conjProfileFilter = new Conjunction();
                    conjProfileFilter.Add(Expression.Eq("objIdCompany", frwUser.objIdCompany));
                    conjProfileFilter.Add(Expression.Eq("objIdProfile", objIdProfile));

                    FrwProfileComponent[] entityProfileComponents = FrwProfileComponent.FindAll(conjProfileFilter);
                    foreach (FrwProfileComponent objIdProfileComponent in entityProfileComponents)
                    {
                        ComponentPermission componentPermission = componentPermissionList.FirstOrDefault(x => x.ComponentId == objIdProfileComponent.objIdComponent.IdComponent);
                        if (componentPermission != null)
                        {
                            // Validação de permissão pela negativa.
                            componentPermission.IsEnabled = objIdProfileComponent.IsEnable.Value ? componentPermission.IsEnabled : objIdProfileComponent.IsEnable.Value;
                            componentPermission.IsVisible = objIdProfileComponent.IsVisible.Value ? componentPermission.IsVisible : objIdProfileComponent.IsVisible.Value;
                        }
                        else
                        {
                            componentPermissionList.Add(new ComponentPermission(objIdProfileComponent.objIdComponent.objIdWindow.IdWindow,
                                                                                objIdProfileComponent.objIdComponent.objIdWindow.WindowEnum,
                                                                                objIdProfileComponent.objIdComponent.IdComponent,
                                                                                objIdProfileComponent.objIdComponent.ComponentNameId)
                            {
                                IsEnabled = objIdProfileComponent.IsEnable.Value,
                                IsVisible = objIdProfileComponent.IsVisible.Value
                            });
                        }
                    }
                }
            }

            return componentPermissionList.ToArray();
        }
        internal static PagePermission[] UserPagePermissions(FrwUser frwUser)
        {
            List<PagePermission> pagePermissionList = new List<PagePermission>();

            Conjunction conjUserProfile = new Conjunction();
            conjUserProfile.Add(Expression.Eq("objIdCompany", frwUser.objIdCompany));
            conjUserProfile.Add(Expression.Eq("objIdUser", frwUser));
            FrwUserProfile[] entityUserProfiles = FrwUserProfile.FindAll(conjUserProfile);
            if (entityUserProfiles != null)
            {
                foreach (FrwProfile objIdProfile in entityUserProfiles.Select(x => x.objIdProfile))
                {
                    Conjunction conjProfileFilter = new Conjunction();
                    conjProfileFilter.Add(Expression.Eq("objIdCompany", frwUser.objIdCompany));
                    conjProfileFilter.Add(Expression.Eq("objIdProfile", objIdProfile));
                    FrwProfileWindow[] entityProfileWindows = FrwProfileWindow.FindAll(conjProfileFilter);
                    if (entityProfileWindows != null)
                    {
                        foreach (FrwProfileWindow objIdProfileWindow in entityProfileWindows)
                        {
                            PagePermission pagePermission = pagePermissionList.FirstOrDefault(x => x.PageId == objIdProfileWindow.objIdWindow.IdWindow);
                            if (pagePermission != null)
                            {
                                // Validação de permissão pela negativa, caso algum perfil tiver, poderá bloquear o acesso.
                                pagePermission.IsReadOnly = objIdProfileWindow.IsReadOnly.Value ? pagePermission.IsReadOnly : objIdProfileWindow.IsReadOnly.Value;
                                pagePermission.IsPreview = objIdProfileWindow.IsPreview.Value ? pagePermission.IsPreview : objIdProfileWindow.IsPreview.Value;
                            }
                            else
                            {
                                pagePermissionList.Add(new PagePermission(objIdProfileWindow.objIdWindow.IdWindow, 
                                                                        objIdProfileWindow.objIdWindow.WindowEnum,
                                                                        objIdProfileWindow.objIdWindow.WindowTitle)
                                {
                                    IsReadOnly = objIdProfileWindow.IsReadOnly.Value,
                                    IsPreview = objIdProfileWindow.IsPreview.Value
                                });
                            }
                        }
                    }
                }
            }

            return pagePermissionList.ToArray();
        }
        private ICriterion GetFiltering(KPFormItemKeyFieldsCollection keys, ActiveRecordBase entity)
        {
            Conjunction conjuntion = new Conjunction();

            if (entity != null && MasterDetailConfig.TypeEntityDetail != null)
            {
                foreach (KPMappingKeyModel key in keys)
                {
                    PropertyInfo propMaster = entity.GetType().GetProperty(key.KeyMaster);
                    PropertyInfo propDetail = MasterDetailConfig.TypeEntityDetail.GetProperty(key.KeyDetail);
                    if (propMaster != null && propDetail != null)
                    {
                        object value = propMaster.GetValue(entity, null);

                        int idKey = 0;
                        if (Int32.TryParse(value.ToString(), out idKey))
                        {
                            // Proteção para não trazer nada quando novo
                            if (idKey == 0)
                            {
                                conjuntion.Add(Expression.Sql(" 1 = 2"));
                                return conjuntion;
                            }

                        }

                        if (propMaster.PropertyType == propDetail.PropertyType)
                        {
                            conjuntion.Add(Expression.Eq(key.KeyDetail, value));
                        }
                        else
                        {
                            if (typeof(ActiveRecordBase).IsSubclassOfRawGeneric(propDetail.PropertyType))
                            {
                                MethodInfo methodFind = propDetail.PropertyType.GetMethodInheritance("Find", new Type[] { typeof(object) });
                                if (methodFind != null)
                                {
                                    object objValue = methodFind.Invoke(null, new object[] { value });
                                    if (objValue != null)
                                    {
                                        conjuntion.Add(Expression.Eq(key.KeyDetail, objValue));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return conjuntion;
        }
Esempio n. 13
0
        protected override void OnInit(EventArgs e)
        {
            try
            {
                base.OnInit(e);
                if (SecuritySession == null)
                {
                    if (User.Identity.IsAuthenticated)
                    {
                        FrwUser loggedUser = FrwUser.FindOne(Expression.Eq("UserLogin", User.Identity.Name));

                        Conjunction conj = new Conjunction();
                        conj.Add(Expression.Eq("IsDefaultCompany", true));
                        conj.Add(Expression.Eq("objIdUser", loggedUser));

                        FrwUserCompany userCompany = FrwUserCompany.FindFirst(conj);
                        string sessionID = null;
                        if (System.Web.HttpContext.Current != null && System.Web.HttpContext.Current.Session != null)
                            sessionID = System.Web.HttpContext.Current.Session.SessionID;

                        KPSessionHelper.SetSession(KPSessionKeyEnum.SESSION_LOGIN,
                                    new KPSecuritySession(sessionID, User.Identity.Name,
                                            loggedUser.objIdCompany.IdCompany, loggedUser.IdUser,
                                            KPFormsAuthentication.UserPagePermissions(loggedUser),
                                            KPFormsAuthentication.UserComponentPermissions(loggedUser)));
                    }
                    else
                        KPFormsAuthentication.Logout();
                }

            }
            catch (Exception)
            {
                throw;
            }

        }