1 using System;
  2
using System;
  2 using System.Data;
  3
using System.Data;
  3 using System.Web.UI;
  4
using System.Web.UI;
  4 using Microsoft.Practices.EnterpriseLibrary.Data;
  5
using Microsoft.Practices.EnterpriseLibrary.Data;
  5 using System.IO;
  6
using System.IO;
  6 7
  7 public partial class Upload_ModifyControl : System.Web.UI.UserControl
  8
public partial class Upload_ModifyControl : System.Web.UI.UserControl
  8
 ...{
  9
...{
  9 protected void btnModify_Click(object sender, EventArgs e)
 10
    protected void btnModify_Click(object sender, EventArgs e)
 10
 ...{
 11
    ...{
 11 // 파일 업로드
 12
        // 파일 업로드
 12 string strDirectory = Server.MapPath(".") + "\\files\\"; //
 13
        string strDirectory = Server.MapPath(".") + "\\files\\"; //
 13 string strFileName = String.Empty;
 14
        string strFileName = String.Empty;
 14 if (!String.IsNullOrEmpty(ctlFileName.FileName))
 15
        if (!String.IsNullOrEmpty(ctlFileName.FileName))
 15
 ...{
 16
        ...{
 16 // 파일명 추출
 17
            // 파일명 추출
 17 strFileName = 
 18
            strFileName = 
 18 GetFilePath(strDirectory, ctlFileName.FileName); 
 19
                GetFilePath(strDirectory, ctlFileName.FileName); 
 19 // 경로 및 파일명으로 저장 실행
 20
            // 경로 및 파일명으로 저장 실행
 20 ctlFileName.PostedFile.SaveAs(
 21
            ctlFileName.PostedFile.SaveAs(
 21 Path.Combine(strDirectory, strFileName)); 
 22
                Path.Combine(strDirectory, strFileName)); 
 22 } 
 23
        } 
 23 // DB 수정
 24
        // DB 수정
 24 int result = DatabaseFactory.CreateDatabase("ConnectionString").
 25
        int result = DatabaseFactory.CreateDatabase("ConnectionString").
 25 ExecuteNonQuery("ModifyUpload"
 26
            ExecuteNonQuery("ModifyUpload"
 26 , txtName.Text, txtEmail.Text
 27
                , txtName.Text, txtEmail.Text
 27 , txtTitle.Text, Request.UserHostAddress
 28
                , txtTitle.Text, Request.UserHostAddress
 28 , DateTime.Now, txtContent.Text
 29
                , DateTime.Now, txtContent.Text
 29 , lstEncoding.SelectedValue, txtHomepage.Text
 30
                , lstEncoding.SelectedValue, txtHomepage.Text
 30 , txtPassword.Text, strFileName
 31
                , txtPassword.Text, strFileName
 31 , ctlFileName.PostedFile.ContentLength
 32
                , ctlFileName.PostedFile.ContentLength
 32 , Request["Num"]
 33
                , Request["Num"]
 33 );
 34
            );
 34
 if (result == -1) ...{
 35
        if (result == -1) ...{
 35 lblError.Text = "암호가 틀립니다.";
 36
            lblError.Text = "암호가 틀립니다.";
 36 }
 37
        }
 37
 else ...{
 38
        else ...{
 38 btnCancel_Click(null, null);
 39
            btnCancel_Click(null, null);
 39 } 
 40
        } 
 40 }
 41
    }
 41 private string GetFilePath(string strBaseDirTemp, string strFileNameTemp)
 42
    private string GetFilePath(string strBaseDirTemp, string strFileNameTemp)
 42
 ...{
 43
    ...{
 43 string strName = //순수파일명 : Test
 44
        string strName = //순수파일명 : Test
 44 Path.GetFileNameWithoutExtension(strFileNameTemp);
 45
            Path.GetFileNameWithoutExtension(strFileNameTemp);
 45 string strExt =        //확장자 : .txt
 46
        string strExt =        //확장자 : .txt
 46 Path.GetExtension(strFileNameTemp);
 47
            Path.GetExtension(strFileNameTemp);
 47 bool blnExists = true;
 48
        bool blnExists = true;
 48 int i = 0;
 49
        int i = 0;
 49 while (blnExists)
 50
        while (blnExists)
 50
 ...{
 51
        ...{
 51 //Path.Combine(경로, 파일명) = 경로+파일명
 52
            //Path.Combine(경로, 파일명) = 경로+파일명
 52 if (File.Exists(Path.Combine(strBaseDirTemp, strFileNameTemp)))
 53
            if (File.Exists(Path.Combine(strBaseDirTemp, strFileNameTemp)))
 53
 ...{
 54
            ...{
 54 strFileNameTemp =
 55
                strFileNameTemp =
 55 strName + "(" + ++i + ")" + strExt;//Test(3).txt
 56
                  strName + "(" + ++i + ")" + strExt;//Test(3).txt
 56 }
 57
            }
 57 else
 58
            else
 58
 ...{
 59
            ...{
 59 blnExists = false;
 60
                blnExists = false;
 60 }
 61
            }
 61 }
 62
        }
 62 return strFileNameTemp;
 63
        return strFileNameTemp;
 63 }
 64
    }
 64 protected void Page_Load(object sender, EventArgs e)
 65
    protected void Page_Load(object sender, EventArgs e)
 65
 ...{
 66
    ...{
 66 if (String.IsNullOrEmpty(Request["Num"]))
 67
        if (String.IsNullOrEmpty(Request["Num"]))
 67
 ...{
 68
        ...{
 68 Response.Write("잘못된 요청입니다.");
 69
            Response.Write("잘못된 요청입니다.");
 69 Response.End();
 70
            Response.End();
 70 }
 71
        }
 71 else
 72
        else
 72
 ...{
 73
        ...{
 73 if (!Page.IsPostBack) // 처음 로드할 때만 예전 데이터 읽어오기
 74
            if (!Page.IsPostBack) // 처음 로드할 때만 예전 데이터 읽어오기
 74
 ...{
 75
            ...{
 75 DisplayData();    
 76
                DisplayData();    
 76 }
 77
            }
 77 }
 78
        }
 78 }
 79
    }
 79 private void DisplayData()
 80
    private void DisplayData()
 80
 ...{
 81
    ...{
 81 using (IDataReader dr = DatabaseFactory.CreateDatabase(
 82
        using (IDataReader dr = DatabaseFactory.CreateDatabase(
 82 "ConnectionString").ExecuteReader(
 83
            "ConnectionString").ExecuteReader(
 83 "ViewUpload", Request["Num"]))
 84
                "ViewUpload", Request["Num"]))
 84
 ...{
 85
        ...{
 85 while (dr.Read()) 
 86
            while (dr.Read()) 
 86
 ...{
 87
            ...{
 87 lblNum.Text = dr[0].ToString();
 88
                lblNum.Text = dr[0].ToString();
 88 txtName.Text = dr["Name"].ToString();
 89
                txtName.Text = dr["Name"].ToString();
 89 txtEmail.Text = dr.GetString(2);
 90
                txtEmail.Text = dr.GetString(2);
 90 txtTitle.Text = dr["Title"].ToString();
 91
                txtTitle.Text = dr["Title"].ToString();
 91 txtHomepage.Text = dr["Homepage"].ToString();
 92
                txtHomepage.Text = dr["Homepage"].ToString();
 92 txtContent.Text = dr["Content"].ToString();//***
 93
                txtContent.Text = dr["Content"].ToString();//***
 93 // 인코딩
 94
                // 인코딩
 94 // 예전에 선택했던 인코딩 지정 : 0, 1, 2 중 하나 인덱스
 95
                // 예전에 선택했던 인코딩 지정 : 0, 1, 2 중 하나 인덱스
 95
 if (dr["Encoding"].ToString() == "HTML") ...{
 96
                if (dr["Encoding"].ToString() == "HTML") ...{
 96 lstEncoding.SelectedIndex = 1;
 97
                    lstEncoding.SelectedIndex = 1;
 97 }
 98
                }
 98
 else if (dr["Encoding"].ToString() == "Mixed") ...{
 99
                else if (dr["Encoding"].ToString() == "Mixed") ...{
 99 lstEncoding.SelectedIndex = 2;
100
                    lstEncoding.SelectedIndex = 2;
100 }
101
                }
101
 else ...{
102
                else ...{
102 lstEncoding.SelectedIndex = 0; // Text
103
                    lstEncoding.SelectedIndex = 0; // Text
103 }
104
                }
104 }
105
            }
105 }
106
        }
106 }
107
    }
107 protected void btnCancel_Click(object sender, EventArgs e)
108
    protected void btnCancel_Click(object sender, EventArgs e)
108
 ...{
109
    ...{
109 // 상세 보기로 이동
110
        // 상세 보기로 이동
110 Response.Redirect("View.aspx?Num=" + Request["Num"]);
111
        Response.Redirect("View.aspx?Num=" + Request["Num"]);
111 }
112
    }
112 }
113
}
113