// 更换 orderInfo 元素里的 distribute 元素中的 refid 字符串 // return: // -1 出错 // >=0 发生替换的个数 public static int ReplaceOrderInfoItemRefID(Hashtable item_refid_change_table, XmlElement root, out string strError) { strError = ""; int nRet = 0; int nChangedCount = 0; XmlNodeList nodes = root.SelectNodes("*/distribute"); for (int i = 0; i < nodes.Count; i++) { string strDistribute = nodes[i].InnerText; if (String.IsNullOrEmpty(strDistribute) == true) { continue; } LocationCollection locations = new LocationCollection(); nRet = locations.Build(strDistribute, out strError); if (nRet == -1) { return(-1); } bool bChanged = false; for (int j = 0; j < locations.Count; j++) { Location location = locations[j]; if (item_refid_change_table.Contains(location.RefID) == true) { location.RefID = (string)item_refid_change_table[location.RefID]; bChanged = true; } } if (bChanged == true) { nodes[i].InnerText = locations.ToString(true); nChangedCount++; } } return(nChangedCount); }
// // return: // -1 出错 // 0 没有发生替换修改 // >0 共修改了多少个<distribute>元素内容 /// <summary> /// 更换 orderInfo 元素里的 distribute 元素中的 refid 字符串 /// </summary> /// <param name="item_refid_change_table">参考 ID 对照表</param> /// <param name="strError">返回出错信息</param> /// <returns>-1 出错; 0 没有发生替换修改; >0 共修改了多少个 distribute 元素内容</returns> public int ReplaceOrderInfoItemRefID(Hashtable item_refid_change_table, out string strError) { strError = ""; int nRet = 0; string strOrderInfo = this.OrderInfo; if (String.IsNullOrEmpty(strOrderInfo) == true) { return(0); } XmlDocument dom = new XmlDocument(); dom.LoadXml("<orderInfo/>"); try { dom.DocumentElement.InnerXml = strOrderInfo; } catch (Exception ex) { strError = "load inner xml error: " + ex.Message; return(-1); } int nChangedCount = 0; XmlNodeList nodes = dom.DocumentElement.SelectNodes("*/distribute"); for (int i = 0; i < nodes.Count; i++) { string strDistribute = nodes[i].InnerText; if (String.IsNullOrEmpty(strDistribute) == true) { continue; } LocationCollection locations = new LocationCollection(); nRet = locations.Build(strDistribute, out strError); if (nRet == -1) { return(-1); } bool bChanged = false; for (int j = 0; j < locations.Count; j++) { Location location = locations[j]; if (item_refid_change_table.Contains(location.RefID) == true) { location.RefID = (string)item_refid_change_table[location.RefID]; bChanged = true; } } if (bChanged == true) { nodes[i].InnerText = locations.ToString(true); nChangedCount++; } } if (nChangedCount > 0) { this.OrderInfo = dom.DocumentElement.InnerXml; } return(nChangedCount); }
// // return: // -1 出错 // 0 没有发生替换修改 // >0 共修改了多少个<distribute>元素内容 /// <summary> /// 更换 orderInfo 元素里的 distribute 元素中的 refid 字符串 /// </summary> /// <param name="item_refid_change_table">参考 ID 对照表</param> /// <param name="strError">返回出错信息</param> /// <returns>-1 出错; 0 没有发生替换修改; >0 共修改了多少个 distribute 元素内容</returns> public int ReplaceOrderInfoItemRefID(Hashtable item_refid_change_table, out string strError) { strError = ""; int nRet = 0; string strOrderInfo = this.OrderInfo; if (String.IsNullOrEmpty(strOrderInfo) == true) return 0; XmlDocument dom = new XmlDocument(); dom.LoadXml("<orderInfo/>"); try { dom.DocumentElement.InnerXml = strOrderInfo; } catch (Exception ex) { strError = "load inner xml error: " + ex.Message; return -1; } int nChangedCount = 0; XmlNodeList nodes = dom.DocumentElement.SelectNodes("*/distribute"); for (int i = 0; i < nodes.Count; i++) { string strDistribute = nodes[i].InnerText; if (String.IsNullOrEmpty(strDistribute) == true) continue; LocationCollection locations = new LocationCollection(); nRet = locations.Build(strDistribute, out strError); if (nRet == -1) return -1; bool bChanged = false; for (int j = 0; j < locations.Count; j++) { Location location = locations[j]; if (item_refid_change_table.Contains(location.RefID) == true) { location.RefID = (string)item_refid_change_table[location.RefID]; bChanged = true; } } if (bChanged == true) { nodes[i].InnerText = locations.ToString(true); nChangedCount++; } } if (nChangedCount > 0) this.OrderInfo = dom.DocumentElement.InnerXml; return nChangedCount; }
// 复制新增 void menu_appendCopyElement_Click(object sender, EventArgs e) { int nPos = this.Container.Items.IndexOf(this); if (nPos == -1) { throw new Exception("not found myself"); } string strError = ""; string strXml = ""; Item source = this.Container.Items[nPos]; // 获得表示事项全部内容的XML记录 int nRet = BuildXml(out strXml, out strError); if (nRet == -1) throw new Exception(strError); string strBatchNo = ""; { string strDefaultXml = this.Container.GetDefaultXml(); if (string.IsNullOrEmpty(strDefaultXml) == false) { XmlDocument dom = new XmlDocument(); dom.LoadXml(strDefaultXml); strBatchNo = DomUtil.GetElementText(dom.DocumentElement, "batchNo"); } } // 修改一些字段 { XmlDocument dom = new XmlDocument(); dom.LoadXml(strXml); // 如果单价和总价都有,则要把总价清空 string strPrice = DomUtil.GetElementText(dom.DocumentElement, "price"); string strTotalPrice = DomUtil.GetElementText(dom.DocumentElement, "totalPrice"); if (string.IsNullOrEmpty(strPrice) == false && string.IsNullOrEmpty(strTotalPrice) == false) DomUtil.SetElementText(dom.DocumentElement, "totalPrice", ""); // 把 location 中的已验收信息清除 string strDistributeString = DomUtil.GetElementText(dom.DocumentElement, "distribute"); if (string.IsNullOrEmpty(strDistributeString) == false) { LocationCollection locations = new LocationCollection(); nRet = locations.Build(strDistributeString, out strError); if (nRet == -1) throw new Exception("馆藏分配去向字符串 '" + strDistributeString + "' 格式错误: " + strError); strDistributeString = locations.ToString(false); DomUtil.SetElementText(dom.DocumentElement, "distribute", strDistributeString); } DomUtil.SetElementText(dom.DocumentElement, "state", ""); DomUtil.SetElementText(dom.DocumentElement, "refID", ""); DomUtil.SetElementText(dom.DocumentElement, "range", ""); DomUtil.SetElementText(dom.DocumentElement, "batchNo", strBatchNo); strXml = dom.DocumentElement.OuterXml; } Item target = this.Container.InsertNewItem(nPos + 1, strXml); #if NO target.StateString = ""; target.RefID = ""; target.RangeString = ""; // TODO: 可以从上一个事项的时候后面自动计算延展 #endif target.EnsureVisible(); }
void DoItems(List<string> item_xmls, ProcessInfo info) { string strError = ""; List<EntityInfo> entityArray = new List<EntityInfo>(); string strRootElementName = ""; foreach (string xml in item_xmls) { if (string.IsNullOrEmpty(xml)) continue; XmlDocument item_dom = new XmlDocument(); item_dom.LoadXml(xml); strRootElementName = item_dom.DocumentElement.LocalName; string strPath = item_dom.DocumentElement.GetAttribute("path"); string strTimestamp = item_dom.DocumentElement.GetAttribute("timestamp"); EntityInfo item = new EntityInfo(); string strRefID = DomUtil.GetElementText(item_dom.DocumentElement, "refID"); if (strRootElementName == "item") { RefreshRefID(info.ItemRefIDTable, ref strRefID); } else if (strRootElementName == "order") { RefreshRefID(info.OrderRefIDTable, ref strRefID); // 记录中 distribute 元素中的 refid 要被替换 string strDistribute = DomUtil.GetElementText(item_dom.DocumentElement, "distribute"); if (string.IsNullOrEmpty(strDistribute) == false) { LocationCollection collection = new LocationCollection(); int nRet = collection.Build(strDistribute, out strError); if (nRet != -1) { collection.RefreshRefIDs(ref info.ItemRefIDTable); } string strNewDistribute = collection.ToString(); if (strNewDistribute != strDistribute) { DomUtil.SetElementText(item_dom.DocumentElement, "distribute", strNewDistribute); } } } else { RefreshRefID(null, ref strRefID); } item.RefID = strRefID; DomUtil.SetElementText(item_dom.DocumentElement, "refID", strRefID); DomUtil.SetElementText(item_dom.DocumentElement, "parent", Global.GetRecordID(info.BiblioRecPath)); string strXml = item_dom.DocumentElement.OuterXml; item.Action = "new"; item.NewRecord = strXml; item.NewTimestamp = ByteArray.GetTimeStampByteArray(strTimestamp); item.OldRecord = ""; item.OldTimestamp = null; entityArray.Add(item); } info.stop.SetMessage("正在为书目记录 '" + info.BiblioRecPath + "' 上传 "+info.UploadedSubItems+"+" + entityArray.Count + " 个下属 " + strRootElementName + " 记录 ..."); info.UploadedSubItems += entityArray.Count; EntityInfo[] errorinfos = null; long lRet = 0; if (strRootElementName == "item") lRet = info.Channel.SetEntities( info.stop, info.BiblioRecPath, entityArray.ToArray(), out errorinfos, out strError); else if (strRootElementName == "order") lRet = info.Channel.SetOrders( info.stop, info.BiblioRecPath, entityArray.ToArray(), out errorinfos, out strError); else if (strRootElementName == "issue") lRet = info.Channel.SetIssues( info.stop, info.BiblioRecPath, entityArray.ToArray(), out errorinfos, out strError); else if (strRootElementName == "comment") lRet = info.Channel.SetComments( info.stop, info.BiblioRecPath, entityArray.ToArray(), out errorinfos, out strError); else { strError = "未知的 strRootElementName '" + strRootElementName + "'"; throw new Exception(strError); } if (lRet == -1) throw new Exception(strError); if (errorinfos == null || errorinfos.Length == 0) return; StringBuilder text = new StringBuilder(); foreach (EntityInfo error in errorinfos) { if (String.IsNullOrEmpty(error.RefID) == true) throw new Exception("服务器返回的EntityInfo结构中RefID为空"); // 正常信息处理 if (error.ErrorCode == ErrorCodeValue.NoError) continue; text.Append(error.RefID + "在提交保存过程中发生错误 -- " + error.ErrorInfo + "\r\n"); info.ItemErrorCount++; } if (text.Length > 0) { strError = "在为书目记录 '" + info.BiblioRecPath + "' 导入下属 '" + strRootElementName + "' 记录的阶段出现错误:\r\n" + text.ToString(); this.OutputText(strError, 2); // 询问是否忽略错误继续向后处理? 此后全部忽略? if (AskContinue(info, strError) == false) throw new Exception(strError); } }