EditNavigatorLinksBox.ascx.cs :  » Bloggers » dasBlog » newtelligence » DasBlog » Web » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Bloggers » dasBlog 
dasBlog » newtelligence » DasBlog » Web » EditNavigatorLinksBox.ascx.cs
namespace newtelligence.DasBlog.Web{
  using System;
  using System.Data;
  using System.Drawing;
  using System.Web;
  using System.Web.UI.WebControls;
  using System.Web.UI.HtmlControls;
    using System.IO;
    using System.Xml;
    using System.Xml.Serialization;
    using newtelligence.DasBlog.Web.Core;
    

  /// <summary>
  ///    Summary description for EditNavigatorLinksBox.
  /// </summary>
  public partial class EditNavigatorLinksBox : System.Web.UI.UserControl
  {
        protected NavigationRoot navigationRoot;
        protected System.Web.UI.WebControls.RequiredFieldValidator validatorRFname;
        private string baseFileName="navigatorLinks.xml";
        protected System.Resources.ResourceManager resmgr;
        

        public string BaseFileName 
        {
            get
            {
                return baseFileName;
            }
            set
            {
                baseFileName = value;
            }
        }


        private void SaveList( string fileName )
        {
            using (StreamWriter s = new StreamWriter(fileName,false,System.Text.Encoding.UTF8))
            {
                XmlSerializer ser = new XmlSerializer(typeof(NavigationRoot));
                ser.Serialize(s,navigationRoot);
            }
        }

        private void LoadList( string fileName )
        {
            if (File.Exists(fileName))
            {
                using (Stream s = File.OpenRead(fileName))
                {
                    XmlSerializer ser = new XmlSerializer(typeof(NavigationRoot));
                    navigationRoot = (NavigationRoot)ser.Deserialize(s);
                }
            }
            else
            {
                navigationRoot = new NavigationRoot();
            }
            Session["newtelligence.DasBlog.Web.EditNavigatorLinksBox.NavigationRoot"] = navigationRoot;
        }

        private void BindGrid()
        {
            navigatorLinksGrid.DataSource = navigationRoot.Items;
            navigatorLinksGrid.Columns[0].HeaderText = resmgr.GetString("text_navigatorlinks_title");
            DataBind();
        }

    protected void Page_Load(object sender, System.EventArgs e)
    {
            if (SiteSecurity.IsInRole("admin") == false) 
            {
                Response.Redirect("~/FormatPage.aspx?path=SiteConfig/accessdenied.format.html");
            }

            resmgr = ((System.Resources.ResourceManager)ApplicationResourceTable.Get());

            if ( !IsPostBack || 
                Session["newtelligence.DasBlog.Web.EditNavigatorLinksBox.NavigationRoot"] == null )
            {
                SharedBasePage requestPage = Page as SharedBasePage;
                string fileName = Path.Combine(SiteConfig.GetConfigPathFromCurrentContext(),baseFileName);
                LoadList( fileName );
            }
            else
            {
                navigationRoot = Session["newtelligence.DasBlog.Web.EditNavigatorLinksBox.NavigationRoot"] as NavigationRoot;
            }
            BindGrid();
    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
      //
      // CODEGEN: This call is required by the ASP.NET Web Form Designer.
      //
      InitializeComponent();
      base.OnInit(e);
    }
    
    /// <summary>
    ///    Required method for Designer support - do not modify
    ///    the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
      this.navigatorLinksGrid.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.navigatorLinksGrid_ItemCommand);
      this.navigatorLinksGrid.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.navigatorLinksGrid_PageIndexChanged);
      this.navigatorLinksGrid.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.navigatorLinksGrid_CancelCommand);
      this.navigatorLinksGrid.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.navigatorLinksGrid_EditCommand);
      this.navigatorLinksGrid.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.navigatorLinksGrid_UpdateCommand);
      this.navigatorLinksGrid.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.navigatorLinksGrid_DeleteCommand);

    }
    #endregion

        private void navigatorLinksGrid_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            
            navigatorLinksGrid.EditItemIndex = e.Item.ItemIndex;
            navigatorLinksGrid.DataBind();
        }

        private void navigatorLinksGrid_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            navigationRoot.Items.RemoveAt(e.Item.DataSetIndex);
            SaveList( Path.Combine(SiteConfig.GetConfigPathFromCurrentContext(),baseFileName));
            Session["newtelligence.DasBlog.Web.EditNavigatorLinksBox.NavigationRoot"] = null;
            
            Response.Redirect( Page.Request.Url.AbsoluteUri, true );
        }

        private void navigatorLinksGrid_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            navigatorLinksGrid.EditItemIndex = -1;
            navigatorLinksGrid.DataBind();
        }

        private void navigatorLinksGrid_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            NavigationLink link = navigationRoot.Items[e.Item.DataSetIndex];
            link.Name = ((TextBox)e.Item.FindControl("textname")).Text;
            link.Url = ((TextBox)e.Item.FindControl("texturl")).Text;
            
            SaveList( Path.Combine(SiteConfig.GetConfigPathFromCurrentContext(),baseFileName));
            Session["newtelligence.DasBlog.Web.EditNavigatorLinksBox.NavigationRoot"] = null;
            
            Response.Redirect( Page.Request.Url.AbsoluteUri, true );
        }                                          

        private void navigatorLinksGrid_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
        {
            navigatorLinksGrid.CurrentPageIndex = e.NewPageIndex;
            navigatorLinksGrid.DataBind();
        }

        private void navigatorLinksGrid_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            if ( e.CommandName == "AddItem" )
            {
                NavigationLink newLink = new NavigationLink();
                newLink.Name = "New Entry";
                navigationRoot.Items.Insert(0,newLink);
                navigatorLinksGrid.CurrentPageIndex = 0;
                navigatorLinksGrid.EditItemIndex = 0;
                BindGrid();
            }
      else if ( e.CommandName == "MoveUp" && e.Item != null )
      {
        int position = e.Item.DataSetIndex;

        if ( position > 0 )
        {
          NavigationLink link = new NavigationLink();
          link.Name = navigationRoot.Items[position].Name;
          link.Url = navigationRoot.Items[position].Url;
          navigationRoot.Items.RemoveAt( position );
          navigationRoot.Items.Insert( position-1, link );
          navigatorLinksGrid.CurrentPageIndex = (position-1) / navigatorLinksGrid.PageSize;
          if ( navigatorLinksGrid.EditItemIndex == position )
          {
            navigatorLinksGrid.EditItemIndex = position - 1;
          }
          else if ( navigatorLinksGrid.EditItemIndex == position - 1)
          {
            navigatorLinksGrid.EditItemIndex = position;
          }  
        }
        SaveList( Path.Combine(SiteConfig.GetConfigPathFromCurrentContext(),baseFileName));
        Session["newtelligence.DasBlog.Web.EditNavigatorLinksBox.NavigationRoot"] = null;
            
        Response.Redirect( Page.Request.Url.AbsoluteUri, true );
      }
      else if ( e.CommandName == "MoveDown" && e.Item != null )
      {
        int position = e.Item.DataSetIndex;

        if ( position < navigationRoot.Items.Count-1 )
        {
          NavigationLink link = new NavigationLink();
          link.Name = navigationRoot.Items[position].Name;
          link.Url = navigationRoot.Items[position].Url;
          navigationRoot.Items.RemoveAt( position );
          navigationRoot.Items.Insert( position+1, link );
          navigatorLinksGrid.CurrentPageIndex = (position+1) / navigatorLinksGrid.PageSize;
          if ( navigatorLinksGrid.EditItemIndex == position )
          {
            navigatorLinksGrid.EditItemIndex = position + 1;
          }
          else if ( navigatorLinksGrid.EditItemIndex == position + 1)
          {
            navigatorLinksGrid.EditItemIndex = position;
          }
        }
        SaveList( Path.Combine(SiteConfig.GetConfigPathFromCurrentContext(),baseFileName));
        Session["newtelligence.DasBlog.Web.EditNavigatorLinksBox.NavigationRoot"] = null;
            
        Response.Redirect( Page.Request.Url.AbsoluteUri, true );
      }
        }        
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.