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); } }