/// /// Copyright (c) 2015 Sensus Metering Systems /// Author: Milan Hanajík /// using System; using System.Windows.Forms; using log4net; using TBF.BenchControl.Generic; namespace TBF.BenchControl.DB.SensusOracle { public partial class DatabaseCfgCtrl : UserControl, IComponentCfgCtrl { static readonly ILog log = LogManager.GetLogger(typeof(DatabaseCfgCtrl)); public bool ShowMore { get { return false; } } DatabaseCfg config; public IComponentCfg Config { get { return config as IComponentCfg; } set { config = value as DatabaseCfg; Redraw(); } } public DatabaseCfgCtrl() { InitializeComponent(); } private void WriterCfgCtrl_Load(object sender, EventArgs e) { for (int i = 0; i < (int)Separator.Count; i++) { separatorComboBox.Items.Add(((Separator)i).ToString()); } Redraw(); } public void Closing() { } void Redraw() { if (config == null) return; /// Control was not loaded, settings were not changed classNameLabel.Text = config.Factory.ClassName; nameTextBox.Text = config.Name; destinationTextBox.Text = config.DestinationPath; yearFoldersCheckBox.Checked = config.YearFolders; monthFoldersCheckBox.Checked = config.MonthFolders; dayFoldersCheckBox.Checked = config.DayFolders; separatorComboBox.Text = config.Separator.ToString(); eliminateSpacesCheckBox.Checked = config.EliminateSpaces; } public void Unlock() { nameTextBox.Enabled = true; destinationTextBox.Enabled = true; destinationButton.Enabled = true; yearFoldersCheckBox.Enabled = true; monthFoldersCheckBox.Enabled = true; dayFoldersCheckBox.Enabled = true; separatorComboBox.Enabled = true; eliminateSpacesCheckBox.Enabled = true; } public CfgUpdateFlags VerifyCfg(ref string message) { CfgUpdateFlags flags = CfgUpdateFlags.None; if (!separatorComboBox.Items.Contains(separatorComboBox.Text)) { flags |= CfgUpdateFlags.Error; message += Environment.NewLine + "Invalid separator"; } return flags; } public CfgUpdateFlags UpdateCfg() { CfgUpdateFlags flags = CfgUpdateFlags.None; if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed if (config.Name != nameTextBox.Text) { config.Name = nameTextBox.Text; flags = CfgUpdateFlags.RestartRqrd; } if (config.DestinationPath != destinationTextBox.Text) { config.DestinationPath = destinationTextBox.Text; if (!config.DestinationPath.EndsWith("\\")) config.DestinationPath += "\\"; flags = CfgUpdateFlags.RestartRqrd; } if (yearFoldersCheckBox.Checked != config.YearFolders) { config.YearFolders = yearFoldersCheckBox.Checked; flags = CfgUpdateFlags.RestartRqrd; } if (monthFoldersCheckBox.Checked != config.MonthFolders) { config.MonthFolders = monthFoldersCheckBox.Checked; flags = CfgUpdateFlags.RestartRqrd; } if (dayFoldersCheckBox.Checked != config.DayFolders) { config.DayFolders = dayFoldersCheckBox.Checked; flags = CfgUpdateFlags.RestartRqrd; } for (int i = 0; i < (int)Separator.Count; i++) { if (((Separator)i).ToString().Equals(separatorComboBox.Text)) { config.Separator = (Separator)i; } } if (eliminateSpacesCheckBox.Checked != config.EliminateSpaces) { config.EliminateSpaces = eliminateSpacesCheckBox.Checked; flags = CfgUpdateFlags.RestartRqrd; } return flags; } private void destinationButton_Click(object sender, EventArgs e) { } } }