// 修改日历 // 分馆用户只能修改自己管辖的分馆的日历 // parameters: // strAction change new delete overwirte(2008/8/23) public int SetCalendar(string strAction, string strLibraryCodeList, CalenderInfo info, out string strError) { strError = ""; { string strLibraryCode = ""; string strPureName = ""; // 解析日历名 ParseCalendarName(info.Name, out strLibraryCode, out strPureName); // 检查日历名中馆代码。必须使用单个馆代码 if (strLibraryCode.IndexOf(",") != -1) { strError = "日历名中馆代码部分不允许含有逗号"; return -1; } // 检查日历名中馆代码。不能使用. if (strLibraryCode.IndexOf(".") != -1) { strError = "日历名中馆代码部分不允许使用符号 '.' "; return -1; } if (SessionInfo.IsGlobalUser(strLibraryCodeList) == false) { if (StringUtil.IsInList(strLibraryCode, strLibraryCodeList) == false) { strError = "当前用户管辖的馆代码为 '" + strLibraryCodeList + "',不包含日历名中的馆代码 '" + strLibraryCode + "',修改操作被拒绝"; return -1; } } } string strXPath = ""; strXPath = "calendars/calendar[@name='" + info.Name + "']"; XmlNodeList nodes = this.LibraryCfgDom.DocumentElement.SelectNodes(strXPath); XmlNode node = null; // 2008/8/23 if (strAction == "overwrite") { if (String.IsNullOrEmpty(info.Name) == true) { strError = "日历名不能为空"; return -1; } if (nodes.Count == 0) { XmlNode root = this.LibraryCfgDom.DocumentElement.SelectSingleNode("calendars"); if (root == null) { root = this.LibraryCfgDom.CreateElement("calendars"); this.LibraryCfgDom.DocumentElement.AppendChild(root); } node = this.LibraryCfgDom.CreateElement("calendar"); root.AppendChild(node); } else if (nodes.Count > 1) { // 增强健壮性 for (int i = 1; i < nodes.Count; i++) { nodes[i].ParentNode.RemoveChild(nodes[i]); } node = nodes[0]; } else { Debug.Assert(nodes.Count == 1, ""); node = nodes[0]; } DomUtil.SetAttr(node, "name", info.Name); // 2008/10/8 增加。原来缺少本行,为一个bug DomUtil.SetAttr(node, "range", info.Range); DomUtil.SetAttr(node, "comment", info.Comment); node.InnerText = info.Content; this.Changed = true; return 0; } if (strAction == "change") { if (nodes.Count == 0) { strError = "日历名 '" + info.Name + "' 不存在"; return -1; } if (nodes.Count > 1) { strError = "日历名 '" + info.Name + "' 存在 " + nodes.Count.ToString() + " 个。修改操作被拒绝。"; return -1; } node = nodes[0]; DomUtil.SetAttr(node, "range", info.Range); DomUtil.SetAttr(node, "comment", info.Comment); node.InnerText = info.Content; this.Changed = true; return 0; } if (strAction == "new") { if (String.IsNullOrEmpty(info.Name) == true) { strError = "日历名不能为空"; return -1; } if (nodes.Count > 0) { strError = "日历名 '" + info.Name + "' 已经存在"; return -1; } XmlNode root = this.LibraryCfgDom.DocumentElement.SelectSingleNode("calendars"); if (root == null) { root = this.LibraryCfgDom.CreateElement("calendars"); this.LibraryCfgDom.DocumentElement.AppendChild(root); } node = this.LibraryCfgDom.CreateElement("calendar"); root.AppendChild(node); DomUtil.SetAttr(node, "name", info.Name); DomUtil.SetAttr(node, "range", info.Range); DomUtil.SetAttr(node, "comment", info.Comment); node.InnerText = info.Content; this.Changed = true; return 0; } if (strAction == "delete") { if (nodes.Count == 0) { strError = "日历名 '" + info.Name + "' 不存在"; return -1; } for (int i = 0; i < nodes.Count; i++) { node = nodes[i]; node.ParentNode.RemoveChild(node); } this.Changed = true; return 0; } strError = "无法识别的strAction参数值 '" + strAction + "' "; return -1; }
// (为管理目的)获得日历 // 分馆用户也能看到全部日历 // parameters: // strAction get list getcount public int GetCalendar(string strAction, string strLibraryCodeList, string strName, int nStart, int nCount, out List<CalenderInfo> contents, out string strError) { contents = new List<CalenderInfo>(); strError = ""; string strXPath = ""; #if NO if (strAction == "list" || strAction == "getcount") strXPath = "calendars/calendar"; // 列出所有 else if (strAction == "get") { if (string.IsNullOrEmpty(strName) == false) strXPath = "calendars/calendar[@name='" + strName + "']"; else strXPath = "calendars/calendar"; // 列出所有 } else { strError = "不能识别的strAction参数 '" + strAction + "'"; return -1; } #endif // 2014/3/2 if (string.IsNullOrEmpty(strName) == false) strXPath = "calendars/calendar[@name='" + strName + "']"; else strXPath = "calendars/calendar"; // 列出所有 XmlNodeList nodes = this.LibraryCfgDom.DocumentElement.SelectNodes(strXPath); // 仅仅需要得到数量 if (strAction == "getcount") return nodes.Count; if (nCount == -1) nCount = nodes.Count - nStart; for (int i = nStart; i < Math.Min(nodes.Count, nStart + nCount); i++) { XmlNode node = nodes[i]; string strCurName = DomUtil.GetAttr(node, "name"); string strComment = DomUtil.GetAttr(node, "comment"); string strRange = DomUtil.GetAttr(node, "range"); CalenderInfo info = new CalenderInfo(); info.Name = strCurName; info.Range = strRange; info.Comment = strComment; if (strAction == "list") { // 不返回内容 contents.Add(info); continue; } info.Content = node.InnerText; contents.Add(info); } return nodes.Count; // 返回总数 }