public static void Localize(this RadioButtonList rbl, LangResource resourceManager) { foreach (ListItem item in rbl.Items) { item.Text = resourceManager.GetString(item.Text); } }
public static void Localize(this DropDownList ddl, LangResource resourceManager) { foreach (ListItem item in ddl.Items) { item.Text = resourceManager.GetString(item.Text); } }
public static void Localize(this CheckBoxList cbl, LangResource resourceManager) { foreach (ListItem item in cbl.Items) { item.Text = resourceManager.GetString(item.Text); } }
public static void Localize(this GridView gridview, LangResource resourceManager) { foreach (DataControlField field in gridview.Columns) { field.HeaderText = resourceManager.GetString(field.HeaderText); } }
public static void Localize(this ValidatorCollection collection, LangResource resoourceManager) { foreach (BaseValidator validator in collection) { validator.ErrorMessage = resoourceManager.GetString(validator.ErrorMessage); } }
private static void Save(SqlTransaction sqlTrans, LangResource langResource) { //-- Record locked? _BaseDB.RecordLocked(sqlTrans, langResource); //-- For Date:Created,Modified,Deleted DateTime eventDate = DateTime.Now.ToUniversalTime(); Guid newRecordLock = Guid.NewGuid(); //-- Params and Sql statements SqlParameter[] sqlParams = { new SqlParameter("@LangResourceID", langResource.RecordID) , new SqlParameter("@LangResourceName", langResource.RecordName) , new SqlParameter("@ResourceType", langResource.ResourceType) , new SqlParameter("@Comment", langResource.Comment) , new SqlParameter("@_EventUser", langResource.UserID) , new SqlParameter("@_EventDate", eventDate) , new SqlParameter("@_NewRecordLock", newRecordLock) }; string sqlInsert = @"INSERT INTO tblLangResource (LangResourceName, ResourceType, Comment, UserCreated, DateCreated, RecordLock) VALUES(@LangResourceName, @ResourceType, @Comment, @_EventUser, @_EventDate, @_NewRecordLock); SELECT @@IDENTITY AS [@@IDENTITY] " ; string sqlUpdate = @"UPDATE tblLangResource set LangResourceName = @LangResourceName , ResourceType = @ResourceType , Comment = @Comment , UserModified = @_EventUser , DateModified = @_EventDate , RecordLock = @_NewRecordLock WHERE LangResourceID = @LangResourceID " ; //-- Execute SQL and set object properties if (langResource.RecordID == 0) { langResource.RecordID = Int32.Parse(SqlHelper.ExecuteDataset(sqlTrans, CommandType.Text, sqlInsert, sqlParams).Tables[0].Rows[0][0].ToString()); langResource.userCreated = langResource.UserID; langResource.dateCreated = eventDate; } else { SqlHelper.ExecuteNonQuery(sqlTrans, CommandType.Text, sqlUpdate, sqlParams); langResource.userModified = langResource.UserID; langResource.dateModified = eventDate; } langResource.RecordLock = newRecordLock; }
private static LangResource LoadMapping(DataRow dr) { LangResource langResource = new LangResource(); langResource.RecordID = (int)dr["LangResourceID"]; langResource.RecordName = (string)dr["LangResourceName"]; langResource.ResourceType = (string)dr["ResourceType"]; langResource.Comment = (string)dr["Comment"]; _BaseDB.LoadMapping(langResource, dr); return(langResource); }
private static LangResource Load(string sqlSelect, SqlParameter[] sqlParams) { //-- Select, Params, Execute SQL string connectionString = _BaseDB.ConnectionString(); DataTable dt = SqlHelper.ExecuteDataset(connectionString, CommandType.Text, sqlSelect, sqlParams).Tables[0]; //-- Lang Object LangResource langResource = new LangResource(); if (dt.Rows.Count > 0) { langResource = LoadMapping(dt.Rows[0]); } return(langResource); }
public static ArrayList LoadList() { //-- Select, Params, Execute SQL string connectionString = _BaseDB.ConnectionString(); string sqlSelectList = "SELECT " + SqlSelectList() + " FROM tblLangResource ORDER BY LangResourceName"; DataTable dt = SqlHelper.ExecuteDataset(connectionString, CommandType.Text, sqlSelectList).Tables[0]; //-- Load Array List ArrayList list = new ArrayList(); foreach (DataRow dr in dt.Rows) { LangResource langResource = LoadMapping(dr); list.Add(langResource); } return(list); }
public static void Localize(this Control control, LangResource resourceManager) { if (control.HasControls()) { foreach (Control subctrl in control.Controls) { subctrl.Localize(resourceManager); } } else { //简单显示 if (control is Localize) { ((Localize)control).Text = resourceManager.GetString(((Localize)control).Text); } //按钮 else if (control is Button) { ((Button)control).Text = resourceManager.GetString(((Button)control).Text); } else if (control is LinkButton) { (control as LinkButton).Text = resourceManager.GetString((control as LinkButton).Text); } //链接 else if (control is HyperLink) { (control as HyperLink).Text = resourceManager.GetString((control as HyperLink).Text); } //列表,list类型需要手动调用 else if (control is RadioButton) { (control as RadioButton).Text = resourceManager.GetString((control as RadioButton).Text); } else if (control is CheckBox) { (control as CheckBox).Text = resourceManager.GetString((control as CheckBox).Text); } } }
//-- Save public static void Save(LangResource langResource) { SqlConnection sqlConn = new SqlConnection(_BaseDB.ConnectionString()); sqlConn.Open(); SqlTransaction sqlTrans = sqlConn.BeginTransaction(); try { Save(sqlTrans, langResource); sqlTrans.Commit(); } catch (Exception ex) { sqlTrans.Rollback(); throw ex; } finally { sqlConn.Close(); } }
public static void Localize(this GridViewRow gvrow, int[] columns, LangResource resourceManager) { if (gvrow.RowType == DataControlRowType.DataRow) { foreach (int i in columns) { if (i < gvrow.Cells.Count) { if (gvrow.Cells[i].Controls.Count == 0) { gvrow.Cells[i].Text = resourceManager.GetString(gvrow.Cells[i].Text); } else { foreach (Control cc in gvrow.Cells[i].Controls) { cc.Localize(resourceManager); } } } } } }
public async Task Execute(string resource, string value) { var strings = resource.Split('|'); var res = strings[0]; var key = strings[1]; var langRes = await _dbContext .Set <LangResourceValue>() .Include(l => l.LangResource) .FirstOrDefaultAsync( c => c.LangResource.Name == res && c.LangResource.Culture.Key == Thread.CurrentThread.CurrentUICulture.IetfLanguageTag && c.Key == key); //?? new LangResourceValue //{ // Key = key, // Value = value, // LangResource = await _dbContext //.Set<LangResource>() //.FirstAsync( // lr => // lr.Culture.Key == Thread.CurrentThread.CurrentUICulture.IetfLanguageTag && // lr.Name == res) //}; if (langRes == null) { var langResource = await _dbContext .Set <LangResource>() .FirstOrDefaultAsync( lr => lr.Culture.Key == Thread.CurrentThread.CurrentUICulture.IetfLanguageTag && lr.Name == res); if (langResource == null) { var langCulture = await _dbContext .Set <LangCulture>() .FirstOrDefaultAsync(c => c.Key == Thread.CurrentThread.CurrentUICulture.IetfLanguageTag); if (langCulture == null) { var langResourceValue = await _langResourceValueQuery.Execute("languages", Thread.CurrentThread.CurrentUICulture.DisplayName.Split(' ')[0]); langCulture = new LangCulture { Key = Thread.CurrentThread.CurrentUICulture.IetfLanguageTag, Language = await _simpleQuery.Execute(new ByNameCondition <Language>(langResourceValue.Value)).FirstOrDefaultAsync() }; } langResource = new LangResource { Culture = langCulture, Name = res }; } langRes = new LangResourceValue { Key = key, Value = value, LangResource = langResource }; _dbContext.Set <LangResourceValue>().Add(langRes); } langRes.Value = value; await _dbContext .SaveChangesAsync(); }
protected override void Seed(DefaultCtx context) { //Debugger.Launch(); try { var cultureSeed = new CultureSeed(context); var langSeed = new LanguageSeed(context); var countrySeed = new ContrySeed(context, cultureSeed, langSeed); var domainSeed = new HttpDomainSeed(context); var educationSeed = new EducationSeed(context); var workingTermsSeed = new WorkingTermsSeed(context); var workingSkillSeed = new WorkingSkillSeed(context); var residenceSeed = new LiveinoutSeed(context); var employmentSeed = new EmploymentSeed(context); var childrenCountSeed = new ChildrenCountSeed(context); var worshipSeed = new ReligionSeed(context); var aboutNannySeed = new AboutNannySeed(context); var aboutNurseSeed = new AboutNurseSeed(context); var aboutHousekeeperSeed = new AboutHousekeeperSeed(context); var workingConditionSeed = new WorkingConditionSeed(context); countrySeed.Execute(); langSeed.Execute(); domainSeed.Execute(); educationSeed.Execute(); workingTermsSeed.Execute(); workingSkillSeed.Execute(); residenceSeed.Execute(); employmentSeed.Execute(); childrenCountSeed.Execute(); worshipSeed.Execute(); aboutNannySeed.Execute(); aboutNurseSeed.Execute(); aboutHousekeeperSeed.Execute(); workingConditionSeed.Execute(); if (context.Metroes.Any()) { return; } var enLangCulture = langSeed.GetCulture("en-US", "languages|english"); var ruLr = new LangResource { Name = "metro", Culture = enLangCulture, Values = new[] { new LangResourceValue { Key = "kazan_prospect_pobedy", Value = "Pobedy prospeck" }, new LangResourceValue { Key = "kazan_gorky", Value = "Gorky" }, new LangResourceValue { Key = "kazan_ametievo", Value = "Ametievo" }, new LangResourceValue { Key = "kazan_sukonnaya_sloboda", Value = "Sukonnaya Sloboda" }, new LangResourceValue { Key = "kazan_ploshad_tukaya", Value = "Ploshad turaya" }, new LangResourceValue { Key = "kazan_kremlin", Value = "Kremlin" }, new LangResourceValue { Key = "kazan_kozia_sloboda", Value = "Kozia Sloboda" }, new LangResourceValue { Key = "kazan_yashlek", Value = "Yashlek" }, new LangResourceValue { Key = "kazan_severny_vokzal", Value = "Severny Vokzal" }, new LangResourceValue { Key = "kazan_aviastroy", Value = "Aviastroy" }, new LangResourceValue { Key = "moscow_tverskaya", Value = "Tverskaya" } } }; context.LangResources.RemoveRange(context.LangResources); context.LangResources.Add(ruLr); context.LangResources.Add(new LangResource { Culture = enLangCulture, Name = "workers", Values = new[] { new LangResourceValue { Key = "range_until", Value = "Range until" }, new LangResourceValue { Key = "search_result", Value = "Search Results" }, new LangResourceValue { Key = "filters_me", Value = "me" }, new LangResourceValue { Key = "filters_address", Value = "address" }, new LangResourceValue { Key = "filters_metro", Value = "metro" }, new LangResourceValue { Key = "filters_apply", Value = "Apply" }, new LangResourceValue { Key = "on_range", Value = "On range" }, new LangResourceValue { Key = "workerType_nannywork", Value = "Nanny" }, new LangResourceValue { Key = "workerType_nursework", Value = "Nurse" }, new LangResourceValue { Key = "workerType_housekeeperwork", Value = "Housekeeper" }, new LangResourceValue { Key = "workerType_nanny", Value = "Nanny" }, new LangResourceValue { Key = "workerType_nurse", Value = "Nurse" }, new LangResourceValue { Key = "workerType_housekeeper", Value = "Housekeeper" }, } }); context.LangResources.Add(new LangResource { Name = "landing", Culture = enLangCulture, Values = new[] { new LangResourceValue { Key = "brand", Value = "Nanny" } } }); context.LangResources.Add(new LangResource { Name = "common", Culture = enLangCulture, Values = new[] { new LangResourceValue { Key = "in", Value = "In" }, new LangResourceValue { Key = "from", Value = "from" }, new LangResourceValue { Key = "kilometers", Value = "km" }, new LangResourceValue { Key = "meters", Value = "m." }, new LangResourceValue { Key = "logon", Value = "LogOn." } } }); context.Metroes.Add(new Metro { Name = "metro|kazan_prospect_pobedy", Lat = 55.74982583593993, Lng = 49.208557284200076, OwnerCountry_Iso = "RU" }); context.Metroes.Add(new Metro { Name = "metro|kazan_gorky", Lat = 55.759477669771954, Lng = 49.19215638320032, OwnerCountry_Iso = "RU" }); context.Metroes.Add(new Metro { Name = "metro|kazan_ametievo", Lat = 55.76497036834872, Lng = 49.166578838034305, OwnerCountry_Iso = "RU" }); context.Metroes.Add(new Metro { Name = "metro|kazan_sukonnaya_sloboda", Lat = 55.77693044535312, Lng = 49.14235202678089, OwnerCountry_Iso = "RU" }); context.Metroes.Add(new Metro { Name = "metro|kazan_ploshad_tukaya", Lat = 55.78654860581989, Lng = 49.12337271579151, OwnerCountry_Iso = "RU" }); context.Metroes.Add(new Metro { Name = "metro|kazan_kremlin", Lat = 55.795829292769206, Lng = 49.106142833648505, OwnerCountry_Iso = "RU" }); context.Metroes.Add(new Metro { Name = "metro|kazan_kozia_sloboda", Lat = 55.8304307, Lng = 49.06608060000008, OwnerCountry_Iso = "RU" }); context.Metroes.Add(new Metro { Name = "metro|kazan_yashlek", Lat = 55.817156, Lng = 49.09857099999999, OwnerCountry_Iso = "RU" }); context.Metroes.Add(new Metro { Name = "metro|kazan_severny_vokzal", Lat = 55.84159170224533, Lng = 49.0821988303947, OwnerCountry_Iso = "RU" }); context.Metroes.Add(new Metro { Name = "metro|kazan_aviastroy", Lat = 55.85560589324356, Lng = 49.08437007464978, OwnerCountry_Iso = "RU" }); context.Metroes.Add(new Metro { Name = "metro|moscow_tverskaya", Lat = 55.7644550, Lng = 37.6059390, OwnerCountry_Iso = "RU" }); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } }