示例#1
0
        public MainWindow()
        {
            this.Loaded += new RoutedEventHandler(MainWindow_Loaded);

            InitializeComponent();
            this.DataContext           = vm;
            SelectConnection.ViewModel = vm;

            this.selectRules.NewRuleButton.Click += new RoutedEventHandler(delegate(Object sender, RoutedEventArgs args)
            {
                String ruleName = "User-defined rule " + (dblint.AllExecutables.GetSQLRules().Count + 1);
                SQLRule newRule = SQLRuleCollection.AddSQLRule(ruleName);
                this.dblint.AllExecutables.AddExecutable(newRule);
                this.updateSQLRuleSet();
            });

            this.selectRules.OnDeleteRule += new DeleteRuleHandler(delegate(Rule rule)
            {
                SQLRuleCollection.RemoveSQLRule(rule.Name);
                this.dblint.AllExecutables.RemoveExecutable(rule.Executable);
                this.updateSQLRuleSet();
            });

            this.selectRules.SaveConfigButon.Click += new RoutedEventHandler(delegate(Object sender, RoutedEventArgs args)
            {
                var saveConfigOptions = new SaveConfigOptions();
                var res = saveConfigOptions.ShowDialog();
                if (res.HasValue && res.Value == true)
                {
                    this.saveConfig(saveConfigOptions);
                }
            });

            this.selectRules.LoadConfigButon.Click += new RoutedEventHandler(delegate(Object sender, RoutedEventArgs args)
            {
                Microsoft.Win32.OpenFileDialog loadDialog = new Microsoft.Win32.OpenFileDialog();
                loadDialog.DefaultExt = ".xml";
                loadDialog.Filter     = "XML Document (.xml)|*.xml";

                bool?result = loadDialog.ShowDialog();

                if (result == true)
                {
                    this.loadConfig(loadDialog.FileName);
                }
            });

            this.loadConfig(Settings.XMLCONFIG);

            this.Closing += new System.ComponentModel.CancelEventHandler(MainWindow_Closing);
        }
示例#2
0
        void saveConfig(SaveConfigOptions saveConfigOptions)
        {
            if (saveConfigOptions.FileName != null)
            {
                Configuration config = new Configuration();

                if (saveConfigOptions.ExportConnection.IsChecked == true)
                {
                    config.Connection = this.vm.CurrentConnection;
                }

                if (saveConfigOptions.ExportRules.IsChecked == true)
                {
                    config.AllRules   = this.dblint.AllExecutables.Where(ex => ex.IsRule());
                    config.RulesToRun = this.getRulesToRun();
                }
                else
                {
                    config.AllRules   = this.dblint.AllExecutables.Where(ex => ex.IsSQLRule() == true);
                    config.RulesToRun = this.getRulesToRun().Where(r => r.IsSQLRule() == true);
                }

                if (saveConfigOptions.ExportSQLRules.IsChecked == false)
                {
                    config.AllRules   = config.AllRules.Where(r => r.IsSQLRule() == false);
                    config.RulesToRun = config.RulesToRun.Where(r => r.IsSQLRule() == false);
                }

                if (saveConfigOptions.ExportTables.IsChecked == true)
                {
                    config.TablesToCheck = this.getTablesToCheck();
                }

                IConfigFile file = new XMLConfigFile(saveConfigOptions.FileName);
                file.Save(config);
            }
        }