/// <summary> /// Constructor /// </summary> /// <param name="chimneyModule">Chimney module</param> /// <param name="automaticConstructions">Instace to preocess saving</param> /// <param name="connection">Database connection</param> public ChimneyModuleForm( ChimneyModule chimneyModule, AutomaticConstructions automaticConstructions, DatabaseConnection connection) { InitializeComponent(); this.chimneyModule = chimneyModule; this.dbConnection = connection; this.automaticConstructions = automaticConstructions; this.currentConstructionList = automaticConstructions.ChimneyConstructions; this.dg_Constructions.ItemsSource = automaticConstructions.ChimneyConstructions; }
/// <summary> /// When construction is being saved, corresponding MainItem has to be updated /// </summary> /// <param name="connection">Database connection</param> /// <param name="construction">Construction to update/add</param> public void UpdateChimneyConstructionMainItem(DatabaseConnection connection, ChimneyConstruction construction) { // Get index of Constructions -> MainItem is on the same index int index = this.ChimneyConstructions == null ? -1 : this.ChimneyConstructions.IndexOf(construction); // Get new Main Item MainItem result = new ChimneyModule(null).CalculateConstruction(connection, construction, index); // New item if (index == -1) { this.ChimneyConstructions.Add(construction); this.ChimneyMainItems.Add(result); return; } // Old result this.ChimneyMainItems[index] = result; }