- using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.IO;
namespace TimeUpGoHome
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
private string shouldGoHomeTime = "18:15";
private string trueGoHomeTime = "";
private DispatcherTimer ShowTimer;
public MainWindow()
{
InitializeComponent();
ShowTimer = new System.Windows.Threading.DispatcherTimer();
ShowTimer.Tick += new EventHandler(ShowCurTimer);//起个Timer一直获取当前时间
ShowTimer.Interval = new TimeSpan(0, 0, 0, 1, 0);
ShowTimer.Start();
this.MyText.Text = "";
}
public void ShowCurTimer(object sender, EventArgs e)
{
//"星期"+DateTime.Now.DayOfWeek.ToString(("d"))
//获得星期几
// this.Tt2.Text = DateTime.Now.ToString("dddd", new System.Globalization.CultureInfo("zh-cn"));
//his.Tt.Text += " ";
//获得年月日
this.Tt2.Text = DateTime.Now.ToString("yyyy年MM月dd日"); //yyyy年MM月dd日
// this.Tt.Text += " ";
//获得时分
this.Tt.Text = DateTime.Now.ToString("HH:mm");
//System.Diagnostics.Debug.Print("this.ShowCurrentTime {0}", this.ShowCurrentTime);
}
private int[] GetHourAndMin(string _timer){
int n = int.Parse(_timer.Substring(0, 2));
int m = int.Parse(_timer.Substring(3,2));
int[] to_back = new int[] { n,m};
return to_back;
}
private int[] GetRemainHourAndMin(int smallMins1,int bigMins2){
int remainMins= bigMins2-smallMins1;
int remainHours=remainMins/60;
int remainRemainMins=remainMins%60;
int[] to_back=new int[]{remainHours,remainRemainMins};
return to_back;
}
private int GetMins(int[] timeTable)
{
return timeTable[0] * 60 + timeTable[1];
}
private void Button_Click(object sender, RoutedEventArgs e)
{
string today_date = this.Tt2.Text;
string trueBackHomeTime = this.Tt.Text;
int[] shouldBackTimeTable = GetHourAndMin(shouldGoHomeTime);
int[] trueBackTimeTable = GetHourAndMin(trueBackHomeTime);
int shouldMins=GetMins(shouldBackTimeTable);
int trueMins=GetMins(trueBackTimeTable);
if (trueMins < shouldMins)
{
this.MyText.Text="时间还没到!!";
}
else
{
this.MyText.Text="";
int[] remainTimes = GetRemainHourAndMin(shouldMins, trueMins);
using
(StreamWriter iFile = new StreamWriter("D:/AfterWorkLog/workLog.txt", true))
iFile.WriteLine("加班时间:" + today_date+" "+ shouldGoHomeTime + " 到 " + trueBackHomeTime + "; 累计:" +remainTimes[0]+"小时 "+remainTimes[1]+ " 分钟");
App.Current.Shutdown();
}
}
}
}