台灣最大程式設計社群網站
∣
免費加入會員
∣登入
∣回首頁∣
您好
線上人數
1107
會員總數:
246691
討論主題:
190104
討論區
程式下載/上傳
科技新聞
專欄文章
會員中心
加值服務
外包接案
求職求才
登入
登出
歡迎您
免費
加入會員
討論區選單
新手必讀
我要提問!!
討論區
個人討論區
我的關注主題
我的黑名單
討論區EP英雄榜
專家等級說明
討論區常見問題
兌換發問點數QP
扣點申請加值服務
申請版主
開發工具
ASP
ASP.NET
C#
VB.NET
VB6
C/C++
PHP
Java
Java Script/ Node.js
AJAX / JSON / jQuery
其他語言
行動裝置開發
Android APP 開發
iOS APP/ swift 開發
Windows Phone APP
資料庫
ACCESS
MS SQL
MySQL
Oracle
其他DB
多媒體 / 網管
CSS/HTML5/Bootstarp
影像處理
office VBA / WinOS
Windows 伺服器
Linux / Unix
網管 / 資安 / VM
硬體 / 週邊 / 其他
綜合
求職求才
外包接案
心情甘苦談
網站經營 / 合夥 / 證照
建言 / 公告
文章區
專欄文章
科技新聞
Blog精華文章
討論區列表
>>
C#
>> C# timer 時間到了但是沒有跳出提示視窗
[]
[
我要回覆
]
1
C# timer 時間到了但是沒有跳出提示視窗
價值 : 50 QP
點閱數:1056 回應數:2
樓主
Martina
0
8
190
5
發送站內信
各位前輩們,我有寫一個行事曆,預定時間到了會跳出提醒,並且有週期的程式
但是時間到了卻都不會跳出提醒,請問是哪裡出錯了嗎?非常感謝~
資料庫是ACCESS,資料表名稱[Remind]
Name Frequency Time Content
提醒1 僅僅一次 2017/8/5 下午 14:00:00 提醒1的內容
提醒2 1天一次 2017/8/5 下午 15:00:00 提醒2的內容
public void frmMain_Load(object sender, EventArgs e) { timer1.Start(); } private void timer1_Tick(object sender, EventArgs e) { myds = dataoperate.getds("select * from tb_Remind"); for (int i = 0; i < myds.Tables[0].Rows.Count; i++) { string strName = myds.Tables[0].Rows[0]["Name"].ToString(); string strFrequency = myds.Tables[0].Rows[1]["Frequency"].ToString(); string strTime = myds.Tables[0].Rows[2]["Time"].ToString(); string strContent = myds.Tables[0].Rows[3]["Content"].ToString(); string[] strTimes = strTime.Split(' '); //判斷提醒方式,並根據提醒方式彈出提醒對話框 if (strFrequency == "僅僅一次") { if (DateTime.Now.ToShortDateString() == strTimes[0] && DateTime.Now.ToLongTimeString() == strTimes[1]) { SoundPlayer s1 = new SoundPlayer("C:/Windows/Media/Alarm01.wav"); s1.Play(); MessageBox.Show(strContent, strName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } } else { int intNum = Convert.ToInt32(strFrequency.Substring(0, 1)); string strUnit = strFrequency.Substring(1, 1); TimeSpan TSpan = DateTime.Now - Convert.ToDateTime(strTimes[0]); switch (strUnit) { case "天": //每幾天提醒一次 if (TSpan.Days % intNum == 0 && DateTime.Now.ToLongTimeString() == strTimes[1]) MessageBox.Show(strContent, strName, MessageBoxButtons.OK, MessageBoxIcon.Information); break; case "週": //每幾週提醒一次 if (TSpan.Days % (intNum * 7) == 0 && DateTime.Now.ToLongTimeString() == strTimes[1]) MessageBox.Show(strContent, strName, MessageBoxButtons.OK, MessageBoxIcon.Information); break; case "月": //每幾月提醒一次 if (TSpan.Days % (intNum * 30) == 0 && DateTime.Now.ToLongTimeString() == strTimes[1]) MessageBox.Show(strContent, strName, MessageBoxButtons.OK, MessageBoxIcon.Information); break; case "年": //每幾年提醒一次 if (TSpan.Days % (intNum * 365) == 0 && DateTime.Now.ToLongTimeString() == strTimes[1]) MessageBox.Show(strContent, strName, MessageBoxButtons.OK, MessageBoxIcon.Information); break; } } } }
搜尋相關Tags的文章:
[ C# ] ,
[ Timer ] ,
[ MessageBox ] ,
本篇文章發表於2017-08-06 11:37
1樓
最有價值解答
QZ_CHUNG
先用Debug模式一行一行看是否真的有進入判斷式裡面吧
本篇文章回覆於2017-08-07 08:49
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
2樓
不錯的參考
春天
DataTime.Now是現在時間,你用ToString的方式去比對的話差一秒都不行,你的Timer是一秒一次嗎?
本篇文章回覆於2017-08-08 10:18
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
1
回覆
如要回應,請先
登入
.
|
網站導覽
|
網站介紹
|
4P點數說明
|
電子報
|
小舖活動
|
大事紀
|
廣告刊登
|
常見問題
|
聯絡我們
|
版權所有 ©copyright 2000 All Rights Reserved