ASP.NET&Spring.NET&NHibernate最佳实践(六)——第3章人事子系统(3)

本文介绍了一个基于Web的人事子系统的界面设计细节,包括部门和员工管理的列表展示、编辑、删除及新增功能实现。通过ASP.NET技术实现了数据绑定与交互。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

3.6. 人事子系统表示层(Web)
修改Depts.aspx
<asp:Panel ID="Panel1" runat="server" GroupingText="部门列表">
        
<br />
        
<asp:GridView ID="GridView1" runat="server" DataSourceID="odsDepts" DataKeyNames="ID"
            AutoGenerateColumns
="False" Width="100%" AllowPaging="true" PageSize="10">
            
<Columns>
                
<asp:TemplateField>
                    
<ItemTemplate>
                        
<asp:Button ID="btnEdit" runat="server" CommandName="Edit" Text="编辑" />
                        
<asp:Button ID="btnDelete" runat="server" CommandName="Delete" Text="删除" OnClientClick="return confirm('您真的要删除吗?')" />
                    
</ItemTemplate>
                    
<EditItemTemplate>
                        
<asp:Button ID="btnUpdate" runat="server" CommandName="Update" Text="更新" />
                        
<asp:Button ID="btnCancel" runat="server" CommandName="Cancel" Text="取消" />
                    
</EditItemTemplate>
                
</asp:TemplateField>
                
<asp:BoundField HeaderText="部门代码" DataField="Code" />
                
<asp:BoundField HeaderText="部门名称" DataField="Name" />
            
</Columns>
        
</asp:GridView>
    
</asp:Panel>
    
<hr />
    
<asp:Panel ID="Panel2" runat="server" GroupingText="新增部门">
        
<br />
        
<asp:FormView ID="FormView1" runat="server" DataSourceID="odsDepts" DefaultMode="Insert">
            
<InsertItemTemplate>
                
<table width="100%" border="0" cellpadding="2" cellspacing="2">
                    
<tr>
                        
<td>
                            部门代码
</td>
                        
<td>
                            
<asp:TextBox ID="txtCode" runat="server" Width="200" Text='<%# Bind("Code") %>' />
                        
</td>
                    
</tr>
                    
<tr>
                        
<td>
                            部门名称
</td>
                        
<td>
                            
<asp:TextBox ID="txtGroupName" runat="server" Width="200" Text='<%# Bind("Name") %>' />
                        
</td>
                    
</tr>
                
</table>
                
<p>
                    
<asp:Button ID="btnInsert" runat="server" CommandName="Insert" Text="新增" />
                
</p>
            
</InsertItemTemplate>
        
</asp:FormView>
    
</asp:Panel>
    
<asp:ObjectDataSource ID="odsDepts" runat="server" TypeName="Guushuuse.SalaryPrj.HR.Helper.HRHelper"
        SelectMethod
="GetAllDepts" InsertMethod="CreateDept" UpdateMethod="UpdateDept"
        DeleteMethod
="DeleteDept"></asp:ObjectDataSource>
修改Employees.aspx
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeFile
="Employees.aspx.cs" Inherits="Employees" 
%>

<asp:Content ID="LeftColumnContent" ContentPlaceHolderID="LeftColumnZone" runat="server">
</asp:Content>
<asp:Content ID="MiddleColumnContent" ContentPlaceHolderID="MiddleColumnZone" runat="server">
    
<asp:Panel ID="Panel1" runat="server" GroupingText="员工列表">
        
<br />
        
<asp:GridView ID="GridView1" runat="server" DataSourceID="odsEmployees" DataKeyNames="ID"
            AutoGenerateColumns
="False" Width="100%" AllowPaging="true" PageSize="10">
            
<Columns>
                
<asp:TemplateField>
                    
<ItemTemplate>
                        
<asp:Button ID="btnEdit" runat="server" CommandName="Edit" Text="编辑" />
                        
<asp:Button ID="btnDelete" runat="server" CommandName="Delete" Text="删除" OnClientClick="return confirm('您真的要删除吗?')" />
                    
</ItemTemplate>
                    
<EditItemTemplate>
                        
<asp:Button ID="btnUpdate" runat="server" CommandName="Update" Text="更新" />
                        
<asp:Button ID="btnCancel" runat="server" CommandName="Cancel" Text="取消" />
                    
</EditItemTemplate>
                
</asp:TemplateField>
                
<asp:BoundField HeaderText="工号" DataField="Code" />
                
<asp:BoundField HeaderText="姓名" DataField="Name" />
                
<asp:TemplateField HeaderText="部门">
                    
<ItemTemplate>
                        
<asp:Label ID="lblDeptName" runat="server" Text='<%# Eval("DeptName") %>' />
                    
</ItemTemplate>
                    
<EditItemTemplate>
                        
<asp:DropDownList ID="lstDepts" runat="server" DataTextField="Name" DataValueField="ID"
                            DataSourceID
="odsDepts" SelectedValue='<%# Bind("DeptID") %>'>
                        
</asp:DropDownList>
                    
</EditItemTemplate>
                
</asp:TemplateField>
            
</Columns>
        
</asp:GridView>
    
</asp:Panel>
    
<hr />
    
<asp:Panel ID="Panel2" runat="server" GroupingText="新增员工">
        
<br />
        
<asp:FormView ID="FormView1" runat="server" DataSourceID="odsEmployees" DefaultMode="Insert">
            
<InsertItemTemplate>
                
<table width="100%" border="0" cellpadding="2" cellspacing="2">
                    
<tr>
                        
<td>
                            工号
</td>
                        
<td>
                            
<asp:TextBox ID="txtCode" runat="server" Width="200" Text='<%# Bind("Code") %>' />
                        
</td>
                    
</tr>
                    
<tr>
                        
<td>
                            姓名
</td>
                        
<td>
                            
<asp:TextBox ID="txtGroupName" runat="server" Width="200" Text='<%# Bind("Name") %>' />
                        
</td>
                    
</tr>
                    
<tr>
                        
<td>
                            部门
</td>
                        
<td>
                            
<asp:DropDownList ID="lstDepts" runat="server" DataTextField="Name" DataValueField="ID"
                                DataSourceID
="odsDepts" SelectedValue='<%# Bind("DeptID") %>'>
                            
</asp:DropDownList>
                        
</td>
                    
</tr>
                
</table>
                
<p>
                    
<asp:Button ID="btnInsert" runat="server" CommandName="Insert" Text="新增" />
                
</p>
            
</InsertItemTemplate>
        
</asp:FormView>
    
</asp:Panel>
    
<asp:ObjectDataSource ID="odsEmployees" runat="server" TypeName="Guushuuse.SalaryPrj.HR.Helper.HRHelper"
        SelectMethod
="GetAllEmployees" InsertMethod="CreateEmployee" UpdateMethod="UpdateEmployee"
        DeleteMethod
="DeleteEmployee"></asp:ObjectDataSource>
    
<asp:ObjectDataSource ID="odsDepts" runat="server" TypeName="Guushuuse.SalaryPrj.HR.Helper.HRHelper"
        SelectMethod
="GetAllDepts"></asp:ObjectDataSource>
</asp:Content>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值