Heim  >  Artikel  >  Backend-Entwicklung  >  Verwenden Sie c#, um ein einfaches Message Board zu erstellen (1)

Verwenden Sie c#, um ein einfaches Message Board zu erstellen (1)

黄舟
黄舟Original
2016-12-17 17:03:161413Durchsuche

Zunächst möchte ich mich bei Bigeagle für seine Hilfe bedanken.
Das Message Board ist in drei Module unterteilt: Nachrichtenliste anzeigen, detaillierte Inhalte anzeigen und Nachrichten veröffentlichen
notepage.cs
Namespace notpage
{
using System;
using System.Data.SQL;
using System.Data ;
mit System.Collections ;


///////////////////////////////////////////////////////////////////////////// /// /////////////////////
//
// Klassenname: Message Board
//
// Beschreibung: Erstellen Sie ein Message-Board-Objekt
//
// Datum: 06.06.2000
//
// Autor: Tianla
/// ////////////////////////////////////////////////////////////////////////////////////// //// //////////////


///


/// Zusammenfassende Beschreibung für Notizseite.
///

Notizseite für öffentliche Klassen
{
//Private Variablen

PRivate int n_intID; //ID-Nummer
privat string n_strTitle; //Betreff
private Zeichenfolge n_strAuthor; //Autor
private Zeichenfolge n_strContent; //Nachrichteninhalt
private DateTime n_dateTime; //Nachrichtenzeit


//Attribute

public int ID
{
get
{
return n_intID ;
}
set
{
n_intID = value;
}
}

public string Title
{
get
{
return n_strTitle ;
}
set
{
n_strTitle = value;
}
}

string Autor
{
get
{
return n_strAuthor ;
}
set
{
n_strAuthor = value ;
}
}
öffentliche Zeichenfolge Inhalt
{
get
{
return n_strContent ;
}
set
{
n_strContent = value ;
}
}
public DateTime adddate
{

get
{
return n_dateTime;
}
set
{
n_dateTime = value;
}
}
//Konstruktor
public notepage()
{
//
// TODO: Hinzufügen Konstruktorlogik hier
//
this.n_intID = 0 ;
this.n_strTitle = "" ;
this.n_strAuthor = "" ;
this.n_strContent = "" ;
this.n_dateTime = System.DateTime.Now;

}

///


///
/// Holen Sie sich den Inhalt der Nachricht
// /
///

///
öffentliche Notizseite GetTopic(int a_intID)
{
//
// TODO: Konstruktorlogik hier hinzufügen
//


//Datenbank lesen
myconn myConn = new myconn();

SQLCommand myCommand = new SQLCommand() ;
myCommand.ActiveConnection = myConn ;
myCommand.CommandText = "n_GetTopicInfo" ; //Gespeicherte Prozedur aufrufen
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add(new 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"];
}


//Löschen
myReader.Close();
myConn.Close() ;

}
catch(Exception e)
{
throw(new Exception("Failed to get the post:" + e.ToString())) ;
}
return objNp;

}

///


///
/// Zweck: verlassen eine Nachricht Der Inhalt wird in der Datenbank gespeichert
///
/// Verwenden Sie Konstruktoren, um Informationen zu übergeben
///
///

///
public bool AddTopic(notepage n_Topic)
{
//
// TODO: Konstruktorlogik hier hinzufügen
//

//Datenbank lesen
myconn myConn = new myconn();

SQLCommand myCommand = new 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(neu 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(Exception e)
{
throw(new Exception("取贴子失败:" + e.ToString())) ;
}
return true;

}


///


/// 取的贴子列表
///

///
/// 返回一个Topic数组
///

public ArrayList GetTopicList()
{
//定义一个forum数组做为返回值
ArrayList arrForumList =new ArrayList() ;

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

Versuchen Sie
{
myConn.Open() ;
SQLDataReader myReader ;
myCommand.Execute(out myReader) ;

for (int i = 0 ; myReader.Read() ; i++)
{
notepage 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())) ;
//return null ;
}

return arrForumList ;
}

}
}

请关注PHP中文网(www .php.cn)!


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:C# Message Queuing-Anwendung-2Nächster Artikel:C# Message Queuing-Anwendung-2