From 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 10:38:18 -0300 Subject: chore: location --- .../Views/Menus/MenuItensView.cs | 375 +++++++++++++++++++++ 1 file changed, 375 insertions(+) create mode 100644 Codemerx/Gestor.Application/Views/Menus/MenuItensView.cs (limited to 'Codemerx/Gestor.Application/Views/Menus/MenuItensView.cs') diff --git a/Codemerx/Gestor.Application/Views/Menus/MenuItensView.cs b/Codemerx/Gestor.Application/Views/Menus/MenuItensView.cs new file mode 100644 index 0000000..b47ecd5 --- /dev/null +++ b/Codemerx/Gestor.Application/Views/Menus/MenuItensView.cs @@ -0,0 +1,375 @@ +using Gestor.Application.Actions; +using Gestor.Application.ViewModels; +using Gestor.Application.Views.Generic; +using Gestor.Common.Validation; +using Gestor.Model.Common; +using Gestor.Model.Domain.Seguros; +using System; +using System.CodeDom.Compiler; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Controls.Primitives; +using System.Windows.Input; +using System.Windows.Markup; +using System.Windows.Media; +using System.Windows.Threading; + +namespace Gestor.Application.Views.Menus +{ + public class MenuItensView : BaseUserControl, IComponentConnector, IStyleConnector + { + internal MenuItem ManterTodosButton; + + internal DataGrid ItemGrid; + + internal DataGridCheckBoxColumn CheckBoxColumn; + + internal DataGridTemplateColumn RenovarColumn; + + internal DataGridTemplateColumn CancelarColumn; + + internal DataGridTemplateColumn SubstituirColumn; + + internal DataGridTemplateColumn ReativarColumn; + + private bool _contentLoaded; + + public MenuItemViewModel ViewModel + { + get; + set; + } + + public MenuItensView(long ramo, ManutencaoItem manutencao = null) + { + base.Tag = "CADASTRO DE ITEM"; + this.ViewModel = new MenuItemViewModel(ramo, manutencao); + base.DataContext = this.ViewModel; + this.InitializeComponent(); + System.Windows.Threading.Dispatcher dispatcher = base.Dispatcher; + if (dispatcher != null) + { + dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(this.ContentLoad)); + } + else + { + } + this.ItemGrid.DataContext = base.DataContext; + this.HabilitarManutencao(manutencao); + Gestor.Application.Actions.Actions.ScrollToItem = (Action)Delegate.Remove(Gestor.Application.Actions.Actions.ScrollToItem, new Action(this.ScrollToIndex)); + Gestor.Application.Actions.Actions.ScrollToItem = (Action)Delegate.Combine(Gestor.Application.Actions.Actions.ScrollToItem, new Action(this.ScrollToIndex)); + } + + private void AutoCompleteBox_OnTextChanged(object sender, RoutedEventArgs e) + { + if (!string.IsNullOrWhiteSpace(((AutoCompleteBox)sender).get_Text())) + { + return; + } + this.ViewModel.FiltrarItem(""); + } + + private void AutoCompleteBox_Populating(object sender, PopulatingEventArgs e) + { + e.set_Cancel(true); + this.ViewModel.Filtrar(ValidationHelper.RemoveDiacritics(e.get_Parameter().Trim())).ContinueWith((Task> searchResult) => { + if (searchResult.Result == null) + { + return; + } + AutoCompleteBox autoCompleteBox = (AutoCompleteBox)sender; + autoCompleteBox.set_ItemsSource(searchResult.Result); + autoCompleteBox.PopulateComplete(); + }, TaskScheduler.FromCurrentSynchronizationContext()); + } + + private void CancelarItem_OnClick(object sender, RoutedEventArgs e) + { + Button button = sender as Button; + if (button == null) + { + return; + } + if (button.DataContext == null) + { + return; + } + this.ViewModel.CancelarItem((Item)button.DataContext); + } + + private void ContentLoad() + { + this.ItemGrid.SelectionChanged += new SelectionChangedEventHandler(this.ItemGrid_OnSelectionChanged); + this.ItemGrid.MouseDoubleClick += new MouseButtonEventHandler((object sender, MouseButtonEventArgs args) => { + }); + } + + public Visual GetDescendantByType(Visual element, Type type) + { + if (element == null) + { + return null; + } + if (element.GetType() == type) + { + return element; + } + Visual descendantByType = null; + FrameworkElement frameworkElement = element as FrameworkElement; + if (frameworkElement != null) + { + frameworkElement.ApplyTemplate(); + } + for (int i = 0; i < VisualTreeHelper.GetChildrenCount(element); i++) + { + Visual child = VisualTreeHelper.GetChild(element, i) as Visual; + descendantByType = this.GetDescendantByType(child, type); + if (descendantByType != null) + { + break; + } + } + return descendantByType; + } + + private void HabilitarManutencao(ManutencaoItem manutencao) + { + this.RenovarColumn.Visibility = System.Windows.Visibility.Collapsed; + this.CancelarColumn.Visibility = System.Windows.Visibility.Collapsed; + this.SubstituirColumn.Visibility = System.Windows.Visibility.Collapsed; + this.ReativarColumn.Visibility = System.Windows.Visibility.Collapsed; + this.CheckBoxColumn.Visibility = System.Windows.Visibility.Collapsed; + this.ManterTodosButton.Visibility = System.Windows.Visibility.Collapsed; + if (manutencao == null) + { + return; + } + switch (manutencao.get_Tipo()) + { + case 0: + { + this.RenovarColumn.Visibility = System.Windows.Visibility.Visible; + this.CheckBoxColumn.Visibility = System.Windows.Visibility.Visible; + this.ManterTodosButton.Visibility = System.Windows.Visibility.Visible; + this.ViewModel.EndossoRenovacao = true; + return; + } + case 1: + { + this.RenovarColumn.Visibility = System.Windows.Visibility.Visible; + this.CancelarColumn.Visibility = System.Windows.Visibility.Visible; + this.SubstituirColumn.Visibility = System.Windows.Visibility.Visible; + this.ViewModel.EndossoRenovacao = true; + return; + } + case 2: + { + this.CancelarColumn.Visibility = System.Windows.Visibility.Visible; + this.ReativarColumn.Visibility = System.Windows.Visibility.Visible; + return; + } + default: + { + return; + } + } + } + + [DebuggerNonUserCode] + [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] + public void InitializeComponent() + { + if (this._contentLoaded) + { + return; + } + this._contentLoaded = true; + System.Windows.Application.LoadComponent(this, new Uri("/Gestor.Application;component/views/menus/menuitensview.xaml", UriKind.Relative)); + } + + private void ItemGrid_OnSelectionChanged(object sender, SelectionChangedEventArgs e) + { + DataGrid dataGrid = (DataGrid)sender; + if (dataGrid != null && dataGrid.SelectedIndex < 0) + { + return; + } + if (!this.ViewModel.AlterandoSelectedItem) + { + this.ViewModel.SelecionaItem((Item)((dataGrid != null ? dataGrid.Items[dataGrid.SelectedIndex] : null))); + } + } + + private void ManterItem_OnClick(object sender, RoutedEventArgs e) + { + Button button = sender as Button; + if (button == null) + { + return; + } + if (button.DataContext == null) + { + return; + } + this.ViewModel.Manter((Item)button.DataContext); + } + + private void ManterItens_OnClick(object sender, RoutedEventArgs e) + { + this.ViewModel.ManterItens(); + } + + private void ReativarItem_OnClick(object sender, RoutedEventArgs e) + { + Button button = sender as Button; + if (button == null) + { + return; + } + if (button.DataContext == null) + { + return; + } + this.ViewModel.Reativar((Item)button.DataContext); + } + + public void ScrollToIndex() + { + this.ScrollToIndex(this.ItemGrid, this.ItemGrid.SelectedIndex); + } + + public void ScrollToIndex(DataGrid grid, int index) + { + ScrollViewer descendantByType = this.GetDescendantByType(grid, typeof(ScrollViewer)) as ScrollViewer; + int num = (index - 5 > 0 ? index - 5 : 0); + if (descendantByType == null) + { + return; + } + descendantByType.ScrollToVerticalOffset((double)num); + } + + private void SubstituirItem_OnClick(object sender, RoutedEventArgs e) + { + Button button = sender as Button; + if (button == null) + { + return; + } + if (button.DataContext == null) + { + return; + } + this.ViewModel.Substituir((Item)button.DataContext); + } + + [DebuggerNonUserCode] + [EditorBrowsable(EditorBrowsableState.Never)] + [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] + void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) + { + switch (connectionId) + { + case 1: + { + ((AutoCompleteBox)target).add_Populating(new PopulatingEventHandler(this, MenuItensView.AutoCompleteBox_Populating)); + ((AutoCompleteBox)target).add_TextChanged(new RoutedEventHandler(this.AutoCompleteBox_OnTextChanged)); + return; + } + case 2: + { + this.ManterTodosButton = (MenuItem)target; + this.ManterTodosButton.Click += new RoutedEventHandler(this.ManterItens_OnClick); + return; + } + case 3: + { + this.ItemGrid = (DataGrid)target; + return; + } + case 4: + { + this.CheckBoxColumn = (DataGridCheckBoxColumn)target; + return; + } + case 5: + { + this.RenovarColumn = (DataGridTemplateColumn)target; + return; + } + case 6: + case 8: + case 10: + { + this._contentLoaded = true; + return; + } + case 7: + { + this.CancelarColumn = (DataGridTemplateColumn)target; + return; + } + case 9: + { + this.SubstituirColumn = (DataGridTemplateColumn)target; + return; + } + case 11: + { + this.ReativarColumn = (DataGridTemplateColumn)target; + return; + } + default: + { + this._contentLoaded = true; + return; + } + } + } + + [DebuggerNonUserCode] + [EditorBrowsable(EditorBrowsableState.Never)] + [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] + void System.Windows.Markup.IStyleConnector.Connect(int connectionId, object target) + { + switch (connectionId) + { + case 6: + { + ((Button)target).Click += new RoutedEventHandler(this.ManterItem_OnClick); + return; + } + case 7: + case 9: + case 11: + { + return; + } + case 8: + { + ((Button)target).Click += new RoutedEventHandler(this.CancelarItem_OnClick); + return; + } + case 10: + { + ((Button)target).Click += new RoutedEventHandler(this.SubstituirItem_OnClick); + return; + } + case 12: + { + ((Button)target).Click += new RoutedEventHandler(this.ReativarItem_OnClick); + return; + } + default: + { + return; + } + } + } + } +} \ No newline at end of file -- cgit v1.2.3