>  기사  >  백엔드 개발  >  C#을 사용하여 간단한 게시판 만들기 (1)

C#을 사용하여 간단한 게시판 만들기 (1)

黄舟
黄舟원래의
2016-12-17 17:03:161413검색

우선 bigeagle님의 도움에 감사의 말씀을 전하고 싶습니다. 이것도 그녀의 bbs를 참고하여 만든 것입니다
게시판은 메시지 목록 나열, 세부 내용 표시, 메시지 게시의 세 가지 모듈로 구성되어 있습니다.
notepage.cs
네임스페이스 페이지 없음
{
System 사용;
System.Data.SQL 사용;
System.Data 사용 ;
System.Collections 사용 ;


///////////////////////////////////////////// /// /////////////////////
//
// 클래스 이름: 게시판
//
// 설명: 게시판 객체 생성
//
// 날짜: 2000/06/06
//
// 작성자: Tianla
/// ///////////////////////////////////////////////// //// //////////////


///


/// 노트페이지 요약 설명
///

공개 수업 노트
{
//개인 변수

PRIvate int n_intID //ID 번호
private string n_strTitle; //제목
비공개 문자열 n_strAuthor; //저자
비공개 문자열 n_strContent; //메시지 내용
private DateTime n_dateTime //메시지 시간


//속성

공개 정수 ID
{
get
{
n_intID 반환 ;
}

{
n_intID = 값 설정;
}
}

문자열 제목
{
get
{
return n_strTitle ;
}
설정
{
n_strTitle = value;
}
}

문자열 작성자
{
get
{
return n_strAuthor ;
}
설정
{
n_strAuthor = 값 ;
}
}
공개 문자열 콘텐츠
{
가져오기
{
n_strContent 반환 ;
}
설정
{
n_strContent = 값 ;
}
}
공개 DateTime 날짜 추가
{

get
{
n_dateTime 반환;
}
set
{
n_dateTime = value;
}
}
//Constructor
공개 메모장()
{
//
// TODO: 추가 생성자 논리는 여기에 있습니다
//
this.n_intID = 0 ;
this.n_strTitle = "" ;
this.n_strAuthor = "" ;
this.n_strContent = "" ;
this.n_dateTime = System.DateTime.Now;

}

///


///
/// 메시지 내용 가져오기
// /
///

///
공개 메모 페이지 GetTopic(int a_intID)
{
//
// TODO: 여기에 생성자 논리 추가
//


//데이터베이스 읽기
myconn myConn = new myconn();

SQLCommand myCommand = 새로운 SQLCommand() ;
myCommand.ActiveConnection = myConn ;
myCommand.CommandText = "n_GetTopicInfo" ; //저장 프로시저 호출
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add(새 항목 SQLParameter("@a_intTopicID" , SQLDataType.Int)) ;
myCommand.Parameters["@a_intTopicID"].Value = a_intID ;

notepage objNp = new notepage();
try
{

myConn.Open() ;
SQLDataReader myReader ;
myCommand.Execute(out myReader) ;
if (myReader.Read())
{
objNp.ID = (int)myReader["ID"] ;
objNp.Title = (string)myReader["Title"] ;
objNp.Author = (string)myReader["Author"] ;
objNp.Content = (string)myReader["Content"];
objNp.adddate = (DateTime)myReader["adddate"];
}


//지우기
myReader.Close();
myConn.Close() ;

}
catch(Exception e)
{
throw(new Exception("게시물을 가져오지 못했습니다:" + e.ToString())) ;
}
return objNp;

}

///

///
/// 목적: 나가기 메시지 내용은 데이터베이스에 저장됩니다
///
/// 생성자를 사용하여 정보 전달
///
///
///
공개 bool AddTopic(notepage n_Topic)
{
//
// TODO: 여기에 생성자 논리 추가
//

//데이터베이스 읽기
myconn myConn = new myconn();

SQLCommand myCommand = 새 SQLCommand() ;
myCommand.ActiveConnection = myConn ;
myCommand.CommandText = "n_addTopic" ; //사용용存储过程
myCommand.CommandType = CommandType.StoredProcedure ;
myCommand.Parameters.Add(new SQLParameter("@a_strTitle" , SQLDataType.VarChar,100)) ;
myCommand.Parameters["@a_strTitle"].Value = n_Topic.Title ;

myCommand.Parameters.Add(새 항목 SQLParameter("@a_strAuthor" , SQLDataType.VarChar,50)) ;
myCommand.Parameters["@a_strAuthor"].Value = n_Topic.Author ;

myCommand.Parameters.Add(new SQLParameter("@a_strContent" , SQLDataType.VarChar,2000)) ;
myCommand.Parameters["@a_strContent"].Value = n_Topic.Content ;

try
{

myConn.Open() ;
myCommand.ExecuteNonQuery() ;

//清场

myConn.Close() ;

}
catch(예외 e)
{
throw(new Exception("取贴子失败:" + e.ToString())) ;
}
return true;

}


///
/// 取的贴子列表
///
/// <비고>
/// 返回一个Topic数组
/// 비고>
공개 ArrayList GetTopicList()
{
//정义一个forum数组做为返回值
ArrayList arrForumList =new ArrayList() ;

//从数据库中读取留言列表
myconn myConn = new myconn();
SQLCommand myCommand = 새 SQLCommand() ;
myCommand.ActiveConnection = myConn ;
myCommand.CommandText = "n_GetTopicList" ; //사용용存储过程
myCommand.CommandType = CommandType.StoredProcedure ;


{
myConn.Open()을 시도해 보세요. ;
SQLDataReader myReader ;
myCommand.Execute(myReader 밖으로) ;

for (int i = 0 ; myReader.Read() ; i++)
{
메모페이지 objItem = new notepage() ;
objItem.ID = myReader["ID"].ToString().ToInt32() ;
objItem.Title = myReader["Title"].ToString() ;
objItem.Author = myReader["Author"].ToString() ;
objItem.adddate = myReader["adddate"].ToString().ToDateTime();
objItem.Content = myReader["Content"].ToString();

arrForumList.Add(objItem) ;
}


//清场
myReader.Close();
myConn.Close() ;

}
catch(SQLException e)
{
throw(new Exception("数据库流错:" + e.ToString())) ;
//null 반환 ;
}

Arrforumlist;
} }



성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.