`
wangdeshui
  • 浏览: 255643 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Get countries from system

阅读更多
   1: using System;
   2: using System.Collections.Generic;
   3: using System.Linq;
   4: using System.Text;
   5: using System.Globalization;
   6: using System.IO;
   7:  
   8: namespace CultureInformation
   9: {
  10:     class Program
  11:     {
  12:         static void Main(string[] args)
  13:         {
  14:             StreamWriter sw = new StreamWriter(@"D:\PopulateTableData.Txt");
  15:             CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
  16:            
  17:             StringBuilder sb = new StringBuilder();
  18:  
  19:             sb.AppendLine(" declare @LocalizableId bigint, @CultureId bigint,@CurrencyId bigint ");
  20:  
  21:             //insert Culture
  22:             foreach (CultureInfo item in cultures)
  23:             {
  24:                 sb.AppendLine(string.Format("INSERT INTO [LocalizableText] ([CultureInvariantText]) VALUES('{0}') ", item.EnglishName.Replace("'", "''")));
  25:                 sb.AppendLine(" set @LocalizableId=IDENT_CURRENT('LocalizableText') ");
  26:                 sb.AppendLine(string.Format("INSERT INTO [Culture]([Code],[Name]) VALUES('{0}',@LocalizableId)", item.Name));
  27:             }
  28:  
  29:             //insert currency
  30:             List<string> currencyList = new List<string>();
  31:             foreach (CultureInfo item in cultures)
  32:             {
  33:                 RegionInfo r = new RegionInfo(item.LCID);
  34:  
  35:                 if (!currencyList.Contains(r.ISOCurrencySymbol))
  36:                 {
  37:                     currencyList.Add(r.ISOCurrencySymbol);
  38:                     sb.AppendLine(string.Format("INSERT INTO [LocalizableText] ([CultureInvariantText]) VALUES ('{0}')", r.CurrencyEnglishName.Replace("'", "''")));
  39:                     sb.AppendLine(" set @LocalizableId=IDENT_CURRENT('LocalizableText') ");
  40:                     sb.AppendLine(string.Format("INSERT INTO Currency ([IsoCode],[Name]) VALUES ('{0}',@LocalizableId)", r.ISOCurrencySymbol));
  41:                 }
  42:             }
  43:  
  44:             // insert country
  45:             List<string> cultureList = new List<string>();
  46:             foreach (CultureInfo item in cultures)
  47:             {
  48:                 RegionInfo r = new RegionInfo(item.LCID);
  49:                 if (!(cultureList.Contains(r.ThreeLetterISORegionName)))
  50:                 {
  51:                     cultureList.Add(r.ThreeLetterISORegionName);
  52:                     if (r.TwoLetterISORegionName.Length > 2) continue;
  53:                     sb.AppendLine(string.Format("INSERT INTO [LocalizableText] ([CultureInvariantText]) VALUES ('{0}')", r.EnglishName.Replace("'", "''")));
  54:                     sb.AppendLine(" set @LocalizableId=IDENT_CURRENT('LocalizableText') ");
  55:                     sb.AppendLine(string.Format(" select @CultureId=[CultureId] from [Culture] where [Code]='{0}'", item.Name));
  56:                     sb.AppendLine(string.Format("  select @CurrencyId=[CurrencyId] from [Currency] where [IsoCode]='{0}'", r.ISOCurrencySymbol));
  57:                     sb.AppendLine(string.Format("INSERT INTO Country([IsoCode3],[IsoCode2],[CurrencyId],[CultureId],[Name]) VALUES('{0}','{1}',@CurrencyId,@CultureId,@LocalizableId)",
  58:                                 r.ThreeLetterISORegionName, r.TwoLetterISORegionName));
  59:                 }
  60:  
  61:             }
  62:  
  63:  
  64:             sw.WriteLine(sb.ToString());
  65:  
  66:             sw.Flush();
  67:             sw.Close();
  68:             Console.ReadLine();
  69:         }
  70:  
  71:  
  72:         public static List<string> GetCountryList()
  73:         {
  74:  
  75:             //create a new Generic list to hold the country names returned
  76:             List<string> cultureList = new List<string>();
  77:             //create an array of CultureInfo to hold all the cultures found, these include the users local cluture, and all the
  78:  
  79:             //cultures installed with the .Net Framework
  80:             CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures);
  81:  
  82:             //loop through all the cultures found
  83:             foreach (CultureInfo culture in cultures)
  84:             {
  85:                 //pass the current culture's Locale ID (http://msdn.microsoft.com/en-us/library/0h88fahh.aspx)
  86:                 //to the RegionInfo contructor to gain access to the information for that culture
  87:                 RegionInfo region = new RegionInfo(culture.LCID);
  88:                 //make sure out generic list doesnt already
  89:                 //contain this country
  90:                 if (!(cultureList.Contains(region.EnglishName)))
  91:  
  92:                     //not there so add the EnglishName (http://msdn.microsoft.com/en-us/library/system.globalization.regioninfo.englishname.aspx)
  93:  
  94:                     //value to our generic list
  95:                     cultureList.Add(region.EnglishName);
  96:             }
  97:             return cultureList;
  98:  
  99:         }
 100:     }
 101: }
分享到:
评论

相关推荐

    system mechanic Activator v1.0

    * Use at your own risk, and don't forget to read instructions carefully!! * Stop all components, including System Mechanic, Firewall, Antivirus, SMSystemAnalyzer, SMTrayNotify, Drive Scrubber & ...

    SQLite数据库 sqlitedll库文件 sqlite驱动JAR包 sqlite工具

    20 ResultSet rs = stmt.executeQuery("SELECT * FROM pmp_countries ORDER BY country_name ASC"); 21 // Iterate the result set, printing each column 22 // if the column was an int, we could do rs.getInt...

    Universal-USB-Installer

    Source Code is made available at time of download, from the official UUI page: http://www.pendrivelinux.com/universal-usb-installer-easy-as-1-2-3/ IMPORTANT! No Warranty is being offered with this ...

    端口查看工具

    of cports.exe, and CurrPorts will automatically use it to get the country/city information for every remote IP address. * Version 2.02: o CurrPorts now displays a simple error message if it fails ...

    计算机网络第六版答案

    Third, if ISPs decide to charge more money to highly profitable content providers (in countries where net neutrality doesn't apply), the content providers can avoid these extra payments. 16. The ...

    WizFlow网页编辑

    is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked ...

    hibernate-shards.jar

    is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked ...

    Diskeeper 2008 v12.0.759.0

    in Diskeeper (and their system) performance. This list summarizes the most important features in the various editions. More information about each of these features is available in the Diskeeper ...

    asp.net mvc

    In order to mitigate JSON hijacking attacks that have the potential for information disclosure, by default, the JsonResult class now responds only to HTTP POST requests. Ajax GET calls to action ...

    吴建业作文观点汇总

    8. The traditional school is a place where children get training of the mind and character to produce self-control, habits of obedience as well as learn to write and read, 9. Lack adequate physical ...

    BIG文件编辑器

    or you can drag & drop files from Windows Explorer into FinalBIG. Just drop the files (or directories!) on the file list of your BIG file. A window will come up telling you that FinalBIG needs to ...

    六级词汇高频词汇

    - 示例:The sophisticated system uses advanced algorithms to process data. 4. **Productive (adj.)** – 生产性的,多产的 - 示例:She had a productive day and completed several important tasks. 5. **...

Global site tag (gtag.js) - Google Analytics