?? functions.cs.svn-base
字號:
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
namespace PlaneSale
{
class Functions
{
private System.Threading.Timer timerBegin = null;
private System.Threading.Timer timerEnd = null;
private System.Threading.Timer timerWarn = null;
public string GetMessage(string key)
{
string str = null;
try
{
str = Global.doc.GetElementsByTagName(key)[0].ChildNodes[0].Value;
}
catch(Exception ex)
{
}
return str;
}
/// <summary>
/// 根據輸入的Code和要取得信息的key來取得相應的信息
/// </summary>
/// <param name="key"></param>
/// <param name="code"></param>
/// <returns></returns>
public string GetMessageByCode(string key,string code)
{
string str = null;
try
{
string tmp = "//info/" + key + "/text()[../../Code/text()='" + code + "']";
str = Global.doc.SelectSingleNode(tmp).Value;
}
catch (Exception ex)
{
}
return str;
}
/// <summary>
/// 設定開始時間
/// </summary>
private TimeSpan SetBeginTimeSpan()
{
DateTime t_now = DateTime.Now;
DateTime t_begin = DateTime.Parse(Global.BeginTime);
TimeSpan ts = t_begin.Subtract(t_now);
int i_day = ts.Days;
int i_hour = ts.Hours;
int i_minutes = ts.Minutes;
int i_second = ts.Seconds;
if (i_day >= 0 && i_hour >= 0 && i_minutes >= 0 && i_second >= 0)
{
Global.form.AddMessage(string.Format("離活動開始還有{0}天{1}小時{2}分{3}秒", i_day, i_hour, i_minutes, i_second));
Global.DOProcessTag = 0;
}
else
{
Global.form.AddMessage(string.Format("活動已經開始{0}天{1}小時{2}分{3}秒", 0-i_day, 0-i_hour, 0-i_minutes, 0-i_second));
ts = TimeSpan.MinValue;
}
return ts;
}
private void StartBeingTimer()
{
TimeSpan ts = SetBeginTimeSpan();
if(!ts.Equals(TimeSpan.MinValue))
timerBegin = new Timer(BeginTimerDo, null, ts, TimeSpan.Zero);
}
/// <summary>
/// 到達活動開始時間時,需要處理的內容
/// </summary>
/// <param name="state"></param>
private void BeginTimerDo(object state)
{
Global.form.AddMessage("活動正式開始");
Global.DOProcessTag = 1;
}
/// <summary>
/// 設定結束時間
/// </summary>
/// <returns></returns>
private TimeSpan SetEndTimeSpan()
{
DateTime t_now = DateTime.Now;
DateTime t_end = DateTime.Parse(Global.EndTime);
TimeSpan ts = t_end.Subtract(t_now);
int i_day = ts.Days;
int i_hour = ts.Hours;
int i_minutes = ts.Minutes;
int i_second = ts.Seconds;
if (i_day >= 0 && i_hour >= 0 && i_minutes >= 0 && i_second >= 0)
{
Global.form.AddMessage(string.Format("離活動結束還有{0}天{1}小時{2}分{3}秒", i_day, i_hour, i_minutes, i_second));
}
else
{
Global.form.AddMessage(string.Format("活動已經結束{0}天{1}小時{2}分{3}秒", 0 - i_day, 0 - i_hour, 0 - i_minutes, 0 - i_second));
ts = TimeSpan.MinValue;
}
return ts;
}
/// <summary>
/// 到達活動結束時間后的處理動作
/// </summary>
/// <param name="state"></param>
private void EndTimerDo(object state)
{
Global.form.AddMessage("活動已經結束");
Global.DOProcessTag = 2;
}
/// <summary>
/// 設定結束時間Timer
/// </summary>
private void StartEndTimer()
{
TimeSpan ts = SetEndTimeSpan();
if (!ts.Equals(TimeSpan.MinValue))
timerEnd = new Timer(EndTimerDo, null, ts, TimeSpan.Zero);
}
/// <summary>
/// 設定結束時間
/// </summary>
/// <returns></returns>
private TimeSpan SetWarnTimeSpan()
{
DateTime t_now = DateTime.Now;
DateTime t_end = DateTime.Parse(Global.WarnTime);
TimeSpan ts = t_end.Subtract(t_now);
int i_day = ts.Days;
int i_hour = ts.Hours;
int i_minutes = ts.Minutes;
int i_second = ts.Seconds;
if (i_day >= 0 && i_hour >= 0 && i_minutes >= 0 && i_second >= 0)
{
Global.form.AddMessage(string.Format("離預警處理還有{0}天{1}小時{2}分{3}秒", i_day, i_hour, i_minutes, i_second));
}
else
{
Global.form.AddMessage(string.Format("預警處理已經結束{0}天{1}小時{2}分{3}秒", 0 - i_day, 0 - i_hour, 0 - i_minutes, 0 - i_second));
ts = TimeSpan.MinValue;
}
return ts;
}
/// <summary>
/// 到預警時間后的處理動作
/// </summary>
/// <param name="state"></param>
private void WarnTimerDo(object state)
{
Global.form.AddMessage("預警處理線程啟動");
Global g = new Global();
g.WarnDo();
}
/// <summary>
/// 設定結束時間Timer
/// </summary>
private void StartWarnTimer()
{
TimeSpan ts = SetWarnTimeSpan();
if (!ts.Equals(TimeSpan.MinValue))
timerWarn = new Timer(WarnTimerDo, null, ts, TimeSpan.Zero);
}
/// <summary>
/// 啟動系統所有的Timer
/// </summary>
public void StartAllTimer()
{
StartBeingTimer();
StartWarnTimer();
StartEndTimer();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -