删除无用文件窗体
This commit is contained in:
parent
23c73b826e
commit
eebb7d067f
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="saveFileName" value="data.db"/>
|
||||
<add key ="sqliteFile" value="DataSource=work.db;"/>
|
||||
</appSettings>
|
||||
</configuration>
|
|
@ -14,11 +14,6 @@ namespace CalendarNotepad.Extends
|
|||
/// <returns>配置值,默认string.Empty</returns>
|
||||
public static string GetValue(string key) => ConfigurationManager.AppSettings[key] ?? string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 保存的文件名sqliteFile
|
||||
/// </summary>
|
||||
public static string GetSaveFileName => GetValue("saveFileName") ?? "";
|
||||
|
||||
/// <summary>
|
||||
/// sqliteFile名
|
||||
/// </summary>
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace CalendarNotepad.Extends
|
|||
/// <summary>
|
||||
/// 压缩文件名
|
||||
/// </summary>
|
||||
public static string ZipFileName { get; set; } = AppConfig.GetSaveFileName;
|
||||
public static string ZipFileName { get; set; } = "";
|
||||
/// <summary>
|
||||
/// 某个文件保存到压缩文件内
|
||||
/// </summary>
|
||||
|
|
170
CalendarNotepad/Main.Designer.cs
generated
170
CalendarNotepad/Main.Designer.cs
generated
|
@ -1,170 +0,0 @@
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
|
||||
/// <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 {
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,156 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<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>
|
|
@ -1,15 +0,0 @@
|
|||
namespace CalendarNotepad.Models
|
||||
{
|
||||
public class SaveFileModel
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据版本
|
||||
/// </summary>
|
||||
public int Ver { get; set; } = 1;
|
||||
/// <summary>
|
||||
/// 工作列表
|
||||
/// </summary>
|
||||
public WorkUnitList WorkList { get; set; } = new WorkUnitList();
|
||||
|
||||
}
|
||||
}
|
|
@ -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
|
||||
{
|
||||
/// <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);
|
||||
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);
|
||||
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<WorkUnitList>(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<SaveFileModel>(str);
|
||||
if(obj == null) {
|
||||
MessageBox.Show("保存数据格式错误!");
|
||||
}
|
||||
if(obj?.Ver == 1) {
|
||||
this.WorkList = obj.WorkList;
|
||||
}
|
||||
}
|
||||
catch(Exception ex) {
|
||||
MessageBox.Show(ex.ToString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
namespace CalendarNotepad.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 工作记录列表。不要直接使用此类,通过Workcontext进行操作
|
||||
/// </summary>
|
||||
public class WorkUnitList:List<WorkUnit> { }
|
||||
}
|
Loading…
Reference in New Issue
Block a user