/// <summary> /// 通过网络时间设置时间差 /// </summary> private async void SetDeltaTimeByNet() { await Task.Run(() => { BtnSetDeltaTimeByNet.Dispatcher.Invoke(() => { BtnSetDeltaTimeByNet.IsEnabled = false; }); try { string t = File.ReadAllText(Settings.Default.NetPath); Settings.Default.deltaTime = Convert.ToInt32(t); BtnSetDeltaTimeByNet.Dispatcher.Invoke(() => { BtnSetDeltaTimeByNet.IsEnabled = true; BtnSetDeltaTimeByNet.Content = ":)"; }); Thread.Sleep(1000);//如果成功,给予一个美丽的微笑! BtnSetDeltaTimeByNet.Dispatcher.Invoke(() => { BtnSetDeltaTimeByNet.Content = "立即刷新"; }); } catch (Exception ex) { ULogger.WriteException(ex); #if !DEBUG MessageBox.Show(@"在试图获取网络时间时出错,若一直出现此错误请关闭'网络时间'功能"); #endif } BtnSetDeltaTimeByNet.Dispatcher.Invoke(() => { BtnSetDeltaTimeByNet.IsEnabled = true; }); }); }
void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { //可以记录日志并转向错误bug窗口友好提示用户 e.Handled = true; MessageBox.Show("消息:" + e.Exception.Message + "\r\n" + e.Exception.StackTrace); ULogger.WriteException(e.Exception); }
void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { //可以记录日志并转向错误bug窗口友好提示用户 if (e.ExceptionObject is Exception ex) { MessageBox.Show(ex.Message); ULogger.WriteException(ex); } }
private void TbDeltaTime_TextChanged(object sender, TextChangedEventArgs e) { try { Settings.Default.deltaTime = int.Parse(TbDeltaTime.Text.ToString()); } catch (Exception ex) { ULogger.WriteException(ex); } }
private void Tbdpi_TextChanged(object sender, TextChangedEventArgs e) { try { Settings.Default.dpi = double.Parse(Tbdpi.Text.ToString()); } catch (Exception ex) { ULogger.WriteException(ex); } }
private void Timer1000_Tick(object sender, EventArgs e) { if (Settings.Default.isCheckIn) { OpenCheckIn.Check(); } foreach (var item in windows) { if (item.Window is FunctionWindow window) { if (window.IsVisible && FunctionWindow.ColorActive) { window.ChangeColor(); } window.Topmost = true; } } Public.SettingWindow.TbChangeHeTime.Text = "长河时间 " + Public.ChangHeTime().ToString(); #if !DEBUG try { Core.Load(Public.pathTime, Public.pathClass); Core.CurrentTime = Public.ChangHeTime(); } catch (Exception ex) { ULogger.WriteException(ex); Public.timeTableWindow.ErrorLoad(); Public.classTableWindow.ErrorLoad(); return; } #else Core.Load(Public.pathTime, Public.pathClass); Core.CurrentTime = Public.ChangHeTime(); #endif //timeWindow.Topmost = true; Public.timeTableWindow.Changedata(Core.CurrentTimeSection, Core.FormatProgress(Core.Progress)); Public.timeTableWindow.MoveLineProgress(Core.Progress); Public.timeWindow.ChangeTime(); int week = (int)Public.ChangHeTime().DayOfWeek; if (Public.ChangHeTime().CompareTo(Core.LastClassEndTime[week]) > 0 && Settings.Default.isTomorrowClass) { //明天课表 Public.classTableWindow.ChangeClass(Core.GetClass((int)Public.ChangHeTime().AddDays(1).DayOfWeek), true); Public.classTableWindow.ChangeWeek(Public.ChangHeTime().AddDays(1).DayOfWeek); } else { //今天课表 Public.classTableWindow.ChangeClass(Core.GetClass()); Public.classTableWindow.ChangeWeek(Public.ChangHeTime().DayOfWeek); } }
private void LoadCboFileList() { try { filesName = GetFiles(); CboStus.ItemsSource = filesName; CboStus.SelectedIndex = CboStus.Items.Count - 1; } catch (Exception ex) { ULogger.WriteException(ex); } }
private List <string> GetFiles() { try { DirectoryInfo dirInfo = new DirectoryInfo(App.path_Dir_File); var i = dirInfo.GetFiles(); #if DEBUG var files = (from x in i where x.Name.Contains("_DEBUG") select x.Name).ToList(); #else var files = (from x in i where x.Name.Length <= 6 select x.Name).ToList(); #endif files.Insert(0, "All"); return(files); } catch (Exception ex) { ULogger.WriteException(ex); return(null); } }
private List <int> GetFinalMissIds(List <string> s) { List <int> t = new List <int>(); foreach (var item in s) { var i = item.Split(','); foreach (var u in i) { try { if (u != "") { t.Add(Int32.Parse(u)); } } catch (Exception ex) { ULogger.WriteException(ex); } } } return(t); }
private void SaveLog() { if (App.CurrentCheckKind == CheckKind.None) { #if !DEBUG MessageBox.Show("不是正常的时间,请自行设置签到种类", "确定"); return; #endif } try { XDocument xDoc; try { xDoc = XDocument.Load(App.path_Dir_File + App.XmlFileName); } catch (Exception exp)//创建新的document { if (exp.Message != "Root element is missing." && exp.Message != "Xml_MissingRoot") { ULogger.WriteException(exp); if (MessageBox.Show("致命的读取错误,按确定继续" + "exp.Message", "错误", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel) { return; } } else { ULogger.WriteInfo("Info", "创建新的XML"); } xDoc = new XDocument(); xDoc.Add(new XElement("Logs")); } string missId = "";//记录缺失的学号 int missNum = 0; foreach (var item in App.Stus) { if (item.CType == CheckType.Absent) { missId += item.Id.ToString() + ","; missNum++; } } if (missId.Length != 0) { missId = missId.Substring(0, missId.Length - 1); } DateTime t = DateTime.Now; var i = (from x in xDoc.Root.Elements() where x.Attribute("checkKind").Value == App.CurrentCheckKind.ToString() && int.Parse(x.Attribute("dayOfWeek").Value) == App.CheckDayOfWeek select x).ToList(); if (i.Count() == 0) { xDoc.Element("Logs").Add(new XElement("Log", new XAttribute("checkKind", App.CurrentCheckKind), new XAttribute("dayOfWeek", (int)App.CheckDayOfWeek), new XAttribute("missId", missId), new XAttribute("time", App.TimeStamp()) )); } else { if (MessageBox.Show("似乎已经签到过了,确定继续", "疑惑", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)//UMessageDialogAsync("似乎已经签到过了", "吼啊", "取消") == { return; } i.Last().SetAttributeValue("missId", missId); i.Last().SetAttributeValue("time", App.TimeStamp()); } string message = string.Format("+{0}s", missNum); #if DEBUG message += " 程序运行在调试模式.如果你在工作,不用惊慌,正常签到后通知QHT即可"; #endif if (MessageBox.Show(message, "OK", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { xDoc.Save(App.path_Dir_File + App.XmlFileName); xDoc.Save(App.path_Dir_Backup + App.TimeStamp() + "_" + App.XmlFileName); #if !DEBUG App.Current.Shutdown(); #endif } } catch (Exception ex) { ULogger.WriteException(ex); } }