using Gestor.Application; using Gestor.Application.Helpers; using Gestor.Application.ViewModels.Financeiro; using Gestor.Application.ViewModels.Generic; using Gestor.Common.Validation; using Gestor.Model.Domain.Common; using Gestor.Model.Domain.Seguros; using MaterialDesignThemes.Wpf; using System; using System.CodeDom.Compiler; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Forms; using System.Windows.Input; using System.Windows.Interop; using System.Windows.Markup; using System.Windows.Media; using System.Windows.Shapes; using System.Windows.Shell; using System.Windows.Threading; namespace Gestor.Application.Views.Financeiro { public class ExtratoWindow : Window, IComponentConnector { private bool _buttonClickable; public ExtratoContaViewModel ViewModel; internal System.Windows.Shell.WindowChrome WindowChrome; internal Grid MinimizeButton; internal Grid MaximizeButton; internal Grid CloseButton; internal System.Windows.Controls.ProgressBar ProgressRing; internal System.Windows.Controls.ComboBox ContaBox; internal DatePicker InicioBox; internal DatePicker FimBox; internal System.Windows.Controls.DataGrid LancamentoGrid; internal TextBlock NaoHaDados; internal MaterialDesignThemes.Wpf.Snackbar Snackbar; private bool _contentLoaded; [DebuggerNonUserCode] [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] internal Delegate _CreateDelegate(Type delegateType, string handler) { return Delegate.CreateDelegate(delegateType, this, handler); } public ExtratoWindow(long id = 0L) { this.ViewModel = new ExtratoContaViewModel(id); 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 { } string str = ApplicationHelper.Versao.ToString(); this.ViewModel.Head = string.Concat(new string[] { Recursos.Usuario.get_Nome(), " - ", Recursos.Empresa.get_Nome(), ", VOCÊ ESTÁ EM RELATÓRIOS DE CONTA CORRENTE | VERSÃO GESTOR ", str }); } public void CloseButton_Click() { base.Close(); } private void CloseSlackBar() { Thread.Sleep(3000); System.Windows.Threading.Dispatcher dispatcher = App.ProgressRing.Dispatcher; if (dispatcher == null) { return; } dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => this.ToggleSnackBar("", false))); } private void ContentLoad() { this.MinimizeButton.MouseEnter += new System.Windows.Input.MouseEventHandler(ExtratoWindow.TopControls_OnMouseEnter); this.MinimizeButton.MouseLeave += new System.Windows.Input.MouseEventHandler(this.TopControls_OnMouseLeave); this.MaximizeButton.MouseEnter += new System.Windows.Input.MouseEventHandler(ExtratoWindow.TopControls_OnMouseEnter); this.MaximizeButton.MouseLeave += new System.Windows.Input.MouseEventHandler(this.TopControls_OnMouseLeave); this.CloseButton.MouseEnter += new System.Windows.Input.MouseEventHandler(ExtratoWindow.TopControls_OnMouseEnter); this.CloseButton.MouseLeave += new System.Windows.Input.MouseEventHandler(this.TopControls_OnMouseLeave); this.InicioBox.LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus); this.InicioBox.PreviewKeyDown += new System.Windows.Input.KeyEventHandler(this.DatePicker_PreviewKeyDown); this.InicioBox.SelectedDateChanged += new EventHandler(this.Periodo_OnSelectedDateChanged); this.FimBox.LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus); this.FimBox.PreviewKeyDown += new System.Windows.Input.KeyEventHandler(this.DatePicker_PreviewKeyDown); this.FimBox.SelectedDateChanged += new EventHandler(this.Periodo_OnSelectedDateChanged); } private void DataAtual_OnDoubleClick(object sender, RoutedEventArgs e) { ((DatePicker)sender).SelectedDate = new DateTime?(Funcoes.GetNetworkTime().Date); } private void DatePicker_OnLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) { DatePicker datePicker = (DatePicker)sender; datePicker.Text = ValidationHelper.FormatDate(datePicker.Text); } private void DatePicker_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e) { if (e.Key != Key.Return) { return; } DatePicker str = (DatePicker)sender; DateTime date = Funcoes.GetNetworkTime().Date; str.Text = date.ToString("dd/MM/yyyy"); } private async void ExportarExcel_OnClick(object sender, RoutedEventArgs e) { await this.ViewModel.GerarExcel(); } private async void GerarResultados_OnClick(object sender, RoutedEventArgs e) { bool flag; if (ValidationHelper.ValidateDate(ValidationHelper.FormatDate(this.InicioBox.Text))) { this.InicioBox.SelectedDate = new DateTime?(DateTime.Parse(ValidationHelper.FormatDate(this.InicioBox.Text))); } if (ValidationHelper.ValidateDate(ValidationHelper.FormatDate(this.FimBox.Text))) { this.FimBox.SelectedDate = new DateTime?(DateTime.Parse(ValidationHelper.FormatDate(this.FimBox.Text))); } DateTime? selectedDate = this.InicioBox.SelectedDate; if (selectedDate.HasValue) { selectedDate = this.FimBox.SelectedDate; if (selectedDate.HasValue) { selectedDate = this.InicioBox.SelectedDate; DateTime? nullable = this.FimBox.SelectedDate; flag = (selectedDate.HasValue & nullable.HasValue ? selectedDate.GetValueOrDefault() > nullable.GetValueOrDefault() : false); if (!flag) { this.ProgressRing.Visibility = System.Windows.Visibility.Visible; this.ViewModel.IsEnabled = false; await this.ViewModel.GerarRelatorio(); this.ViewModel.IsEnabled = true; this.ProgressRing.Visibility = System.Windows.Visibility.Collapsed; return; } else { await this.ViewModel.ShowMessage("A DATA FINAL NÃO PODE SER MENOR QUE A DATA INICIAL DO FILTRO.", "OK", "", false); return; } } } await this.ViewModel.ShowMessage("NECESSÁRIO PREENCHER O PERIODO INICIAL E FINAL PARA O FILTRO.", "OK", "", false); } [DllImport("user32.dll", CharSet=CharSet.None, ExactSpelling=false)] private static extern bool GetCursorPos(out MainWindow.Point lpPoint); [DllImport("user32.dll", CharSet=CharSet.None, ExactSpelling=false)] private static extern bool GetMonitorInfo(IntPtr hMonitor, ExtratoWindow.Monitorinfo lpmi); private async void Imprimir_OnClick(object sender, RoutedEventArgs e) { await this.ViewModel.Print(); } [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/financeiro/extratowindow.xaml", UriKind.Relative)); } public void MaximizeButton_Click() { base.WindowState = (base.WindowState == System.Windows.WindowState.Normal ? System.Windows.WindowState.Maximized : System.Windows.WindowState.Normal); } public void MinimizeButton_Click() { base.WindowState = System.Windows.WindowState.Minimized; } [DllImport("user32.dll", CharSet=CharSet.None, ExactSpelling=false, SetLastError=true)] private static extern IntPtr MonitorFromPoint(MainWindow.Point pt, ExtratoWindow.MonitorOptions dwFlags); protected sealed override void OnStateChanged(EventArgs e) { object obj; base.BorderThickness = new Thickness((double)(base.WindowState != System.Windows.WindowState.Maximized)); System.Windows.Shell.WindowChrome windowChrome = this.WindowChrome; if (base.WindowState == System.Windows.WindowState.Maximized) { obj = null; } else { obj = 4; } windowChrome.ResizeBorderThickness = new Thickness((double)obj); this.WindowChrome.CaptionHeight = (double)((base.WindowState == System.Windows.WindowState.Maximized ? 33 : 30)); this.ViewModel.MaximizeRestore = (base.WindowState == System.Windows.WindowState.Maximized ? Geometry.Parse((string)System.Windows.Application.Current.Resources["Restore"]) : Geometry.Parse((string)System.Windows.Application.Current.Resources["Maximize"])); base.OnStateChanged(e); } private void Periodo_OnSelectedDateChanged(object sender, SelectionChangedEventArgs e) { this.ViewModel.LimparRelatorio(); } private void SnackbarMessage_ActionClick(object sender, RoutedEventArgs e) { this.Snackbar.set_IsActive(false); } [DebuggerNonUserCode] [EditorBrowsable(EditorBrowsableState.Never)] [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: { ((ExtratoWindow)target).Initialized += new EventHandler(this.Window_OnInitialized); return; } case 2: { this.WindowChrome = (System.Windows.Shell.WindowChrome)target; return; } case 3: { this.MinimizeButton = (Grid)target; this.MinimizeButton.MouseLeftButtonDown += new MouseButtonEventHandler(this.TopControls_OnMouseLeftButtonDown); this.MinimizeButton.MouseLeftButtonUp += new MouseButtonEventHandler(this.TopControls_OnMouseLeftButtonUp); return; } case 4: { this.MaximizeButton = (Grid)target; this.MaximizeButton.MouseLeftButtonDown += new MouseButtonEventHandler(this.TopControls_OnMouseLeftButtonDown); this.MaximizeButton.MouseLeftButtonUp += new MouseButtonEventHandler(this.TopControls_OnMouseLeftButtonUp); return; } case 5: { this.CloseButton = (Grid)target; this.CloseButton.MouseLeftButtonDown += new MouseButtonEventHandler(this.TopControls_OnMouseLeftButtonDown); this.CloseButton.MouseLeftButtonUp += new MouseButtonEventHandler(this.TopControls_OnMouseLeftButtonUp); return; } case 6: { this.ProgressRing = (System.Windows.Controls.ProgressBar)target; return; } case 7: { this.ContaBox = (System.Windows.Controls.ComboBox)target; return; } case 8: { this.InicioBox = (DatePicker)target; this.InicioBox.LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus); this.InicioBox.MouseDoubleClick += new MouseButtonEventHandler(this.DataAtual_OnDoubleClick); return; } case 9: { this.FimBox = (DatePicker)target; this.FimBox.LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus); this.FimBox.MouseDoubleClick += new MouseButtonEventHandler(this.DataAtual_OnDoubleClick); return; } case 10: { ((System.Windows.Controls.MenuItem)target).Click += new RoutedEventHandler(this.GerarResultados_OnClick); return; } case 11: { ((System.Windows.Controls.MenuItem)target).Click += new RoutedEventHandler(this.Imprimir_OnClick); return; } case 12: { ((System.Windows.Controls.MenuItem)target).Click += new RoutedEventHandler(this.ExportarExcel_OnClick); return; } case 13: { this.LancamentoGrid = (System.Windows.Controls.DataGrid)target; return; } case 14: { this.NaoHaDados = (TextBlock)target; return; } case 15: { this.Snackbar = (MaterialDesignThemes.Wpf.Snackbar)target; return; } case 16: { ((SnackbarMessage)target).add_ActionClick(new RoutedEventHandler(this.SnackbarMessage_ActionClick)); return; } } this._contentLoaded = true; } public void ToggleSnackBar(string message, bool active = true) { this.Snackbar.get_Message().Content = message; this.Snackbar.set_IsActive(active); if (!active) { return; } Task.Factory.StartNew(new Action(this.CloseSlackBar)); } private static void TopControls_OnMouseEnter(object sender, System.Windows.Input.MouseEventArgs e) { ((Grid)sender).Background = (((Grid)sender).Name == "CloseButton" ? new SolidColorBrush(Colors.IndianRed) : new SolidColorBrush(Colors.Gray)); Path child = VisualTreeHelper.GetChild((Grid)sender, 0) as Path; if (child != null) { child.Stroke = new SolidColorBrush(Colors.White); } } private void TopControls_OnMouseLeave(object sender, System.Windows.Input.MouseEventArgs e) { this._buttonClickable = false; ((Grid)sender).Background = new SolidColorBrush(Colors.Transparent); Path child = VisualTreeHelper.GetChild((Grid)sender, 0) as Path; if (child != null) { child.Stroke = new SolidColorBrush(Colors.White); } } private void TopControls_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { this._buttonClickable = true; ((Grid)sender).Background = (((Grid)sender).Name == "CloseButton" ? new SolidColorBrush(Colors.Red) : new SolidColorBrush(Colors.DimGray)); } private void TopControls_OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (this._buttonClickable) { MethodInfo method = base.GetType().GetMethod(string.Concat(((Grid)sender).Name, "_Click")); if (method == null) { return; } method.Invoke(this, null); } } private void Window_OnInitialized(object sender, EventArgs e) { WindowInteropHelper windowInteropHelper = new WindowInteropHelper(this); windowInteropHelper.EnsureHandle(); HwndSource hwndSource = HwndSource.FromHwnd(windowInteropHelper.Handle); if (hwndSource == null) { return; } hwndSource.AddHook(new HwndSourceHook(this.WindowProc)); } private IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (msg == 36) { this.WmGetMinMaxInfo(lParam); } return IntPtr.Zero; } private void WmGetMinMaxInfo(IntPtr lParam) { MainWindow.Point point; System.Drawing.Rectangle workingArea = Screen.FromHandle((new WindowInteropHelper(this)).Handle).WorkingArea; base.MaxHeight = (double)workingArea.Height; ExtratoWindow.GetCursorPos(out point); IntPtr intPtr = ExtratoWindow.MonitorFromPoint(new MainWindow.Point(0, 0), ExtratoWindow.MonitorOptions.MonitorDefaulttoprimary); ExtratoWindow.Monitorinfo monitorinfo = new ExtratoWindow.Monitorinfo(); if (!ExtratoWindow.GetMonitorInfo(intPtr, monitorinfo)) { return; } IntPtr intPtr1 = ExtratoWindow.MonitorFromPoint(point, ExtratoWindow.MonitorOptions.MonitorDefaulttonearest); ExtratoWindow.Minmaxinfo structure = (ExtratoWindow.Minmaxinfo)Marshal.PtrToStructure(lParam, typeof(ExtratoWindow.Minmaxinfo)); if (!intPtr.Equals(intPtr1)) { structure.ptMaxPosition.X = monitorinfo.rcMonitor.Left; structure.ptMaxPosition.Y = monitorinfo.rcMonitor.Top; structure.ptMaxSize.X = monitorinfo.rcMonitor.Right - monitorinfo.rcMonitor.Left; structure.ptMaxSize.Y = monitorinfo.rcMonitor.Bottom - monitorinfo.rcMonitor.Top; } else { structure.ptMaxPosition.X = monitorinfo.rcWork.Left; structure.ptMaxPosition.Y = monitorinfo.rcWork.Top; structure.ptMaxSize.X = monitorinfo.rcWork.Right - monitorinfo.rcWork.Left; structure.ptMaxSize.Y = monitorinfo.rcWork.Bottom - monitorinfo.rcWork.Top; } Marshal.StructureToPtr(structure, lParam, true); } private struct Minmaxinfo { private readonly MainWindow.Point ptReserved; public ExtratoWindow.Point ptMaxSize; public ExtratoWindow.Point ptMaxPosition; private readonly MainWindow.Point ptMinTrackSize; private readonly MainWindow.Point ptMaxTrackSize; } private class Monitorinfo { private readonly int cbSize; public readonly ExtratoWindow.Rect rcMonitor; public readonly ExtratoWindow.Rect rcWork; private readonly int dwFlags; public Monitorinfo() { } } private enum MonitorOptions : uint { MonitorDefaulttoprimary = 1, MonitorDefaulttonearest = 2 } public struct Point { public int X; public int Y; public Point(int x, int y) { this.X = x; this.Y = y; } } public struct Rect { public int Left; public int Top; public int Right; public int Bottom; } } }