private void LoadData() { string path = Application.StartupPath + "\\info.txt"; if (!File.Exists(path)) { return; } StreamReader reader = new StreamReader(path); string line; while ((line = reader.ReadLine()) != null) { string[] items = line.Split('\t'); AlarmData data = new AlarmData(); data.Name = items[0]; data.Type = (AlarmType)Enum.Parse(typeof(AlarmType), items[1]); if (data.Type == AlarmType.Weekly) { data.Day = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), items[2]); } else { data.Date = Convert.ToInt32(items[2]); } _dataList.Add(data); } reader.Close(); UpdateListView(); }
private void Save(string name, int type, object day) { AlarmData data = new AlarmData(); data.Name = name; data.Type = type == 0 ? AlarmType.Weekly : AlarmType.Monthly; if (data.Type == AlarmType.Weekly) { data.Day = (DayOfWeek)day; } else { data.Date = (int)day; } _dataList.Add(data); WriteToFile(); }