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

📄 addbook.cs

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

    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using ASPNET.StarterKit.Communities;


    //*********************************************************************
    //
    // AddBook Class
    //
    // Represents the Add Book page. Enables users to list new books.
    //
    //*********************************************************************

    public class AddBook : ContentAddPage {
    
        string _skinFileName = "Books_AddBook.ascx";
        string _sectionContent = "ASPNET.StarterKit.Communities.Books.BookSection";
        
 
		TextBox txtBookTitle;
        TopicPicker dropTopics;
		TextBox txtBookAuthor;
		TextBox txtBookISBN;
		TextBox txtBookPrice;
		TextBox txtBookPurchaseLink;
		TextBox txtBookBriefDescription;
		HtmlTextBox txtBookFullDescription;
		HtmlInputFile txtImageFile;
		DisplayBookImage imgBookImage;
		TextBox txtBookPublicationDate;
		TextBox txtBookPublisher;
		TextBox txtBookPublisherLink;

        //*********************************************************************
        //
        // SkinLoadBook
        //
        // The skin load event happens after a page skin has been loaded.
        // Here, we grab the necessary controls from the page skin.
        //
        //*********************************************************************
        void SkinLoadBook(Object s, SkinLoadEventArgs e) {
  
   			// Find the Form so that we can change the EncType of the post.
			HtmlForm form = (HtmlForm)Page.FindControl("PageForm");
			form.Enctype="multipart/form-data";

			// Find Book Title
			txtBookTitle = (TextBox)GetControl(e.Skin, "txtBookTitle" );
 
            // Find Topic Picker
            dropTopics = (TopicPicker)GetControl(e.Skin, "dropTopics");
            
			// Find Author
			txtBookAuthor = (TextBox)GetControl(e.Skin, "txtBookAuthor" );

			// Find ISBN
			txtBookISBN = (TextBox)GetControl(e.Skin, "txtBookISBN" );
            
			// Find Price
			txtBookPrice = (TextBox)GetControl(e.Skin, "txtBookPrice" );

			// Find Purchase Link
			txtBookPurchaseLink = (TextBox)GetControl(e.Skin, "txtBookPurchaseLink" );
            
			//Find Brief Description
			txtBookBriefDescription = (TextBox)GetControl(e.Skin, "txtBookBriefDescription" );
 
			// Find Full Description
			txtBookFullDescription= (HtmlTextBox)GetControl(e.Skin, "txtBookFullDescription" );

            // Find the image upload button
			txtImageFile = (HtmlInputFile)GetControl(e.Skin, "txtImageFile");

			// Find the Book image 
			imgBookImage = (DisplayBookImage)GetControl(e.Skin, "imgBookImage");
			imgBookImage.Visible = false;
			
			// Find the Publication Date
			txtBookPublicationDate = (TextBox)GetControl(e.Skin, "txtBookPublicationDate");
			
			// Find the Publisher
			txtBookPublisher = (TextBox)GetControl(e.Skin, "txtBookPublisher");
			
			// Find the Publisher Link
			txtBookPublisherLink = (TextBox)GetControl(e.Skin, "txtBookPublisherLink");
        }
        




        //*********************************************************************
        //
        // SubmitBook Method
        //
        // This method is raised by clicking the Add button in the Add 
        // Book form. It adds the book to the database.
        //
        //*********************************************************************
    	private void SubmitBook(Object s, EventArgs e) {
			if (Page.IsValid) {
			    // Check moderation status
			    int moderationStatus = 1;
			    if (objSectionInfo.EnableModeration && !objUserInfo.MayModerate)
			        moderationStatus = 0;
			        
			    // Get Topic
			    int topicID = -1;
			    if (objSectionInfo.EnableTopics)
			        topicID = Int32.Parse(dropTopics.SelectedItem.Value);    
			        
			        
				// Add the book
				int contentPageID = BookUtility.AddBook
					(
					objUserInfo.Username,
					objSectionInfo.ID,
					moderationStatus,
					txtBookTitle.Text,
					txtBookBriefDescription.Text,
					txtBookFullDescription.Text,
					txtBookAuthor.Text,
					txtBookISBN.Text,
					txtBookPurchaseLink.Text,
					Decimal.Parse(txtBookPrice.Text),
					DateTime.Parse(txtBookPublicationDate.Text),
					txtBookPublisher.Text,
					txtBookPublisherLink.Text,
					topicID
					);

                // Add the Image
    		    ImageUtility.AddSectionImage(contentPageID, txtImageFile.PostedFile);
                    
				
				// Show warning message if moderation enabled
				if (objSectionInfo.EnableModeration && !objUserInfo.MayModerate)
				    Context.Response.Redirect(CommunityGlobals.CalculatePath("Messages_Message.aspx?message=moderation"));

                // Otherwise, redirect to default page and send notifications
	            Context.Server.ScriptTimeout = 10 * 60;
				Context.Response.Redirect(CommunityGlobals.CalculatePath("Default.aspx"), false);
	            Context.Response.Flush();
	            Context.Response.Close();            

				NotifyUtility.SendNotifications(objSectionInfo.ID, contentPageID, txtBookTitle.Text, objUserInfo.Username);
			    Context.Response.End();    
			}
		}



        //*********************************************************************
        //
        // AddBook Constructor
        //
        // Calls the base SkinnedCommunityControl constructor
        // and assigns the default page skin. 
        //
        //*********************************************************************

        public AddBook() : base() {
            // Assign a default skin file name
            SkinFileName = _skinFileName;
            
            // Specify section content
            SectionContent = _sectionContent;
            
            // Wire-up event handlers
            this.SkinLoad += new SkinLoadEventHandler(SkinLoadBook);
            this.Submit += new SubmitEventHandler(SubmitBook);
        }





    }
}

⌨️ 快捷键说明

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