示例#1
0
        /// <summary>
        /// 根据名称获取SQL(或视图)语句 (已经处理过注释,和参数替换的内容)
        /// </summary>
        /// <param name="key"></param>
        /// <param name="stringFormatValues">如果需要格式化大括号参数</param>
        /// <returns></returns>
        public static string GetCode(string key, params object[] stringFormatValues)
        {
            if (!string.IsNullOrEmpty(key))
            {
                Dictionary <string, string> fileList = FileList;
                if (fileList.ContainsKey(key))
                {
                    string text = fileList[key];

                    if (text.Contains(":\\"))
                    {
                        text = FileExtend.ReadAllText(text);
                        int index = text.LastIndexOf("/*");
                        if (index > -1)//去掉注释
                        {
                            text = Regex.Replace(text, @"/\*[.\s\S]*?\*/", string.Empty, RegexOptions.IgnoreCase);
                        }
                    }
                    text = text.Trim();
                    if (stringFormatValues.Length > 0)
                    {
                        text = string.Format(text, stringFormatValues);
                    }
                    text = FormatPara(text.Trim());      //去掉空格
                    if (key[0] == 'V' && text[0] != '(') //补充语法
                    {
                        text = "(" + text + ") " + key;
                    }

                    //参数化格式
                    return(text);
                }
            }
            return(key);
        }
示例#2
0
 /// <summary>
 /// 根据名称获取原始的SQL(或视图)语句
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 internal static string GetSourceCode(string key)
 {
     if (!string.IsNullOrEmpty(key))
     {
         if (FileList != null && FileList.ContainsKey(key))
         {
             string path = FileList[key];
             return(FileExtend.ReadAllText(path));
         }
     }
     return(string.Empty);
 }
示例#3
0
        /// <summary>
        /// 根据名称获取SQL(或视图)语句 (已经处理过注释,和参数替换的内容)
        /// </summary>
        /// <param name="key"></param>
        /// <param name="stringFormatValues">如果需要格式化大括号参数</param>
        /// <returns></returns>
        public static string GetCode(string key, params object[] stringFormatValues)
        {
            if (!string.IsNullOrEmpty(key))
            {
                if (key[0] == '_')
                {
                    key = key.Substring(1);
                }
                Dictionary <string, string> fileList = FileList;
                if (fileList.ContainsKey(key))
                {
                    string text   = fileList[key];
                    string folder = null;
                    if (text.Contains(":\\"))
                    {
                        folder = text;
                        text   = FileExtend.ReadAllText(text);
                        int index = text.LastIndexOf("/*");
                        if (index > -1)//去掉注释
                        {
                            text = Regex.Replace(text, @"/\*[.\s\S]*?\*/", string.Empty, RegexOptions.IgnoreCase);
                        }
                    }
                    text = text.Trim();
                    if (stringFormatValues.Length > 0)
                    {
                        text = string.Format(text, stringFormatValues);
                    }
                    text = FormatPara(text.Trim());                                       //去掉空格
                    if (key[0] == 'V' && text[0] != '(' && !string.IsNullOrEmpty(folder)) //补充语法
                    {
                        //如果文件夹名包含数据库名,则补充数据库前缀。
                        foreach (string name in CrossDb.DbTables.Keys)
                        {
                            if (folder.IndexOf("\\" + name + "\\", StringComparison.OrdinalIgnoreCase) > -1)
                            {
                                text = "(" + text + ") " + name + "." + key;//补充数据库前缀。
                                break;
                            }
                        }
                    }

                    //参数化格式
                    return(text);
                }
            }
            return(key);
        }
示例#4
0
        /// <summary>
        /// 根据名称获取原始的SQL(或视图)语句
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string Get(string key)
        {
            if (!string.IsNullOrEmpty(key))
            {
                string   file  = key.Replace(".sql", "") + ".sql";
                string[] files = Directory.GetFiles(SqlCode.path, file, SearchOption.AllDirectories);
                if (files != null && files.Length > 0)
                {
                    return(FileExtend.ReadAllText(files[0]));
                }

                if (FileList != null && FileList.ContainsKey(key))
                {
                    string path = FileList[key];
                    return(FileExtend.ReadAllText(path));
                }
            }
            return(string.Empty);
        }