블로그 이미지
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

Category

Recent Post

Recent Comment

Archive

2009. 10. 6. 17:51 .Net Project/ASP.NET 3.5 Sp1
반응형


Web.Config ConnectinStrings 추가하여 데이터 베이스 연결 문자열 작성  
 <connectionStrings>
    <add name="ConnectionString" 
            connectionString="server=.;database=Basic;uid=Basic;pwd=1234"
            providerName="System.Data.SqlClient"></add>
  </connectionStrings>
 


--[0]기본형 게시판(Basic)용 테이블 설계
--[!] Drop Table dbo.Basic

Create Table dbo.Basic
(
   Num Int Identity(1,1) Not Null Primary Key,
--번호
   Name VarChar(25) Not Null, --이름
   Email VarChar(100) Null, --에메일
   Title VarChar(150) Not Null,
--제목
   PostDate DateTime Default
GetDate() Not Null, --작성일
   PostIP VarChar(15) Not Null, --작성IP

   Content Text Not Null,
--내용
   Password VarChar(20) Not Null, --비밀번호
   ReadCount Int Default 0,
--조회수
   Encoding VarChar(10) Not Null, --인코딩(HTML/Text/Mixed)
   HomePage VarChar(100) Null, --홈페이지
   ModifyDate SmallDateTime Null,--수정일
   ModifyIP VarChar(15) Null
--수정 IP
)
Select *From Basic
--[!] 6개 예시문
--[1] 입력

Insert Basic
Values
(
     '홍길동','h@h.com',
     '홍길동입니다.(냉무)',
     GetDate(),'127.0.0.1',
     '안녕하세요.','1234',
     0,'Text', 'http://www.a.com/',
     NULL,     --널
     ''     --(Empty)
)
Go

--[2]출력 : List.aspx
Select
 Num, Name, Email,
 Title, PostDate, ReadCount
From Basic --Join On
--Where
--Group by
--Having
Order By Num Desc  
Go

--[3]상세 : View.aspx
Select *From Basic Where Num=1
Go

--[4]수정 : Modify.aspx
Begin Tran
     Update Basic
     Set
          Name = '백두산',
          Email =
'b@b.com',
          Homepage = 'http://b.com/',
          Title = '새로운 제목',
          Content     = '<u>내용</u>',
          Encoding = 'HTML',
          ModifyDate = GetDate(),
          ModifyIP = '127.0.0.1'
     Where Num = 1
--RollBack Tran
Commit Tran
Go

--[5]삭제 : Delete.aspx
Begin Transaction
 Delete Basic
 Where Num=2
--RollBack Transaction
Commit Transaction
Go

--[6]검색 : Search.aspx
Select *From Basic Where Name Like '%백두산%'
Or
Title Like '새%'
Or
Content Like '%3'
Go

--[7] 기본형 게시판에 글을 작성하는 저장 프로시저 : WriteBasic
Create Proc dbo.WriteBasic

 @Name VarChar(25),
 @Email VarChar(100),
 @Title VarChar(150),
 @PostIP VarChar(20),
 @Content Text,
 @Password VarChar(20),
 @Encoding VarChar(10),
 @Homepage VarChar(100)
--With Encryption
As
 Insert Basic
 (
    Name,Email,Title,PostIP,Content,
    Password,Encoding,HomePage
 )
 Values
 (
    @Name,@Email,@Title,@PostIP,@Content,
    @Password,@Encoding,@HomePage
 )
Go   

--[8]기본형 게시판에서 데이터를 읽어오는 저장 프로시저 : ListBasic
Create Procedure dbo.ListBasic
As
 Select *From Basic
 Order By Num Desc
Go

--[9]조회수 증가 시켜주는 저장 프로시저 : UpdateReadCount
Create Proc dbo.UpdateReadCountBasic
   @Num Int
As
   Update Basic
   Set ReadCount = ReadCount + 1
   Where Num = @Num
Go

--[10]해당 글을 세부적으로 읽어오는 저장 프로시저 : ViewBasic
Create Procedure dbo.ViewBasic
   @Num Int
As
   Update Basic
   Set ReadCount = ReadCount + 1
   Where Num = @Num
 
   Select *From Basic
   Where Num = @Num
Go

--[11]해당 글에 대한 비밀번호 읽어오는 저장 프로시저 : ReadPasword
Create Proc dbo.ReadPasswordBasic
   @Num Int
As
   Select Password
   From Basic
   Where Num = @Num
Go 

--[12] 해당 글 지우는 저장 프로시저 : DeleteBasic
Create Proc dbo.DeleteBasic
 @Password VarChar(20),
 @Num Int
As
  Declare @cnt Int
     -- 암호와 번호가 맞으면 1을 반환
     Select @cnt = Count(*) From Basic
     Where Num = @Num And Password = @Password

     If @cnt > 0
          Delete Basic Where Num = @Num And Password = @Password
     Else    
          Return -1

Go 

--[13] 해당 글을 수정하는 저장 프로시저 : ModifyBasic
Create Proc dbo.ModifyBasic
     @Name VarChar(25), @Email VarChar(100),
     @Title VarChar(150), @ModifyIP VarChar(15),
     @Content Text,
     @Encoding VarChar(10), @Homepage VarChar(100),
     @Password VarChar(20), @Num Int
As
     Declare @cnt Int
     Select @cnt = Count(*) From Basic
     Where Num = @Num And Password = @Password

     If @cnt > 0  -- 넘겨져 온 번호와 암호가 맞는 데이터가 있다면...
          Update Basic
          Set
               Name = @Name, Email = @Email,
               Title = @Title, ModifyIP = @ModifyIP,
               ModifyDate = GetDate(), Content = @Content,
               Encoding = @Encoding, Homepage = @Homepage
          Where Num = @Num And Password = @Password
     Else
          Return -1 -- 암호가 틀리면 -1을 반환하자...
Go

--[14] 검색 저장 프로시저 : 동적 SQL문
Create Proc dbo.SearchBasic
     @SearchField VarChar(25),
     @SearchQuery VarChar(25)
As
     Declare @strSql VarChar(150) -- 변수 선언
     Set @strSql = '
     Select * From Basic
     Where '
          + @SearchField + ' Like ''%'
          + @SearchQuery + '%'' Order By Num Desc'
     --Print @strSql
     Exec (@strSql)
Go

SearchBasic ' 1 = 1; Drop Table Basic --', '메롱~'
Go

SearchBasic 'Name', '홍길동'
Go


--[12] 검색 저장 프로시저 : 정적 쿼리문
Alter Proc dbo.SearchBasic
      @SearchField VarChar(25),
      @SearchQuery VarChar(25)
As
     Set @SearchQuery = '%' + @SearchQuery + '%'
     SELECT *
     FROM Basic
     WHERE
      (
           CASE @SearchField
                WHEN 'Name' THEN Name
                WHEN 'Email' THEN Email
                WHEN 'Title' THEN Title
           ELSE
                @SearchQuery
           END
      )
      LIKE
      @SearchQuery
     Order By Num Desc
Go 



반응형
posted by Magic_kit
2009. 10. 6. 13:08 .Net Project/ASP.NET 3.5 Sp1
반응형
- Textbox 실행화면

-TextBox 화면 디자인


- TextBox 소스화면

 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 Control_FrmTextBox : System.Web.UI.Page
{    

    protected void Button1_Click(object sender, EventArgs e)
    {
        //이름
        string name = txtSingleLine.Text;

        //소개
        string Intro = txtMultiLine.Text;

        //암호
        string password = txtPassword.Text;

        //레이블 출력
        this.lblDisplay.Text = String.Format("{0}{1}{2}{1}{3}{1}",
        name, "<br />", Intro.Replace("\r\n","<br />"), password);
  
  }
}




반응형
posted by Magic_kit
2009. 10. 6. 13:00 .Net Project/ASP.NET 3.5 Sp1
반응형

- Button 실행화면


- Button 디자인 화면

- Button 소스화면

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 Control_FrmButton : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    //증가
    protected void btnUp_Click(object sender, EventArgs e)
    {
        txtNum.Text = Convert.ToString(Convert.ToInt32(txtNum.Text) + 1);
    }
    //감소
    protected void btnDown_Click(object sender, EventArgs e)
    {
     //txtNum.Text = Convert.ToString(Convert.ToUInt32(txtNum.Text) - 1);
        txtNum.Text = Convert.ToString(Int32.Parse(txtNum.Text) - 1);
    }



반응형
posted by Magic_kit
2009. 10. 6. 12:56 .Net Project/ASP.NET 3.5 Sp1
반응형
-Lavel 실행화면

-Lavel 디자인

- Lavel 소스화면

 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 Control_FrmLabel : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DisplayEven(); //1~100까지 합
        DisplayXmas(); //올 크리스마스가 몇일 남았는지
    }

    private DateTime Now;
    private DateTime Xmas;
    //크리스마스 몇일 남았는가 ?
    private void DisplayXmas()
    {
        Now = DateTime.Now;             
        Xmas = new DateTime(2009, 12, 24);

        TimeSpan Result = Xmas - Now  ;
       
        lblDate.Text = Result.Days.ToString();
    }

    //1~100까지 짝수의  합
    private void DisplayEven()
    {
        int Temp = 0;

        for (int i = 0; i <= 100; i++)
        {
            if (i%2 == 0)
            {
                Temp += i;   
            }         
           
        }
        this.lblID.Text = Temp.ToString();
    }
}


반응형
posted by Magic_kit