protected void SaveSites() { // Remove old items string newValues = ValidationHelper.GetString(usSites.Value, null); string items = DataHelper.GetNewItemsInList(newValues, currentValues); bool somethingChanged = false; bool hasErrors = false; if (!string.IsNullOrEmpty(items)) { string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (newItems != null) { // Add all new items to site foreach (string item in newItems) { int siteId = ValidationHelper.GetInteger(item, 0); SiteInfo si = SiteInfoProvider.GetSiteInfo(siteId); CultureInfo ci = CultureInfoProvider.GetCultureInfo(culture.CultureID); if ((si != null) && (ci != null)) { // Check if site does not contain document from this culture TreeProvider tree = new TreeProvider(CMSContext.CurrentUser); DataSet nodes = tree.SelectNodes(si.SiteName, "/%", ci.CultureCode, false, null, null, null, -1, false, 1, "NodeID"); if (DataHelper.DataSourceIsEmpty(nodes)) { CultureInfoProvider.RemoveCultureFromSite(culture.CultureID, siteId); somethingChanged = true; } else { hasErrors = true; ShowError(string.Format(GetString("Culture_Edit_Sites.ErrorRemoveSiteFromCulture"), si.DisplayName)); continue; } } } } } // Add new items items = DataHelper.GetNewItemsInList(currentValues, newValues); if (!string.IsNullOrEmpty(items)) { string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (newItems != null) { // Add all new items to site foreach (string item in newItems) { int siteId = ValidationHelper.GetInteger(item, 0); // Add cullture to site SiteInfo si = SiteInfoProvider.GetSiteInfo(siteId); if (si != null) { if (CultureInfoProvider.LicenseVersionCheck(si.DomainName, FeatureEnum.Multilingual, VersionActionEnum.Insert)) { CultureInfoProvider.AddCultureToSite(culture.CultureID, siteId); somethingChanged = true; } else { hasErrors = true; ShowError(GetString("licenselimitation.siteculturesexceeded")); break; } } } } } // If there were some errors, reload uniselector if (hasErrors) { usSites.Value = GetCultureSites(); usSites.Reload(true); } if (somethingChanged) { ShowInformation(GetString("General.ChangesSaved")); } }
protected void uniSelector_OnSelectionChanged(object sender, EventArgs e) { bool relaodNeeded = false; // Remove old items string newValues = ValidationHelper.GetString(uniSelector.Value, null); string items = DataHelper.GetNewItemsInList(newValues, currentValues); if (!String.IsNullOrEmpty(items)) { string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (newItems != null) { // Initialize tree provider TreeProvider tree = new TreeProvider(); // Add all new items to site foreach (string item in newItems) { string cultureCode = ValidationHelper.GetString(item, ""); // Get the documents assigned to the culture being removed DataSet nodes = tree.SelectNodes(siteName, "/%", cultureCode, false, null, null, null, -1, false); if (DataHelper.DataSourceIsEmpty(nodes)) { CultureInfoProvider.RemoveCultureFromSite(cultureCode, siteName); ShowChangesSaved(); } else { relaodNeeded = true; AddError(String.Format(GetString("site_edit_cultures.errorremoveculturefromsite"), cultureCode) + '\n', null); } } } } // Catch license limitations Exception try { // Add new items items = DataHelper.GetNewItemsInList(currentValues, newValues); if (!String.IsNullOrEmpty(items)) { string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (newItems != null) { // Add all new items to site foreach (string item in newItems) { string cultureCode = ValidationHelper.GetString(item, ""); CultureInfoProvider.AddCultureToSite(cultureCode, siteName); } } ShowChangesSaved(); } } catch (Exception ex) { relaodNeeded = true; ShowError(ex.Message); } if (relaodNeeded) { // Get the active cultures from DB DataSet ds = CultureInfoProvider.GetCultures("CultureID IN (SELECT CultureID FROM CMS_SiteCulture WHERE SiteID = " + si.SiteID + ")", null, 0, "CultureCode"); if (!DataHelper.DataSourceIsEmpty(ds)) { currentValues = TextHelper.Join(";", SystemDataHelper.GetStringValues(ds.Tables[0], "CultureCode")); uniSelector.Value = currentValues; uniSelector.Reload(true); } } }