public static MemorialDayCollection Load(string path) { MemorialDayCollection memorialDays = new MemorialDayCollection(); try { using (FileStream data = new FileStream(path, FileMode.OpenOrCreate)) { if (data.Length == 0) { throw new Exception("Bad File"); } BinaryReader br = new BinaryReader(data); uint count = br.ReadUInt32(); for (int i = 0; i < count; i++) { UInt32 y = br.ReadUInt32(); UInt32 m = br.ReadUInt32(); UInt32 w = br.ReadUInt32(); UInt32 d = br.ReadUInt32(); memorialDays.Add(new MemorialDay(y, m, d, br.ReadString(), br.ReadString(), br.ReadString())); } } } catch (Exception e) { MessageBox.Show(e.Message + "\n\n加载纪念日数据失败。", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(memorialDays); }
public Anniversary(IServiceProvider Services) : base(Services) { Content.RootDirectory = "./Plugin/Anniversary/Data"; licon = Image.FromFile("./Plugin/Anniversary/Data/Image/licon.png"); micon = Image.FromFile("./Plugin/Anniversary/Data/Image/micon.png"); sicon = Image.FromFile("./Plugin/Anniversary/Data/Image/sicon.png"); memorialDays = MemorialDayAccessor.Load(MemorialDaysDataPath); CreateMenu(); InitializeLayoutEngine(); InitializeCalendar(); }
public static void SaveMemorialDaysData(MemorialDayCollection memorialDays, string path) { using (FileStream data = new FileStream("./Plugin/Anniversary/md.dat", FileMode.Create)) { BinaryWriter bw = new BinaryWriter(data); bw.Write((UInt32)memorialDays.Count); foreach (MemorialDay md in memorialDays) { bw.Write((UInt32)md.Date.Year); bw.Write((UInt32)md.Date.Month); bw.Write((UInt32)(md.Date.Week.HasValue ? md.Date.Week.Value : uint.MaxValue)); bw.Write((UInt32)md.Date.Day); bw.Write(md.Title); bw.Write(md.Description); bw.Write(md.ImagePath); } } }
public AnniversaryCalendar(MemorialDayCollection mdays) { InitializeComponent(); //MDayDescTip.IsBalloon = true; MDayDescTip.UseFading = true; MDayDescTip.UseAnimation = true; updateMDayForm = new MemorialDayViewer(); updateMDayForm.MemorialDays = mdays; memorialDays = mdays; CurrentYear = (uint)DateTime.Today.Year; CurrentMonth = (uint)DateTime.Today.Month; stringFormat = new StringFormat(); stringFormat.LineAlignment = StringAlignment.Center; stringFormat.Alignment = StringAlignment.Center; MouseDown += new MouseEventHandler(AnniversaryCalendar_MouseDown); MouseMove += new MouseEventHandler(AnniversaryCalendar_MouseMove); MouseUp += new MouseEventHandler(AnniversaryCalendar_MouseUp); }