int LoadOperLogs(List<string> dates, out string strError) { strError = ""; _operLogItems = new List<OperLogData>(); _operLogTable = new Hashtable(); EnableControls(false); stop.Style = StopStyle.EnableHalfStop; stop.OnStop += new StopEventHandler(this.Channel.DoStop); stop.Initial("正在装载日志记录 ..."); stop.BeginLoop(); try { ProgressEstimate estimate = new ProgressEstimate(); OperLogLoader loader = new OperLogLoader(); loader.Channel = this.Channel; loader.Stop = this.Progress; loader.estimate = estimate; loader.FileNames = dates; loader.Level = 2; // this.MainForm.OperLogLevel; loader.AutoCache = false; loader.CacheDir = ""; loader.Prompt -= new MessagePromptEventHandler(loader_Prompt); loader.Prompt += new MessagePromptEventHandler(loader_Prompt); foreach (OperLogItem item in loader) { if (stop != null && stop.State != 0) { strError = "用户中断"; return 0; } if (stop != null) stop.SetMessage("正在获取 " + item.Date + " " + item.Index.ToString() + " " + estimate.Text + "..."); if (string.IsNullOrEmpty(item.Xml) == true) continue; XmlDocument dom = new XmlDocument(); try { dom.LoadXml(item.Xml); } catch (Exception ex) { strError = "日志记录 " + item.Date + " " + item.Index.ToString() + " XML 装入 DOM 的时候发生错误: " + ex.Message; DialogResult result = MessageBox.Show(this, strError + "\r\n\r\n是否跳过此条记录继续处理?", "ReportForm", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (result == System.Windows.Forms.DialogResult.No) return -1; // 记入日志,继续处理 // this.GetErrorInfoForm().WriteHtml(strError + "\r\n"); continue; } string strOperation = DomUtil.GetElementText(dom.DocumentElement, "operation"); if (strOperation != "borrow" && strOperation != "return") continue; string strAction = DomUtil.GetElementText(dom.DocumentElement, "action"); string strOperator = DomUtil.GetElementText(dom.DocumentElement, "operator"); string strOperTime = DomUtil.GetElementText(dom.DocumentElement, "operTime"); string strItemBarcode = DomUtil.GetElementText(dom.DocumentElement, "itemBarcode"); string strItemRecPath = ""; XmlNode node = dom.DocumentElement.SelectSingleNode("itemRecord/@recPath"); if (node == null) { strError = "缺乏 itemRecord 元素的 recPath 属性"; continue; } else strItemRecPath = node.Value; OperLogData data = (OperLogData)_operLogTable[strItemRecPath]; if (data == null) { data = new OperLogData(); data.ItemRecPath = strItemRecPath; _operLogItems.Add(data); _operLogTable[strItemRecPath] = data; } data.ItemBarcode = strItemBarcode; data.Action = strAction; data.Operator = strOperator; data.OperTime = SQLiteUtil.GetLocalTime(strOperTime); data.OperCount++; } return 0; } catch (Exception ex) { strError = "获取日志记录的过程中出现异常: " + ex.Message; return -1; } finally { stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.Channel.DoStop); stop.Initial(""); stop.Style = StopStyle.None; EnableControls(true); } }
void AppendExtraColumns(ListViewItem item, OperLogData data) { if (this._defs == null) return; int nBatchNoIndex = this._defs.source_types.IndexOf("batch_no"); int nOperatorIndex = this._defs.source_types.IndexOf("operator"); int nOperTimeIndex = this._defs.source_types.IndexOf("oper_time"); int target_index = this._defs._base_colmun_defs.Count + 2; if (nBatchNoIndex != -1) ListViewUtil.ChangeItemText(item, target_index + nBatchNoIndex, "#operlog"); if (nOperatorIndex != -1) ListViewUtil.ChangeItemText(item, target_index + nOperatorIndex, data.Operator); if (nOperTimeIndex != -1) ListViewUtil.ChangeItemText(item, target_index + nOperTimeIndex, data.OperTime); }