/// <summary> /// 在Hash表中查找ID编号的配置 并将结果放在DaoStruct结构中 /// </summary> /// <param name="sid"></param> /// <returns></returns> public DaoStruct ObtainConfig(string sid) { Hashtable hash = new Hashtable(); hash = newinstance.getHash(); if (hash == null) { throw new Exception("Class [ParseDaoConfig'] 解析数据访问对象配置没有数据"); } DaoStruct daostruct = new DaoStruct(); foreach (DictionaryEntry de in hash) { if (de.Key.ToString() == sid) { daostruct = (DaoStruct)de.Value; break; } } return(daostruct); }
/// <summary> /// 将配置信息加载到HASH表中,Hash.key = 配置中的ID属性 Hash.Value = DaoStruct结构 /// </summary> /// <returns></returns> private Hashtable getDaoConfig() { Hashtable hashtable = new Hashtable(); hashtable.Clear(); XmlDocument oChildDoc = new XmlDocument(); XmlNode oXmlNodes; XmlNode oXmlNode; XmlNode sqlNodes; XmlNode sqlNode; XmlNode dbNodes; XmlNode dbNode; string sconstr = ""; string sdbtype = ""; string sid = ""; string sqlid = ""; string spacehold = ""; try { oXmlNodes = oXmlDoc.DocumentElement.SelectSingleNode("sqlmapconfig"); dbNodes = oXmlDoc.DocumentElement.SelectSingleNode("dao"); for (int i = 0; i < oXmlNodes.ChildNodes.Count; i++) { oXmlNode = oXmlNodes.ChildNodes[i]; sid = oXmlNode.Attributes.GetNamedItem("dbtype").InnerXml; oChildDoc.Load(dicConfig + oXmlNode.Attributes.GetNamedItem("resource").InnerXml); for (int k = 0; k < dbNodes.ChildNodes.Count; k++) { dbNode = dbNodes.ChildNodes[k]; if (sid == dbNode.Attributes.GetNamedItem("id").InnerXml) { sdbtype = dbNode.Attributes.GetNamedItem("type").InnerXml; spacehold = dbNode.Attributes.GetNamedItem("spacehold").InnerXml; if (spacehold.ToLower() == "true") { string tempstr = ""; sconstr = dbNode.SelectSingleNode("property").InnerXml; int b = sconstr.IndexOf('{') + 1; int e = sconstr.IndexOf('}'); tempstr = sconstr.Substring(b, e - b); sconstr = sconstr.Replace("{" + tempstr + "}", BASEDIC + tempstr); } else { sconstr = dbNode.SelectSingleNode("property").InnerXml; } break; } } sqlNodes = oChildDoc.SelectSingleNode("sqlmap"); for (int j = 0; j < sqlNodes.ChildNodes.Count; j++) { sqlNode = sqlNodes.ChildNodes[j]; DaoStruct daostruct = new DaoStruct(); daostruct.ConStr = sconstr; daostruct.DbType = sdbtype.ToLower(); daostruct.OperationType = sqlNode.Attributes.GetNamedItem("type").InnerXml.ToLower(); daostruct.ClassName = sqlNode.Attributes.GetNamedItem("class").InnerXml; if (sqlNode.Attributes.GetNamedItem("resultclass") != null) { daostruct.ResultClassName = sqlNode.Attributes.GetNamedItem("resultclass").InnerXml; } else { daostruct.ResultClassName = ""; } if (sqlNode.Attributes.GetNamedItem("desc") != null) { daostruct.Desc = sqlNode.Attributes.GetNamedItem("desc").InnerXml; } else { daostruct.Desc = ""; } if (sqlNode.Attributes.GetNamedItem("islog") != null) { string logstr = sqlNode.Attributes.GetNamedItem("islog").InnerXml.ToLower(); if (logstr == "true") { daostruct.IsLog = true; } else { daostruct.IsLog = false; } } else { daostruct.IsLog = false; } daostruct.SqlStr = sqlNode.InnerXml; sqlid = sqlNode.Attributes.GetNamedItem("id").InnerXml; hashtable.Add(sqlid, daostruct); } } } catch (XmlException e) { throw new Exception("Class [ParseDaoConfig'] 解析数据访问对象配置出错" + e.Message); } return(hashtable); }