public SetProject(Plan plan = null) { InitializeComponent(); cmbDifficulty.SelectedIndex = 0; cmbRepeat.SelectedIndex = 0; cmbHabitual.SelectedIndex = 0; cmbState.SelectedIndex = 1; dtpAssumeTime.Value = DateTime.Today; //this.txtProjectName.Focus(); this.plan = plan; var list = Enum.GetValues(typeof(effec)); List<string> ss = new List<string>(); foreach (var e in list) { ss.Add(e.ToString()); } this.cmbEffect.Items.AddRange(ss.ToArray()); cmbEffect.SelectedIndex = cmbEffect.Items.IndexOf(effec.杂物.ToString()); ss = new List<string>(); foreach (var po in Logic.PositonList) { ss.Add(po.name); } this.cbPosition.Items.AddRange(ss.ToArray()); cbPosition.SelectedIndex = 0; this.cbTransmitPostion.Items.AddRange(ss.ToArray()); cbTransmitPostion.SelectedIndex = 0; }
public void AddPlan(Plan p) { planList.Add(p); if (p.ParentPlanID != -1) { InitParentChildPair(p); } else { treeRoots.Add(p); } }
private void btnSetFinished_Click(object sender, EventArgs e) { Plan plan = new Plan(); plan.Name = txtName.Text; plan.Id = ++Plan.IDmax; ParentPlan?.AddSubPlan(plan); if (ParentPlan != null) { plan.Effect = ParentPlan.Effect; plan.position = ParentPlan.position; } Logic.planManager.AddPlan(plan); Form1.BindPlan(); Close(); }
public static TreeNode GetPlanNodeToSelect(TreeView tv, Plan plan) { List<Plan> parentList = new List<Plan> { plan }; for (; parentList[parentList.Count - 1].ParentPlan != null;) { parentList.Add(parentList[parentList.Count - 1].ParentPlan); } int index = parentList.Count - 1; foreach (TreeNode node in tv.Nodes) { if (node.Text == parentList[index].Name) { var n = FindPlanNode(node, parentList, index - 1); if (n != null) return n; } } return null; }
/// <summary> /// 将窗口里设置的值赋给project/routine /// </summary> void ProjectGetValue(Project project, DateTime date) { project.Name = txtProjectName.Text; project.Diff = (difficulty)cmbDifficulty.SelectedIndex; project.Remark = txtRemark.Text; project.Status = (stat)cmbState.SelectedIndex; project.position = cbPosition.SelectedIndex == 0 ? null : Logic.GetPosition(cbPosition.Text); project.toPosition = cbTransmitPostion.SelectedIndex == 0 ? null : Logic.GetPosition(cbTransmitPostion.Text); project.Effect = (effec)Enum.Parse(typeof(effec), cmbEffect.Text); project.Forever = cbForever.Checked; project.startRing = cbRemind.Checked; if (cmbHabitual.SelectedIndex != 0) { foreach (Routine item in Logic.RoutineList) { if (cmbHabitual.Text == item.Name) { project.RoutineID = item.Id; break; } } } if (!(project is Routine)) { if (btnSetFinished.Text != "完成" && btnSetFinished.Text != "间隔的修改") { Logic.InsertPlansProject( planTV_SetProject.SelectedNode != null ? Logic.planManager.GetPlanByID(planTV_SetProject.SelectedNode.Name) : null, project); } if (planTV_SetProject.SelectedNode != null && (btnSetFinished.Text == "完成" || btnSetFinished.Text == "间隔的修改")) { plan = Logic.planManager.GetPlanByID(planTV_SetProject.SelectedNode.Name); } } if (cmbState.SelectedIndex == 0) { project.UsedTime = dtpFinishTime.Value - dtpStartTime.Value; } #region if (project is Routine) { ((Routine)project).RepeatType = (RepeatTYPE)cmbRepeat.SelectedIndex; if (cmbRepeat.SelectedIndex == 4)//repeatType列表更改后需更改 { dtpGap.Value = new DateTime(dtpGap.Value.Year, dtpGap.Value.Month, dtpGap.Value.Day, dtpGap.Value.Hour, dtpGap.Value.Minute, 0, 0); ((Routine)project).Gap = dtpGap.Value.Subtract(date.Date); } if (planTV_SetProject.SelectedNode != null) { var pl = Logic.planManager.GetPlanByID(planTV_SetProject.SelectedNode.Name); ((Routine)project).Plan = pl.Id; } if ((planTV_SetProject.SelectedNode == null) && ((Routine)project).Plan != null) { ((Routine)project).Plan = null; } } else { project.StartTime = dtpStartTime.Value; project.FinishedTime = dtpFinishTime.Value; } if (dtpAssumeTime.Checked) { dtpAssumeTime.Value = new DateTime(date.Date.Year, date.Date.Month, date.Date.Day, dtpAssumeTime.Value.Hour, dtpAssumeTime.Value.Minute, 0, 0); project.AssumeTime = dtpAssumeTime.Value.Subtract(date.Date); } project.StartLine = GetTimeLine(dtpEarilestStartTime, dtpEarilestStartDate); project.DeadLine = GetTimeLine(dtpLatestFinishTime, dtpLatestFinishDate); #endregion }
void InitPlanPart(Project project) { if (project != null) { if (project is Routine) { plan = ((Routine)project).Plan != null ? Logic.planManager.GetPlanByID(((Routine)project).Plan.ToString()) : null; } else { plan = Logic.planManager.GetProjectsPlan(project); } if (plan != null) { initPlanEffect = true; } } SetTreeView(); }
private void btnClearPlan_Click(object sender, EventArgs e) { plan = null; planTV_SetProject.SelectedNode = null; foreach (TreeNode node in planTV_SetProject.Nodes) { node.BackColor = Color.Azure; } }
public Plan GetPlanByName(string name, Plan parentPlan = null) { if (parentPlan != null) { foreach (Plan item in parentPlan.SubPlans) { if (item.Name == name) { return item; } } } else { foreach (Plan item in planList) { if (item.Name == name) { return item; } } } MessageBox.Show(@"GetPlanByName error"); return null; }
void InitParentChildPair(Plan p) { if (p.ParentPlanID != -1) { var parent = GetPlanByID(p.ParentPlanID.ToString()); parent.AddSubPlan(p); p.ParentPlan = parent; } }
Plan whoIsParent(Plan p1, Plan p2) { Plan tempPlan = p1; for (; tempPlan.ParentPlan != null;) { tempPlan = tempPlan.ParentPlan; if (tempPlan.Id == p2.Id) { return p2; } } tempPlan = p2; for (; tempPlan.ParentPlan != null;) { tempPlan = tempPlan.ParentPlan; if (tempPlan.Id == p1.Id) { return p1; } } return null; }
static void AddSubPlanTreeNode(TreeNode tn, Plan plan) { tn.Text = plan.Name; tn.Name = plan.Id.ToString(); foreach (var sp in plan.SubPlans) { TreeNode t = new TreeNode(); tn.Nodes.Add(t); AddSubPlanTreeNode(t, sp); } }
public void SetDirty(Plan plan) { Plan tempPlan = plan; tempPlan.dirty = true; for (; tempPlan.ParentPlan != null;) { tempPlan = tempPlan.ParentPlan; tempPlan.dirty = true; } }
public List<string> GetSubPlansName(Plan plan = null) { var list = new List<string>(); if (plan == null) { treeRoots.ForEach(p => list.Add(p.Name)); } else { list = plan.GetSubPlansNamelist(); } return list; }
//插入新建的plan和project的关系 public static void InsertPlansProject(Plan plan, Project project) { var formerPlan = planManager.GetProjectsPlan(project); formerPlan?.RemoveSubProject(project); plan?.AddSubproject(project); }
public static TreeNode GetPlanTree(Plan plan) { TreeNode t = new TreeNode(); AddSubPlanTreeNode(t, plan); return t; }
private void ModifyPlan() { if (dgvPlan.SelectedRows.Count != 1) { MessageBox.Show("请选择一个项目"); return; } string id = dgvPlan.CurrentRow.Cells["Id4"].Value.ToString(); //string status = dgvProject.CurrentRow.Cells["status"].Value.ToString(); Plan plan = new Plan(); BindProject(); plan = Logic.planManager.GetPlanByID(id); SetPlan setPlan = new SetPlan { plan = plan, Form1 = this }; setPlan.GetPlan(plan); setPlan.Show(); }
public bool AddSubPlan(Plan plan) { if (SubPlans.Any(p => p.Id == plan.Id)) { return false; } SubPlans.Add(plan); plan.ParentPlanID = Id; return true; }