public void RemoveAllExceptRunning() { List <Control> toBeRemoved = new List <Control>(); // Remove all that are not running. foreach (Control ctrl in this.layoutPanel.Controls) { if (!(ctrl is RestorePlanViewControl)) { continue; } RestorePlanViewControl obj = ctrl as RestorePlanViewControl; if (!obj.OperationIsRunning) { toBeRemoved.Add(ctrl); } } // Remove them. foreach (Control ctrl in toBeRemoved) { this.layoutPanel.Controls.Remove(ctrl); } }
public bool ControlsAlreadyContainControlForPlan(Models.RestorePlan plan) { foreach (Control ctrl in this.layoutPanel.Controls) { if (!(ctrl is RestorePlanViewControl)) { continue; } RestorePlanViewControl obj = ctrl as RestorePlanViewControl; Models.RestorePlan objPlan = obj.Model as Models.RestorePlan; if (objPlan.Id.Equals(plan.Id)) { return(true); } } return(false); }
public void LoadPlans() { RemoveAllExceptRunning(); var plans = dao.GetAllActive(); foreach (var plan in plans) { if (ControlsAlreadyContainControlForPlan(plan)) { continue; } RestorePlanViewControl viewControl = new RestorePlanViewControl(); viewControl.Model = plan; viewControl.Deleted += (object sender, EventArgs e) => { RestorePlanViewControl control = sender as RestorePlanViewControl; layoutPanel.Controls.Remove(control); }; this.layoutPanel.Controls.Add(viewControl); } }