-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainForm.cs
156 lines (140 loc) · 5.64 KB
/
MainForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace CountDownWinform
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
toolTip1.SetToolTip(this.checkBox1, "强力模式为置顶弹窗,会影响全屏游戏,非强力模式为类似小刻食堂的气泡");
toolTip1.SetToolTip(this.dataGridView1, "选中后按delete键删除该行");
var data = new SettingOptions().ReadOption("countDownList");
if (data != null)
{
List<CountDownEntity> list = JsonConvert.DeserializeObject<List<CountDownEntity>>(data);
list.Sort((x, y) => { return x.Index.CompareTo(y.Index); });
foreach (var item in list)
{
AddDataGridView(Convert.ToDateTime(item.Time), item.Name, item.Remark);
}
}
}
private void timer1_Tick(object sender, EventArgs e)
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
var time = Convert.ToDateTime(dataGridView1.Rows[i].Cells[2].Value.ToString());
var timespan = time - DateTime.Now;
if (timespan.TotalSeconds > 0)
{
dataGridView1.Rows[i].Cells[3].Value = CommonHelper.TimespanToText(timespan);
}
else
{
notifyIcon1.ShowBalloonTip(5000, dataGridView1.Rows[i].Cells[0].Value.ToString() + "的倒计时已经结束", dataGridView1.Rows[i].Cells[1].Value.ToString() == ""?"快去看看吧": dataGridView1.Rows[i].Cells[1].Value.ToString(), ToolTipIcon.Info);
if (checkBox1.Checked)
{
this.TopMost = true;
if (WindowState == FormWindowState.Minimized)
{
WindowState = FormWindowState.Normal;
ShowInTaskbar = true;
}
timer1.Enabled = false;
MessageBox.Show(dataGridView1.Rows[i].Cells[1].Value.ToString() + "倒计时已经结束");
timer1.Enabled = true;
this.TopMost = false;
}
dataGridView1.Rows.RemoveAt(i);
CheckHasRow();
}
}
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (dataGridView1.SelectedRows.Count > 0)
{
var data = dataGridView1.SelectedRows[0];
}
}
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
if (MessageBox.Show("确认要删除选中的行吗?", "删除确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
dataGridView1.Rows.Remove(dataGridView1.SelectedRows[0]);
CheckHasRow();
}
}
}
private void CheckHasRow()
{
if (dataGridView1.Rows.Count <= 0)
{
timer1.Enabled = false;
}
else
{
timer1.Enabled = true;
}
SaveCountDown();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
notifyIcon1.ShowBalloonTip(5000, "小刻食堂倒计时程序已最小化", "小刻食堂继续为你分秒必争", ToolTipIcon.None);
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
WindowState = FormWindowState.Normal;
ShowInTaskbar = true;
}
this.Activate();
}
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Dispose();
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
AddCountForm acf = new AddCountForm();
acf.ShowDialog(this);
}
public void AddDataGridView(DateTime timeStop, string name, string remake)
{
dataGridView1.Rows.Insert(0, name, remake, timeStop.ToString("yyyy/MM/dd HH:mm:ss"), CommonHelper.TimespanToText(timeStop - DateTime.Now));
CheckHasRow();
}
public void SaveCountDown()
{
List<CountDownEntity> list = new List<CountDownEntity>();
foreach (DataGridViewRow row in dataGridView1.Rows)
{
list.Add(new CountDownEntity
{
Index = row.Index,
Name = row.Cells["Column1"].Value.ToString(),
Time = row.Cells["Column2"].Value.ToString(),
Remark = row.Cells["Column3"].Value.ToString(),
});
}
new SettingOptions().SaveOption("countDownList", JsonConvert.SerializeObject(list));
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("https://github.com/LiuZiYang1/Ceobe-Canteen-Count-Down");
}
}
}