多层多数据库模式开发的实验(八)表示层

    表示层的设计牵扯到很多非技术性问题,如美工、用户接受度、操作度等问题,但是在这篇文章中,将不会涉及这些问题!这些内容和本系列文章的关系不是很密切。这里将主要从如何调用我们的逻辑层的角度讨论表示层的设计。

    一般来说,表示层的职责有以下两点:

      1.接受用户的输入。

      2.向用户呈现信息。

      总体来说,就是与用户的交互。我们就以这2个方面来进行设计,下面看看代码实现:

Default.aspx:

ContractedBlock.gifExpandedBlockStart.gif Code
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    
<title>无标题页</title>
</head>
<body>
    
<form id="form1" runat="server">
    
    
<asp:Button ID="Button1" runat="server" Text="随机新增用户记录" onclick="Button1_Click" />
    
<br />      
    
<asp:Button ID="Button2" runat="server" Text="获取用户记录列表" onclick="Button2_Click" />
    
<br />
    
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    
<asp:Button ID="Button3" runat="server" Text="根据ID获取指定用户记录信息" onclick="Button3_Click" />
    
<br />
    
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    
<asp:Button ID="Button4" runat="server" Text="根据姓名获取指定用户记录信息" onclick="Button4_Click"  />
    
<asp:GridView ID="GridView1" runat="server">
    
</asp:GridView>
    
    
<hr />
    
    
<asp:Button ID="Button5" runat="server" Text="随机新增部门记录" onclick="Button5_Click"  />
    
<br />      
    
<asp:Button ID="Button6" runat="server" Text="获取部门记录列表" onclick="Button6_Click"  />
    
<br />
    
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
    
<asp:Button ID="Button7" runat="server" Text="根据ID获取指定部门记录信息" onclick="Button7_Click"  />
    
<br />
    
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
    
<asp:Button ID="Button8" runat="server" Text="根据姓名获取指定部门记录信息" onclick="Button8_Click"   />
    
<asp:GridView ID="GridView2" runat="server">
    
</asp:GridView>
    
    
<hr />
    部门
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox><asp:Button ID="Button9" runat="server" Text="根据ID获取指定部门的用户记录信息" onclick="Button9_Click"  />
    
<br />
    用户
<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
    
<br />
    
<asp:Button ID="Button10" runat="server" Text="加用户指定部门" onclick="Button10_Click"  />        
    
<asp:GridView ID="GridView3" runat="server">
    
</asp:GridView>
    
    
</form>
</body>
</html>

 

Default.aspx.cs

ContractedBlock.gif ExpandedBlockStart.gif Code
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using MWC.Entity;
using MWC.BusinessLogic;

public partial class _Default : System.Web.UI.Page 
ExpandedBlockStart.gifContractedBlock.gif
{
    
protected void Page_Load(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        
    }

    
protected void Button1_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        
//随机新增用户记录
        MWC.Entity.User ua = new MWC.Entity.User();
        
        Random rnd 
= new Random(DateTime.Now.Millisecond);

        ua.UserID 
= Guid.NewGuid();
        ua.UserName 
= "User" + rnd.Next(1,100);

        MWC.BusinessLogic.User ub 
= new MWC.BusinessLogic.User();

        ub.Add(ua);
    }

    
protected void Button2_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        
//获取用户记录列表
        MWC.BusinessLogic.User ub = new MWC.BusinessLogic.User();

        GridView1.DataSource 
= ub.List();
        GridView1.DataBind();
    }

    
protected void Button3_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        
//根据ID获取指定用户记录信息
        MWC.BusinessLogic.User ub = new MWC.BusinessLogic.User();

        Guid userID 
= new Guid(TextBox1.Text);

        GridView1.DataSource 
= ub.Info(userID);
        GridView1.DataBind();
    }

    
protected void Button4_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        
//根据姓名获取指定用户记录信息
        MWC.BusinessLogic.User ub = new MWC.BusinessLogic.User();

        GridView1.DataSource 
= ub.Info(TextBox2.Text);
        GridView1.DataBind();
    }

    
protected void Button5_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        
//随机新增部门记录
        MWC.Entity.Group ga = new MWC.Entity.Group();

        Random rnd 
= new Random(DateTime.Now.Millisecond);

        ga.GroupID 
= Guid.NewGuid();
        ga.GroupName 
= "Group" + rnd.Next(1100);

        MWC.BusinessLogic.Group gb 
= new MWC.BusinessLogic.Group();

        gb.Add(ga);
    }

    
protected void Button6_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        
//获取部门记录列表
        MWC.BusinessLogic.Group gb = new MWC.BusinessLogic.Group();

        GridView2.DataSource 
= gb.List();
        GridView2.DataBind();
    }

    
protected void Button7_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        
//根据ID获取指定部门记录信息
        MWC.BusinessLogic.Group gb = new MWC.BusinessLogic.Group();

        Guid groupID 
= new Guid(TextBox3.Text);

        GridView2.DataSource 
= gb.Info(groupID);
        GridView2.DataBind();
    }

    
protected void Button8_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        
//根据姓名获取指定部门记录信息
        MWC.BusinessLogic.Group gb = new MWC.BusinessLogic.Group();

        GridView2.DataSource 
= gb.Info(TextBox4.Text);
        GridView2.DataBind();
    }

    
protected void Button9_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        
//根据ID获取指定部门的用户记录信息
        MWC.BusinessLogic.Group gb = new MWC.BusinessLogic.Group();

        Guid groupID 
= new Guid(TextBox5.Text);

        GridView3.DataSource 
= gb.UserList(groupID);
        GridView3.DataBind();
    }

    
protected void Button10_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        
//加用户指定部门
        MWC.BusinessLogic.Group gb = new MWC.BusinessLogic.Group();
        Guid groupID 
= new Guid(TextBox5.Text);
        Guid userID 
= new Guid(TextBox6.Text);
        gb.AddUser(groupID, userID);
    }

}

 

注意:因为这是最终的客户端,在使用我们前面的各个模块前,需要将其加入到引用。即在WEB目录下会生成bin目录,下面会包含编译好的各模块的dll文件。系统发布时会用到这些文件。

    至此,我们通过一系列的文章实验了多层多数据库的开发。欢迎大家同我进行交流学习!

转载于:https://www.cnblogs.com/squabbyfish/archive/2008/11/12/1332164.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值