/// <summary>Gets the current entity from the database, or returns a new entity.</summary> public WM.CultureCode GetCurrent_CultureCode() { WM.CultureCode cultureCode = null; if (this.New_CultureCode) { cultureCode = new CultureCode(); } else { cultureCode = WM.CultureCode.Get(this.CultureCode); } //if (string.IsNullOrEmpty(this.CultureCode)) throw new ArgumentNullException("CultureCode"); if (null == cultureCode) { throw new InvalidOperationException(string.Format("The specified {0} was not found (it may have been deleted).", _entityName_cultureCode.ToLower())); } //check permissions... //if(cultureCode.UserId != (Guid)_user.ProviderUserKey) throw new System.Security.SecurityException("The current user is not authorized to view that item."); return(cultureCode); }
protected void SetSystemDefaultButton_Click(object sender, EventArgs e) { WM.CultureCode oldDefaultCulture = WM.CultureCode.Find(null, true, null, null).First; WM.CultureCode.SetDefaultCulture(this.CultureCode); Msg.ShowSuccess(string.Format( "Changed the system default culture from <strong>{0}</strong> to <strong>{1}</strong>.", oldDefaultCulture.Name, this.CultureCode)); }
/// <summary>Gets the current entity and fills its with the form input values.</summary> public WM.CultureCode GetInput_CultureCode() { WM.CultureCode cultureCode = GetCurrent_CultureCode(); string cultureCodeInput = CultureCodeCtl.Text.Trim().ToLower(); //if we are in "create new" mode, don't update an existing culture. if (this.New_CultureCode && null != WM.CultureCode.Get(cultureCodeInput)) { Msg.ShowError(string.Format("The {0} '{1}' already exists.", _entityName_cultureCode.ToLower(), cultureCodeInput)); return(null); } try //attempt to create a CultureInfo object using the culture code. { System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(cultureCodeInput); } catch { Msg.ShowError(string.Format("'{0}' is not a valid {1}.", cultureCodeInput, _entityName_cultureCode.ToLower())); return(null); } if (cultureCode.IsNew) { cultureCode.Name = cultureCodeInput; } //'IsDefault' is updated via other means. //cultureCode.IsDefault = IsDefaultCtl.Checked; cultureCode.IsActive = IsActiveCtl.Checked; if (AliasToCultureCodeCtl.SelectedIndex > 0) { //validate: double-check to make sure that we are not aliasing to an alias //(we _could_ allow aliases-to-aliases, but let's keep it simple for now). WM.CultureCode aliasToCultureCode = WM.CultureCode.Get(AliasToCultureCodeCtl.Text); if (aliasToCultureCode.IsAlias) { Msg.ShowError("Cannot alias to another alias."); return(null); } } //validation passed; set the alias key. cultureCode.AliasToCultureCode = AliasToCultureCodeCtl.Text; return(cultureCode); }
public static MasterDetailItem GetSafeResource(int moduleId, string cultureCode) { MasterDetailItem itemRes = MasterDetailItem.GetResource(moduleId, cultureCode); if (null == itemRes) { //try default culture WM.CultureCode defaultCultureCode = WM.CultureCode.GetDefaultCulture(); if (null != defaultCultureCode && WM.CultureCode.Current != defaultCultureCode.Name) { itemRes = MasterDetailItem.GetResource(moduleId, defaultCultureCode.Name); } } return(itemRes); }
protected void CultureCode_SaveButton_Click(object sender, EventArgs e) { if (!Page.IsValid) { return; } WM.CultureCode cultureCode = GetInput_CultureCode(); if (null == cultureCode) { return; //validation failed. } cultureCode.Save(); List_CultureCode(null, null); Msg.ShowSuccess(string.Format("Saved {0} '{1}'.", _entityName_cultureCode.ToLower(), cultureCode.Name)); }
public void Load_CultureCode(WM.CultureCode cultureCode) { //string.Format("Set the system default culture code to <strong>{0}</strong>.", SetSystemDefaultButton.ToolTip = string.Format("Set the system default culture to '{0}'.", this.CultureCode); bool isDefault = cultureCode.IsDefault; IsDefaultMsg.Visible = isDefault; IsNotDefaultMsg.Visible = !isDefault; IsActiveCtl.Enabled = !isDefault; if (isDefault) { IsActiveCtl.ToolTip = "The system default culture must be active."; } NewCultureCodeNamePanel.Visible = false; //CultureCodeCtl.Text = cultureCode.Name; IsActiveCtl.Checked = cultureCode.IsActive; AliasToCultureCodeCtl.Text = cultureCode.AliasToCultureCode; }
private void Edit_CultureCode() { MultiViewCtl.SetActiveView(View_Edit_CultureCode); WM.CultureCode cultureCode = GetCurrent_CultureCode(); if (cultureCode.IsNew) { //create new Page.Title = "Create New " + _entityName_cultureCode; NewCultureCodeNamePanel.Visible = true; IsDefaultMsg.Visible = false; IsNotDefaultMsg.Visible = false; CultureCodeNameHeaderCtl.InnerHtml = "New " + _entityName_cultureCode; } else { //update existing Page.Title = "Edit " + _entityName_cultureCode; CultureCodeNameHeaderCtl.InnerHtml = cultureCode.Name; Load_CultureCode(cultureCode); } Page.Form.DefaultButton = CultureCode_SaveButton.UniqueID; }