diff --git a/CalendarNotepad/App.config b/CalendarNotepad/App.config index 67f824c..544cd51 100644 --- a/CalendarNotepad/App.config +++ b/CalendarNotepad/App.config @@ -1,7 +1,6 @@  - \ No newline at end of file diff --git a/CalendarNotepad/Extends/AppConfig.cs b/CalendarNotepad/Extends/AppConfig.cs index 7e68f3c..1026edf 100644 --- a/CalendarNotepad/Extends/AppConfig.cs +++ b/CalendarNotepad/Extends/AppConfig.cs @@ -14,11 +14,6 @@ namespace CalendarNotepad.Extends /// 配置值,默认string.Empty public static string GetValue(string key) => ConfigurationManager.AppSettings[key] ?? string.Empty; - /// - /// 保存的文件名sqliteFile - /// - public static string GetSaveFileName => GetValue("saveFileName") ?? ""; - /// /// sqliteFile名 /// diff --git a/CalendarNotepad/Extends/ZipExtend.cs b/CalendarNotepad/Extends/ZipExtend.cs index 289db93..99e61a7 100644 --- a/CalendarNotepad/Extends/ZipExtend.cs +++ b/CalendarNotepad/Extends/ZipExtend.cs @@ -12,7 +12,7 @@ namespace CalendarNotepad.Extends /// /// 压缩文件名 /// - public static string ZipFileName { get; set; } = AppConfig.GetSaveFileName; + public static string ZipFileName { get; set; } = ""; /// /// 某个文件保存到压缩文件内 /// diff --git a/CalendarNotepad/Main.Designer.cs b/CalendarNotepad/Main.Designer.cs deleted file mode 100644 index 6b0a9ad..0000000 --- a/CalendarNotepad/Main.Designer.cs +++ /dev/null @@ -1,170 +0,0 @@ -namespace CalendarNotepad -{ - partial class Main - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) { - if(disposing && (components != null)) { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - 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; - } -} \ No newline at end of file diff --git a/CalendarNotepad/Main.cs b/CalendarNotepad/Main.cs deleted file mode 100644 index 616b726..0000000 --- a/CalendarNotepad/Main.cs +++ /dev/null @@ -1,86 +0,0 @@ -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"); - } - - /// - /// 返回当前选择的时间段 - /// - /// 时间段 - private string GetDateRange() => - this.rbAllDay.Checked ? "全天" : - this.rbMorning.Checked ? "上午" : - this.rbAfternoon.Checked ? "下午" : - ""; - - private void rtbMsg_TextChanged(object sender,EventArgs e) { - var data = new WorkUnit { - 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(); - 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); - } - }); - } - } -} diff --git a/CalendarNotepad/Main.resx b/CalendarNotepad/Main.resx deleted file mode 100644 index f51a8ab..0000000 --- a/CalendarNotepad/Main.resx +++ /dev/null @@ -1,156 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - - True - - \ No newline at end of file diff --git a/CalendarNotepad/Models/SaveFileModel.cs b/CalendarNotepad/Models/SaveFileModel.cs deleted file mode 100644 index cd161f3..0000000 --- a/CalendarNotepad/Models/SaveFileModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace CalendarNotepad.Models -{ - public class SaveFileModel - { - /// - /// 数据版本 - /// - public int Ver { get; set; } = 1; - /// - /// 工作列表 - /// - public WorkUnitList WorkList { get; set; } = new WorkUnitList(); - - } -} diff --git a/CalendarNotepad/Models/WorkContext.cs b/CalendarNotepad/Models/WorkContext.cs deleted file mode 100644 index 6141dce..0000000 --- a/CalendarNotepad/Models/WorkContext.cs +++ /dev/null @@ -1,125 +0,0 @@ -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 -{ - /// - /// 上下文 - /// - public class WorkContext - { - /// - /// 数据版本 - /// - public int Ver { get; set; } = 1; - /// - /// 工作列表 - /// - 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); - 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; - } - } - } - - /// - /// 获取工作单元 - /// - /// 工作日期 - /// 工作范围 - /// - public WorkUnit GetUnit(string workDay,string workRange) { - var qu = this.WorkList.Where(a => a.WorkDay == workDay); - return qu.Any() ? qu.First() : new WorkUnit { WorkDay = workDay,WorkMessage = "" }; - } - - public void SaveToFile() { - var file = AppConfig.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(str) ?? new WorkUnitList(); - } - - public void LoadFromFile() { - var file = AppConfig.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(str); - if(obj == null) { - MessageBox.Show("保存数据格式错误!"); - } - if(obj?.Ver == 1) { - this.WorkList = obj.WorkList; - } - } - catch(Exception ex) { - MessageBox.Show(ex.ToString()); - return; - } - } - } -} diff --git a/CalendarNotepad/Models/WorkUnitList.cs b/CalendarNotepad/Models/WorkUnitList.cs deleted file mode 100644 index 4165061..0000000 --- a/CalendarNotepad/Models/WorkUnitList.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace CalendarNotepad.Models -{ - /// - /// 工作记录列表。不要直接使用此类,通过Workcontext进行操作 - /// - public class WorkUnitList:List { } -}