private void LoadMasterPage(string id) { try { int mpId = Convert.ToInt32(id); db_config_master_page dcm = new db_config_master_page(); dcm.Open(); MasterPage mp = dcm.Get(mpId); mp_id.Value = mp.ID.ToString(CultureInfo.InvariantCulture); mp_title.Value = mp.Title; mp_desc.InnerText = mp.Description; mp_options.InnerText = mp.Options; SetPageTitle(mp.Title); dcm.Close(); } catch (Exception ex) { Generic.JavaScriptInjector("alert('" + ex.Message + "');"); } }
/// <summary> /// Save current master page that user is editing /// </summary> private static void SaveMasterPage(int id, string title, string desc, string options) { try { db_config_master_page dcm = new db_config_master_page(); dcm.Open(); MasterPage mp = id >= 0 ? dcm.Get(id) : new MasterPage(); mp.Title = title; mp.Description = desc; mp.Options = options; if (id >= 0) dcm.Commit(); else dcm.Add(mp); dcm.Close(); Generic.ParentJavascriptMethodInjector("RefreshTree()"); } catch (Exception ex) { Generic.JavaScriptInjector("alert('" + ex.Message + "');"); } }
private void BuildTree() { db_config_master_page dcmp = new db_config_master_page(); dcmp.Open(); foreach (MasterPage mp in dcmp.AllMasterPages.OrderBy(x => x.Title)) { TreeItem ti = new TreeItem { Text = mp.Title, ObjId = mp.ID.ToString() }; List<TreeItem> sti = new List<TreeItem>(); foreach (DbConfig.Page page in dcmp.GetAllPages(mp.ID).OrderBy(x => x.Title)) { sti.Add(new TreeItem() { Text = page.Title, ObjId = page.ID.ToString() }); } ti.SubTreeItems = sti; _treeItems.Add(ti); } dcmp.Close(); }
public string DeleteMasterPage(string masterPageId, string ctrl) { string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey")); if (ctrl != crlHash) return string.Empty; db_config_master_page dcmp = null; try { dcmp = new db_config_master_page(); dcmp.Open(); dcmp.Delete(Convert.ToInt32(masterPageId)); return "Operation Done"; } catch (Exception ex) { return ex.Message; } finally { if (dcmp != null) dcmp.Close(); } }
/// <summary> /// Generate header bar /// </summary> private void FillMenuBar(OptionItems foOptions) { string username = "******"; try { headerContainer.Controls.Clear(); UserLoginData user = (UserLoginData)db_config_sessions.GetUserAuthentication(); OptionItems userOi = null; db_config_master_page dcmp = new db_config_master_page(); dcmp.Open(); List<string> userFavorites = new List<string>(); // user not autenticated show just public pages if (user == null) { dcmp.SelectPublicObjectsFromDb(); } else { // user autenticated show public pages and user pages dcmp.SelectAuthenticatedObjectsFromDb(user.UserPages); userOi = new OptionItems(user.User.UserOptions); userFavorites = userOi.GetList("favorites"); // prepare username to be used in error exception. username = user.User.Name; } // set url to use when the page start SelectDefaultPage(foOptions.GetSingle("default_page"), user != null ? userOi.GetSingle("default_frontoffice_page") : ""); MenuBar mb = new MenuBar(); mb.AddHeader("Home", "frontoffice.aspx"); // just show data if is not refresh if (!IsPostBack) { mb.AddHeader("Site pages", ""); // site pages int headerId = mb.GetHeaderPosition("Site pages"); db_config_page dcp; foreach (DbConfig.MasterPage item in dcmp.AllMasterPages) { // just show pages that admin dont want to hide from you :) List<DbConfig.Page> visiblePages = (from p in dcmp.GetAllPages(item.ID) where (new OptionItems(p.Options).GetSingle("hidden_from_frontoffice").Equals("true")) == false select p).ToList(); dcp = new db_config_page(dcmp.Db, visiblePages, item.ID); if (user == null) dcp.SelectPublicObjectsFromDb(); else dcp.SelectAuthenticatedObjectsFromDb(user.UserPages); // will just add master page if it has visible pages to show, // if the master page does not have pages will not get here. if (dcp.AllPages.Count > 0) { // add master page to menu mb.AddMenuItem(headerId, item.Title, ""); int menuItemId = mb.GetMenuPosition(headerId, item.Title); // add pages to sub menus foreach (DbConfig.Page subItem in dcp.AllPages) mb.AddSubMenuItem(headerId, menuItemId, subItem.Title, "page.aspx?nm=" + subItem.Name); } dcp.Close(); } if (userFavorites.Count > 0) // favorites { mb.AddHeader("Favorites", ""); int favItemId = mb.GetHeaderPosition("Favorites"); dcp = new db_config_page(dcmp.Db, new List<DbConfig.Page>(), -1); dcp.Refresh(); foreach (string favpage in userFavorites) { if (!dcp.PageExists(favpage)) continue; DbConfig.Page p = dcp.Get(favpage); mb.AddMenuItem(favItemId, p.Title, "page.aspx?nm=" + p.Name); } dcp.Close(); } } dcmp.Close(); headerContainer.Controls.Add(mb.Get()); Generic.JavaScriptInjector("js", mb.GetLoginJavascript()); } catch (Exception ex) { throw new Exception("error: fill menu bar for user " + username + " - " + ex.Message + " ..."); } }
/// <summary> /// Build master page selector if ID is negative then it will select first item /// </summary> private void BuildPageSelector(int currentMasterPageId) { db_config_master_page dcm = null; // Clear all items p_masterpageid.Items.Clear(); try { dcm = new db_config_master_page(); dcm.Open(); List<MasterPage> allMasterPages = dcm.AllMasterPages.OrderBy(x=>x.Title).ToList(); for (int i = 0; i < allMasterPages.Count; i++) { p_masterpageid.Items.Add(new ListItem( allMasterPages[i].Title, allMasterPages[i].ID.ToString(CultureInfo.InvariantCulture) )); // Get the page position then set the selector index if (allMasterPages[i].ID == currentMasterPageId) p_masterpageid.SelectedIndex = i; } } catch (Exception ex) { throw new Exception("error: building master page list " + ex.Message); } finally { if (dcm != null) dcm.Close(); } }