public Caption GetCaption(string strLang) { Caption OneCaption = null; // 匹配中仅仅得1分的第一个对象 for (int i = 0; i < this.Captions.Count; i++) { Caption caption = this.Captions[i]; if (String.IsNullOrEmpty(strLang) == true) // 如果给出的语言为未知, 则直接返回第一个caption { return(caption); } int nRet = CompareLang(caption.Lang, strLang); if (nRet == 2 || // 匹配得2分 String.IsNullOrEmpty(caption.Lang) == true) // 或者为中立语言 { return(caption); } if (nRet == 1 && OneCaption == null) { OneCaption = caption; } } return(OneCaption); // 如果有1分匹配的话 }
// 2012/2/8 // 返回左端匹配或者完全匹配的所有Caption public List <Caption> GetCaptions(string strLang) { List <Caption> results = new List <Caption>(); for (int i = 0; i < this.Captions.Count; i++) { Caption caption = this.Captions[i]; if (String.IsNullOrEmpty(strLang) == true) // 如果给出的语言为未知, 则直接返回第一个caption { results.Add(caption); return(results); } int nRet = CompareLang(caption.Lang, strLang); if (nRet == 2 || // 匹配得2分 String.IsNullOrEmpty(caption.Lang) == true) // 或者为中立语言 { results.Add(caption); } else if (nRet == 1) { results.Add(caption); } } return(results); }
// 2014/8/29 // 获得一个 from 的 stylelist public string GetFromStyles(string strDbName, string strFrom, string strLang) { KernelDbInfo db = this.FindDb(strDbName); if (db == null) { return(null); } // 遍历当前数据库的所有form foreach (From from in db.Froms) { // 注: 同一个语言代码的 caption,也可能有不止一个 List <Caption> captions = from.GetCaptions(strLang); if (captions == null || captions.Count == 0) { // 防范没有找到的情形 Caption tempCaption = from.GetCaption(null); // 获得中立语言的caption if (tempCaption == null) { throw new Exception("数据库 '" + db.Captions[0].Value + "' 中没有找到From事项 " + from.ToString() + " 的任何Caption"); } captions.Add(tempCaption); } foreach (Caption caption in captions) { if (caption.Value == strFrom) { return(from.Styles); } } #if NO Caption tempCaption = from.GetCaption(strLang); if (tempCaption == null) { // 防范没有找到的情形 tempCaption = from.GetCaption(null); // 获得中立语言的caption if (tempCaption == null) { throw new Exception("数据库 '" + db.Captions[0].Value + "' 中没有找到From事项 " + from.ToString() + " 的任何Caption"); } } if (tempCaption.Value == strFrom) { return(from.Styles); } #endif } return(null); }
// 根据从服务器获得的名称数组,构造为本类可以使用的List<Caption>类型 public static int BuildCaptions(string[] names, out List <Caption> captions, out string strError) { strError = ""; captions = new List <Caption>(); for (int i = 0; i < names.Length; i++) { string strName = names[i]; int nRet = strName.IndexOf(':'); string strLang = ""; string strValue = ""; if (nRet != -1) { strLang = strName.Substring(0, nRet); strValue = strName.Substring(nRet + 1); } else { strLang = strName; strValue = ""; strError = "出现错误的事项 '" + strName + "',中间缺乏冒号 "; return(-1); } Caption caption = new Caption(strLang, strValue); captions.Add(caption); } return(0); }
// 从特定的数据库中, 匹配出满足特定风格列表的from列表 // parameters: // strFromStyle from style的列表, 以逗号分割。 // 如果为空,表示全部途径(2007/9/13) // return: // null 没有找到 // 以逗号分割的from名列表 public string BuildCaptionListByStyleList(string strDbName, string strFromStyles, string strLang) { KernelDbInfo db = this.FindDb(strDbName); if (db == null) { return(null); } // string strResult = ""; // 2007/9/13 if (String.IsNullOrEmpty(strFromStyles) == true || strFromStyles == "<全部>" || strFromStyles.ToLower() == "<all>") { return("<all>"); // strFromStyles = "<all>"; } List <string> results = new List <string>(); // 拆分出单独的style字符串 string[] styles = strFromStyles.Split(new char[] { ',' }); for (int i = 0; i < styles.Length; i++) { string strStyle = styles[i].Trim(); if (String.IsNullOrEmpty(strStyle) == true) { continue; } // 2012/5/16 // 忽略 _time/_freetime,_rfc1123time/_utime等表示检索特性的style if (StringUtil.HasHead(strStyle, "_") == true && StringUtil.HasHead(strStyle, "__") == false) // 但是 __ 引导的要参与匹配 { continue; } // 遍历当前数据库的所有form的styles for (int j = 0; j < db.Froms.Count; j++) { string strStyles = db.Froms[j].Styles; if (StringUtil.IsInList(strStyle, strStyles) == true || strStyle == "<all>") // 2007/9/13 // 注:后来发现内核本来就支持<all>的from后,这里就没有必要了,但是代码仍保留 { Caption tempCaption = db.Froms[j].GetCaption(strLang); if (tempCaption == null) { // 防范没有找到的情形 tempCaption = db.Froms[j].GetCaption(null); // 获得中立语言的caption if (tempCaption == null) { throw new Exception("数据库 '" + db.Captions[0].Value + "' 中没有找到下标为 " + j.ToString() + " 的From事项的任何Caption"); } } // 全部路径情况下,要不包含"__id"途径 if (strStyle == "<all>" && tempCaption.Value == "__id") { continue; } #if NO if (strResult != "") { strResult += ","; } strResult += tempCaption.Value; #endif results.Add(tempCaption.Value); } } } // return strResult; StringUtil.RemoveDupNoSort(ref results); return(StringUtil.MakePathList(results)); }