初步完成
This commit is contained in:
		
							parent
							
								
									82bef73c4c
								
							
						
					
					
						commit
						10da0285c1
					
				@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
 | 
			
		||||
# Visual Studio Version 17
 | 
			
		||||
VisualStudioVersion = 17.6.33829.357
 | 
			
		||||
MinimumVisualStudioVersion = 10.0.40219.1
 | 
			
		||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CalendarNotepad", "CalendarNotepad\CalendarNotepad.csproj", "{875F30C8-8B0B-43B6-A4A4-4ED9870E2021}"
 | 
			
		||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CalendarNotepad", "CalendarNotepad\CalendarNotepad.csproj", "{875F30C8-8B0B-43B6-A4A4-4ED9870E2021}"
 | 
			
		||||
EndProject
 | 
			
		||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharkingTest", "SharkingTest\SharkingTest.csproj", "{60DC4219-39A6-4B9B-9172-934C3427E859}"
 | 
			
		||||
EndProject
 | 
			
		||||
Global
 | 
			
		||||
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 | 
			
		||||
@ -15,6 +17,10 @@ Global
 | 
			
		||||
		{875F30C8-8B0B-43B6-A4A4-4ED9870E2021}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{875F30C8-8B0B-43B6-A4A4-4ED9870E2021}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{875F30C8-8B0B-43B6-A4A4-4ED9870E2021}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
		{60DC4219-39A6-4B9B-9172-934C3427E859}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
			
		||||
		{60DC4219-39A6-4B9B-9172-934C3427E859}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{60DC4219-39A6-4B9B-9172-934C3427E859}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{60DC4219-39A6-4B9B-9172-934C3427E859}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
	EndGlobalSection
 | 
			
		||||
	GlobalSection(SolutionProperties) = preSolution
 | 
			
		||||
		HideSolutionNode = FALSE
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										6
									
								
								CalendarNotepad/App.config
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								CalendarNotepad/App.config
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,6 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8" ?>
 | 
			
		||||
<configuration>
 | 
			
		||||
	<appSettings>
 | 
			
		||||
		<add key="saveFileName" value="data.db"/>
 | 
			
		||||
	</appSettings>
 | 
			
		||||
</configuration>
 | 
			
		||||
							
								
								
									
										92
									
								
								CalendarNotepad/Extends/Shaking.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								CalendarNotepad/Extends/Shaking.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,92 @@
 | 
			
		||||
 | 
			
		||||
namespace CalendarNotepad.Extends
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 防止抖动执行任务
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class Shaking:IDisposable
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 下一个要执行的任务
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        protected Task? Next { get; set; }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 执行计时器
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        protected System.Timers.Timer Timer { get; set; }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 等待执行时间
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public int TimespanSeconds { get; set; }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 使用默认方式实例化
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public Shaking() : this(5) { }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 实例化,默认抖动执行间隔5秒
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="timeSpanSeconds">抖动执行时间间隔。秒</param>
 | 
			
		||||
        public Shaking(int timeSpanSeconds) {
 | 
			
		||||
            this.TimespanSeconds = timeSpanSeconds * 1000;
 | 
			
		||||
            this.Timer = new System.Timers.Timer {
 | 
			
		||||
                Interval = this.TimespanSeconds
 | 
			
		||||
            };
 | 
			
		||||
            this.Timer.Elapsed += Timer_Tick;
 | 
			
		||||
            this.Timer.Stop();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        protected void Timer_Tick(object? sender,EventArgs e) {
 | 
			
		||||
            this.Timer.Stop();
 | 
			
		||||
            this.Timer.Dispose();
 | 
			
		||||
            if(this.Next == null) {
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            var n = this.Next;
 | 
			
		||||
            this.Next = null;
 | 
			
		||||
            n.Start();
 | 
			
		||||
        }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 防抖执行任务
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="task">要执行的任务</param>
 | 
			
		||||
        public void Run(Task task) {
 | 
			
		||||
            this.Next = task;
 | 
			
		||||
            if(this.Timer != null) {
 | 
			
		||||
                this.Timer.Stop();
 | 
			
		||||
                this.Timer.Dispose();
 | 
			
		||||
            }
 | 
			
		||||
            this.Timer = new System.Timers.Timer {
 | 
			
		||||
                Interval = this.TimespanSeconds,
 | 
			
		||||
            };
 | 
			
		||||
            this.Timer.Elapsed += Timer_Tick;
 | 
			
		||||
            this.Timer.Start();
 | 
			
		||||
        }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 防抖执行委托
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="action">要执行的委托</param>
 | 
			
		||||
        public void Run(Action action) => Run(new Task(action));
 | 
			
		||||
 | 
			
		||||
        public void Dispose() {
 | 
			
		||||
            if(this.Timer != null) {
 | 
			
		||||
                this.Timer.Stop();
 | 
			
		||||
                this.Timer.Dispose();
 | 
			
		||||
            }
 | 
			
		||||
            this.Next = null;
 | 
			
		||||
            GC.SuppressFinalize(this);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void RunNow() {
 | 
			
		||||
            var n = this.Next;
 | 
			
		||||
            this.Next = null;
 | 
			
		||||
            if(n == null) {
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            if(this.Timer != null) {
 | 
			
		||||
                this.Timer.Stop();
 | 
			
		||||
                this.Timer.Dispose();
 | 
			
		||||
            }
 | 
			
		||||
            n.Start();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										9
									
								
								CalendarNotepad/Extends/StringExtend.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								CalendarNotepad/Extends/StringExtend.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
			
		||||
namespace CalendarNotepad.Extends
 | 
			
		||||
{
 | 
			
		||||
    public static class StringExtend
 | 
			
		||||
    {
 | 
			
		||||
        public static bool IsNullOrEmpty(this string? str) => str == null || string.IsNullOrEmpty(str);
 | 
			
		||||
 | 
			
		||||
        public static bool IsNotNullOrEmpty(this string? str) => !str.IsNullOrEmpty();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										62
									
								
								CalendarNotepad/Extends/ZipExtend.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								CalendarNotepad/Extends/ZipExtend.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,62 @@
 | 
			
		||||
using CalendarNotepad.Models;
 | 
			
		||||
using System.IO.Compression;
 | 
			
		||||
using System.Text;
 | 
			
		||||
 | 
			
		||||
namespace CalendarNotepad.Extends
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 压缩文件帮助类
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public static class ZipExtend
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 压缩文件名
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public static string ZipFileName { get; set; } = CNOptions.GetSaveFileName;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 某个文件保存到压缩文件内
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="str">内容</param>
 | 
			
		||||
        /// <param name="entryName">压缩文件内容文件名</param>
 | 
			
		||||
        public static void SaveToFile(string str,string entryName) {
 | 
			
		||||
            using var fs = new FileStream(ZipFileName,FileMode.OpenOrCreate);
 | 
			
		||||
            using var archive = new ZipArchive(fs,ZipArchiveMode.Create);
 | 
			
		||||
            var entry = archive.CreateEntry(entryName);
 | 
			
		||||
            using var es = entry.Open();
 | 
			
		||||
            using var sw = new StreamWriter(es,Encoding.UTF8);
 | 
			
		||||
            sw.Write(str);
 | 
			
		||||
            sw.Flush();
 | 
			
		||||
        }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 读取压缩文件中文件内容
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="entryName">压缩文件内容文件名</param>
 | 
			
		||||
        /// <returns>内容</returns>
 | 
			
		||||
        public static string GetFormFile(string entryName) {
 | 
			
		||||
            if(!File.Exists(ZipFileName)) {
 | 
			
		||||
                ZipFile.Open(ZipFileName,ZipArchiveMode.Create).Dispose();
 | 
			
		||||
                return "";
 | 
			
		||||
            }
 | 
			
		||||
            using var zipfile = ZipFile.OpenRead(ZipFileName);
 | 
			
		||||
            var entry = zipfile.GetEntry(entryName);
 | 
			
		||||
            if(entry == null) {
 | 
			
		||||
                return "";
 | 
			
		||||
            }
 | 
			
		||||
            var st = entry.Open();
 | 
			
		||||
            var sr = new StreamReader(st,Encoding.UTF8);
 | 
			
		||||
            var str = sr.ReadToEnd();
 | 
			
		||||
            return str;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 获取压缩库中所有文件名
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <returns>文件名列表</returns>
 | 
			
		||||
        public static IEnumerable<string> GetFiles() {
 | 
			
		||||
            using var zipfile = ZipFile.OpenRead(ZipFileName);
 | 
			
		||||
            foreach(var en in zipfile.Entries) {
 | 
			
		||||
                yield return en.Name;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										111
									
								
								CalendarNotepad/Form1.Designer.cs
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										111
									
								
								CalendarNotepad/Form1.Designer.cs
									
									
									
										generated
									
									
									
								
							@ -1,111 +0,0 @@
 | 
			
		||||
namespace CalendarNotepad
 | 
			
		||||
{
 | 
			
		||||
    partial class Form1
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        ///  Required designer variable.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        private System.ComponentModel.IContainer components = null;
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        ///  Clean up any resources being used.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
 | 
			
		||||
        protected override void Dispose(bool disposing) {
 | 
			
		||||
            if(disposing && (components != null)) {
 | 
			
		||||
                components.Dispose();
 | 
			
		||||
            }
 | 
			
		||||
            base.Dispose(disposing);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #region Windows Form Designer generated code
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        ///  Required method for Designer support - do not modify
 | 
			
		||||
        ///  the contents of this method with the code editor.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        private void InitializeComponent() {
 | 
			
		||||
            toolStrip1 = new ToolStrip();
 | 
			
		||||
            tscbYear = new ToolStripComboBox();
 | 
			
		||||
            tscbMonth = new ToolStripComboBox();
 | 
			
		||||
            tabPanel = new TableLayoutPanel();
 | 
			
		||||
            label1 = new Label();
 | 
			
		||||
            toolStrip1.SuspendLayout();
 | 
			
		||||
            tabPanel.SuspendLayout();
 | 
			
		||||
            SuspendLayout();
 | 
			
		||||
            // 
 | 
			
		||||
            // toolStrip1
 | 
			
		||||
            // 
 | 
			
		||||
            toolStrip1.Items.AddRange(new ToolStripItem[] { tscbYear,tscbMonth });
 | 
			
		||||
            toolStrip1.Location = new Point(0,0);
 | 
			
		||||
            toolStrip1.Name = "toolStrip1";
 | 
			
		||||
            toolStrip1.Size = new Size(465,25);
 | 
			
		||||
            toolStrip1.TabIndex = 0;
 | 
			
		||||
            toolStrip1.Text = "toolStrip1";
 | 
			
		||||
            // 
 | 
			
		||||
            // tscbYear
 | 
			
		||||
            // 
 | 
			
		||||
            tscbYear.DropDownStyle = ComboBoxStyle.DropDownList;
 | 
			
		||||
            tscbYear.Items.AddRange(new object[] { "2024","2025" });
 | 
			
		||||
            tscbYear.Name = "tscbYear";
 | 
			
		||||
            tscbYear.Size = new Size(121,25);
 | 
			
		||||
            // 
 | 
			
		||||
            // tscbMonth
 | 
			
		||||
            // 
 | 
			
		||||
            tscbMonth.DropDownStyle = ComboBoxStyle.DropDownList;
 | 
			
		||||
            tscbMonth.Name = "tscbMonth";
 | 
			
		||||
            tscbMonth.Size = new Size(121,25);
 | 
			
		||||
            // 
 | 
			
		||||
            // tabPanel
 | 
			
		||||
            // 
 | 
			
		||||
            tabPanel.CellBorderStyle = TableLayoutPanelCellBorderStyle.InsetDouble;
 | 
			
		||||
            tabPanel.ColumnCount = 2;
 | 
			
		||||
            tabPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent,50F));
 | 
			
		||||
            tabPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent,50F));
 | 
			
		||||
            tabPanel.Controls.Add(label1,1,0);
 | 
			
		||||
            tabPanel.Dock = DockStyle.Fill;
 | 
			
		||||
            tabPanel.Location = new Point(0,25);
 | 
			
		||||
            tabPanel.Name = "tabPanel";
 | 
			
		||||
            tabPanel.Padding = new Padding(10);
 | 
			
		||||
            tabPanel.RowCount = 2;
 | 
			
		||||
            tabPanel.RowStyles.Add(new RowStyle(SizeType.Percent,50F));
 | 
			
		||||
            tabPanel.RowStyles.Add(new RowStyle(SizeType.Percent,50F));
 | 
			
		||||
            tabPanel.Size = new Size(465,225);
 | 
			
		||||
            tabPanel.TabIndex = 1;
 | 
			
		||||
            // 
 | 
			
		||||
            // label1
 | 
			
		||||
            // 
 | 
			
		||||
            label1.AutoSize = true;
 | 
			
		||||
            label1.Location = new Point(237,13);
 | 
			
		||||
            label1.Name = "label1";
 | 
			
		||||
            label1.Size = new Size(15,17);
 | 
			
		||||
            label1.TabIndex = 0;
 | 
			
		||||
            label1.Text = "1";
 | 
			
		||||
            // 
 | 
			
		||||
            // Form1
 | 
			
		||||
            // 
 | 
			
		||||
            AutoScaleDimensions = new SizeF(7F,17F);
 | 
			
		||||
            AutoScaleMode = AutoScaleMode.Font;
 | 
			
		||||
            ClientSize = new Size(465,250);
 | 
			
		||||
            Controls.Add(tabPanel);
 | 
			
		||||
            Controls.Add(toolStrip1);
 | 
			
		||||
            Name = "Form1";
 | 
			
		||||
            Text = "Form1";
 | 
			
		||||
            Load += Form1_Load;
 | 
			
		||||
            toolStrip1.ResumeLayout(false);
 | 
			
		||||
            toolStrip1.PerformLayout();
 | 
			
		||||
            tabPanel.ResumeLayout(false);
 | 
			
		||||
            tabPanel.PerformLayout();
 | 
			
		||||
            ResumeLayout(false);
 | 
			
		||||
            PerformLayout();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        private ToolStrip toolStrip1;
 | 
			
		||||
        private ToolStripComboBox tscbYear;
 | 
			
		||||
        private ToolStripComboBox tscbMonth;
 | 
			
		||||
        private TableLayoutPanel tabPanel;
 | 
			
		||||
        private Label label1;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -1,41 +0,0 @@
 | 
			
		||||
namespace CalendarNotepad
 | 
			
		||||
{
 | 
			
		||||
    public partial class Form1:Form
 | 
			
		||||
    {
 | 
			
		||||
        public Form1() {
 | 
			
		||||
            InitializeComponent();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void Form1_Load(object sender,EventArgs e) {
 | 
			
		||||
            var year1 = 2024;
 | 
			
		||||
            do {
 | 
			
		||||
                this.tscbYear.Items.Add(year1);
 | 
			
		||||
                year1++;
 | 
			
		||||
            } while(year1 > DateTime.Now.Year + 1);
 | 
			
		||||
            this.tscbYear.Text = DateTime.Now.Year.ToString();
 | 
			
		||||
            for(int i = 0;i < 12;i++) {
 | 
			
		||||
                this.tscbMonth.Items.Add((i + 1) + "ÔÂ");
 | 
			
		||||
            }
 | 
			
		||||
            this.tscbMonth.Text = DateTime.Now.Month.ToString() + "ÔÂ";
 | 
			
		||||
 | 
			
		||||
            this.tabPanel.RowStyles.Clear();
 | 
			
		||||
            this.tabPanel.ColumnStyles.Clear();
 | 
			
		||||
            this.tabPanel.RowCount = 7;
 | 
			
		||||
            this.tabPanel.ColumnCount = 7;
 | 
			
		||||
            for(int i = 0;i < 7;i++) {
 | 
			
		||||
                this.tabPanel.RowStyles.Add(new RowStyle(SizeType.Percent,100 / 7));
 | 
			
		||||
                this.tabPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent,100 / 7));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            this.tabPanel.Controls.Clear();
 | 
			
		||||
            int d = 1;
 | 
			
		||||
            for(int x = 0;x < 7;x++) {
 | 
			
		||||
                for(int y = 0;y < 7;y++) {
 | 
			
		||||
                    var lab = new Label();
 | 
			
		||||
                    lab.Text = d++.ToString();
 | 
			
		||||
                    this.tabPanel.Controls.Add(lab,y,x);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										170
									
								
								CalendarNotepad/Main.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										170
									
								
								CalendarNotepad/Main.Designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							@ -0,0 +1,170 @@
 | 
			
		||||
namespace CalendarNotepad
 | 
			
		||||
{
 | 
			
		||||
    partial class Main
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Required designer variable.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        private System.ComponentModel.IContainer components = null;
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Clean up any resources being used.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
 | 
			
		||||
        protected override void Dispose(bool disposing) {
 | 
			
		||||
            if(disposing && (components != null)) {
 | 
			
		||||
                components.Dispose();
 | 
			
		||||
            }
 | 
			
		||||
            base.Dispose(disposing);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #region Windows Form Designer generated code
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Required method for Designer support - do not modify
 | 
			
		||||
        /// the contents of this method with the code editor.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        private void InitializeComponent() {
 | 
			
		||||
            mcWorkDay = new MonthCalendar();
 | 
			
		||||
            splitContainer1 = new SplitContainer();
 | 
			
		||||
            groupBox1 = new GroupBox();
 | 
			
		||||
            rbAllDay = new RadioButton();
 | 
			
		||||
            rbAfternoon = new RadioButton();
 | 
			
		||||
            rbMorning = new RadioButton();
 | 
			
		||||
            label1 = new Label();
 | 
			
		||||
            rtbMsg = new RichTextBox();
 | 
			
		||||
            ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit();
 | 
			
		||||
            splitContainer1.Panel1.SuspendLayout();
 | 
			
		||||
            splitContainer1.Panel2.SuspendLayout();
 | 
			
		||||
            splitContainer1.SuspendLayout();
 | 
			
		||||
            groupBox1.SuspendLayout();
 | 
			
		||||
            SuspendLayout();
 | 
			
		||||
            // 
 | 
			
		||||
            // mcWorkDay
 | 
			
		||||
            // 
 | 
			
		||||
            mcWorkDay.FirstDayOfWeek = Day.Monday;
 | 
			
		||||
            mcWorkDay.Location = new Point(9,9);
 | 
			
		||||
            mcWorkDay.MaxSelectionCount = 1;
 | 
			
		||||
            mcWorkDay.MinDate = new DateTime(2000,1,1,0,0,0,0);
 | 
			
		||||
            mcWorkDay.Name = "mcWorkDay";
 | 
			
		||||
            mcWorkDay.ShowTodayCircle = false;
 | 
			
		||||
            mcWorkDay.TabIndex = 0;
 | 
			
		||||
            mcWorkDay.DateChanged += monthCalendar1_DateChanged;
 | 
			
		||||
            mcWorkDay.DateSelected += monthCalendar1_DateSelected;
 | 
			
		||||
            // 
 | 
			
		||||
            // splitContainer1
 | 
			
		||||
            // 
 | 
			
		||||
            splitContainer1.Dock = DockStyle.Fill;
 | 
			
		||||
            splitContainer1.FixedPanel = FixedPanel.Panel1;
 | 
			
		||||
            splitContainer1.Location = new Point(0,0);
 | 
			
		||||
            splitContainer1.Name = "splitContainer1";
 | 
			
		||||
            // 
 | 
			
		||||
            // splitContainer1.Panel1
 | 
			
		||||
            // 
 | 
			
		||||
            splitContainer1.Panel1.Controls.Add(groupBox1);
 | 
			
		||||
            splitContainer1.Panel1.Controls.Add(mcWorkDay);
 | 
			
		||||
            // 
 | 
			
		||||
            // splitContainer1.Panel2
 | 
			
		||||
            // 
 | 
			
		||||
            splitContainer1.Panel2.Controls.Add(label1);
 | 
			
		||||
            splitContainer1.Panel2.Controls.Add(rtbMsg);
 | 
			
		||||
            splitContainer1.Size = new Size(642,400);
 | 
			
		||||
            splitContainer1.SplitterDistance = 234;
 | 
			
		||||
            splitContainer1.TabIndex = 1;
 | 
			
		||||
            // 
 | 
			
		||||
            // groupBox1
 | 
			
		||||
            // 
 | 
			
		||||
            groupBox1.Controls.Add(rbAllDay);
 | 
			
		||||
            groupBox1.Controls.Add(rbAfternoon);
 | 
			
		||||
            groupBox1.Controls.Add(rbMorning);
 | 
			
		||||
            groupBox1.Location = new Point(12,201);
 | 
			
		||||
            groupBox1.Name = "groupBox1";
 | 
			
		||||
            groupBox1.Size = new Size(201,51);
 | 
			
		||||
            groupBox1.TabIndex = 5;
 | 
			
		||||
            groupBox1.TabStop = false;
 | 
			
		||||
            groupBox1.Text = "时间段";
 | 
			
		||||
            // 
 | 
			
		||||
            // rbAllDay
 | 
			
		||||
            // 
 | 
			
		||||
            rbAllDay.AutoSize = true;
 | 
			
		||||
            rbAllDay.Checked = true;
 | 
			
		||||
            rbAllDay.Location = new Point(6,22);
 | 
			
		||||
            rbAllDay.Name = "rbAllDay";
 | 
			
		||||
            rbAllDay.Size = new Size(50,21);
 | 
			
		||||
            rbAllDay.TabIndex = 1;
 | 
			
		||||
            rbAllDay.TabStop = true;
 | 
			
		||||
            rbAllDay.Text = "全天";
 | 
			
		||||
            rbAllDay.UseVisualStyleBackColor = true;
 | 
			
		||||
            // 
 | 
			
		||||
            // rbAfternoon
 | 
			
		||||
            // 
 | 
			
		||||
            rbAfternoon.AutoSize = true;
 | 
			
		||||
            rbAfternoon.Location = new Point(118,22);
 | 
			
		||||
            rbAfternoon.Name = "rbAfternoon";
 | 
			
		||||
            rbAfternoon.Size = new Size(50,21);
 | 
			
		||||
            rbAfternoon.TabIndex = 3;
 | 
			
		||||
            rbAfternoon.Text = "下午";
 | 
			
		||||
            rbAfternoon.UseVisualStyleBackColor = true;
 | 
			
		||||
            // 
 | 
			
		||||
            // rbMorning
 | 
			
		||||
            // 
 | 
			
		||||
            rbMorning.AutoSize = true;
 | 
			
		||||
            rbMorning.Location = new Point(62,22);
 | 
			
		||||
            rbMorning.Name = "rbMorning";
 | 
			
		||||
            rbMorning.Size = new Size(50,21);
 | 
			
		||||
            rbMorning.TabIndex = 2;
 | 
			
		||||
            rbMorning.Text = "上午";
 | 
			
		||||
            rbMorning.UseVisualStyleBackColor = true;
 | 
			
		||||
            // 
 | 
			
		||||
            // label1
 | 
			
		||||
            // 
 | 
			
		||||
            label1.AutoSize = true;
 | 
			
		||||
            label1.Location = new Point(3,9);
 | 
			
		||||
            label1.Name = "label1";
 | 
			
		||||
            label1.Size = new Size(56,17);
 | 
			
		||||
            label1.TabIndex = 1;
 | 
			
		||||
            label1.Text = "信息记录";
 | 
			
		||||
            // 
 | 
			
		||||
            // rtbMsg
 | 
			
		||||
            // 
 | 
			
		||||
            rtbMsg.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
 | 
			
		||||
            rtbMsg.EnableAutoDragDrop = true;
 | 
			
		||||
            rtbMsg.Location = new Point(3,35);
 | 
			
		||||
            rtbMsg.Name = "rtbMsg";
 | 
			
		||||
            rtbMsg.Size = new Size(389,353);
 | 
			
		||||
            rtbMsg.TabIndex = 0;
 | 
			
		||||
            rtbMsg.Text = "";
 | 
			
		||||
            rtbMsg.TextChanged += rtbMsg_TextChanged;
 | 
			
		||||
            // 
 | 
			
		||||
            // Main
 | 
			
		||||
            // 
 | 
			
		||||
            AutoScaleDimensions = new SizeF(7F,17F);
 | 
			
		||||
            AutoScaleMode = AutoScaleMode.Font;
 | 
			
		||||
            ClientSize = new Size(642,400);
 | 
			
		||||
            Controls.Add(splitContainer1);
 | 
			
		||||
            Name = "Main";
 | 
			
		||||
            Text = "工作记录";
 | 
			
		||||
            FormClosing += Main_FormClosing;
 | 
			
		||||
            Load += Main_Load;
 | 
			
		||||
            splitContainer1.Panel1.ResumeLayout(false);
 | 
			
		||||
            splitContainer1.Panel2.ResumeLayout(false);
 | 
			
		||||
            splitContainer1.Panel2.PerformLayout();
 | 
			
		||||
            ((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit();
 | 
			
		||||
            splitContainer1.ResumeLayout(false);
 | 
			
		||||
            groupBox1.ResumeLayout(false);
 | 
			
		||||
            groupBox1.PerformLayout();
 | 
			
		||||
            ResumeLayout(false);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        private MonthCalendar mcWorkDay;
 | 
			
		||||
        private SplitContainer splitContainer1;
 | 
			
		||||
        private RadioButton rbAllDay;
 | 
			
		||||
        private RadioButton rbAfternoon;
 | 
			
		||||
        private RadioButton rbMorning;
 | 
			
		||||
        private RichTextBox rtbMsg;
 | 
			
		||||
        private Label label1;
 | 
			
		||||
        private GroupBox groupBox1;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										87
									
								
								CalendarNotepad/Main.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								CalendarNotepad/Main.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,87 @@
 | 
			
		||||
using CalendarNotepad.Extends;
 | 
			
		||||
using CalendarNotepad.Models;
 | 
			
		||||
 | 
			
		||||
namespace CalendarNotepad
 | 
			
		||||
{
 | 
			
		||||
    public partial class Main:Form
 | 
			
		||||
    {
 | 
			
		||||
        public WorkContext Context { get; set; }
 | 
			
		||||
        public Shaking SaveFileShaking { get; set; } = new Shaking(5);
 | 
			
		||||
 | 
			
		||||
        public Main() {
 | 
			
		||||
            this.Context = new WorkContext();
 | 
			
		||||
 | 
			
		||||
            InitializeComponent();
 | 
			
		||||
 | 
			
		||||
            //this.Context.LoadFromFile();
 | 
			
		||||
            this.Context.GetWorkListFormZipFile();
 | 
			
		||||
            var today = DateTime.Now.ToString("yyyyMMdd");
 | 
			
		||||
            this.mcWorkDay.TodayDate = DateTime.Now;
 | 
			
		||||
            this.rbAllDay.Checked = true;
 | 
			
		||||
            var unit = this.Context.GetUnit(today,GetDateRange());
 | 
			
		||||
            this.rtbMsg.Text = unit.WorkMessage;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void monthCalendar1_DateChanged(object sender,DateRangeEventArgs e) {
 | 
			
		||||
            var selectedDate = e.Start.ToString("yyyyMMdd");
 | 
			
		||||
            var selectedRange = GetDateRange();
 | 
			
		||||
            var unit = this.Context.GetUnit(selectedDate,selectedRange);
 | 
			
		||||
            this.rtbMsg.Text = unit.WorkMessage;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void monthCalendar1_DateSelected(object sender,DateRangeEventArgs e) {
 | 
			
		||||
            //MessageBox.Show("monthCalendar1_DateSelected");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 返回当前选择的时间段
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <returns>时间段</returns>
 | 
			
		||||
        private string GetDateRange() =>
 | 
			
		||||
            this.rbAllDay.Checked ? "全天" :
 | 
			
		||||
            this.rbMorning.Checked ? "上午" :
 | 
			
		||||
            this.rbAfternoon.Checked ? "下午" :
 | 
			
		||||
            "";
 | 
			
		||||
 | 
			
		||||
        private void rtbMsg_TextChanged(object sender,EventArgs e) {
 | 
			
		||||
            var data = new WorkUnit {
 | 
			
		||||
                DayRange = GetDateRange(),
 | 
			
		||||
                WorkDay = this.mcWorkDay.SelectionStart.ToString("yyyyMMdd"),
 | 
			
		||||
                WorkMessage = this.rtbMsg.Text,
 | 
			
		||||
            };
 | 
			
		||||
            this.Context.AddOrReplace(data);
 | 
			
		||||
 | 
			
		||||
            //this.SaveFileShaking.Run(this.Context.SaveToFile);
 | 
			
		||||
            this.SaveFileShaking.Run(this.Context.SaveWorkListToZipFile);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void Main_FormClosing(object sender,FormClosingEventArgs e) {
 | 
			
		||||
            this.SaveFileShaking.RunNow();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void Main_Load(object sender,EventArgs e) {
 | 
			
		||||
            Task.Factory.StartNew(async () => {
 | 
			
		||||
                while(true) {
 | 
			
		||||
                    if(this.Context == null) {
 | 
			
		||||
                        continue;
 | 
			
		||||
                    }
 | 
			
		||||
                    var days = new List<DateTime>();
 | 
			
		||||
                    var curD = this.mcWorkDay.SelectionStart;
 | 
			
		||||
                    var year = curD.Year;
 | 
			
		||||
                    var month = curD.Month;
 | 
			
		||||
                    for(DateTime i = new DateTime(year,month,1);i.Month == curD.Month;i = i.AddDays(1)) {
 | 
			
		||||
                        var df = i.ToString("yyyyMMdd");
 | 
			
		||||
                        var m = this.Context.GetUnit(df,GetDateRange());
 | 
			
		||||
                        if(m.WorkMessage.IsNotNullOrEmpty()) {
 | 
			
		||||
                            days.Add(i);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    this.Invoke(() => {
 | 
			
		||||
                        this.mcWorkDay.BoldedDates = days.ToArray();
 | 
			
		||||
                    });
 | 
			
		||||
                    await Task.Delay(5 * 1000);
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -117,7 +117,40 @@
 | 
			
		||||
  <resheader name="writer">
 | 
			
		||||
    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
 | 
			
		||||
  </resheader>
 | 
			
		||||
  <metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
 | 
			
		||||
    <value>17, 17</value>
 | 
			
		||||
  <metadata name="mcWorkDay.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
 | 
			
		||||
    <value>True</value>
 | 
			
		||||
  </metadata>
 | 
			
		||||
  <metadata name="splitContainer1.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
 | 
			
		||||
    <value>True</value>
 | 
			
		||||
  </metadata>
 | 
			
		||||
  <metadata name="groupBox1.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
 | 
			
		||||
    <value>True</value>
 | 
			
		||||
  </metadata>
 | 
			
		||||
  <metadata name="rbAllDay.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
 | 
			
		||||
    <value>True</value>
 | 
			
		||||
  </metadata>
 | 
			
		||||
  <metadata name="rbAfternoon.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
 | 
			
		||||
    <value>True</value>
 | 
			
		||||
  </metadata>
 | 
			
		||||
  <metadata name="rbMorning.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
 | 
			
		||||
    <value>True</value>
 | 
			
		||||
  </metadata>
 | 
			
		||||
  <metadata name="label1.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
 | 
			
		||||
    <value>True</value>
 | 
			
		||||
  </metadata>
 | 
			
		||||
  <metadata name="rtbMsg.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
 | 
			
		||||
    <value>True</value>
 | 
			
		||||
  </metadata>
 | 
			
		||||
  <metadata name="rbAllDay.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
 | 
			
		||||
    <value>True</value>
 | 
			
		||||
  </metadata>
 | 
			
		||||
  <metadata name="rbAfternoon.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
 | 
			
		||||
    <value>True</value>
 | 
			
		||||
  </metadata>
 | 
			
		||||
  <metadata name="rbMorning.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
 | 
			
		||||
    <value>True</value>
 | 
			
		||||
  </metadata>
 | 
			
		||||
  <metadata name="$this.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
 | 
			
		||||
    <value>True</value>
 | 
			
		||||
  </metadata>
 | 
			
		||||
</root>
 | 
			
		||||
							
								
								
									
										23
									
								
								CalendarNotepad/Models/CNOptions.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								CalendarNotepad/Models/CNOptions.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,23 @@
 | 
			
		||||
using System.Configuration;
 | 
			
		||||
 | 
			
		||||
namespace CalendarNotepad.Models
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 应用配置
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public static class CNOptions
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 获取配置的值
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="key">键</param>
 | 
			
		||||
        /// <returns>值</returns>
 | 
			
		||||
        public static string? GetValue(string key) => ConfigurationManager.AppSettings[key];
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 保存的文件名
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public static string GetSaveFileName => GetValue("saveFileName") ?? "";
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										15
									
								
								CalendarNotepad/Models/SaveFileModel.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								CalendarNotepad/Models/SaveFileModel.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,15 @@
 | 
			
		||||
namespace CalendarNotepad.Models
 | 
			
		||||
{
 | 
			
		||||
    public class SaveFileModel
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 数据版本
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public int Ver { get; set; } = 1;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 工作列表
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public WorkUnitList WorkList { get; set; } = new WorkUnitList();
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										125
									
								
								CalendarNotepad/Models/WorkContext.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										125
									
								
								CalendarNotepad/Models/WorkContext.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,125 @@
 | 
			
		||||
using CalendarNotepad.Extends;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Text.Json;
 | 
			
		||||
using System.Text.Json.Nodes;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
namespace CalendarNotepad.Models
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 上下文
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class WorkContext
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 数据版本
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public int Ver { get; set; } = 1;
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 工作列表
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        private WorkUnitList WorkList { get; set; } = new WorkUnitList();
 | 
			
		||||
 | 
			
		||||
        private static object _lockObj = new object();
 | 
			
		||||
 | 
			
		||||
        public void AddOrReplace(WorkUnit unit) {
 | 
			
		||||
            lock(_lockObj) {
 | 
			
		||||
                var qu = this.WorkList.Where(a => a.WorkDay == unit.WorkDay && a.DayRange == unit.DayRange);
 | 
			
		||||
                if(qu.Any() && unit.WorkMessage.IsNullOrEmpty()) {
 | 
			
		||||
                    qu.ToList().ForEach(a => this.WorkList.Remove(a));
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
                if(qu.Any() && unit.WorkMessage.IsNotNullOrEmpty()) {
 | 
			
		||||
                    qu.ToList().ForEach(a => a.WorkMessage = unit.WorkMessage);
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
                if(!qu.Any() && unit.WorkMessage.IsNullOrEmpty()) {
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
                if(!qu.Any() && unit.WorkMessage.IsNotNullOrEmpty()) {
 | 
			
		||||
                    this.WorkList.Add(unit);
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 获取工作单元
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="workDay">工作日期</param>
 | 
			
		||||
        /// <param name="workRange">工作范围</param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public WorkUnit GetUnit(string workDay,string workRange) {
 | 
			
		||||
            var qu = this.WorkList.Where(a => a.WorkDay == workDay && a.DayRange == workRange);
 | 
			
		||||
            return qu.Any() ? qu.First() : new WorkUnit { DayRange = workRange,WorkDay = workDay,WorkMessage = "" };
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void SaveToFile() {
 | 
			
		||||
            var file = CNOptions.GetSaveFileName;
 | 
			
		||||
            if(file.IsNullOrEmpty()) {
 | 
			
		||||
                MessageBox.Show("没有配置数据保存文件!");
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            if(!Path.IsPathFullyQualified(file)) {
 | 
			
		||||
                file = Path.Combine(Application.StartupPath,file);
 | 
			
		||||
            }
 | 
			
		||||
            var path = Path.GetDirectoryName(file);
 | 
			
		||||
            if(!Directory.Exists(path)) {
 | 
			
		||||
                Directory.CreateDirectory(path);
 | 
			
		||||
            }
 | 
			
		||||
            if(File.Exists(file)) {
 | 
			
		||||
                File.Delete(file);
 | 
			
		||||
            }
 | 
			
		||||
            var jsonModel = new SaveFileModel {
 | 
			
		||||
                Ver = this.Ver,WorkList = this.WorkList,
 | 
			
		||||
            };
 | 
			
		||||
            var str = JsonSerializer.Serialize(jsonModel);
 | 
			
		||||
            File.WriteAllText(file,str,Encoding.UTF8);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void SaveWorkListToZipFile() {
 | 
			
		||||
            var str = JsonSerializer.Serialize(this.WorkList);
 | 
			
		||||
            ZipExtend.SaveToFile(str,"WorkContext.json");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void GetWorkListFormZipFile() {
 | 
			
		||||
            var str = ZipExtend.GetFormFile("WorkContext.json");
 | 
			
		||||
            if(str.IsNullOrEmpty()) {
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            this.WorkList = JsonSerializer.Deserialize<WorkUnitList>(str) ?? new WorkUnitList();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void LoadFromFile() {
 | 
			
		||||
            var file = CNOptions.GetSaveFileName;
 | 
			
		||||
            if(file.IsNullOrEmpty()) {
 | 
			
		||||
                MessageBox.Show("没有配置数据保存文件!");
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            if(!Path.IsPathFullyQualified(file)) {
 | 
			
		||||
                file = Path.Combine(Application.StartupPath,file);
 | 
			
		||||
            }
 | 
			
		||||
            if(!File.Exists(file)) {
 | 
			
		||||
                MessageBox.Show("没有找到数据文件!");
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            try {
 | 
			
		||||
                var str = File.ReadAllText(file);
 | 
			
		||||
                var obj = JsonSerializer.Deserialize<SaveFileModel>(str);
 | 
			
		||||
                if(obj == null) {
 | 
			
		||||
                    MessageBox.Show("保存数据格式错误!");
 | 
			
		||||
                }
 | 
			
		||||
                if(obj?.Ver == 1) {
 | 
			
		||||
                    this.WorkList = obj.WorkList;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            catch(Exception ex) {
 | 
			
		||||
                MessageBox.Show(ex.ToString());
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										21
									
								
								CalendarNotepad/Models/WorkUnit.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								CalendarNotepad/Models/WorkUnit.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,21 @@
 | 
			
		||||
namespace CalendarNotepad.Models
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 工作记录单元
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class WorkUnit
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 工作日期
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string? WorkDay { get; set; }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 时间段
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string? DayRange { get; set; }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 内容
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string? WorkMessage { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										7
									
								
								CalendarNotepad/Models/WorkUnitList.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								CalendarNotepad/Models/WorkUnitList.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,7 @@
 | 
			
		||||
namespace CalendarNotepad.Models
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 工作记录列表。不要直接使用此类,通过Workcontext进行操作
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class WorkUnitList:List<WorkUnit> { }
 | 
			
		||||
}
 | 
			
		||||
@ -10,7 +10,7 @@ namespace CalendarNotepad
 | 
			
		||||
            // To customize application configuration such as set high DPI settings or default font,
 | 
			
		||||
            // see https://aka.ms/applicationconfiguration.
 | 
			
		||||
            ApplicationConfiguration.Initialize();
 | 
			
		||||
            Application.Run(new Form1());
 | 
			
		||||
            Application.Run(new Main());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										23
									
								
								SharkingTest/Program.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								SharkingTest/Program.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,23 @@
 | 
			
		||||
// See https://aka.ms/new-console-template for more information
 | 
			
		||||
using CalendarNotepad.Extends;
 | 
			
		||||
 | 
			
		||||
Console.WriteLine("Hello, World!");
 | 
			
		||||
 | 
			
		||||
var showMsg = () => Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")} show message!");
 | 
			
		||||
 | 
			
		||||
var reMsg = () => $"{DateTime.Now.ToString("HH:mm:ss")} show message!";
 | 
			
		||||
 | 
			
		||||
var task = new Task<string>(reMsg);
 | 
			
		||||
 | 
			
		||||
var shaking = new Shaking(10);
 | 
			
		||||
 | 
			
		||||
//showMsg();
 | 
			
		||||
//await Task.Delay(5 * 1000);
 | 
			
		||||
//shaking.Run(showMsg);
 | 
			
		||||
 | 
			
		||||
shaking.Run(task);
 | 
			
		||||
shaking.Run(task);
 | 
			
		||||
Console.WriteLine(task.Result);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Console.ReadKey();
 | 
			
		||||
							
								
								
									
										70
									
								
								SharkingTest/Shaking.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								SharkingTest/Shaking.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,70 @@
 | 
			
		||||
 | 
			
		||||
namespace CalendarNotepad.Extends
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// 防止抖动执行任务
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class Shaking
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 下一个要执行的任务
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        protected Task? Next { get; set; }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 执行计时器
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        protected System.Timers.Timer Timer { get; set; }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 等待执行时间
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public int TimespanSeconds { get; set; }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 使用默认方式实例化
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public Shaking() : this(5) { }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 实例化,默认抖动执行间隔5秒
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="timeSpanSeconds">抖动执行时间间隔。秒</param>
 | 
			
		||||
        public Shaking(int timeSpanSeconds) {
 | 
			
		||||
            this.TimespanSeconds = timeSpanSeconds * 1000;
 | 
			
		||||
            this.Timer = new System.Timers.Timer {
 | 
			
		||||
                Interval = this.TimespanSeconds
 | 
			
		||||
            };
 | 
			
		||||
            this.Timer.Elapsed += Timer_Tick;
 | 
			
		||||
            this.Timer.Stop();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        protected void Timer_Tick(object? sender,EventArgs e) {
 | 
			
		||||
            this.Timer.Stop();
 | 
			
		||||
            this.Timer.Dispose();
 | 
			
		||||
            if(this.Next == null) {
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            var n = this.Next;
 | 
			
		||||
            this.Next = null;
 | 
			
		||||
            n.Start();
 | 
			
		||||
        }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 防抖执行任务
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="task">要执行的任务</param>
 | 
			
		||||
        public void Run(Task task) {
 | 
			
		||||
            this.Next = task;
 | 
			
		||||
            if(this.Timer != null) {
 | 
			
		||||
                this.Timer.Stop();
 | 
			
		||||
                this.Timer.Dispose();
 | 
			
		||||
            }
 | 
			
		||||
            this.Timer = new System.Timers.Timer {
 | 
			
		||||
                Interval = this.TimespanSeconds,
 | 
			
		||||
            };
 | 
			
		||||
            this.Timer.Elapsed += Timer_Tick;
 | 
			
		||||
            this.Timer.Start();
 | 
			
		||||
        }
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 防抖执行委托
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="action">要执行的委托</param>
 | 
			
		||||
        public void Run(Action action) => Run(new Task(action));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										10
									
								
								SharkingTest/SharkingTest.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								SharkingTest/SharkingTest.csproj
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,10 @@
 | 
			
		||||
<Project Sdk="Microsoft.NET.Sdk">
 | 
			
		||||
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <OutputType>Exe</OutputType>
 | 
			
		||||
    <TargetFramework>net6.0</TargetFramework>
 | 
			
		||||
    <ImplicitUsings>enable</ImplicitUsings>
 | 
			
		||||
    <Nullable>enable</Nullable>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
 | 
			
		||||
</Project>
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user