public void loadTime(string path) { if (File.Exists(path)) { timers.Clear(); string[] lines = File.ReadAllLines(path); for (int i = 0; i < lines.Length; i++) { TimeSpot timeObj = new TimeSpot(); string str = lines[i]; if (str.Contains("#")) { string[] strs = str.Split(separator, 2); timeObj.timePosition = Int64.Parse(strs[0]); timeObj.comment = strs[1]; } else { timeObj.timePosition = Int64.Parse(lines[i]); } if (lines[i].Trim() != "") { timers.Add(timeObj); } } } }
private void button2_Click(object sender, EventArgs e) { TimeSpot timeObj = new TimeSpot(); timeObj.timePosition = SystemClock; timers.Add(timeObj); saveTime(tempFilename); }
private void mnuRecordTimeComment_Click(object sender, EventArgs e) { bool tmp = this.TopMost; this.TopMost = false; bool paused = IsPaused; bool haveTime = timers.Count > 0; if (!haveTime) { errorSound.Play();; MessageBox.Show("尚未开始计时"); return; } if (!paused) { TimeSpot timeObj = new TimeSpot(); timeObj.timePosition = SystemClock; timers.Add(timeObj); } else { TimeSpot timeObj = new TimeSpot(); timeObj.timePosition = SystemClock; timers.Add(timeObj); timeObj = new TimeSpot(); timeObj.timePosition = SystemClock; timers.Add(timeObj); } string msg; InputBox ipb = new InputBox(this); if (ipb.GetInput(out msg) == DialogResult.OK) { (timers[timers.Count - 1]).comment = msg; } ipb.Dispose(); if (!paused) { TimeSpot timeObj = new TimeSpot(); timeObj.timePosition = SystemClock; timers.Add(timeObj); } saveTime(tempFilename); this.TopMost = tmp; }
public void saveTime(string path) { StringBuilder sbuilder = new StringBuilder(); for (int i = 0; i < timers.Count; i++) { TimeSpot timeObj = timers[i]; sbuilder.Append(timeObj.timePosition); if (null != timeObj.comment && "" != timeObj.comment) { sbuilder.Append("#").Append(timeObj.comment); } if (i < timers.Count - 1) { sbuilder.Append("\n"); } } File.WriteAllText(path, sbuilder.ToString()); }