Ejemplo n.º 1
0
        private void ModalGenerator(String element, List <String> dataStrings, Dictionary <String, DateTime> months)
        {
            Window modal = new Window
            {
                Title                 = element,
                SizeToContent         = SizeToContent.WidthAndHeight,
                WindowStartupLocation = WindowStartupLocation.CenterScreen,
                ResizeMode            = ResizeMode.NoResize
            };


            Grid modalGrid = new Grid
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment   = VerticalAlignment.Stretch
            };
            RowDefinition row = new RowDefinition();

            row.Height = GridLength.Auto;
            modalGrid.RowDefinitions.Add(row);

            RowDefinition row2 = new RowDefinition();

            row2.Height = GridLength.Auto;
            modalGrid.RowDefinitions.Add(row2);

            CleanGrid(modalGrid);
            Grid gridPanel = new Grid();

            if (element == ADICIONAR)
            {
                ComboBox comboBox = new ComboBox();
                comboBox.ItemsSource = dataStrings;
                Grid.SetRow(comboBox, 0);
                modalGrid.Children.Add(comboBox);
                comboBox.SelectionChanged += (sender, e) =>
                {
                    if ((String)comboBox.SelectedItem == PRODUTOS)
                    {
                        gridPanel = Produto.GetInputModal(ADICIONAR, null);
                    }
                    if ((String)comboBox.SelectedItem == DESPESAS)
                    {
                        gridPanel = Despesa.GetInputModal(ADICIONAR, null);
                    }
                    if ((String)comboBox.SelectedItem == IVA)
                    {
                        gridPanel = Iva.GetInputModal(ADICIONAR, null);
                    }
                    if ((String)comboBox.SelectedItem == RECEITAS)
                    {
                        gridPanel = Receita.GetInputModal(ADICIONAR, null);
                    }

                    Grid.SetRow(gridPanel, 1);
                    modalGrid.Children.Add(gridPanel);
                };

                modal.Content = modalGrid;
                modal.ShowDialog();
            }

            if (element == EDITAR)
            {
                var mainGridColletion = mainGrid.Children;
                if (mainGridColletion != null)
                {
                    List <DataGrid> dataGrid = new List <DataGrid>();
                    foreach (var grid in mainGridColletion)
                    {
                        if (grid.GetType() == typeof(DataGrid))
                        {
                            dataGrid.Add((DataGrid)grid);
                        }
                    }

                    foreach (var grid in dataGrid)
                    {
                        if (grid.SelectedItem != null)
                        {
                            if (grid.Name == PRODUTOS)
                            {
                                gridPanel = Produto.GetInputModal(EDITAR, (Produto_Table)grid.SelectedItem);
                            }
                            if (grid.Name == DESPESAS)
                            {
                                gridPanel = Despesa.GetInputModal(EDITAR, (Despesas_Table)grid.SelectedItem);
                            }
                            if (grid.Name == IVA)
                            {
                                gridPanel = Iva.GetInputModal(EDITAR, (IVA_Table)grid.SelectedItem);
                            }
                            if (grid.Name == RECEITAS)
                            {
                                gridPanel = Receita.GetInputModal(EDITAR, (Receita_Table)grid.SelectedItem);
                            }
                        }
                    }

                    Grid.SetRow(gridPanel, 1);
                    modalGrid.Children.Add(gridPanel);
                    modal.Content = modalGrid;
                    modal.ShowDialog();
                }
            }

            if (element == REMOVER)
            {
            }

            if (element == RELATORIO)
            {
                ComboBox comboBox = new ComboBox();
                comboBox.ItemsSource = months.Keys;
                Grid.SetRow(comboBox, 0);
                modalGrid.Children.Add(comboBox);
                comboBox.SelectionChanged += (sender, e) =>
                {
                    if (modalGrid.Children.Count > 1)
                    {
                        modalGrid.Children.RemoveAt(1);
                    }
                    months.TryGetValue(comboBox.SelectedItem.ToString(), out DateTime date);
                    gridPanel = GetReportModal(date);
                    Grid.SetRow(gridPanel, 1);
                    modalGrid.Children.Add(gridPanel);
                };
                modal.Content = modalGrid;
                modal.ShowDialog();
            }
        }