增加工作类型,休假,病假,加班等。

This commit is contained in:
FalconFly 2024-07-22 14:21:23 +08:00
parent a58c8c9fda
commit 715b90972d
4 changed files with 280 additions and 43 deletions

View File

@ -20,5 +20,9 @@ namespace CalendarNotepad.Models
/// 内容 /// 内容
/// </summary> /// </summary>
public string? WorkMessage { get; set; } public string? WorkMessage { get; set; }
/// <summary>
/// 工作类型。如正常上班,休假,加班等
/// </summary>
public string? WorkType { get; set; }
} }
} }

View File

@ -28,6 +28,16 @@
tabControl1 = new TabControl(); tabControl1 = new TabControl();
tpWorkManage = new TabPage(); tpWorkManage = new TabPage();
splitContainer1 = new SplitContainer(); splitContainer1 = new SplitContainer();
flowLayoutPanel1 = new FlowLayoutPanel();
btSave = new Button();
btReset = new Button();
gbWorkTypes = new GroupBox();
C_WorkTypes = new FlowLayoutPanel();
radioButton1 = new RadioButton();
radioButton3 = new RadioButton();
radioButton2 = new RadioButton();
radioButton4 = new RadioButton();
radioButton5 = new RadioButton();
mcWorkDay = new MonthCalendar(); mcWorkDay = new MonthCalendar();
rtbMsg = new RichTextBox(); rtbMsg = new RichTextBox();
tabControl1.SuspendLayout(); tabControl1.SuspendLayout();
@ -36,6 +46,9 @@
splitContainer1.Panel1.SuspendLayout(); splitContainer1.Panel1.SuspendLayout();
splitContainer1.Panel2.SuspendLayout(); splitContainer1.Panel2.SuspendLayout();
splitContainer1.SuspendLayout(); splitContainer1.SuspendLayout();
flowLayoutPanel1.SuspendLayout();
gbWorkTypes.SuspendLayout();
C_WorkTypes.SuspendLayout();
SuspendLayout(); SuspendLayout();
// //
// tabControl1 // tabControl1
@ -68,6 +81,8 @@
// //
// splitContainer1.Panel1 // splitContainer1.Panel1
// //
splitContainer1.Panel1.Controls.Add(flowLayoutPanel1);
splitContainer1.Panel1.Controls.Add(gbWorkTypes);
splitContainer1.Panel1.Controls.Add(mcWorkDay); splitContainer1.Panel1.Controls.Add(mcWorkDay);
// //
// splitContainer1.Panel2 // splitContainer1.Panel2
@ -77,6 +92,111 @@
splitContainer1.SplitterDistance = 236; splitContainer1.SplitterDistance = 236;
splitContainer1.TabIndex = 9; splitContainer1.TabIndex = 9;
// //
// flowLayoutPanel1
//
flowLayoutPanel1.AutoSize = true;
flowLayoutPanel1.Controls.Add(btSave);
flowLayoutPanel1.Controls.Add(btReset);
flowLayoutPanel1.Location = new Point(9,296);
flowLayoutPanel1.Name = "flowLayoutPanel1";
flowLayoutPanel1.Size = new Size(214,29);
flowLayoutPanel1.TabIndex = 8;
//
// btSave
//
btSave.Location = new Point(3,3);
btSave.Name = "btSave";
btSave.Size = new Size(75,23);
btSave.TabIndex = 8;
btSave.Text = "保存";
btSave.UseVisualStyleBackColor = true;
btSave.Click += btSave_Click;
//
// btReset
//
btReset.Location = new Point(84,3);
btReset.Name = "btReset";
btReset.Size = new Size(75,23);
btReset.TabIndex = 9;
btReset.Text = "还原";
btReset.UseVisualStyleBackColor = true;
btReset.Click += btReset_Click;
//
// gbWorkTypes
//
gbWorkTypes.Controls.Add(C_WorkTypes);
gbWorkTypes.Location = new Point(6,198);
gbWorkTypes.Name = "gbWorkTypes";
gbWorkTypes.Size = new Size(220,92);
gbWorkTypes.TabIndex = 7;
gbWorkTypes.TabStop = false;
gbWorkTypes.Text = "类型";
//
// C_WorkTypes
//
C_WorkTypes.Controls.Add(radioButton1);
C_WorkTypes.Controls.Add(radioButton3);
C_WorkTypes.Controls.Add(radioButton2);
C_WorkTypes.Controls.Add(radioButton4);
C_WorkTypes.Controls.Add(radioButton5);
C_WorkTypes.Dock = DockStyle.Fill;
C_WorkTypes.Location = new Point(3,19);
C_WorkTypes.Name = "C_WorkTypes";
C_WorkTypes.Size = new Size(214,70);
C_WorkTypes.TabIndex = 2;
//
// radioButton1
//
radioButton1.AutoSize = true;
radioButton1.Location = new Point(3,3);
radioButton1.Name = "radioButton1";
radioButton1.Size = new Size(50,21);
radioButton1.TabIndex = 0;
radioButton1.Text = "工作";
radioButton1.UseVisualStyleBackColor = true;
//
// radioButton3
//
radioButton3.AutoSize = true;
radioButton3.Checked = true;
radioButton3.Location = new Point(59,3);
radioButton3.Name = "radioButton3";
radioButton3.Size = new Size(50,21);
radioButton3.TabIndex = 1;
radioButton3.TabStop = true;
radioButton3.Text = "休假";
radioButton3.UseVisualStyleBackColor = true;
//
// radioButton2
//
radioButton2.AutoSize = true;
radioButton2.Location = new Point(115,3);
radioButton2.Name = "radioButton2";
radioButton2.Size = new Size(50,21);
radioButton2.TabIndex = 1;
radioButton2.Text = "病假";
radioButton2.UseVisualStyleBackColor = true;
//
// radioButton4
//
radioButton4.AutoSize = true;
radioButton4.Location = new Point(3,30);
radioButton4.Name = "radioButton4";
radioButton4.Size = new Size(50,21);
radioButton4.TabIndex = 2;
radioButton4.Text = "年假";
radioButton4.UseVisualStyleBackColor = true;
//
// radioButton5
//
radioButton5.AutoSize = true;
radioButton5.Location = new Point(59,30);
radioButton5.Name = "radioButton5";
radioButton5.Size = new Size(50,21);
radioButton5.TabIndex = 3;
radioButton5.Text = "事假";
radioButton5.UseVisualStyleBackColor = true;
//
// mcWorkDay // mcWorkDay
// //
mcWorkDay.FirstDayOfWeek = Day.Sunday; mcWorkDay.FirstDayOfWeek = Day.Sunday;
@ -99,10 +219,10 @@
rtbMsg.Size = new Size(486,399); rtbMsg.Size = new Size(486,399);
rtbMsg.TabIndex = 7; rtbMsg.TabIndex = 7;
rtbMsg.Text = ""; rtbMsg.Text = "";
rtbMsg.TextChanged += rtbMsg_TextChanged;
// //
// WorkMain // WorkMain
// //
AcceptButton = btSave;
AutoScaleDimensions = new SizeF(7F,17F); AutoScaleDimensions = new SizeF(7F,17F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(740,435); ClientSize = new Size(740,435);
@ -114,9 +234,14 @@
tabControl1.ResumeLayout(false); tabControl1.ResumeLayout(false);
tpWorkManage.ResumeLayout(false); tpWorkManage.ResumeLayout(false);
splitContainer1.Panel1.ResumeLayout(false); splitContainer1.Panel1.ResumeLayout(false);
splitContainer1.Panel1.PerformLayout();
splitContainer1.Panel2.ResumeLayout(false); splitContainer1.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit(); ((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit();
splitContainer1.ResumeLayout(false); splitContainer1.ResumeLayout(false);
flowLayoutPanel1.ResumeLayout(false);
gbWorkTypes.ResumeLayout(false);
C_WorkTypes.ResumeLayout(false);
C_WorkTypes.PerformLayout();
ResumeLayout(false); ResumeLayout(false);
} }
@ -127,5 +252,15 @@
private MonthCalendar mcWorkDay; private MonthCalendar mcWorkDay;
private RichTextBox rtbMsg; private RichTextBox rtbMsg;
private SplitContainer splitContainer1; private SplitContainer splitContainer1;
private GroupBox gbWorkTypes;
private RadioButton radioButton3;
private RadioButton radioButton2;
private RadioButton radioButton1;
private FlowLayoutPanel C_WorkTypes;
private RadioButton radioButton4;
private RadioButton radioButton5;
private Button btSave;
private FlowLayoutPanel flowLayoutPanel1;
private Button btReset;
} }
} }

View File

@ -11,48 +11,22 @@ namespace CalendarNotepad
public WorkMain() { public WorkMain() {
InitializeComponent(); InitializeComponent();
this.rtbMsg.EnableAutoDragDrop = true; this.rtbMsg.EnableAutoDragDrop = true;
this.DataReset();
//if(File.Exists(AppConfig.GetSaveFileName)) { this.rtbMsg.TextChanged += RtbMsg_TextChanged;
// var str = ZipExtend.GetFormFile("WorkContext.json"); foreach(var c in this.C_WorkTypes.Controls) {
// if(str.IsNullOrEmpty()) { var rab = c as RadioButton;
// return; if(rab != null) {
// } rab.CheckedChanged += Rab_CheckedChanged;
// var wl = JsonSerializer.Deserialize<WorkUnitList>(str) ?? new WorkUnitList(); }
// if(wl == null) { }
// return;
// }
// this.Db.Deleteable<WorkUnit>().ExecuteCommand();
// foreach(var i in wl) {
// this.Db.Insertable(i).ExecuteCommand();
// }
//}
} }
private void rtbMsg_TextChanged(object sender,EventArgs e) { private void Rab_CheckedChanged(object? sender,EventArgs e) {
this.DataChanged();
}
var wd = this.mcWorkDay.SelectionStart.ToString("yyyyMMdd"); private void RtbMsg_TextChanged(object? sender,EventArgs e) {
var dr = "全天"; this.DataChanged();
var msg = this.rtbMsg.Text;
var exp = Expressionable.Create<WorkUnit>().And(a => a.DayRange == dr && a.WorkDay == wd).ToExpression();
var qu = this.Db.Queryable<WorkUnit>().Where(exp).ToList();
if(qu.Any() && msg.IsNullOrEmpty()) {
this.Db.Deleteable<WorkUnit>().Where(exp).ExecuteCommand();
return;
}
if(qu.Any() && msg.IsNotNullOrEmpty()) {
this.Db.Updateable<WorkUnit>().Where(exp).SetColumns(a => a.WorkMessage == msg).ExecuteCommand();
return;
}
if(!qu.Any() && msg.IsNotNullOrEmpty()) {
this.Db.Insertable<WorkUnit>(new WorkUnit {
DayRange = dr,WorkDay = wd,WorkMessage = msg,
}).ExecuteCommand();
return;
}
} }
private void WorkMain_FormClosing(object sender,FormClosingEventArgs e) { private void WorkMain_FormClosing(object sender,FormClosingEventArgs e) {
@ -67,12 +41,15 @@ namespace CalendarNotepad
var sr = "全天"; var sr = "全天";
var qu = this.Db.Queryable<WorkUnit>().Where(a => a.DayRange == sr && a.WorkDay == wd).ToList(); var qu = this.Db.Queryable<WorkUnit>().Where(a => a.DayRange == sr && a.WorkDay == wd).ToList();
if(qu.Any()) { if(qu.Any()) {
this.rtbMsg.Text = qu.First().WorkMessage; var fir = qu.First();
this.rtbMsg.Text = fir.WorkMessage;
this.SetWorkType(fir.WorkType);
} }
else { else {
this.rtbMsg.Rtf = ""; this.rtbMsg.Text = "";
this.SetWorkType("休假");
} }
this.DataReset();
Task.Factory.StartNew(() => { Task.Factory.StartNew(() => {
this.Invoke(() => { this.Invoke(() => {
this.mcWorkDay.BoldedDates = GetBoldDays().ToArray(); this.mcWorkDay.BoldedDates = GetBoldDays().ToArray();
@ -98,5 +75,78 @@ namespace CalendarNotepad
private void WorkMain_Load(object sender,EventArgs e) { private void WorkMain_Load(object sender,EventArgs e) {
mcWorkDay_DateChanged(null,null); mcWorkDay_DateChanged(null,null);
} }
/// <summary>
/// 获取工作类型
/// </summary>
/// <returns></returns>
private string GetWorkType() {
foreach(Control c in this.C_WorkTypes.Controls) {
var rb = c as RadioButton;
if(rb != null && rb.Checked) {
return rb.Text;
}
}
return "";
}
/// <summary>
/// 设置工作类型
/// </summary>
/// <param name="t">工作类型</param>
private void SetWorkType(string? t) {
if(t.IsNullOrEmpty()) {
return;
}
foreach(Control c in this.C_WorkTypes.Controls) {
var rb = c as RadioButton;
if(rb != null && rb.Text == t) {
rb.Checked = true;
return;
}
}
}
private void btSave_Click(object sender,EventArgs e) {
var wd = this.mcWorkDay.SelectionStart.ToString("yyyyMMdd");
var dr = "全天";
var msg = this.rtbMsg.Text;
var wt = GetWorkType();
var exp = Expressionable.Create<WorkUnit>().And(a => a.DayRange == dr && a.WorkDay == wd).ToExpression();
var qu = this.Db.Queryable<WorkUnit>().Where(exp).ToList();
if(qu.Any() && msg.IsNullOrEmpty()) {
this.Db.Deleteable<WorkUnit>().Where(exp).ExecuteCommand();
this.DataReset();
return;
}
if(qu.Any() && msg.IsNotNullOrEmpty()) {
this.Db.Updateable<WorkUnit>().Where(exp)
.SetColumns(a => a.WorkMessage == msg)
.SetColumns(a => a.WorkType == wt)
.ExecuteCommand();
this.DataReset();
return;
}
if(!qu.Any() && msg.IsNotNullOrEmpty()) {
this.Db.Insertable<WorkUnit>(new WorkUnit {
DayRange = dr,WorkDay = wd,WorkMessage = msg,WorkType = wt,
}).ExecuteCommand();
this.DataReset();
return;
}
}
private void btReset_Click(object sender,EventArgs e) {
mcWorkDay_DateChanged(sender,null);
this.DataReset();
}
private void DataChanged() {
this.btSave.Enabled = true;
this.btReset.Enabled = true;
}
private void DataReset() {
this.btSave.Enabled = false;
this.btReset.Enabled = false;
}
} }
} }

View File

@ -117,4 +117,52 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="tabControl1.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="tpWorkManage.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="flowLayoutPanel1.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="btSave.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="btReset.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="gbWorkTypes.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="C_WorkTypes.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="radioButton1.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="radioButton3.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="radioButton2.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="radioButton4.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="radioButton5.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="mcWorkDay.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="$this.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root> </root>