public static bool StartPlan(long id) { try { foreach (EPlan p in EPlanDictionary.GetInstance().GetList()) { if (p.state == true) { p.state = false; p.stopF += 1; p.lastT += DateTime.Now - p.startT.Last();//*** have problem here *** } } EPlan plan = EPlanDictionary.GetInstance().find(id); plan.state = true; plan.startF += 1; plan.startT.Add(DateTime.Now); return(true); } catch (Exception ex) { Logger.WriteLogs("MainFormController/StartPlan Error: " + ex.Message); return(false); } }
public static bool AddPlan(string p, long id) { try { if (TaskDictionary.GetInstance().find(0) == null) { Model.Elements.Task task = new Model.Elements.Task(); task.name = "DEFAULT"; task.id = 0; task.scale = 31; TaskDictionary.GetInstance().Add(task); STask st = new STask(); st.name = "DEFAULT_STASK"; st.id = 0; st.order = 0; STaskDictionary.GetInstance().Add(st); SubTask subt = new SubTask(); subt.name = p; subt.id = id; subt.showT = DateTime.Now; SubTaskDictionary.GetInstance().Add(subt); EPlan plan = new EPlan(); plan.name = p; plan.id = id; plan.showT = DateTime.Now; EPlanDictionary.GetInstance().Add(plan); st.subtaskID.Add(subt.id); task.staskID.Add(st.id); } else { Model.Elements.Task task = TaskDictionary.GetInstance().find(0); SubTask subt = new SubTask(); subt.name = p; subt.id = id; subt.showT = DateTime.Now; SubTaskDictionary.GetInstance().Add(subt); EPlan plan = new EPlan(); plan.name = p; plan.id = id; plan.showT = DateTime.Now; EPlanDictionary.GetInstance().Add(plan); STaskDictionary.GetInstance().find(0).subtaskID.Add(subt.id); } return(true); } catch (Exception ex) { Logger.WriteLogs("MainFormController/AddPlan Error: " + ex.Message); return(false); } }
private string isSameName(string name) { if (EPlanDictionary.GetInstance().GetList().Exists(p => (p.name == name))) { //sameNameCount += 1; return(isSameName(name + "*")); } else { return(name); } }
public static bool DonePlan(long id) { try { EPlan plan = EPlanDictionary.GetInstance().find(id); if (plan.state) { plan.endT = DateTime.Now; plan.lastT += DateTime.Now - plan.startT.Last(); plan.endState = true; plan.progress += 10; } return(true); } catch (Exception ex) { Logger.WriteLogs("MainFormController/DonePlan Error: " + ex.Message); return(false); } }
private void ViewInit() { //"Everyday" initialization //"Closed" initialization if (EPlanDictionary.GetInstance().GetList() != null) { for (int i = 0; i < EPlanDictionary.GetInstance().GetList().Count; i++) { TreeNode node = new TreeNode(); node.Text = EPlanDictionary.GetInstance().GetList()[i].name; node.Tag = EPlanDictionary.GetInstance().GetList()[i].id; if (EPlanDictionary.GetInstance().GetList()[i].endState) { closedTreeView.Nodes.Add(node); if (EPlanDictionary.GetInstance().GetList()[i].steps != null) { for (int j = 0; j < EPlanDictionary.GetInstance().GetList()[i].steps.Count; j++) { closedTreeView .Nodes[closedTreeView.Nodes.Count - 1] .Nodes .Add(EPlanDictionary.GetInstance().GetList()[i].steps[j].name); } } } else { planTreeView.Nodes.Add(node); if (EPlanDictionary.GetInstance().GetList()[i].steps != null) { for (int j = 0; j < EPlanDictionary.GetInstance().GetList()[i].steps.Count; j++) { planTreeView .Nodes[planTreeView.Nodes.Count - 1] .Nodes .Add(EPlanDictionary.GetInstance().GetList()[i].steps[j].name); } } //set the color of started plan if (EPlanDictionary.GetInstance().GetList()[i].state) { planTreeView.Nodes.Find(node.Text, false)[0].BackColor = Color.Green; toolStripProgressBar1.Value = EPlanDictionary.GetInstance().GetList()[i].progress; toolStripLabel2.Text = EPlanDictionary.GetInstance().GetList()[i].progress.ToString(); } } } planTreeView.ExpandAll(); closedTreeView.ExpandAll(); } //initial "task" if (TaskDictionary.GetInstance().GetList() != null) { for (int i = 0; i < TaskDictionary.GetInstance().GetList().Count; i++) { TreeNode node = new TreeNode(); node.Text = TaskDictionary.GetInstance().GetList()[i].name; node.Tag = TaskDictionary.GetInstance().GetList()[i].id; taskTreeView.Nodes.Add(node); } } //initial "Everyday1" DateTime dt = DateTime.Now; int h = dt.Hour; int tn; if (dt.Minute < 30) { tn = h * 100; } else { tn = h * 100 + 50; } int[] timescale = new int[48]; int loca = 16; while (true) { timescale[loca] = tn; loca++; loca = (loca > 47) ? loca - 48 : loca; tn += 50; tn = (tn >= 2400) ? tn - 2400 : tn; if (loca == 16) { break; } } label1.Text = ((timescale[0] / 100 < 10) ? ("0" + (timescale[0] / 100).ToString()) : (timescale[0] / 100).ToString()) + ":" + ((timescale[0] % 100 == 0) ? "00" : "30") + " __"; label2.Text = ((timescale[1] / 100 < 10) ? ("0" + (timescale[1] / 100).ToString()) : (timescale[1] / 100).ToString()) + ":" + ((timescale[1] % 100 == 0) ? "00" : "30") + " __"; label3.Text = ((timescale[2] / 100 < 10) ? ("0" + (timescale[2] / 100).ToString()) : (timescale[2] / 100).ToString()) + ":" + ((timescale[2] % 100 == 0) ? "00" : "30") + " __"; label4.Text = ((timescale[3] / 100 < 10) ? ("0" + (timescale[3] / 100).ToString()) : (timescale[3] / 100).ToString()) + ":" + ((timescale[3] % 100 == 0) ? "00" : "30") + " __"; label5.Text = ((timescale[4] / 100 < 10) ? ("0" + (timescale[4] / 100).ToString()) : (timescale[4] / 100).ToString()) + ":" + ((timescale[4] % 100 == 0) ? "00" : "30") + " __"; label6.Text = ((timescale[5] / 100 < 10) ? ("0" + (timescale[5] / 100).ToString()) : (timescale[5] / 100).ToString()) + ":" + ((timescale[5] % 100 == 0) ? "00" : "30") + " __"; label7.Text = ((timescale[6] / 100 < 10) ? ("0" + (timescale[6] / 100).ToString()) : (timescale[6] / 100).ToString()) + ":" + ((timescale[6] % 100 == 0) ? "00" : "30") + " __"; label8.Text = ((timescale[7] / 100 < 10) ? ("0" + (timescale[7] / 100).ToString()) : (timescale[7] / 100).ToString()) + ":" + ((timescale[7] % 100 == 0) ? "00" : "30") + " __"; label9.Text = ((timescale[8] / 100 < 10) ? ("0" + (timescale[8] / 100).ToString()) : (timescale[8] / 100).ToString()) + ":" + ((timescale[8] % 100 == 0) ? "00" : "30") + " __"; label10.Text = ((timescale[9] / 100 < 10) ? ("0" + (timescale[9] / 100).ToString()) : (timescale[9] / 100).ToString()) + ":" + ((timescale[9] % 100 == 0) ? "00" : "30") + " __"; label11.Text = ((timescale[10] / 100 < 10) ? ("0" + (timescale[10] / 100).ToString()) : (timescale[10] / 100).ToString()) + ":" + ((timescale[10] % 100 == 0) ? "00" : "30") + " __"; label12.Text = ((timescale[11] / 100 < 10) ? ("0" + (timescale[11] / 100).ToString()) : (timescale[11] / 100).ToString()) + ":" + ((timescale[11] % 100 == 0) ? "00" : "30") + " __"; label13.Text = ((timescale[12] / 100 < 10) ? ("0" + (timescale[12] / 100).ToString()) : (timescale[12] / 100).ToString()) + ":" + ((timescale[12] % 100 == 0) ? "00" : "30") + " __"; label14.Text = ((timescale[13] / 100 < 10) ? ("0" + (timescale[13] / 100).ToString()) : (timescale[13] / 100).ToString()) + ":" + ((timescale[13] % 100 == 0) ? "00" : "30") + " __"; label15.Text = ((timescale[14] / 100 < 10) ? ("0" + (timescale[14] / 100).ToString()) : (timescale[14] / 100).ToString()) + ":" + ((timescale[14] % 100 == 0) ? "00" : "30") + " __"; label16.Text = ((timescale[15] / 100 < 10) ? ("0" + (timescale[15] / 100).ToString()) : (timescale[15] / 100).ToString()) + ":" + ((timescale[15] % 100 == 0) ? "00" : "30") + " __"; label17.Text = ((timescale[16] / 100 < 10) ? ("0" + (timescale[16] / 100).ToString()) : (timescale[16] / 100).ToString()) + ":" + ((timescale[16] % 100 == 0) ? "00" : "30") + " __"; label18.Text = ((timescale[17] / 100 < 10) ? ("0" + (timescale[17] / 100).ToString()) : (timescale[17] / 100).ToString()) + ":" + ((timescale[17] % 100 == 0) ? "00" : "30") + " __"; label19.Text = ((timescale[18] / 100 < 10) ? ("0" + (timescale[18] / 100).ToString()) : (timescale[18] / 100).ToString()) + ":" + ((timescale[18] % 100 == 0) ? "00" : "30") + " __"; label20.Text = ((timescale[19] / 100 < 10) ? ("0" + (timescale[19] / 100).ToString()) : (timescale[19] / 100).ToString()) + ":" + ((timescale[19] % 100 == 0) ? "00" : "30") + " __"; label21.Text = ((timescale[20] / 100 < 10) ? ("0" + (timescale[20] / 100).ToString()) : (timescale[20] / 100).ToString()) + ":" + ((timescale[20] % 100 == 0) ? "00" : "30") + " __"; label22.Text = ((timescale[21] / 100 < 10) ? ("0" + (timescale[21] / 100).ToString()) : (timescale[21] / 100).ToString()) + ":" + ((timescale[21] % 100 == 0) ? "00" : "30") + " __"; label23.Text = ((timescale[22] / 100 < 10) ? ("0" + (timescale[22] / 100).ToString()) : (timescale[22] / 100).ToString()) + ":" + ((timescale[22] % 100 == 0) ? "00" : "30") + " __"; label24.Text = ((timescale[23] / 100 < 10) ? ("0" + (timescale[23] / 100).ToString()) : (timescale[23] / 100).ToString()) + ":" + ((timescale[23] % 100 == 0) ? "00" : "30") + " __"; label25.Text = ((timescale[24] / 100 < 10) ? ("0" + (timescale[24] / 100).ToString()) : (timescale[24] / 100).ToString()) + ":" + ((timescale[24] % 100 == 0) ? "00" : "30") + " __"; label26.Text = ((timescale[25] / 100 < 10) ? ("0" + (timescale[25] / 100).ToString()) : (timescale[25] / 100).ToString()) + ":" + ((timescale[25] % 100 == 0) ? "00" : "30") + " __"; label27.Text = ((timescale[26] / 100 < 10) ? ("0" + (timescale[26] / 100).ToString()) : (timescale[26] / 100).ToString()) + ":" + ((timescale[26] % 100 == 0) ? "00" : "30") + " __"; label28.Text = ((timescale[27] / 100 < 10) ? ("0" + (timescale[27] / 100).ToString()) : (timescale[27] / 100).ToString()) + ":" + ((timescale[27] % 100 == 0) ? "00" : "30") + " __"; label29.Text = ((timescale[28] / 100 < 10) ? ("0" + (timescale[28] / 100).ToString()) : (timescale[28] / 100).ToString()) + ":" + ((timescale[28] % 100 == 0) ? "00" : "30") + " __"; label30.Text = ((timescale[29] / 100 < 10) ? ("0" + (timescale[29] / 100).ToString()) : (timescale[29] / 100).ToString()) + ":" + ((timescale[29] % 100 == 0) ? "00" : "30") + " __"; label31.Text = ((timescale[30] / 100 < 10) ? ("0" + (timescale[30] / 100).ToString()) : (timescale[30] / 100).ToString()) + ":" + ((timescale[30] % 100 == 0) ? "00" : "30") + " __"; label32.Text = ((timescale[31] / 100 < 10) ? ("0" + (timescale[31] / 100).ToString()) : (timescale[31] / 100).ToString()) + ":" + ((timescale[31] % 100 == 0) ? "00" : "30") + " __"; label33.Text = ((timescale[32] / 100 < 10) ? ("0" + (timescale[32] / 100).ToString()) : (timescale[32] / 100).ToString()) + ":" + ((timescale[32] % 100 == 0) ? "00" : "30") + " __"; label34.Text = ((timescale[33] / 100 < 10) ? ("0" + (timescale[33] / 100).ToString()) : (timescale[33] / 100).ToString()) + ":" + ((timescale[33] % 100 == 0) ? "00" : "30") + " __"; label35.Text = ((timescale[34] / 100 < 10) ? ("0" + (timescale[34] / 100).ToString()) : (timescale[34] / 100).ToString()) + ":" + ((timescale[34] % 100 == 0) ? "00" : "30") + " __"; label36.Text = ((timescale[35] / 100 < 10) ? ("0" + (timescale[35] / 100).ToString()) : (timescale[35] / 100).ToString()) + ":" + ((timescale[35] % 100 == 0) ? "00" : "30") + " __"; label37.Text = ((timescale[36] / 100 < 10) ? ("0" + (timescale[36] / 100).ToString()) : (timescale[36] / 100).ToString()) + ":" + ((timescale[36] % 100 == 0) ? "00" : "30") + " __"; label38.Text = ((timescale[37] / 100 < 10) ? ("0" + (timescale[37] / 100).ToString()) : (timescale[37] / 100).ToString()) + ":" + ((timescale[37] % 100 == 0) ? "00" : "30") + " __"; label39.Text = ((timescale[38] / 100 < 10) ? ("0" + (timescale[38] / 100).ToString()) : (timescale[38] / 100).ToString()) + ":" + ((timescale[38] % 100 == 0) ? "00" : "30") + " __"; label40.Text = ((timescale[39] / 100 < 10) ? ("0" + (timescale[39] / 100).ToString()) : (timescale[39] / 100).ToString()) + ":" + ((timescale[39] % 100 == 0) ? "00" : "30") + " __"; label41.Text = ((timescale[40] / 100 < 10) ? ("0" + (timescale[40] / 100).ToString()) : (timescale[40] / 100).ToString()) + ":" + ((timescale[40] % 100 == 0) ? "00" : "30") + " __"; label42.Text = ((timescale[41] / 100 < 10) ? ("0" + (timescale[41] / 100).ToString()) : (timescale[41] / 100).ToString()) + ":" + ((timescale[41] % 100 == 0) ? "00" : "30") + " __"; label43.Text = ((timescale[42] / 100 < 10) ? ("0" + (timescale[42] / 100).ToString()) : (timescale[42] / 100).ToString()) + ":" + ((timescale[42] % 100 == 0) ? "00" : "30") + " __"; label44.Text = ((timescale[43] / 100 < 10) ? ("0" + (timescale[43] / 100).ToString()) : (timescale[43] / 100).ToString()) + ":" + ((timescale[43] % 100 == 0) ? "00" : "30") + " __"; label45.Text = ((timescale[44] / 100 < 10) ? ("0" + (timescale[44] / 100).ToString()) : (timescale[44] / 100).ToString()) + ":" + ((timescale[44] % 100 == 0) ? "00" : "30") + " __"; label46.Text = ((timescale[45] / 100 < 10) ? ("0" + (timescale[45] / 100).ToString()) : (timescale[45] / 100).ToString()) + ":" + ((timescale[45] % 100 == 0) ? "00" : "30") + " __"; label47.Text = ((timescale[46] / 100 < 10) ? ("0" + (timescale[46] / 100).ToString()) : (timescale[46] / 100).ToString()) + ":" + ((timescale[46] % 100 == 0) ? "00" : "30") + " __"; label48.Text = ((timescale[47] / 100 < 10) ? ("0" + (timescale[47] / 100).ToString()) : (timescale[47] / 100).ToString()) + ":" + ((timescale[47] % 100 == 0) ? "00" : "30") + " __"; label49.Text = ((timescale[0] / 100 < 10) ? ("0" + (timescale[0] / 100).ToString()) : (timescale[0] / 100).ToString()) + ":" + ((timescale[0] % 100 == 0) ? "00" : "30") + " __"; }
private void Timer_Tick(object sender, EventArgs e) { foreach (EPlan p in EPlanDictionary.GetInstance().GetList()) { if (p.state == true) { int sec = (int)(DateTime.Now - p.startT.Last() + p.lastT).TotalSeconds; if (sec < 60) { timeHour.Text = "00"; timeMin.Text = "00"; if (sec < 10) { timeSec.Text = "0" + sec.ToString(); } else { timeSec.Text = sec.ToString(); } } else if (sec < 3600) { int min = sec / 60; int s = (sec - min * 60); timeHour.Text = "00"; if (min < 10) { timeMin.Text = "0" + min.ToString(); } else { timeMin.Text = min.ToString(); } if (sec < 10) { timeSec.Text = "0" + sec.ToString(); } else { timeSec.Text = sec.ToString(); } } else { int h = sec / 3600; int min = (sec - 3600 * h) / 60; int s = (sec - min * 60 - h * 3600); if (h < 10) { timeHour.Text = "0" + h.ToString(); } else { timeHour.Text = h.ToString(); } if (min < 10) { timeMin.Text = "0" + min.ToString(); } else { timeMin.Text = min.ToString(); } if (sec < 10) { timeSec.Text = "0" + sec.ToString(); } else { timeSec.Text = sec.ToString(); } } if (sec <= 9000) { if (sec == 600 || sec == 1200 || sec == 1800 || sec == 2400 || sec == 3000 || sec == 3600 || sec == 4200 || sec == 4800 || sec == 5400 || sec == 6000 || sec == 6600 || sec == 7200 || sec == 7800 || sec == 8400 || sec == 9000) { p.progress += 1; toolStripProgressBar1.Value = (p.progress < 100) ? p.progress : 100; toolStripLabel5.Text = p.progress.ToString() + '%'; } } } } }
private static void LoadTodoList() { try { PopularityCal.Calculator(); } catch (Exception ex) { Logger.WriteLogs("Load PopularityCal Error: " + ex.Message); } try { float totalWorkHour = 0; Dictionary <long, int> popDic = new Dictionary <long, int>(); Dictionary <long, int> sortedPopDic = new Dictionary <long, int>(); foreach (Model.Elements.Task t in TaskDictionary.GetInstance().GetList()) { if (!t.state) { popDic.Add(t.id, t.popularity); } } sortedPopDic = popDic.OrderBy(o => o.Value).ToDictionary(o => o.Key, p => p.Value); foreach (KeyValuePair <long, int> kvp in sortedPopDic) { if (kvp.Value == 0) { Dictionary <int, long> staskDic = new Dictionary <int, long>(); foreach (long l in TaskDictionary.GetInstance().find(kvp.Key).staskID) { if (!STaskDictionary.GetInstance().find(l).state) { staskDic.Add(STaskDictionary.GetInstance().find(l).order, l); } } Dictionary <int, long> sortedStaskDic = staskDic.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value); Dictionary <int, long> subtaskDic = new Dictionary <int, long>(); foreach (long l in STaskDictionary.GetInstance().find(sortedStaskDic.First().Value).subtaskID) { if (!SubTaskDictionary.GetInstance().find(l).state) { subtaskDic.Add(SubTaskDictionary.GetInstance().find(l).order, l); } } Dictionary <int, long> sortedSubtaskDic = subtaskDic.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value); SubTaskDictionary.GetInstance().find(sortedSubtaskDic.First().Value).ready = true; if (SubTaskDictionary.GetInstance().find(sortedSubtaskDic.First().Value).expecLastT == null) { totalWorkHour += 1; } else { totalWorkHour += SubTaskDictionary.GetInstance().find(sortedSubtaskDic.First().Value).expecLastT.Hours; } } } Dictionary <long, int> revSortedPopDic = sortedPopDic.Reverse().ToDictionary(o => o.Key, p => p.Value); int maxNum = 0; while (totalWorkHour < 16) { int forN = 0; foreach (KeyValuePair <long, int> kvp in revSortedPopDic) { if (kvp.Value != 0) { Dictionary <int, long> staskDic = new Dictionary <int, long>(); foreach (long l in TaskDictionary.GetInstance().find(kvp.Key).staskID) { if (!STaskDictionary.GetInstance().find(l).state) { staskDic.Add(STaskDictionary.GetInstance().find(l).order, l); } } Dictionary <int, long> sortedStaskDic = staskDic.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value); Dictionary <int, long> subtaskDic = new Dictionary <int, long>(); foreach (long l in STaskDictionary.GetInstance().find(sortedStaskDic.First().Value).subtaskID) { if (!SubTaskDictionary.GetInstance().find(l).state && !SubTaskDictionary.GetInstance().find(l).ready) { subtaskDic.Add(SubTaskDictionary.GetInstance().find(l).order, l); } } Dictionary <int, long> sortedSubtaskDic = subtaskDic.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value); SubTaskDictionary.GetInstance().find(sortedSubtaskDic.First().Value).ready = true; if (SubTaskDictionary.GetInstance().find(sortedSubtaskDic.First().Value).expecLastT == null) { totalWorkHour += 1; } else { totalWorkHour += SubTaskDictionary.GetInstance().find(sortedSubtaskDic.First().Value).expecLastT.Hours; } } forN += 1; if (forN > maxNum) { break; } } maxNum += 1; if (maxNum > 24) { break; } } foreach (SubTask st in SubTaskDictionary.GetInstance().GetList()) { EPlan ep = new EPlan(); ep.name = st.name; ep.id = st.id; ep.finalT = st.finalT; ep.lastT = st.lastT; ep.showT = st.showT; ep.startF = st.startF; ep.stopF = st.stopF; ep.startT = st.startT; ep.stopT = st.stopT; EPlanDictionary.GetInstance().Add(ep); } } catch (Exception ex) { Logger.WriteLogs("Load TodoList Error: " + ex.Message); } }