⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 movecontentpage.cs

📁 一个ASP.NET下的中文内容管理和社区系统
💻 CS
字号:
namespace ASPNET.StarterKit.Communities {

    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Data.SqlClient;



    //*********************************************************************
    //
    // MoveContentPage Class
    //
    // Represents the Move Content Page. Enables users to move
    // content pages from one section to another.
    //
    //*********************************************************************

    public class MoveContentPage : SkinnedCommunityControl {
    
        string _skinFileName = "ContentPages_MoveContentPage.ascx";

        Label lblTitle;
        ListBox lstSections;
        CheckBox chkApprove;
        Panel pnlOtherSections;
        Panel pnlNoOtherSections;
        Button btnMove;
        Button btnCancel;

        //*********************************************************************
        //
        // MoveContentPage Constructor
        //
        // Calls the base SkinnedCommunityControl constructor
        // and assigns the default page skin. Also checks whether
        // current user has permissions to move (edit and moderate).
        //
        //*********************************************************************
        
		public MoveContentPage() : base() {
            // Check Security
            if (!objUserInfo.MayModerate && !objUserInfo.MayEdit)
                CommunityGlobals.ForceLogin();


            // Assign a default skin file name
            if (SkinFileName == null)
                SkinFileName = _skinFileName;
        }
        
   
        //*********************************************************************
        //
        // SkinType Property
        //
        // Specifies the skins directory where this page's skin file is located.
        //
        //*********************************************************************
        
        override protected string SkinType {
            get { return "ContentSkins"; }
        }


        //*********************************************************************
        //
        // ContentPageID Property
        //
        // Represents the Content Page ID of the resource being moved.
        //
        //*********************************************************************

        int ContentPageID {
            get { return (int)ViewState["ContentPageID"]; }
            set { ViewState["ContentPageID"] = value; }
        }



        //*********************************************************************
        //
        // ReturnUrl Property
        //
        // Represents the page that the user is redirected back to.
        //
        //*********************************************************************
        
        public string ReturnUrl {
            get {return (string)ViewState["ReturnUrl"];}
            set {ViewState["ReturnUrl"] = value; }
        
        }

        
        //*********************************************************************
        //
        // InitializeSkin Method
        //
        // Retrieves all the controls from the page skin.
        //
        //*********************************************************************

        override protected void InitializeSkin(Control skin) {
                
            // Find Title Label
            lblTitle = (Label)GetControl(skin, "lblTitle");
            
            // Find the section listbox
            lstSections = (ListBox)GetControl(skin, "lstSections");
            
            // Find the approve checkbox
            chkApprove = (CheckBox)GetControl(skin, "chkApprove");
            
            // Find the other sections panel
            pnlOtherSections = (Panel)GetControl(skin, "pnlOtherSections");
            
            // Find the no other sections panel
            pnlNoOtherSections = (Panel)GetControl(skin, "pnlNoOtherSections");
            
            // Find OK Button
            btnMove = (Button)GetControl(skin, "btnMove");
    		btnMove.Click += new System.EventHandler(btnMove_Click);

            // Find Cancel Button
            btnCancel = (Button)GetControl(skin, "btnCancel");
    		btnCancel.Click += new System.EventHandler(btnCancel_Click);
        } 



        //*********************************************************************
        //
        // OnLoad Method
        //
        // Assigns values to the controls from the page skin.
        //
        //*********************************************************************

        override protected void OnLoad(EventArgs e) {
            if (!Page.IsPostBack) {
                // Get the contentPageID
                ContentPageID = Int32.Parse(Context.Request.QueryString["id"]);


                // Get the return URL
                ReturnUrl = Context.Request.QueryString["ReturnUrl"];
                
                // Get the ContentPage Info
                ContentPageInfo _contentPageInfo = ContentPageUtility.GetContentPageInfoFromDB(ContentPageID, objSectionInfo.ID);
                
                // Assign Title
                EnsureChildControls();
                lblTitle.Text = _contentPageInfo.Title;
                
                // Get other sections
                lstSections.DataSource = GetOtherSections(objSectionInfo.ID);
                lstSections.DataTextField = "section_title";
                lstSections.DataValueField = "section_id";
                lstSections.DataBind();
                
                // Hide/display panels
                if (lstSections.Items.Count == 0) {
                    pnlNoOtherSections.Visible = true;
                    pnlOtherSections.Visible = false;
                }
                else {   
                    pnlNoOtherSections.Visible = false;
                    pnlOtherSections.Visible = true;
                }
                
                // Hide approve checkbox if already approved
                if (_contentPageInfo.ModerationStatus == ModerationStatus.Approved)
                    chkApprove.Visible = false;
                
            }
        
        }
        


        //*********************************************************************
        //
        // GetOtherSections Method
        //
        // Retrieves all sections of the same type from the database.
        //
        //*********************************************************************
        
        private SqlDataReader GetOtherSections(int sectionID) {
            SqlConnection conPortal = new SqlConnection(CommunityGlobals.ConnectionString);
            SqlCommand cmd = new SqlCommand("Community_GetOtherSections", conPortal);
            cmd.CommandType = CommandType.StoredProcedure;
            
            cmd.Parameters.Add("@communityID", CommunityGlobals.CommunityID);
            cmd.Parameters.Add("@sectionID", sectionID);
            
            conPortal.Open();
            SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            return dr;
        }

        
        //*********************************************************************
        //
        // btnMove_Click Method
        //
        // This method is raised by clicking the Move button. It 
        // moves the content page to a new section, and handles
        // notification and moderation.
        //
        //*********************************************************************
        
        void btnMove_Click(Object s, EventArgs e) {
            int sectionID;
            
            if (lstSections.SelectedIndex != -1) {
                // Get selected section
                sectionID = Int32.Parse(lstSections.SelectedItem.Value);

                // Get the ContentPage Info
                ContentPageInfo contentPageInfo = ContentPageUtility.GetContentPageInfoFromDB(ContentPageID, objSectionInfo.ID);

                // Content has not been approved
                if (contentPageInfo.ModerationStatus != ModerationStatus.Approved) {
                    // if the current user can moderate the new section, then move and approve
                    if (SectionUtility.MayModerate(objUserInfo, sectionID) && chkApprove.Checked) {    
                        ContentPageUtility.MoveContentPage(ContentPageID, ModerationStatus.Approved, sectionID);
                        NotifyUtility.SendNotifications(sectionID, ContentPageID, contentPageInfo.Title, objUserInfo.Username);
                    }
                    else
                        ContentPageUtility.MoveContentPage(ContentPageID, ModerationStatus.Pending, sectionID);
                }
                else
                    ContentPageUtility.MoveContentPage(ContentPageID, ModerationStatus.Approved, sectionID);
            
                
                // redirect back to origin
                if (ReturnUrl != null)
                    Context.Response.Redirect(CommunityGlobals.CalculatePath(ReturnUrl));     
                else
                    Context.Response.Redirect(CommunityGlobals.CalculatePath("default.aspx"));
            }
        }       
 
        //*********************************************************************
        //
        // btnCancel_Click Method
        //
        // This method is raised by clicking the Cancel button in the Delete 
        // Content Page Form. The method redirects the user back to the
        // original page that the user came from.
        //
        //*********************************************************************

 
        void btnCancel_Click(Object s, EventArgs e) {
            if (ReturnUrl != null)
                Context.Response.Redirect( CommunityGlobals.CalculatePath(ReturnUrl));     
            else
                Context.Response.Redirect( CommunityGlobals.CalculatePath(String.Format("{0}.aspx", ContentPageID)));
        
        }       
 
        


    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -