Human Resources ASP.NET 웹 사이트(EDM 샘플 응용 프로그램)

Human Resources ASP.NET 응용 프로그램은 네트워크 또는 인터넷에서 다음 예제를 사용하여 정의하고 컴파일한 데이터를 표시할 때 사용할 수 있는 인터페이스입니다. Human Resources Skills WinApp(EDM 샘플 응용 프로그램). 이 웹 응용 프로그램에서 참조하는 스키마와 DLL은 Windows 응용 프로그램에서 사용하는 것과 동일합니다. 웹 사이트는 다음 세 단계로 빌드됩니다.

  1. 입력을 관리하고 데이터를 표시하기 위한 텍스트 상자와 표 뷰 컨트롤을 갖춘 웹 페이지상의 폼으로 사용자 인터페이스를 디자인합니다.

  2. 입력 이벤트를 처리하고 사용자가 입력한 매개 변수에 대해 검색 결과를 표시하도록 인터페이스 뒤에 ASP.NET 코드를 씁니다.

  3. ASP.NET 응용 프로그램을 실행하고 HRSkills 데이터 모델에서 사용되는 SQL Server 저장 데이터에 연결하도록 IIS를 구성합니다.

사용자 인터페이스

사용자 인터페이스는 검색 매개 변수를 정의하는 텍스트 입력용 텍스트 상자 2개로 구성됩니다. 사용자는 성의 첫 글자를 기준으로 직원을 검색하거나 키워드로 기술을 검색할 수 있습니다. 이러한 매개 변수에 대한 검색 결과는 EDM 개체 쿼리에 바인딩된 표 뷰 컨트롤에 의해 표시되며 직원, 기술 및 기술 정보 그리고 개인 참조를 나타냅니다.

사용자 인터페이스는 다음 화면 표시로 나타납니다.

ASP.NET HR Skills 응용 프로그램 쿼리 결과

다음 XML 사양에서는 사용자에게 표시될 웹 페이지상의 폼과 컨트롤을 정의합니다. 이 구문을 Visual Studio에서 ASP.NET 웹 응용 프로그램의 Default.aspx 파일에 복사합니다.

<%@ 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 >
    <title>HR Skills Online</title>
</head>
<body>
    <form id="form1" >
    &nbsp;<asp:Label ID="Label1"  Font-Bold="True" 
        Text="Filter employees by first letter of last name; 
        Use * to get all employees: "></asp:Label>
&nbsp;<asp:TextBox ID="TextBox1"  MaxLength="1" 
        ontextchanged="TextBox1_TextChanged" Width="29px" 
        AutoPostBack="True"></asp:TextBox>
&nbsp;&nbsp;
        <br />
        <asp:Label ID="Label2"  Font-Bold="True" 
        Text="Search for skills on  keyword; Use * to get all skills: ">
        </asp:Label>
        <asp:TextBox ID="TextBox2"  MaxLength="50" 
        Width="271px" AutoPostBack="True" 
        ontextchanged="TextBox2_TextChanged">
        </asp:TextBox>
&nbsp;<asp:GridView 
        ID="GridView1"  BackColor="LightGoldenrodYellow" 
        BorderColor="Tan" BorderWidth="1px" CellPadding="2" 
        ForeColor="Black" 
        onselectedindexchanged="GridView1_SelectedIndexChanged" 
        Caption="Employees (Click row for skills)" CaptionAlign="Top"
        CellSpacing="1">
            <footerstyle backcolor="Tan" />
            <selectedrowstyle backcolor="DarkSlateBlue"
            forecolor="GhostWhite" />
            <pagerstyle backcolor="PaleGoldenrod" 
            forecolor="DarkSlateBlue" 
            horizontalalign="Center" />
            <headerstyle backcolor="Tan" font-bold="True" 
            font-size="Medium" />
            <alternatingrowstyle backcolor="PaleGoldenrod" />
        </asp:GridView>
        <br />
        <asp:GridView 
        ID="GridView2"  BackColor="LightGoldenrodYellow" 
        BorderColor="Tan" BorderWidth="1px" CellPadding="2" 
        ForeColor="Black" 
        onselectedindexchanged="GridView2_SelectedIndexChanged" 
        Caption="Skills (Click row for details)" CaptionAlign="Top" 
        CellSpacing="1" 
        PageSize="5">
            <footerstyle backcolor="Tan" />
            <selectedrowstyle backcolor="DarkSlateBlue" 
            forecolor="GhostWhite" />
            <pagerstyle backcolor="PaleGoldenrod" 
            forecolor="DarkSlateBlue" horizontalalign="Center" />
            <headerstyle backcolor="Tan" font-bold="True" />
            <alternatingrowstyle backcolor="PaleGoldenrod" />
        </asp:GridView>
        <br />
        <asp:GridView ID="GridView3"  
        BackColor="LightGoldenrodYellow" 
        BorderColor="Tan" BorderWidth="1px" CaptionAlign="Top"
        CellPadding="2" 
        CellSpacing="1" ForeColor="Black" 
        onselectedindexchanged="GridView3_SelectedIndexChanged">
            <footerstyle backcolor="Tan" forecolor="GhostWhite" />

            <pagerstyle backcolor="PaleGoldenrod" 
            forecolor="DarkSlateBlue" 
            horizontalalign="Center" />
            <headerstyle backcolor="Tan" font-bold="True" />
            <alternatingrowstyle backcolor="PaleGoldenrod" />
        </asp:GridView>
    </form>
</body>
</html>

웹 컨트롤 뒤의 ASP.NET 코드

사용자 입력에 의해 생성된 이벤트를 처리하는 C# 코드는 Default.aspx.cs 코드 숨김 파일에 있습니다. 다음 코드는 개체 쿼리를 정의하고 결과를 표 뷰 컨트롤에 바인딩하는 데 사용합니다. 이 작업에 대한 자세한 내용은 HR Skills 응용 프로그램 코드(EDM 샘플 응용 프로그램)를 참조하십시오.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HRSkillsModel;
using System.Data.Objects;

namespace HRSkillsOnline
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void GridView1_SelectedIndexChanged(object sender,
        EventArgs e)
        {
            GridView2.SelectedIndex = -1;
            GridView3.SelectedIndex = -1;
            string connectionStr =
                Application.Contents["connectionString"] as string;


            using (HRSkillsEntities HRSkills = new HRSkillsEntities())
            {
                Guid empId = new Guid(
                    GridView1.SelectedRow.Cells[1].Text);
                // Find the Employee.
                ObjectParameter param = new ObjectParameter("p", empId);

                Employees employee = HRSkills.Employees.Where(
                    "it.EmployeeId = @p", param).First();

                employee.Skills.Load();

                GridView2.Caption = "Skills of "
                    + employee.FirstName + " " +
                    employee.LastName;

                GridView2.AutoGenerateSelectButton = true;
                GridView2.DataSource = employee.Skills;
                GridView2.DataBind();
                GridView2.Focus();

                // Find Employee references.
                employee.References.Load();

                GridView3.AutoGenerateSelectButton = false;
                GridView3.Caption = "References for "
                    + employee.FirstName + " " +
                    employee.LastName;

                GridView3.DataSource = employee.References;
                GridView3.DataBind();
            }


        }

        protected void GridView2_SelectedIndexChanged(object sender,
            EventArgs e)
        {
            string connectionStr =
                Application.Contents["connectionString"] as string;

            using (HRSkillsEntities HRSkills = new HRSkillsEntities())
            {
                // Create a ObjectParameter from the SkillId property 
                // and get the Skill.
                Guid skillId = new Guid(
                    GridView2.SelectedRow.Cells[1].Text);

                ObjectParameter param =
                    new ObjectParameter("p", skillId);

                Skills skill = HRSkills.Skills.Where("it.SkillId = @p",
                    param).First();

                // Load the SkillInfo entities using 
                // SkillInfo_Skill association.
                skill.SkillInfo.Load();

                GridView3.AutoGenerateSelectButton = true;
                GridView3.DataSource = skill.SkillInfo;
                GridView3.DataBind();
                GridView3.Caption = "Skills URLs for " +
                    GridView2.SelectedRow.Cells[2].Text;
                GridView3.Focus();
            }

        }
        protected void TextBox1_TextChanged(object sender, EventArgs e)
        {
            GridView1.SelectedIndex = -1;
            GridView2.SelectedIndex = -1;
            GridView3.SelectedIndex = -1;

            string connectionStr =
                Application.Contents["connectionString"] as string;

            using (HRSkillsEntities HRSkills = new HRSkillsEntities())
            {
                if ("*".Equals(TextBox1.Text))
                {
                    GridView1.Caption = "All Employees in System";
                    GridView1.AutoGenerateSelectButton = true;
                    GridView1.DataSource = 
                        HRSkills.Employees.Execute(
                        MergeOption.OverwriteChanges);
                    GridView1.DataBind();

                    TextBox1.Text = "";
                    return;
                }
                ObjectParameter param =
                    new ObjectParameter("p", TextBox1.Text.ToUpper());

                ObjectQuery<Employees> dbQuery = 
                    HRSkills.Employees.Where(
                    "SqlServer.SUBSTRING(it.LastName, 1, 1) = @p",
                    param);

                GridView1.Caption = "Employees' last name on: " +
                    TextBox1.Text.ToUpper();
                GridView1.AutoGenerateSelectButton = true;
                GridView1.DataSource = 
                    dbQuery.Execute(MergeOption.OverwriteChanges);
                GridView1.DataBind();
            }
            TextBox1.Text = "";
        }

        protected void TextBox2_TextChanged(object sender, EventArgs e)
        {
            string connectionStr =
                Application.Contents["connectionString"] as string;

            using (HRSkillsEntities HRSkills = new HRSkillsEntities())
            {
                GridView1.SelectedIndex = -1;
                GridView2.SelectedIndex = -1;
                GridView3.SelectedIndex = -1;

                if ("*".Equals(TextBox2.Text))
                {
                    GridView2.Caption = "All Skills in System.";
                    GridView2.AutoGenerateSelectButton = true;
                    GridView2.DataSource = 
                        HRSkills.Skills.Execute(
                        MergeOption.OverwriteChanges );
                    GridView2.DataBind();
                    GridView1.DataSource = null;
                    GridView1.DataBind();

                    TextBox2.Text = "";
                    return;
                }

                // Create ObjectParameter from each keyword 
                // and search properties of Skills.

                ObjectParameter param = new ObjectParameter(
                    "p", "%" + TextBox2.Text.Trim(
                    '\"', '&', '%', '$', '#') + "%");

                ObjectQuery<Skills> skillsQuery =
                    HRSkills.Skills.Where(
                    "it.BriefDescription Like @p " +
                    "OR it.SkillName Like @p", param);

                List<Employees> employeeList = new List<Employees>();
                foreach (Skills skill in skillsQuery)
                {
                    skill.EmployeesReference.Load();
                    employeeList.Add(skill.Employees);
                }

                GridView1.Caption = "Employees with skills on " +
                    TextBox2.Text;
                GridView1.AutoGenerateSelectButton = true;
                GridView1.DataSource = employeeList;
                GridView1.DataBind();

                GridView2.Caption = "Skills on " +
                    TextBox2.Text;
                GridView2.AutoGenerateSelectButton = true;
                GridView2.DataSource = 
                    skillsQuery.Execute(MergeOption.OverwriteChanges);
                GridView2.DataBind();
            }
            TextBox2.Text = "";
        }

        protected void GridView3_SelectedIndexChanged(object sender,
            EventArgs e)
        {
            string scriptString = @"<script> window.open('" +
                GridView3.SelectedRow.Cells[2].Text +
                "', left=100)</script>";
            if (!ClientScript.IsClientScriptBlockRegistered("PopUpWindow"))
                ClientScript.RegisterClientScriptBlock(GridView3.GetType(),
                    "PopUpWindow", scriptString);
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}

참고 항목

개념

Human Resources Skills WinApp(EDM 샘플 응용 프로그램)