ManageBooks.cs

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using DotNetNuke;
using System.Web.UI;
using System.Reflection;

namespace CEL.Modules.CELLibrary
{

	partial class ManageBooks : Entities.Modules.PortalModuleBase
	{

		protected void Page_Load(object sender, System.EventArgs e)
		{
			try {
				if (!Page.IsPostBack) {
					LocalizeSetting();
					ViewState("AllowPaging") = "False";
					this.lnkShow.Text = "Show 10 records per page";
					LoadLibraryGrid("");
				}
			//Module failed to load
			} catch (Exception exc) {
				ProcessModuleLoadException(this, exc);
			}
		}
		public void LocalizeSetting()
		{
			//Me.lblSearch.Text = DotNetNuke.Services.Localization.Localization.GetString("lblSearch", Me.LocalResourceFile)


		}
		public string getViewDetailLink(string Title, int LibraryID)
		{
			return "<a href='" + EditUrl("LibraryID", LibraryID, "ViewBookDetails", "back=vbd") + "'>" + Title + "</a>";
		}
		public string getBorrowedByname(int OwnerID)
		{
			int borrowedByID = 0;
			//Dim objLibraryCon As New CELLibraryController
			//Dim dtTable As DataTable = objLibraryCon.GetBorrowedBookByLibraryID(LibraryID)
			//If dtTable.Rows.Count > 0 Then

			UserController objUserCon = new UserController();
			UserInfo objUserInfo = objUserCon.GetUser(PortalId, OwnerID);
			if ((objUserInfo != null))
				return objUserInfo.Username;
			//End If
			return "";
		}
		protected void dgLibrary_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			if (e.CommandName == "Borrow") {
				Response.Redirect(EditUrl("LibraryID", Conversion.Val(e.CommandArgument), "Borrow", "back=vbd"), true);
			} else if (e.CommandName == "EditBook") {
				Response.Redirect(EditUrl("LibraryID", Conversion.Val(e.CommandArgument), "AddBook"), true);
			} else if (e.CommandName == "Delete") {
				CELLibraryController objLibraryCon = new CELLibraryController();
				objLibraryCon.DeleteLibraryByID(Conversion.Val(e.CommandArgument));
				LoadLibraryGrid("");
			} else if (e.CommandName == "Archive") {
				CELLibraryController objLibraryCon = new CELLibraryController();
				objLibraryCon.ArchiveBook(Conversion.Val(e.CommandArgument));
				LoadLibraryGrid("");
			}

		}
		protected void dgLibrary_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			if (e.Item.ItemType == ListItemType.Header | e.Item.ItemType == ListItemType.Footer) {
			} else {
				e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#ffffcc'");
				e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#eeeeee'");

				LinkButton lnkArchiveIT = (LinkButton)e.Item.FindControl("lnkArchive");
				lnkArchiveIT.Attributes.Add("onclick", "return confirm('Confirm Archive It');");

				LinkButton lnkDelete = (LinkButton)e.Item.FindControl("lnkDelete");
				lnkDelete.Attributes.Add("onclick", "return confirm('Confirm Delete It');");

				Label lblReferenceOnly = (Label)e.Item.FindControl("lblReferenceOnly");
				if (lblReferenceOnly.Text == "1")
					e.Item.Cells(3).Text = "";

			}
		}
		public void LoadLibraryGrid(string SearchString)
		{
			CELLibraryController objLibraryCon = new CELLibraryController();
			DataTable dtTable = null;
			dtTable = objLibraryCon.getAllNonArchivedLibrary(ModuleId);
			if (Convert.ToString(ViewState("AllowPaging")) == "True") {
				this.dgLibrary.AllowPaging = true;
				this.dgLibrary.PageSize = 10;

			} else {
				this.dgLibrary.AllowPaging = false;
			}
			this.dgLibrary.DataSource = dtTable;
			this.dgLibrary.DataBind();
		}

		protected void lnkViewArchived_Click(object sender, System.EventArgs e)
		{
			Response.Redirect(EditUrl("Archived"), true);
		}

		protected void lnkBack_Click(object sender, System.EventArgs e)
		{
			Response.Redirect(NavigateURL(TabId), true);
		}

		protected void lnkAddNewButton_Click(object sender, System.EventArgs e)
		{
			Response.Redirect(EditUrl("AddBook"), true);
		}

		protected void dgLibrary_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
		{
			dgLibrary.CurrentPageIndex = e.NewPageIndex;
			LoadLibraryGrid("");
		}
		//<asp:LinkButton ID="lnkViewBookDetails" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"LibraryID") %>' runat="server" CommandName="ViewBookDetails">View</asp:LinkButton>&nbsp;/&nbsp;

		protected void lnkBorrowedBooks_Click(object sender, System.EventArgs e)
		{
			Response.Redirect(EditUrl("BorrowedBooks"), true);
		}

		protected void lnkShow_Click(object sender, System.EventArgs e)
		{
			if (this.lnkShow.Text == "Show 10 records per page") {
				ViewState("AllowPaging") = "True";
				//ViewState("PagingSize") = "10"
				this.lnkShow.Text = "Show all records";
			} else if (this.lnkShow.Text == "Show all records") {
				ViewState("AllowPaging") = "False";
				this.lnkShow.Text = "Show 10 records per page";
			}
			LoadLibraryGrid("");
		}
		public ManageBooks()
		{
			Load += Page_Load;
		}
	}
}
posted @ 2010-07-13 00:12  小生不才  阅读(174)  评论(0编辑  收藏  举报