/// <summary> /// Обновляет значения полей /// </summary> public override void FillControls() { BeginUpdate(); flowLayoutPanelItems.Controls.Clear(); if (Flight != null && Flight.FuelTankCollection != null) { for (int i = 0; i < Flight.FuelTankCollection.Count; i++) { FuelControlItem item = new FuelControlItem(Flight.FuelTankCollection[i]); item.AfterRemainChanget += ItemAfterRemainChanget; item.RefuelChanget += ItemRefuelChanget; item.OnBoardChanget += ItemOnBoardChanget; item.SpentChanget += ItemSpentChanget; item.BeforeRemainChanget += ItemBeforeRemainChanget; if (i > 0) { item.ShowHeaders = false; } flowLayoutPanelItems.Controls.Add(item); } GetTotalBefore(); GetTotalRefuel(); GetTotalOnBoard(); GetTotalSpent(); GetTotalAfter(); } //Дополнительные поля будем брать из первой записи if (Flight != null && Flight.FuelTankCollection != null && Flight.FuelTankCollection.Count >= 1) { textCalculateUplift.Text = Flight.FuelTankCollection[0].CalculateUplift.ToString(); textActualUplift.Text = Flight.FuelTankCollection[0].ActualUpliftLit.ToString(); textDiscrepancy.Text = Flight.FuelTankCollection[0].Discrepancy.ToString(); textDensity.Text = Flight.FuelTankCollection[0].Density.ToString(); } else { textCalculateUplift.Text = textActualUplift.Text = textDiscrepancy.Text = textDensity.Text = ""; } EndUpdate(); }
/* * Перегружаемые методы */ #region public override void ApplyChanges() /// <summary> /// Применить к объекту сделанные изменения на контроле. /// Если не все данные удовлетворяют формату ввода (например при вводе чисел), свойства объекта не изменяются, возвращается false /// Вызов base.ApplyChanges() обязателен /// </summary> /// <returns></returns> public override void ApplyChanges() { // Применяем сделанные изменения объектам for (int i = 0; i < flowLayoutPanelItems.Controls.Count; i++) { FuelControlItem c = flowLayoutPanelItems.Controls[i] as FuelControlItem; if (c == null) { continue; } c.ApplyChanges(); if (Flight != null && Flight.FuelTankCollection != null && !ConditionExists(c.FuelCondition)) { Flight.FuelTankCollection.Add(c.FuelCondition); } } // Сохраняем общие параметры if (Flight != null && Flight.FuelTankCollection != null && Flight.FuelTankCollection.Count >= 1) { FuelTankCondition c = Flight.FuelTankCollection[0]; c.CalculateUplift = UsefulMethods.StringToDouble(textCalculateUplift.Text); c.ActualUpliftLit = UsefulMethods.StringToDouble(textActualUplift.Text); c.Discrepancy = UsefulMethods.StringToDouble(textDiscrepancy.Text); c.Density = UsefulMethods.StringToDouble(textDensity.Text); // Сохраняем эти значения на всякий случай во все остальные записи коллекции for (int i = 1; i < Flight.FuelTankCollection.Count; i++) { Flight.FuelTankCollection[i].CalculateUplift = c.CalculateUplift; Flight.FuelTankCollection[i].ActualUpliftLit = c.ActualUpliftLit; Flight.FuelTankCollection[i].Discrepancy = c.Discrepancy; Flight.FuelTankCollection[i].Density = c.Density; } } base.ApplyChanges(); }