/// <summary> /// Generate dbo.Country. Write your time consuming task here /// </summary> /// <param name="s"></param> public void LTT_CountryCode(string s) { using (var ctx = new RT2020Entities()) { ctx.Configuration.LazyLoadingEnabled = false; #region Generate missing dbo.Country from VWG.Community.Util.CountryCodes var dboCounttries = ctx.Country.ToList(); var ccodes = new CountryCodes(); var codelist = ccodes.GetList(); OpenCC.Load(); using (var scope = ctx.Database.BeginTransaction()) { try { foreach (var item in codelist) { //! CountryCode = ISO3166_1_Alpha_2,CountryName = CLDR_displayname if (item.ISO3166_1_Alpha_2 == String.Empty) { continue; } // 2020.11.25 paulus: 再改番用 ISO3166_1_Alpha_2 //var exist = ctx.Country.Where(x => x.CountryCode == item.FIPS).FirstOrDefault(); var exist = ctx.Country.Where(x => x.CountryCode == item.ISO3166_1_Alpha_2).FirstOrDefault(); if (exist == null) { exist = new Country(); exist.CountryId = Guid.NewGuid(); exist.CountryCode = item.ISO3166_1_Alpha_2; exist.CountryName = item.CLDR_displayname; if (!String.IsNullOrEmpty(item.official_name_cn)) { exist.CountryName_Chs = item.official_name_cn; exist.CountryName_Cht = OpenCC.Convert(item.official_name_cn, OpenCCType.s2hk.ToString("g")); } ctx.Country.Add(exist); ctx.SaveChanges(); } else { exist.CountryName = item.CLDR_displayname; exist.CountryName_Chs = item.official_name_cn; exist.CountryName_Cht = OpenCC.Convert(item.official_name_cn, OpenCCType.s2hk.ToString("g")); ctx.SaveChanges(); } _CurrentItem = exist.CountryName; } scope.Commit(); } catch { scope.Rollback(); } } #endregion } }
private void cmdConvert_Click(object sender, EventArgs e) { switch (_CurrentMode) { case CurrentMode.Text: try { OpenCC.Load(); txtResult.Text = OpenCC.Convert(txtSource.Text, _ConfigFileName); } catch (Exception exception) { MessageBox.Show(exception.Message); } break; case CurrentMode.FileList: //FileListUtility.ConvertAndStoreFilesInList(fileListItems, _ConfigFileName); break; } }
/// <summary> /// 將費時嘅工序放喺呢度做 /// </summary> /// <param name="s"></param> public void LTT_MemberPhoneNumber(string s) { // Write your time consuming task here using (var ctx = new RT2020Entities()) { ctx.Configuration.LazyLoadingEnabled = false; #region Generate random phone numbers for each Member var mbrAddresses = ctx.MemberAddress.Where(x => x.PhoneTag1Value != "" || x.PhoneTag2Value != ""); var counts = mbrAddresses.Count(); if (counts > 0) { OpenCC.Load(); var ccodes = new CountryCodes(); var codelist = ccodes.GetList(); using (var scope = ctx.Database.BeginTransaction()) { try { List <String> countries = new List <string>(); foreach (var item in mbrAddresses) { /* 假設條件(address 先決): * 1. 非 ASCII 地址就係中國 * 2. 由 Address 找到所屬 Country,分為:中國﹑香港﹑其他 * 3. 如果 match 唔倒,當係 香港 */ String country = "", areacode = "", number1 = "", number2 = ""; country = IsChinese(item.Address) ? "china" : StripCountry(item.Address); if (country != String.Empty) { country = country.ToLower().Replace(".", ""); var validCountry = ccodes.FindByDisplayName(country); var found = validCountry != null ? true : false; if (!found) { country = "hong kong"; } var inList = countries.Where(x => x == country).FirstOrDefault(); if (inList == null) { countries.Add(country); } } _CurrentItem = (--counts).ToString(); //ctx.SaveChanges(); } #region 顯示結果:countries 有哂啲 unique 嘅名,轉做 array 再轉為 json string 方便顯示個 result var str = String.Join("; ", countries.OrderBy(x => x).ToArray()); _AllCountries = Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(str)).Replace("?", ""); #endregion //scope.Commit(); } catch { //scope.Rollback(); } } } #endregion } }