private void CurrentGoalsSub() { var GoalsInfo = Lists.GoalsList.ToList(); ArrayList GoalsArray = new ArrayList(); ArrayList CheckArray = new ArrayList(); foreach (var item in Lists.GoalsInfoList.Where(c => c.Goal_Id == FetchCurrentGoalId)) { GoalsArray.Add(item.Info); CheckArray.Add(item.Completed); } for (int i = 0; i <= GoalsArray.Count - 1; i++) { CurrentGoals curg = new CurrentGoals(); curg.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(61)))), ((int)(((byte)(61)))), ((int)(((byte)(66))))); curg.Checked = bool.Parse(CheckArray[i].ToString()); if (!curg.Checked) { curg.CheckEnabled = true; } curg.GoalName = GoalsArray[i].ToString(); curg.Dock = System.Windows.Forms.DockStyle.Top; curg.Location = new System.Drawing.Point(3, 3); curg.Name = string.Format("CurrentGoal{0}", i.ToString()); curg.Size = new System.Drawing.Size(308, 30); curg.TabIndex = 0; flowLayoutPanelCurrent.Controls.Add(curg); } }
void bw_DoWork(object sender, DoWorkEventArgs e) { var length = Lists.GoalsInfoList.Where(c => c.Goal_Id == FetchCurrentGoalId).ToList(); ArrayList idArray = new ArrayList(); foreach (var item in Lists.GoalsInfoList.Where(c => c.Goal_Id == FetchCurrentGoalId)) { idArray.Add(item.ID); } for (int i = 1; i <= length.Count; i++) { int id = int.Parse(idArray[i - 1].ToString()); var upd = db.GoalsInfo.Where(c => c.Goal_Id == FetchCurrentGoalId && c.ID == id).FirstOrDefault(); CurrentGoals curg = flowLayoutPanelCurrent.Controls.Find(string.Format("CurrentGoal{0}", (i - 1).ToString()), true).FirstOrDefault() as CurrentGoals; upd.Completed = curg.Checked; db.Entry(upd).State = EntityState.Modified; } db.SaveChanges(); DbEntities dbrefresh = new DbEntities(); Lists.GoalsInfoList = db.GoalsInfo.ToList(); }