diff options
| author | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 13:38:18 +0000 |
|---|---|---|
| committer | Lucas Faria Mendes <lucas.fariamo08@gmail.com> | 2026-03-30 13:38:18 +0000 |
| commit | 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (patch) | |
| tree | e1c3b20ea08f0cf71122a1e73f0d395f8fd83874 /Gestor.Application/Helpers/BindingHelper.cs | |
| parent | 674ca83ba9243a9e95a7568c797668dab6aee26a (diff) | |
| download | gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.tar.gz gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.zip | |
chore: location
Diffstat (limited to 'Gestor.Application/Helpers/BindingHelper.cs')
| -rw-r--r-- | Gestor.Application/Helpers/BindingHelper.cs | 239 |
1 files changed, 0 insertions, 239 deletions
diff --git a/Gestor.Application/Helpers/BindingHelper.cs b/Gestor.Application/Helpers/BindingHelper.cs deleted file mode 100644 index 3c9d76e..0000000 --- a/Gestor.Application/Helpers/BindingHelper.cs +++ /dev/null @@ -1,239 +0,0 @@ -using CurrencyTextBoxControl;
-using Gestor.Common.Helpers;
-using Gestor.Model.Helper;
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Linq;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Controls.Primitives;
-using System.Windows.Data;
-
-namespace Gestor.Application.Helpers
-{
- public static class BindingHelper
- {
- public static void AddBinding(object control, string path, ValidationRule rule = null)
- {
- Type type = control.GetType();
- Binding binding = new Binding()
- {
- Mode = BindingMode.TwoWay,
- UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
- Path = new PropertyPath(path, Array.Empty<object>())
- };
- if (rule != null)
- {
- binding.ValidationRules.Add(rule);
- binding.ValidationRules[0].ValidatesOnTargetUpdated = true;
- }
- string name = type.Name;
- if (name == "TextBox")
- {
- ((TextBox)control).SetBinding(TextBox.TextProperty, binding);
- return;
- }
- if (name == "DatePicker")
- {
- ((DatePicker)control).SetBinding(DatePicker.SelectedDateProperty, binding);
- return;
- }
- if (name != "CurrencyTextBox")
- {
- return;
- }
- ((CurrencyTextBox)control).SetBinding(CurrencyTextBox.NumberProperty, binding);
- }
-
- public static void AddValidationRule(object control, ValidationRule rule = null)
- {
- //
- // Current member / type: System.Void Gestor.Application.Helpers.BindingHelper::AddValidationRule(System.Object,System.Windows.Controls.ValidationRule)
- // File path: C:\AggerSeguros\Gestor.Application.exe
- //
- // Product version: 0.0.0.0
- // Exception in: System.Void AddValidationRule(System.Object,System.Windows.Controls.ValidationRule)
- //
- // Object reference not set to an instance of an object.
- // at Telerik.JustDecompiler.Decompiler.TypeInference.TypeInferer.FindLowestCommonAncestor(ICollection`1 typeNodes) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\TypeInference\TypeInferer.cs:line 515
- // at Telerik.JustDecompiler.Decompiler.TypeInference.TypeInferer.MergeWithLowestCommonAncestor() in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\TypeInference\TypeInferer.cs:line 459
- // at Telerik.JustDecompiler.Decompiler.TypeInference.TypeInferer.ProcessSingleConstraints() in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\TypeInference\TypeInferer.cs:line 378
- // at Telerik.JustDecompiler.Decompiler.TypeInference.TypeInferer.InferTypes() in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\TypeInference\TypeInferer.cs:line 331
- // at Telerik.JustDecompiler.Decompiler.ExpressionDecompilerStep.Process(DecompilationContext theContext, BlockStatement body) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\ExpressionDecompilerStep.cs:line 104
- // at Telerik.JustDecompiler.Decompiler.DecompilationPipeline.RunInternal(MethodBody body, BlockStatement block, ILanguage language) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\DecompilationPipeline.cs:line 100
- // at Telerik.JustDecompiler.Decompiler.DecompilationPipeline.Run(MethodBody body, ILanguage language) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\DecompilationPipeline.cs:line 72
- // at Telerik.JustDecompiler.Decompiler.Extensions.Decompile(MethodBody body, ILanguage language, DecompilationContext& context, TypeSpecificContext typeContext) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\Extensions.cs:line 61
- // at Telerik.JustDecompiler.Decompiler.WriterContextServices.BaseWriterContextService.DecompileMethod(ILanguage language, MethodDefinition method, TypeSpecificContext typeContext) in D:\a\CodemerxDecompile\CodemerxDecompile\src\JustDecompileEngine\src\JustDecompiler.Shared\Decompiler\WriterContextServices\BaseWriterContextService.cs:line 133
- //
- // mailto: JustDecompilePublicFeedback@telerik.com
-
- }
-
- private static List<KeyValuePair<string, string>> AfterTreatment<T>(bool withSelect, bool orderByLabel, List<KeyValuePair<string, string>> comboData, List<KeyValuePair<string, string>> comboValues, bool orderbyAttr = false)
- {
- List<KeyValuePair<string, string>> list = comboData;
- if (!withSelect)
- {
- list.RemoveAt(0);
- }
- list.AddRange(comboValues);
- if (orderbyAttr)
- {
- Type type = typeof(T);
- list = list.OrderBy<KeyValuePair<string, string>, int?>((KeyValuePair<string, string> s) => {
- if (s.Key == string.Empty)
- {
- return new int?(0);
- }
- return EnumHelper.GetOrder<T>((T)Enum.Parse(type, s.Key));
- }).ToList<KeyValuePair<string, string>>();
- return list;
- }
- if (!orderByLabel)
- {
- return list;
- }
- list = (
- from in list
- orderby Math.Sign(ValidationHelper.ToFloat(x.Key)), Math.Abs(ValidationHelper.ToFloat(x.Key))
- select ).ToList<KeyValuePair<string, string>>();
- list = (
- from in list
- orderby list.IndexOf(s) != 0, s.Value
- select ).ToList<KeyValuePair<string, string>>();
- return list;
- }
-
- private static List<KeyValuePair<string, string>> BeforeTreatment<T>(string defaultValue, string defaultText)
- {
- defaultText = (defaultText == string.Empty ? "Selecione" : defaultText);
- return new List<KeyValuePair<string, string>>()
- {
- new KeyValuePair<string, string>(defaultValue, defaultText)
- };
- }
-
- public static List<KeyValuePair<string, string>> BindingData<T>(bool withSelect = true, bool enumDefault = true, string defaultValue = "", string defaultText = "", bool orderByLabel = false, bool showAll = false, bool orderbyAttr = false)
- {
- List<KeyValuePair<string, string>> keyValuePairs = BindingHelper.BeforeTreatment<T>(defaultValue, defaultText);
- Type type = typeof(T);
- List<KeyValuePair<string, string>> list = Enum.GetNames(type).AsEnumerable<string>().Where<string>((string x) => {
- if (showAll)
- {
- return true;
- }
- T t = (T)Enum.Parse(type, x);
- bool? @default = EnumHelper.GetDefault<T>(t);
- bool hidden = EnumHelper.GetHidden<T>(t);
- if (@default.HasValue && @default.Value != enumDefault)
- {
- return false;
- }
- return !hidden;
- }).Select<string, KeyValuePair<string, string>>((string x) => {
- T t = (T)Enum.Parse(type, x);
- return new KeyValuePair<string, string>(EnumHelper.Value<T>(t), EnumHelper.GetDescription<T>(t));
- }).ToList<KeyValuePair<string, string>>();
- return BindingHelper.AfterTreatment<T>(withSelect, orderByLabel, keyValuePairs, list, orderbyAttr);
- }
-
- public static void DeleteValidationRule(object control)
- {
- Binding binding;
- string name = control.GetType().Name;
- if (name == "TextBox")
- {
- binding = BindingOperations.GetBinding((TextBox)control, TextBox.TextProperty) ?? new Binding()
- {
- Mode = BindingMode.TwoWay,
- UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
- };
- binding.ValidationRules.Clear();
- ((TextBox)control).SetBinding(TextBox.TextProperty, binding);
- return;
- }
- if (name == "DatePicker")
- {
- binding = BindingOperations.GetBinding((DatePicker)control, DatePicker.SelectedDateProperty) ?? new Binding()
- {
- Mode = BindingMode.TwoWay,
- UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
- };
- binding.ValidationRules.Clear();
- ((DatePicker)control).SetBinding(DatePicker.SelectedDateProperty, binding);
- return;
- }
- if (name != "CurrencyTextBox")
- {
- return;
- }
- binding = BindingOperations.GetBinding((CurrencyTextBox)control, CurrencyTextBox.NumberProperty) ?? new Binding()
- {
- Mode = BindingMode.TwoWay,
- UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
- };
- binding.ValidationRules.Clear();
- ((CurrencyTextBox)control).SetBinding(CurrencyTextBox.NumberProperty, binding);
- }
-
- public static string GetPath(object control)
- {
- Binding binding;
- PropertyPath path;
- string name = control.GetType().Name;
- if (name == "TextBox")
- {
- binding = BindingOperations.GetBinding((TextBox)control, TextBox.TextProperty);
- if (binding == null)
- {
- return "";
- }
- path = binding.Path;
- }
- else if (name == "DatePicker")
- {
- binding = BindingOperations.GetBinding((DatePicker)control, DatePicker.SelectedDateProperty);
- if (binding == null)
- {
- return "";
- }
- path = binding.Path;
- }
- else if (name == "CurrencyTextBox")
- {
- binding = BindingOperations.GetBinding((CurrencyTextBox)control, CurrencyTextBox.NumberProperty);
- if (binding == null)
- {
- return "";
- }
- path = binding.Path;
- }
- else if (name == "ComboBox")
- {
- binding = BindingOperations.GetBinding((ComboBox)control, Selector.SelectedItemProperty);
- if (binding == null)
- {
- return "";
- }
- path = binding.Path;
- }
- else
- {
- if (name != "AutoCompleteBox")
- {
- return "";
- }
- binding = BindingOperations.GetBinding((AutoCompleteBox)control, AutoCompleteBox.SelectedItemProperty);
- if (binding == null)
- {
- return "";
- }
- path = binding.Path;
- }
- return path.Path;
- }
- }
-}
\ No newline at end of file |