コード例 #1
0
ファイル: FProcess.cs プロジェクト: leonardo1994/ERP
        public virtual void ButtonActive_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (!IsValid())
            {
                return;
            }

            var nameMethod = InvokeMethod.Methods.FirstOrDefault(c => c.Key == TypeExecute.InsertOrUpdate).Value;

            if (string.IsNullOrEmpty(nameMethod))
            {
                MessageBox.Show("Método InsertOrUpdate não configurado\nController: " + InvokeMethod.TypeController.Name,
                                "ESR Softwares", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }

            var obj = CurrentControl;

            // Via reflexão executa método crud, passando o registro atual.
            if (!SReflection.ExecuteContext(InvokeMethod.TypeController, nameMethod, obj))
            {
                MessageBox.Show("Não foi possível executar a função.",
                                "ESR Softwares", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            else
            {
                MessageBox.Show("Processo concluído.",
                                "ESR Softwares", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
コード例 #2
0
        /// <summary>
        /// Método responsável em executar o crud da tela.
        /// </summary>
        /// <param name="typeAction"></param>
        private bool ExecuteApp(TypeAction typeAction)
        {
            var    nameMethod = string.Empty;
            object obj        = null;

            if (typeAction != TypeAction.Insert)
            {
                if (typeAction == TypeAction.Remove)
                {
                    nameMethod = InvokeMethod.Methods.FirstOrDefault(c => c.Key == TypeExecute.Remove).Value;
                    if (string.IsNullOrEmpty(nameMethod))
                    {
                        MessageBox.Show("Método Remove não configurado\nController: " + InvokeMethod.TypeController.Name,
                                        "ESR Softwares", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    }
                    obj = CurrentControl.Id;
                }
            }
            else
            {
                nameMethod = InvokeMethod.Methods.FirstOrDefault(c => c.Key == TypeExecute.InsertOrUpdate).Value;
                if (string.IsNullOrEmpty(nameMethod))
                {
                    MessageBox.Show("Método InsertOrUpdate não configurado\nController: " + InvokeMethod.TypeController.Name,
                                    "ESR Softwares", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
                obj = CurrentControl;
            }

            // Via reflexão executa método crud, passando o registro atual.
            var lReturn = SReflection.ExecuteContext(InvokeMethod.TypeController, nameMethod, obj);

            return(lReturn);
        }
コード例 #3
0
        public void UpdateDataSource()
        {
            var result = new SReflection().GetListContext(ObjetoApp.TypeController, ObjetoApp.Methods[TypeExecute.SearchAll]);

            SComponent.DataSource = result as IList;
            SComponent.Refresh();
            SComponent.ClearSelected();
        }
コード例 #4
0
ファイル: SNumeric.cs プロジェクト: leonardo1994/ERP
        private void SComponentOnValueChanged(object sender, EventArgs eventArgs)
        {
            ValueControl = SComponent.Value;

            if (ObjetoApp != null)
            {
                var method = ObjetoApp.Methods.FirstOrDefault(d => d.Key == TypeExecute.Search).Value;
                ObjectControl = new SReflection().FindIdContext(ObjetoApp.TypeController, method, ValueControl);
                ValueControl  = null;
            }
        }
コード例 #5
0
ファイル: SComboBox.cs プロジェクト: leonardo1994/ERP
        private void SComponentOnLostFocus(object sender, EventArgs eventArgs)
        {
            if (RibbonTab != null)
            {
                GetSForm().RemoveAba(RibbonTab);
            }

            if (!string.IsNullOrEmpty(PropertySearch))
            {
                var property = ObjetoApp.TypeModel.GetProperty(PropertySearch);
                if (property != null && !string.IsNullOrEmpty(SComponent.Text))
                {
                    var dataSource = SComponent.DataSource as IList;
                    var item       = dataSource.Where(PropertySearch + " = @0", SComponent.Text).Select("Id");
                    if (!item.Any())
                    {
                        var rt = MessageBox.Show("Item não existe na lista, deseja cadastrar novo ?", "ESR Softwares", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (rt == DialogResult.Yes)
                        {
                            if (Form == null)
                            {
                                if (FormType != null)
                                {
                                    Form = new SReflection().CreateNewInstance <FForm>(FormType);
                                }
                            }
                            Form.StateForm = StateForm.Inserting;
                            if (Form.CurrentControl == null)
                            {
                                Form.bindingSource.AddNew();
                            }
                            var property1 = Form.CurrentControl.GetType().GetProperty(PropertySearch);
                            property1.SetValue(Form.CurrentControl, SComponent.Text);
                            Form.ShowDialog();
                        }
                        else
                        {
                            SComponent.SelectedIndex = -1;
                            SComponent.Text          = "";
                            ValueControl             = null;
                        }
                    }
                    foreach (var item1 in item)
                    {
                        SComponent.SelectedValue = item1;
                    }
                }
            }
        }
コード例 #6
0
ファイル: SComboBox.cs プロジェクト: leonardo1994/ERP
 private void SComponentOnGotFocus(object sender, EventArgs eventArgs)
 {
     try
     {
         if (Form == null)
         {
             if (FormType != null)
             {
                 Form = new SReflection().CreateNewInstance <FForm>(FormType);
             }
         }
         if (FormType != null)
         {
             RibbonTab = GetSForm().AddTab(Form, this);
         }
         var value = SComponent.SelectedIndex;
         SComponent.SelectedIndex = value;
     }
     catch (Exception)
     {
         // Ignore
     }
 }
コード例 #7
0
ファイル: SControl.cs プロジェクト: leonardo1994/ERP
 private void SetValueProperty(object obj)
 {
     try
     {
         if (PropertyControl == null)
         {
             return;
         }
         if (GetSForm()?.CurrentControl == null)
         {
             return;
         }
         if (obj == null)
         {
             obj = new SReflection().ConvertProperty(PropertyControl);
         }
         PropertyControl.SetValue(GetSForm().CurrentControl, obj);
         ShootError(IsValid());
     }
     catch (Exception)
     {
         // Ignote
     }
 }
コード例 #8
0
ファイル: SControl.cs プロジェクト: leonardo1994/ERP
        private Dictionary <string, bool> IsValid()
        {
            if (!(FindForm() is FBase))
            {
                return(new Dictionary <string, bool>());
            }
            if (!(GetSForm().StateForm == StateForm.Inserting || GetSForm().StateForm == StateForm.Editing))
            {
                return(new Dictionary <string, bool>());
            }
            try
            {
                if (Name == string.Empty)
                {
                    return(new Dictionary <string, bool>());
                }
                Validations = new Dictionary <string, bool>();

                if (GetSForm() == null)
                {
                    RemoveErrorProvider();
                    return(new Dictionary <string, bool>());
                }
                if (PropertyControl == null)
                {
                    return(new Dictionary <string, bool>());
                }
                var validationAttributes = GetAttribute();
                var reflection           = new SReflection();
                foreach (var attribute in validationAttributes)
                {
                    try
                    {
                        var validationAttribute = attribute as ValidationAttribute;
                        if (validationAttribute == null)
                        {
                            continue;
                        }
                        bool isValid;

                        var operatorValue = GetAttribute <OperationValue>(PropertyControl);
                        if (operatorValue != null)
                        {
                            decimal result     = 0;
                            var     component1 =
                                GetSForm()
                                .GetListControls()
                                .FirstOrDefault(c => c.Name == operatorValue.PropertyOperationName);
                            var componentTotal =
                                GetSForm()
                                .GetListControls()
                                .FirstOrDefault(c => c.Name == operatorValue.PropertyResultName);
                            if (component1 != null)
                            {
                                if (componentTotal != null)
                                {
                                    switch (operatorValue.TypeOperation)
                                    {
                                    case TypeOperation.Division:
                                        if ((decimal)ValueControl != 0)
                                        {
                                            result = (decimal)component1.ValueControl / (decimal)ValueControl;
                                        }
                                        break;

                                    case TypeOperation.Multiplication:
                                        result = (decimal)ValueControl * (decimal)component1.ValueControl;
                                        break;

                                    case TypeOperation.Sum:
                                        result = (decimal)ValueControl + (decimal)component1.ValueControl;
                                        break;

                                    case TypeOperation.Subtraction:
                                        result = (decimal)component1.ValueControl - (decimal)ValueControl;
                                        break;

                                    case TypeOperation.SubtractionInversion:
                                        result = (decimal)ValueControl - (decimal)component1.ValueControl;
                                        break;

                                    case TypeOperation.SubtractionPorcent:
                                        result = (decimal)component1.ValueControl - (((decimal)component1.ValueControl / 100) * (decimal)ValueControl);
                                        break;

                                    case TypeOperation.AditionalPorcent:
                                        result = (decimal)component1.ValueControl + (((decimal)component1.ValueControl / 100) * (decimal)ValueControl);
                                        break;

                                    case TypeOperation.PorcentValue:
                                        result = (((decimal)component1.ValueControl / 100) * (decimal)ValueControl);
                                        break;

                                    default:
                                        result = 0;
                                        break;
                                    }
                                }
                            }
                            componentTotal.Disable      = false;
                            componentTotal.ValueControl = result;
                        }

                        if (validationAttribute is LockedTrueValue)
                        {
                            var lockedTrueValue = validationAttribute as LockedTrueValue;
                            var valid           = false;
                            if (lockedTrueValue.UniqueValue)
                            {
                                valid = lockedTrueValue.Value[0].ToString() != ValueControl.ToString();
                            }
                            for (var i = 0; i < lockedTrueValue.PropertyName.Count(); i++)
                            {
                                if (!lockedTrueValue.UniqueValue)
                                {
                                    valid = lockedTrueValue.Value[i]?.ToString() != PropertyControl?.GetValue(GetSForm()?.CurrentControl)?.ToString();
                                }

                                var component = GetSForm().GetListControls().FirstOrDefault(c => c.Name == lockedTrueValue.PropertyName[i]);
                                component.Disable = valid;
                                if (!valid)
                                {
                                    component.Clear();
                                }
                            }
                        }

                        if (validationAttribute is CompareAttribute)
                        {
                            var otherName     = validationAttribute.GetType().GetProperty("OtherProperty").GetValue(validationAttribute).ToString();
                            var otherProperty = CurrentControl.GetType().GetProperty(otherName);
                            var otherValue    = otherProperty.GetValue(CurrentControl);
                            isValid = otherValue?.ToString() == ValueControl.ToString();
                        }
                        else
                        {
                            if (this is SComboBox)
                            {
                                isValid = !ValueControl.ToString().Equals("0");
                            }
                            else
                            {
                                isValid = validationAttribute.IsValid(ValueControl);
                            }
                        }
                        var key = validationAttribute.FormatErrorMessage(DisplayName(PropertyControl));
                        if (!isValid && !Validations.ContainsKey(key))
                        {
                            Validations.Add(key, false);
                        }

                        var compoundIndex = GetSForm().GetAttribute <CompoundIndex>();
                        var unique        = attribute as Unique;

                        if ((compoundIndex != null && compoundIndex.Properties.Contains(Name)) || unique != null)
                        {
                            var typeValue = ValueControl as string;
                            if (!(typeValue != null && ReferenceEquals(ValueControl, string.Empty)))
                            {
                                // Pego o tipo do contexto.
                                var typeDataSource = GetSForm().InvokeMethod.TypeModel;

                                // Para garantia de Lista anonima (generica), pesquisa pela propriedade Id,
                                // chave primária do objeto.
                                var property = PropertyControl;

                                // Pego o valor da propriedade do objeto atual.
                                var value = ValueControl;

                                // se o tipo do objeto já foi informado para mesmo contexto, não é passado mais.
                                var parameterType = Expression.Parameter(typeDataSource);

                                // passa o tipo da propriedade
                                var prop = Expression.Property(parameterType, property);
                                // converte o tipo do dado, para garantir a identidade do mesmo.
                                var convertedValue = reflection.ChangeType(value, property.PropertyType);
                                // cria expressao do valor que será passada na expressão.
                                var soap = Expression.Constant(convertedValue);
                                // relaciona a propriedade com o dado. Exemplo: param0 => param0 == 1
                                var equal = Expression.Equal(prop, soap);

                                Expression expressionCompound = null;
                                // Se acaso for index composto adiciona mais uma expressão
                                if (compoundIndex != null && compoundIndex.Properties.Contains(Name))
                                {
                                    // Pesquiso  as outras propriedades que fazem parte da composição.
                                    var properties = compoundIndex.Properties.Where(c => c != Name);

                                    expressionCompound = (from index in properties select typeDataSource.GetProperty(index) into propertyCompoundId let propCompoundId = Expression.Property(parameterType, propertyCompoundId) let convertedValueCompoundId = reflection.ChangeType(propertyCompoundId.GetValue(GetSForm().CurrentControl), propertyCompoundId.PropertyType) let soapCompoundId = Expression.Constant(convertedValueCompoundId) select Expression.Equal(propCompoundId, soapCompoundId)).Aggregate(expressionCompound, (current, equalCompoundId) => current == null ? equalCompoundId : Expression.And(equalCompoundId, current));
                                }

                                if (expressionCompound != null)
                                {
                                    equal = Expression.And(equal, expressionCompound);
                                }

                                var propertyId = typeDataSource.GetProperty("Id");
                                // passa o tipo da propriedade
                                var propId = Expression.Property(parameterType, propertyId);
                                // converte o tipo do dado, para garantir a identidade do mesmo.
                                var convertedValueId = Convert.ChangeType(propertyId.GetValue(GetSForm().CurrentControl), propertyId.PropertyType);
                                // cria expressao do valor que será passada na expressão.
                                var soapId = Expression.Constant(convertedValueId);
                                // relaciona a propriedade com o dado. Exemplo: param0 => param0 == 1
                                var equalId = Expression.NotEqual(propId, soapId);

                                var yourExpression = Expression.And(equal, equalId);

                                var delegateType = typeof(Func <,>).MakeGenericType(typeDataSource, typeof(bool));
                                var expression   = Expression.Lambda(delegateType, yourExpression, true, parameterType);
                                var objetoApp    = GetSForm().InvokeMethod;
                                var method       = objetoApp.Methods.FirstOrDefault(c => c.Key == TypeExecute.Search).Value;
                                if (string.IsNullOrEmpty(method))
                                {
                                    MessageBox.Show("Método Search não configurado\nController: " + objetoApp.TypeController.Name,
                                                    "ESR Softwares", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                                }
                                var result = reflection.GetListContext(objetoApp.TypeController, method, expression);

                                var components = GetSForm().GetListControls().Where(c =>
                                {
                                    if (compoundIndex == null)
                                    {
                                        return(false);
                                    }
                                    foreach (var s in compoundIndex.Properties)
                                    {
                                        if (Equals(s, c.Name))
                                        {
                                            break;
                                        }
                                    }
                                    return(false);
                                });

                                if (result.Any())
                                {
                                    if (compoundIndex != null && compoundIndex.Properties.Contains(Name))
                                    {
                                        var enumerable      = components as IList <IComponent> ?? components.ToList();
                                        var componentValues = enumerable.Aggregate("", (current, component) => current + component.Caption + " = " + component.ValueControl + " ");
                                        foreach (var component in enumerable)
                                        {
                                            component.SetError("Já existem dados com " + componentValues);
                                            component.ComponentBackColor = Color.FromArgb(255, 255, 173, 178);
                                        }
                                        Validations.Add("Já existem dados com " + (componentValues == "" ? " este registro" : componentValues), false);
                                    }
                                    else
                                    {
                                        Validations.Add("Este " + GetTextLabel() + " já existe, considere em informar outro", false);
                                    }
                                }
                                else
                                {
                                    foreach (var component in components)
                                    {
                                        if (!component.Validations.Values.Contains(false))
                                        {
                                            component.RemoveErrorProvider();
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                    SComponent.BackColor = Validations.Values.Contains(false) ? Color.FromArgb(255, 255, 173, 178) : Color.White;
                }
                return(Validations);
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message);
            }
        }
コード例 #9
0
ファイル: SComboBox.cs プロジェクト: leonardo1994/ERP
        /// <summary>
        /// Atualiza todos os objetos filhos do elemento.
        /// </summary>
        public void UpdateChilds()
        {
            if (ValueControl == null)
            {
                return;
            }

            // Pego todos os filhos do elemento.
            var getChilds = GetSForm()?.GetListControls()?.Where(c => GetAttribute <DependencyKey>(c.PropertyControl)?.NamePropertyDependent == Name);

            //Atualizo os filhos.
            if (getChilds != null && getChilds.Any())
            {
                foreach (var item in getChilds)
                {
                    var child = item as SComboBox;
                    if (child == null)
                    {
                        continue;
                    }
                    var childApp = child.ObjetoApp;

                    var reflection = new SReflection();

                    // Crio uma expressão, para pesquisar na tabela de relacionamento, com Id da tabela principal.
                    var typeDataSource = childApp.TypeModel;
                    var property       = typeDataSource.GetProperty(Name);

                    if (property == null)
                    {
                        MessageBox.Show("Não será possível carregar os componentes filhos [" + (GlobalUser.Translates.FirstOrDefault(c => c.PropertyName == child.Name)?.Portugues ?? child.Name) + "].\nCausa: Propriedade " + Name + " não encontrada para o Modelo: " + childApp.TypeModel.Name + " definido no componente: " + child.Name,
                                        "ESR SOFTWARES", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }

                    var itemt = Expression.Parameter(typeDataSource);

                    var        soap  = Expression.Constant(ValueControl);
                    var        prop  = Expression.Property(itemt, property);
                    Expression equal = property.PropertyType == typeof(int?) ? Expression.Equal(prop, Expression.Convert(soap, typeof(int?))) : Expression.Equal(prop, soap);

                    var delegateType = typeof(Func <,>).MakeGenericType(typeDataSource, typeof(bool));

                    var yourExpression = Expression.Lambda(delegateType, equal, true, itemt);

                    var method = childApp.Methods.FirstOrDefault(c => c.Key == TypeExecute.Search).Value;
                    if (string.IsNullOrEmpty(method))
                    {
                        MessageBox.Show("Método Search não configurado para controller: " + childApp.TypeController.Name + " Componente: " + child.Name);
                        return;
                    }

                    var childList = _sReflection.GetListContext(childApp.TypeController, method, yourExpression);

                    if (!childList.Any())
                    {
                        childList.Clear();
                    }
                    child.SetList(childList);
                    child.Refresh();
                }
            }
        }
コード例 #10
0
ファイル: FBase.cs プロジェクト: leonardo1994/ERP
 /// <summary>
 /// Força atualização de todos os objetos da tela.
 /// </summary>
 public void RefreshControls()
 {
     try
     {
         var fieldsForm = GetListControls().OrderBy(c => c.Index);
         foreach (var fieldInfo in fieldsForm)
         {
             if (StateForm != StateForm.Waiting)
             {
                 if (GlobalUser.User != null)
                 {
                     foreach (var groupUser in GlobalUser.User.GroupUsers)
                     {
                         foreach (var groupPermission in groupUser.GroupAccess.GroupPermissions)
                         {
                             if (groupPermission.Permission.TypeComponent != TypeComponent.Field)
                             {
                                 continue;
                             }
                             if (groupPermission.Permission.NamePermission != fieldInfo.Name)
                             {
                                 continue;
                             }
                             if (groupPermission.Permission.Delete)
                             {
                                 fieldInfo.Disable = false;
                             }
                             else if (groupPermission.Permission.Insert)
                             {
                                 fieldInfo.Disable = false;
                             }
                             else if (groupPermission.Permission.Update)
                             {
                                 fieldInfo.Disable = false;
                             }
                             else if (groupPermission.Permission.Visible)
                             {
                                 fieldInfo.Visible = false;
                             }
                         }
                     }
                 }
             }
             fieldInfo.Refresh();
             if (StateForm == StateForm.Inserting && !fieldInfo.DisabledAutomaticNumbering)
             {
                 var fieldConf = GlobalUser.AutomaticNumberings.FirstOrDefault(c => c.DbTable.TableName == InvokeMethod.TypeModel.Name && c.FieldName == fieldInfo.Name);
                 if (fieldConf != null)
                 {
                     var sequencia = AutomaticNumberingApp.GerarSequencia(fieldConf.DbTableId, fieldConf.FieldName);
                     if (sequencia.HasValue)
                     {
                         var reflection      = new SReflection();
                         var valueConvertido = reflection.ConvertValue(sequencia, fieldInfo.PropertyControl);
                         fieldInfo.ValueControl         = valueConvertido;
                         GlobalUser.AutomaticNumberings = AutomaticNumberingApp.Search().ToList();
                     }
                     fieldInfo.Disable = false;
                 }
             }
         }
     }
     catch (Exception)
     {
     }
 }