using System; using System.Collections.Generic; using System.Windows.Forms; using TBF.BenchControl; using TBF.BenchControl.Generic; namespace ResultsBrowser.Forms { public partial class PrinterConfigDlg : Form { public string PrinterClass; /// To be initialized in the constructor public string PrinterCfg; IList printerFactories; /// Printer components classes IComponentFactory printerFactory; public PrinterConfigDlg() { InitializeComponent(); printerFactories = new List(); foreach (var fctry in TbfComponents.Factories) { if (fctry.ClassName.Contains("Output.Printers.")) printerFactories.Add(fctry); } } private void PrinterClassDlg_Load(object sender, EventArgs e) { printerClassComboBox.Items.Add("---"); foreach (var fctry in printerFactories) { printerClassComboBox.Items.Add(fctry.ClassName); } printerClassComboBox.Text = string.IsNullOrEmpty(PrinterClass) ? "---" : PrinterClass; } private void changePrinterClassButton_Click(object sender, EventArgs e) { printerClassComboBox.Enabled = true; } private void cancelButton_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; Close(); } private void configureButton_Click(object sender, EventArgs e) { string oriClassName = PrinterClass; PrinterClass = string.Empty; if (printerClassComboBox.Text != "---") { foreach (var pc in printerFactories) { if (printerClassComboBox.Text == pc.ClassName) PrinterClass = pc.ClassName; } } printerFactory = GetFactory(PrinterClass); if (printerFactory == null) { MessageBox.Show("Invalid printer"); return; } IComponentCfg printerCfg; if ((oriClassName != printerFactory.ClassName) || string.IsNullOrEmpty(PrinterCfg)) { printerCfg = printerFactory.DefaultConfig(); } else { Config.Entities.Component cmpnt = new Config.Entities.Component(); cmpnt.Name = "printer"; cmpnt.ClassName = PrinterClass; cmpnt.Parameters = PrinterCfg; printerCfg = printerFactory.CmpntCfgFromCmpntEntity(cmpnt); } IComponentCfgCtrl cfgControl = printerCfg.GetControl(); cfgControl.Config = printerCfg; cfgControl.Config.ItemNr = 0; TBF.ComponentParametersDlg cfgForm = new TBF.ComponentParametersDlg(); cfgForm.TbfComponents = new List(); cfgForm.ComponentCfgCtrl = cfgControl; cfgForm.UnlockAfterStart = true; DialogResult dr = cfgForm.ShowDialog(); if (dr != DialogResult.OK) return; PrinterCfg = (printerCfg != null) ? printerCfg.CreateDbEntity().Parameters : string.Empty; DialogResult = DialogResult.OK; Close(); } /// /// Updates component factory /// /// Component class name /// Reference to a factory /// true when factory changed IComponentFactory GetFactory(string className) { if (!string.IsNullOrEmpty(className)) { foreach (var fac in TbfComponents.Factories) { if (fac.ClassName == className) return fac; } } return null; } } }