当前位置: 首页>>代码示例>>C#>>正文


C# DataProvider.GetReader方法代码示例

本文整理汇总了C#中DataProvider.GetReader方法的典型用法代码示例。如果您正苦于以下问题:C# DataProvider.GetReader方法的具体用法?C# DataProvider.GetReader怎么用?C# DataProvider.GetReader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataProvider的用法示例。


在下文中一共展示了DataProvider.GetReader方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetEnumScript

        public static string GetEnumScript(DataProvider provider, TableSchema.Table tbl, bool GenerateEnumDebugText, string[] EnumSettings,
		 string[] EnumSettingsExclude, ICodeLanguage language)
        {
            string rtn = "";
            bool IsVb = (language.Identifier=="VB.NET");
            string commentmarker = (IsVb ? "'" : "//");

            if (GenerateEnumDebugText) { rtn += "\r\n\r\n\t\t" + commentmarker + " tbl: " + tbl.Name; }

            for (int k = 0; k < EnumSettings.Length; k++) {
                string enumSetting = EnumSettings[k];
                string enumSettingExlude = "";
                if (EnumSettingsExclude.Length > k) { enumSettingExlude = EnumSettingsExclude[k]; }

                string[] settings = enumSetting.Split(new char[] { ':' });
                string regExFind = "";
                if (settings.Length > 0) { regExFind = settings[0].Trim(); }

                bool matched = regExFind.Length > 0
                    && Regex.IsMatch(tbl.Name, regExFind, RegexOptions.IgnoreCase);
                bool excluded = enumSettingExlude.Trim() != ""
                    && Regex.IsMatch(tbl.Name, enumSettingExlude.Trim(), RegexOptions.IgnoreCase);

                bool found = matched && !excluded;
                if (GenerateEnumDebugText) { rtn += "\r\n\t\t" + commentmarker + " " + k.ToString() + ": " + (matched ? "" : "not ") + "matched '" + regExFind + "'"; }
                if (GenerateEnumDebugText) { rtn += "\r\n\t\t" + commentmarker + " " + k.ToString() + ": " + (excluded ? "" : "not ") + "excluded '" + enumSettingExlude.Trim() + "'"; }

                if (found) {
                    string SqlScript = "";
                    //if (GenerateEnumDebugText) { SqlScript += "\r\n\t\t// tbl: " + tbl.Name + "\r\n\t\t// match: " + enumSetting; }

                    // Get Enum Details
                    string EnumName = "";
                    string IdCol = "";
                    string DescriptionCol = "";
                    string multiKeyCol = "";
                    string SqlWhereClause = "";
                    bool idColIsString = false;
                    bool isMulti = false;

                    bool idColFound = false;
                    bool descColFound = false;
                    bool multiKeyColFound = false;

                    if (settings.Length > 1) { EnumName = settings[1].Trim(); }
                    if (EnumName.StartsWith(MultiMarker, StringComparison.InvariantCultureIgnoreCase)) {
                        isMulti = true;
                        multiKeyCol = EnumName.Substring(MultiMarker.Length);
                    }
                    if (settings.Length > 2) { IdCol = settings[2].Trim(); }
                    if (settings.Length > 3) { DescriptionCol = settings[3].Trim(); }
                    if (settings.Length > 4) { SqlWhereClause = settings[4].Trim(); }

                    // check the cols do actually exist if specified
                    foreach (var col in tbl.Columns) {
                        if (IdCol == "" && col.IsPrimaryKey) { IdCol = col.ColumnName; }
                        if (DescriptionCol == "" && !col.IsPrimaryKey && !col.IsForeignKey
                        && col.DataType == System.Data.DbType.String) { DescriptionCol = col.ColumnName; }

                        if (IdCol == col.ColumnName) { idColFound = true; idColIsString = (col.DataType == System.Data.DbType.String); }
                        if (DescriptionCol == col.ColumnName) { descColFound = true; }

                        if (isMulti && multiKeyCol == col.ColumnName) { multiKeyColFound = true; }
                    }

                    if (EnumName == "") { EnumName = GetEnumName(tbl.ClassName, idColIsString); }

                    // generate the script or a warning message
                    if (!idColFound || !descColFound || (isMulti && !multiKeyColFound)) {
                        SqlScript += "\r\n\t\t" + commentmarker + " " + tbl.Name + ": enumSetting could not be matched to ID" + (isMulti ? ", Key " : "")
                        + " and Description columns. Setting=" + enumSetting + "\r\n";
                    }
                    else {
                        //pull the tables in a reader
                        int rowCount = 0;
                        List<string> enumValList = new List<string>();
                        string enumMemberScript = "";
                        string lastKeyVal = "";
                        string sql = GetEnumSql(IdCol, DescriptionCol, multiKeyCol, tbl.Name, SqlWhereClause);
                        try {
                            using (IDataReader rdr = provider.GetReader(new QueryCommand(sql))) {
                                while (rdr.Read()) {
                                    string enumMemberName = CleanUp(rdr[DescriptionCol].ToString());
                                    if (enumValList.Contains(enumMemberName)) {
                                        int uniqueVal = 0;
                                        string tempMemberName = enumMemberName;
                                        while (enumValList.Contains(tempMemberName)) {
                                            tempMemberName = enumMemberName + (++uniqueVal).ToString();
                                        }
                                        enumMemberName = tempMemberName;
                                    }

                                    string enumMemberValue = rdr[IdCol].ToString();
                                    string enumKeyVal = (isMulti ? CleanUp(rdr[multiKeyCol].ToString()) : "");

                                    if (rowCount != 0 && lastKeyVal != enumKeyVal) {
                                        // we are doing a multi read, use the key val to generate an enum for each block of key values
                                        string tempEnumName = GetEnumName(lastKeyVal, idColIsString);
                                        SqlScript += GetEnumHeaderFooter(tbl.Name, tempEnumName, IdCol, DescriptionCol, enumMemberScript, idColIsString, IsVb);
                                        enumMemberScript = "";
//.........这里部分代码省略.........
开发者ID:RyanDansie,项目名称:SubSonic-2.0,代码行数:101,代码来源:EnumTemplateHelper.cs


注:本文中的DataProvider.GetReader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。