Example #1
0
        private void AppStartup()
        {
            if (File.Exists(Config.userFilePath))
            {
                Config.applicationUser = ApplicationFiletasks.ReadFromXmlFile <ApplicationUser>(Config.userFilePath);
            }
            if (File.Exists(Config.appDbFilePath))
            {
                Config.appDb = ApplicationFiletasks.ReadFromXmlFile <ApplicationConnections>(Config.appDbFilePath);
            }

            if (Config.appDb.HostName == string.Empty || Config.applicationUser.UserName == string.Empty)
            {
                Window config = new Config();
                config.Show();
            }
            else
            {
                MainWinBuild(false);
            }
        }
Example #2
0
        private void InitSettings()
        {
            Window window = this;

            window.Name  = "winConfig";
            window.Style = FindStyle("winStyle");
            //window.Closed += new EventHandler((s, e) =>
            //    {
            //        WindowTasks.ResetWinMain();
            //    });

            Grid       mainGrid   = new Grid();
            TabControl tabControl = new TabControl();

            TabItem logintab = new TabItem
            {
                Header = "User Login"
            };

            logintab.GotFocus += new RoutedEventHandler((s, e) =>
            {
                window.SizeToContent = SizeToContent.WidthAndHeight;
            });

            TabItem appDbTab = new TabItem
            {
                Header = "Application Host"
            };

            appDbTab.GotFocus += new RoutedEventHandler((s, e) =>
            {
                window.SizeToContent = SizeToContent.WidthAndHeight;
            });

            tabControl.Items.Add(logintab);
            tabControl.Items.Add(appDbTab);

            RowDefinition row1 = new RowDefinition
            {
                Height = GridLength.Auto
            };

            RowDefinition row2 = new RowDefinition
            {
                Height = GridLength.Auto
            };

            mainGrid.RowDefinitions.Add(row1);
            mainGrid.RowDefinitions.Add(row2);

            StackPanel controlDbStackPanel = new StackPanel
            {
                Style = FindStyle("winEditPanelStyle")
            };

            appDbTab.Content = controlDbStackPanel;

            StackPanel settingsStackPanel = new StackPanel
            {
                Style = FindStyle("winEditPanelStyle")
            };

            logintab.Content = settingsStackPanel;

            StackPanel buttonStackPanel = new StackPanel
            {
                Style = FindStyle("winButtonStack")
            };

            Style textBoxStyle = FindStyle("winTextBoxStyle");
            Style labelStyle   = FindStyle("winLabelStyle");

            Button buttonClose = new Button
            {
                Name    = "btnClose",
                Content = "Close",
                Style   = FindStyle("winButtonStyle")
            };

            buttonClose.Click += new RoutedEventHandler((s, e) =>
            {
                WindowTasks.WinClose(s, e);
            });

            Button buttonSave = new Button
            {
                Name    = "btnSave",
                Content = "Save",
                Style   = FindStyle("winButtonStyle")
            };

            buttonSave.Click += new RoutedEventHandler((s, e) =>
            {
                ApplicationFiletasks.WriteToXmlFile <ApplicationConnections>(appDbFilePath, appDb);
                ApplicationFiletasks.WriteToXmlFile <ApplicationUser>(userFilePath, applicationUser);
                WindowTasks.WinClose(s, e);
            });

            Button buttonCancel = new Button
            {
                Name    = "btnCancel",
                Content = "Cancel",
                Style   = FindStyle("winButtonStyle")
            };

            buttonCancel.Click += new RoutedEventHandler((s, e) =>
            {
                if (Config.appDb.HostName == string.Empty || Config.applicationUser.UserName == string.Empty)
                {
                    ApplicationUtils.AppShutdown(s, e);
                }
                else
                {
                    WindowTasks.WinClose(s, e);
                }
            });

            buttonStackPanel.Children.Add(buttonSave);
            buttonStackPanel.Children.Add(buttonClose);
            buttonStackPanel.Children.Add(buttonCancel);

            Grid.SetRow(controlDbStackPanel, 0);
            mainGrid.Children.Add(tabControl);

            if (File.Exists(appDbFilePath))
            {
                appDb = ApplicationFiletasks.ReadFromXmlFile <ApplicationConnections>(appDbFilePath);
                BuildFormClass(controlDbStackPanel, labelStyle, textBoxStyle, appDb, out controlDbStackPanel);
            }
            else
            {
                ApplicationFiletasks.WriteToXmlFile <ApplicationConnections>(appDbFilePath, appDb);
                BuildFormClass(controlDbStackPanel, labelStyle, textBoxStyle, appDb, out controlDbStackPanel);
            }

            if (File.Exists(userFilePath))
            {
                applicationUser = ApplicationFiletasks.ReadFromXmlFile <ApplicationUser>(userFilePath);
                BuildFormClass(settingsStackPanel, labelStyle, textBoxStyle, applicationUser, out settingsStackPanel);
            }
            else
            {
                ApplicationFiletasks.WriteToXmlFile <ApplicationUser>(userFilePath, applicationUser);
                BuildFormClass(settingsStackPanel, labelStyle, textBoxStyle, applicationUser, out settingsStackPanel);
            }

            Grid.SetRow(buttonStackPanel, 1);
            mainGrid.Children.Add(buttonStackPanel);

            window.Content       = mainGrid;
            window.SizeToContent = SizeToContent.WidthAndHeight;
        }