CSLA.Net 3.0.5プロジェクト管理例UI ProjectList.aspx


<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeFile="ProjectList.aspx.cs" Inherits="PTWeb.ProjectList" Title="    " %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div>
        <strong>  <br />
        </strong>
        <%-- AllowPaging="True"     
            PageSize="4"   4 
            DataKeyNames="Id"             ,           Key           ,         
            (549)
        --%>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" AllowSorting="true" 
            DataSourceID="ProjectListDataSource" PageSize="4" DataKeyNames="Id" OnRowDeleted="GridView1_RowDeleted">
            <Columns>
            <%-- Visible="False"        --%>
                <asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" Visible="False" />
                <%--     
                     DataNavigateUrlFields="Id"    DataNavigateUrlFormatString="ProjectEdit.aspx?id={0}
                          ID                      URL
                                              
                                       HyperLinkField           ,    DataNavigateUrlFields   。DataNavigateUrlFields 
                               DataNavigateUrlFormatString            ,    HyperLinkField        。 
                --%>
                <asp:HyperLinkField DataNavigateUrlFields="Id" DataNavigateUrlFormatString="ProjectEdit.aspx?id={0}"
                    DataTextField="Name" HeaderText="  " />
                    <%-- ShowDeleteButton="True" SelectText="Edit" 
                                                     
                    
                    --%>
                <asp:CommandField ShowDeleteButton="True" SelectText="Edit" />
            </Columns>
        </asp:GridView>
        <asp:LinkButton ID="NewProjectButton" runat="server" OnClick="NewProjectButton_Click">    </asp:LinkButton>
        <br />
        <br />
        <asp:Label ID="ErrorLabel" runat="server" ForeColor="Red"></asp:Label>
        <csla:CslaDataSource ID="ProjectListDataSource" runat="server" TypeName="ProjectTracker.Library.ProjectList, ProjectTracker.Library"
            OnDeleteObject="ProjectListDataSource_DeleteObject" OnSelectObject="ProjectListDataSource_SelectObject"
            TypeSupportsPaging="False" TypeSupportsSorting="False">
        </csla:CslaDataSource>
        <br />
    </div>
</asp:Content>

 
//======================================================================
//   
//        Guid1:               d08d215e-c7a9-4079-95d1-54704d568a8a
//        CLR  :             2.0.50727.3053
//                :    ProjectList
//            :            SOFTWARE-FRT-08
//              :        PTWeb
//           :              ProjectList
//              :        2008-10-2 19:08:08
//              :        TECHSTAR
//               :      frt
//            :            2008
//
//        Created by Terry.Feng.C (   ) at 2008-10-2 19:08:08
//        
//
//======================================================================

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ProjectTracker.Library;

namespace PTWeb
{
    /// <summary>
    ///     RoleList      ,         
    /// </summary>
    public partial class ProjectList : System.Web.UI.Page
    {
        #region     
        private void ApplyAuthorizationRules()
        {
            this.GridView1.Columns[this.GridView1.Columns.Count - 1].Visible = Project.CanDeleteObject();
            NewProjectButton.Visible = ProjectTracker.Library.Project.CanAddObject();
        }

        private ProjectTracker.Library.ProjectList GetProjectList()
        {
            object businessObject = Session["currentObject"];
            if (businessObject == null || !(businessObject is ProjectTracker.Library.ProjectList))
            {
                businessObject = ProjectTracker.Library.ProjectList.GetProjectList();
                Session["currentObject"] = businessObject;
            }
            return (ProjectTracker.Library.ProjectList)businessObject;
        }


        #endregion

        #region     

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Session["currentObject"] = null;
                //  
                ApplyAuthorizationRules();
            }
            else
                ErrorLabel.Text = string.Empty;
        }

        #region GridView1

        /// <summary>
        ///           ,  Session,  GridView,            ,     DeleteObject          ,            
        ///    GridView   ,DataBind     SelectObject  ,         GetProjectList,     Sessions,   Null,        
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
        {
            // Session     ,             
            Session["currentObject"] = null;
            //       SelectObject  
            GridView1.DataBind();
        }

        protected void NewProjectButton_Click(object sender, EventArgs e)
        {
            // allow user to add a new project
            //        ,        
            Response.Redirect("ProjectEdit.aspx");
        }

        #endregion


        #endregion

        #region     


        #region ProjectListDataSource

        /// <summary>
        /// /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ProjectListDataSource_DeleteObject( object sender, Csla.Web.DeleteObjectArgs e)
        {
            try
            {
                //  Guid  ,              
                ProjectTracker.Library.Project.DeleteProject( new Guid(e.Keys["Id"].ToString()));
                e.RowsAffected = 1;
            }
            catch (Csla.DataPortalException ex)
            {
                this.ErrorLabel.Text = ex.BusinessException.Message;
                e.RowsAffected = 0;
            }
            catch (Exception ex)
            {
                this.ErrorLabel.Text = ex.Message;
                e.RowsAffected = 0;
            }
        }

        protected void ProjectListDataSource_SelectObject( object sender, Csla.Web.SelectObjectArgs e)
        {
            //  ,         
            e.BusinessObject = GetProjectList();
        }

        #endregion


        #endregion

    }
}