블로그 이미지
Magic_kit
study 관련자료를 한곳으로 자기 개발 목적으로 재태크 재무 관리 목적으로 일상생활의 팁을 공유 하기 위하여 블로그를 개설 하였습니다.

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

Category

Recent Post

Recent Comment

Archive

2009. 10. 15. 11:59 .Net Project/ASP.NET 3.5 Sp1
반응형
 Upload/Modify.Cs

 <%@ Page Language="C#" AutoEventWireup="true"
         CodeFile="Modify.aspx.cs" Inherits="Upload_Modify" %>

<!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">
    <div>    
        이름 :
        <asp:TextBox ID="txtName" runat="server"></asp:TextBox><br />
        이메일 :
        <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox><br />
        홈페이지 :
        <asp:TextBox ID="txtHomepage" runat="server"></asp:TextBox><br />
        제목 :
        <asp:TextBox ID="txtTitle" runat="server"></asp:TextBox><br />
        내용 :
        <asp:TextBox ID="txtContent" runat="server"
                TextMode="MultiLine" Columns="20" Rows="5"></asp:TextBox><br />
        파일첨부 :
        <asp:FileUpload ID="ctlFileName" runat="server" />
        <asp:HiddenField ID="hidFileName" runat="server" />
        <asp:HiddenField ID="hidFileSize" runat="server" />
        <br />
        인코딩 :
        <asp:RadioButtonList ID="lstEncoding" runat="server"
            RepeatDirection="Horizontal"
            RepeatLayout="Flow">
            <asp:ListItem Selected="true">Text</asp:ListItem>
            <asp:ListItem>HTML</asp:ListItem>
            <asp:ListItem>Mixed</asp:ListItem>
        </asp:RadioButtonList>
        <br />
        암호 :
        <asp:TextBox ID="txtPassword" runat="server"
                TextMode="Password"></asp:TextBox><br />
        <br />
        <asp:LinkButton ID="btnModify" runat="server"
                onclick="btnModify_Click">수정</asp:LinkButton>
               
        <a href="View.aspx?Num=<%= Request["Num"] %>">취소</a><br />
        <asp:Label ID="lblError" runat="server" ForeColor="Red"></asp:Label>
       
    </div>
    </form>
</body>
</html>


 Upload/Modify.Cs

 using System;
using System.IO;

public partial class Upload_Modify : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (String.IsNullOrEmpty(Request["Num"]))
        {
            Response.Write("잘못된 요청입니다.");
            Response.End();
        }
        else
        {
            if (!Page.IsPostBack) //***** 처음 로드할 때만 예전 데이터 읽어오기
            {
                DisplayData();
            }
        }
    }
    private void DisplayData()
    {
        UploadEntity ue = new UploadEntity();
        UploadBiz ub = new UploadBiz();
        ue = ub.ViewUpload(Convert.ToInt32(Request["Num"]));

        // 각각의 컨트롤에 바인딩
        txtName.Text = ue.Name;
        txtEmail.Text = ue.Email;
        txtTitle.Text = ue.Title;
        txtHomepage.Text = ue.Homepage;
        txtContent.Text = ue.Content;

        // 수정 페이지에서 추가
        hidFileName.Value = ue.FileName;
        hidFileSize.Value = ue.FileSize.ToString();

        // 예전 인코딩에 따른 라디오버튼 리스트 선택
        if (ue.Encoding.ToLower() == "html")
        {
            lstEncoding.SelectedIndex = 1;
        }
        else if (ue.Encoding.ToLower() == "mixed")
        {
            lstEncoding.SelectedIndex = 2;
        }
        else
        {
            lstEncoding.SelectedIndex = 0; // 기본값
        }
    }
    protected void btnModify_Click(object sender, EventArgs e)
    {
        // 파일 업로드
        string strDirectory = Server.MapPath(".") + "
\\files\\"; //
        string strFileName = String.Empty;
        int intFileSize = 0;
        if (!String.IsNullOrEmpty(ctlFileName.FileName))
        { // 첨부된 파일이 있다면,       
            // 파일명 추출
            strFileName =
            // 파일명 중복처리 필요
            UploadUtil.GetFilePath(strDirectory, ctlFileName.FileName); 
          
            // (경로 + 파일명)으로 저장 실행
            ctlFileName.PostedFile.SaveAs
                             (Path.Combine(strDirectory, strFileName));
            intFileSize = ctlFileName.PostedFile.ContentLength; // 파일사이즈
        }
        else
        {
            strFileName = hidFileName.Value;
            intFileSize = Convert.ToInt32(hidFileSize.Value);
        }

        // DB 저장
        UploadBiz ub = new UploadBiz();

        UploadEntity ue = new UploadEntity();
        ue.Num = Convert.ToInt32(Request["Num"]);
        ue.Name = txtName.Text;
        ue.Email = txtEmail.Text;
        ue.Title = txtTitle.Text;
        //ue.PostIP = Request.UserHostAddress;
        ue.Content = txtContent.Text;
        ue.Password = txtPassword.Text;
        ue.Encoding = lstEncoding.SelectedValue;
        ue.Homepage = txtHomepage.Text;
        ue.FileName = strFileName; // 변경...
        ue.FileSize = intFileSize; // 변경...
        ue.ModifyDate = DateTime.Now;
        ue.ModifyIP = Request.UserHostAddress;

        int result = ub.ModifyUpload(ue);
        if (result == -1)
        {
            lblError.Text = "암호가 틀립니다.";
        }
        else
        {
            // 상세보기로 이동
            Response.Redirect("View.aspx?Num=" + Request["Num"]);
        }
    }
}






반응형
posted by Magic_kit
2009. 10. 15. 11:55 .Net Project/ASP.NET 3.5 Sp1
반응형
 Upload/Delete.aspx

 <%@ Page Language="C#" AutoEventWireup="true"
         CodeFile="Delete.aspx.cs" Inherits="Upload_Delete" %>

<!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">
    <div>
        <asp:Label ID ="lblNum" runat="server" ForeColor="Red"></asp:Label>
        번 글을 삭제 하시겠습니까? <br />
        암호
        <asp:TextBox ID="txtPassword" runat="server"
                TextMode="Password"></asp:TextBox>
        <asp:Button ID="btnDelete" runat="server" Text="삭제"
                OnClientClick='return confirm("정말로 삭제하시겠습니까?");'
                onclick="btnDelete_Click"  />
        <asp:Label ID="lblError" runat="server" ForeColor="Red"></asp:Label>   
   
    </div>
    </form>
</body>
</html>


 Upload/Delete.Cs

using System;

public partial class Upload_Delete : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //넘겨져 온 쿼리스트링 값 검사
        if (String.IsNullOrEmpty(Request["Num"]))
        {
            Response.Write("잘못된 요청입니다.");
            Response.End();
        }
        else
        {
            lblNum.Text = Request["Num"];
        }
       
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        UploadBiz ub = new UploadBiz();

        //이미 업로드된 파일명 얻기
        string fileName = "";
        UploadEntity ue = ub.ViewUpload(Convert.ToInt32(Request["Num"]));
        fileName = ue.FileName;

        int result = ub.DeleteUpload
                         (Convert.ToInt32(Request["Num"]), txtPassword.Text);
       
        if (result == -1)
        {
            lblError.Text = "암호가 틀립니다.";
        }
        else
        {
            if (fileName != "")
            {
                try
                {
                    System.IO.File.Delete
                               (Server.MapPath(".") + "
\\files\\" + fileName);
                }
                catch (Exception)
                {                    
                    //empty
                }
            }
            //리스트로 이동
            Response.Redirect("List.aspx");
        }
    }
}




반응형
posted by Magic_kit
2009. 10. 15. 11:52 .Net Project/ASP.NET 3.5 Sp1
반응형

 Upload/View.aspx

 <%@ Page Language="C#" AutoEventWireup="true"
        CodeFile="View.aspx.cs" Inherits="Upload_View" %>

<!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">
    <div>
        번호:<asp:Label ID="lblNum" runat="server"></asp:Label><br />
        제목:
        <asp:Label ID="lblTitle" runat="server"></asp:Label><br />
        이름:<asp:Label ID="lblName" runat="server"></asp:Label><br />
        이메일:<asp:Label ID="lblEmail" runat="server"></asp:Label><br />
        홈페이지:<asp:Label ID="lblHomepage" runat="server"></asp:Label><br />
        작성일:<asp:Label ID="lblPostDate" runat="server"></asp:Label><br />
        조회수:<asp:Label ID="lblReadCount" runat="server"></asp:Label><br />
        IP주소:<asp:Label ID="lblPostIP" runat="server"></asp:Label><br />
        파일 :
        <asp:Label ID="lblFileName" runat="server" /><br />
        파일 :
        <asp:HyperLink ID="lnkFileName" runat="server"></asp:HyperLink><br />
        파일 :
        <asp:PlaceHolder ID="ctlFileName" runat="server"></asp:PlaceHolder>
        <br />
        내용:<asp:Label ID="lblContent" runat="server"></asp:Label><br />
        <br />
       
        <asp:Button ID="btnModify" runat="server"
                Text="수정" onclick="btnModify_Click" />
       
     <input type="button" id="btnDelete" value="삭제"
            onclick="location.href='Delete.aspx?Num=<%= Request["Num"] %>';" />
           
        <asp:Button ID="btnList" runat="server"
            Text="리스트" OnClientClick="location.href='List.aspx';return false;"
            onclick="btnList_Click" />
      </div>
    </form>
</body>
</html>


 Upload/View.Cs

using System;
using System.Collections;
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;

public partial class Upload_View : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (String.IsNullOrEmpty(Request["Num"]))
        {
            Response.Write("잘못된 요청입니다");
            Response.End();
        }
        else
        {
            if (!Page.IsPostBack)
            {
                DisplayData();
            }
        }

    }
    private void DisplayData()
    {
        UploadEntity ue = new UploadEntity();
        UploadBiz ub = new UploadBiz();
        ue = ub.ViewUpload(Convert.ToInt32(Request["Num"]));

        // 각각의 컨트롤에 바인딩
        lblNum.Text = Request["Num"];
        lblName.Text = ue.Name;
        lblEmail.Text = ue.Email;
        lblTitle.Text = ue.Title;
        lblHomepage.Text = ue.Homepage;
        lblPostDate.Text = ue.PostDate.ToString();
        lblReadCount.Text = ue.ReadCount.ToString();
        lblPostIP.Text = ue.PostIP;

        // 인코딩에 따른 내용 표시
        string content = "";
        if (ue.Encoding.ToLower() == "text") // Text : 입력한 소스 그대로 화면에 출력
        {
            content = ue.Content.Replace("&", "&amp;").Replace("<", "&lt;")
                .Replace(">", "&gt;").Replace("\r\n", "<br />")
                    .Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
        }
        else if (ue.Encoding.ToLower() == "mixed") // Mixed : 태그처리 + 엔터처리
        {
            content = ue.Content.Replace("\r\n", "<br />");
        }
        else
        {
            content = ue.Content; // HTML : 태그처리
        }
        lblContent.Text = content;

        //[1]
        lblFileName.Text = String.Format
            ("<a href='Down.aspx?FileName={0}'>{0}</a> / 다운수 : {1}"
            , ue.FileName, ue.DownCount);
       
        //[2]
        lnkFileName.Text = ue.FileName;
        lnkFileName.NavigateUrl = String.Format
                  ("~/Upload/Down.aspx?FileName={0}", ue.FileName);
        
        //[3]
        //[a] 동적으로 하이퍼링크를 만들어서
        HyperLink lnk = new HyperLink();
        lnk.Text = ue.FileName.ToString();
        lnk.NavigateUrl = String.Format
             ("~/Upload/Down.aspx?FileName={0}", ue.FileName);
       
        //[b] 플레이스홀더 컨트롤에 추가
        ctlFileName.Controls.Add(lnk);
    }
    //수정
    protected void btnModify_Click(object sender, EventArgs e)
    {
        //수정 페이지로 이동
        Response.Redirect("Modify.aspx?Num=" + Request["Num"]);
    }
    //리스트
    protected void btnList_Click(object sender, EventArgs e)
    {
        //리스트 페이지로 이동
        Response.Redirect("List.aspx?Num=" + Request["Num"]);
    }
}







반응형
posted by Magic_kit
2009. 10. 15. 09:08 .Net Project/ASP.NET 3.5 Sp1
반응형
 Menu Server Control
- ASP2.0에서 새로 추가된 Menu 서버 컨트롤 의미
- TreeView 서버 컨트롤 처럼 계층적으로 데이터를 팝업 메뉴로 보여 줄 수 있다.
- TreeView 서버 컨트롤 처럼 XMLDataSource 서버 컨트롤과 SiteMapDataSource
   서버 컨트롤에만 바인딩 가능

 TreeView Control
 - 계층적으로 보여줄 수 있기 때문에 TreeView 서버 컨트롤과 SiteMapDataSource 서버
   컨트롤에 바인딩 가능 (SiteMapDataSource 서버 컨트롤에서 사용하는 .Sitemap 파일 보여줌)

 그 밖의 데이터 바인딩 컨트롤  
- DropDownList 서버컨트롤
- RadioButtonList 서버컨트롤
- CheckBoxList 서버컨트롤
- 다음과 같은 컨트롤이 존재 하고 있습니다.  



반응형
posted by Magic_kit