void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (_modified)
            {
                DialogResult res = MessageDisplay.QueryWithCancel(Translator.Translate("TXT_SAVE_BEFORE_EXIT"),
                                                                  Translator.Translate("TXT_APPLY_CFG"), MessageBoxIcon.Question);

                if (res == DialogResult.Yes)
                {
                    _config.WriteXml(_cfgPath);
                }
                else if (res == DialogResult.Cancel)
                {
                    e.Cancel = true;
                }
            }
        }
        private void tsmiExportPartial_Click(object sender, EventArgs e)
        {
            try
            {
                string selRemoteName = string.Empty;

                TreeNode node = tvRemotes.SelectedNode;
                if (node != null)
                {
                    if (node.Tag is RCCServiceConfig.RemoteControlRow)
                    {
                        selRemoteName = (node.Tag as RCCServiceConfig.RemoteControlRow).RemoteName;
                    }
                    else if (node.Tag is RCCServiceConfig.RemoteButtonsRow)
                    {
                        selRemoteName = (node.Tag as RCCServiceConfig.RemoteButtonsRow).RemoteName;
                    }
                }

                RCCServiceConfig partialConfig = new RCCServiceConfig();

                var remote = (from rc in _config.RemoteControl
                              where rc.RemoteName == selRemoteName
                              select rc).FirstOrDefault();

                if (remote != null)
                {
                    partialConfig.RemoteControl.AddRemoteControlRow(selRemoteName,
                                                                    remote.InputPinName, remote.InputPinCfgData, remote.OutputPinName, remote.OutputPinCfgData, remote.Enabled);

                    var buttons = (from rb in _config.RemoteButtons
                                   where rb.RemoteName == selRemoteName
                                   select rb);

                    if (buttons != null)
                    {
                        foreach (var button in buttons)
                        {
                            partialConfig.RemoteButtons.AddRemoteButtonsRow(selRemoteName,
                                                                            button.InputData, button.OutputData, button.ButtonName, button.TargetWndName, button.Enabled, button.TimedRepeatRate);
                        }

                        partialConfig.RemoteButtons.AcceptChanges();
                    }

                    partialConfig.RemoteControl.AcceptChanges();

                    OPMSaveFileDialog dlg = new OPMSaveFileDialog();
                    dlg.Filter     = Translator.Translate("TXT_CONFIG_FILES_FILTER");
                    dlg.DefaultExt = "config";
                    dlg.Title      = Translator.Translate("TXT_EXPORT_PARTIAL");

                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        partialConfig.WriteXml(dlg.FileName);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorDispatcher.DispatchError(ex, false);
            }
        }
Esempio n. 3
0
        private void tsmiExportPartial_Click(object sender, EventArgs e)
        {
            try
            {
                string selRemoteName = string.Empty;

                TreeNode node = tvRemotes.SelectedNode;
                if (node != null)
                {
                    if (node.Tag is RCCServiceConfig.RemoteControlRow)
                    {
                        selRemoteName = (node.Tag as RCCServiceConfig.RemoteControlRow).RemoteName;
                    }
                    else if (node.Tag is RCCServiceConfig.RemoteButtonsRow)
                    {
                        selRemoteName = (node.Tag as RCCServiceConfig.RemoteButtonsRow).RemoteName;
                    }
                }

                RCCServiceConfig partialConfig = new RCCServiceConfig();

                var remote = (from rc in _config.RemoteControl
                        where rc.RemoteName == selRemoteName
                        select rc).FirstOrDefault();

                if (remote != null)
                {
                    partialConfig.RemoteControl.AddRemoteControlRow(selRemoteName, 
                        remote.InputPinName, remote.InputPinCfgData, remote.OutputPinName, remote.OutputPinCfgData, remote.Enabled);

                    var buttons = (from rb in _config.RemoteButtons
                                    where rb.RemoteName == selRemoteName
                                    select rb);

                    if (buttons != null)
                    {
                        foreach(var button in buttons)
                        {
                            partialConfig.RemoteButtons.AddRemoteButtonsRow(selRemoteName, 
                                button.InputData, button.OutputData, button.ButtonName, button.TargetWndName, button.Enabled, button.TimedRepeatRate);
                        }

                        partialConfig.RemoteButtons.AcceptChanges();
                    }

                    partialConfig.RemoteControl.AcceptChanges();

                    OPMSaveFileDialog dlg = new OPMSaveFileDialog();
                    dlg.Filter = Translator.Translate("TXT_CONFIG_FILES_FILTER");
                    dlg.DefaultExt = "config";
                    dlg.Title = Translator.Translate("TXT_EXPORT_PARTIAL");

                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        partialConfig.WriteXml(dlg.FileName);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorDispatcher.DispatchError(ex);
            }
        }