111,126
社区成员
发帖
与我相关
我的任务
分享
public class dl
{
string constr = System.Configuration.ConfigurationManager.ConnectionStrings["CBooksConnectionString"].ToString();
public DataSet selectds()
{
SqlConnection mycon = new SqlConnection(constr);
DataSet myds = new DataSet();
using (mycon) {
mycon.Open();
SqlDataAdapter sda = new SqlDataAdapter("select * from books",mycon);
sda.Fill(myds);
}
return myds;
}
public void deleteok(int bookid)
{
SqlConnection mycon = new SqlConnection(constr);
using(mycon)
{
SqlCommand scom = new SqlCommand("delete from books where bookid=@bid",mycon);
scom.Parameters.Add("@bid", SqlDbType.Int, 8).Value = bookid;
mycon.Open();
int okvalue = scom.ExecuteNonQuery();
return okvalue;
}
}
public int updateok(string bookID, string bookTitle, string bookISBN, int bookPrice,
string bookPublisher, string bookAuthor, string bookCoverUrl,
DateTime bookDate)
{
int returnValue;
SqlConnection mycon = new SqlConnection(constr);
using(mycon)
{
string sqlstr = "UPDATE Books SET " +
"bookTitle=@bookTitle, " +
"bookISBN=@bookISBN, " +
"bookPrice=@bookPrice, " +
"bookPublisher=@bookPublisher, " +
"bookAuthor=@bookAuthor, " +
"bookCoverUrl=@bookCoverUrl, " +
"bookDate=@bookDate " +
"WHERE " +
"bookID = @bookID ";
SqlCommand sqlCmd = new SqlCommand(sqlstr, mycon);
if (bookCoverUrl == null) bookCoverUrl = "";
sqlCmd.Parameters.Add("@bookID", SqlDbType.NChar, 10).Value = bookID;
sqlCmd.Parameters.Add("@bookTitle", SqlDbType.NChar, 50).Value = bookTitle;
sqlCmd.Parameters.Add("@bookISBN", SqlDbType.NChar, 20).Value = bookISBN;
sqlCmd.Parameters.Add("@bookPrice", SqlDbType.Int).Value = bookPrice;
sqlCmd.Parameters.Add("@bookPublisher", SqlDbType.NChar, 10).Value = bookPublisher;
sqlCmd.Parameters.Add("@bookAuthor", SqlDbType.NChar, 10).Value = bookAuthor;
sqlCmd.Parameters.Add("@bookCoverUrl", SqlDbType.NChar, 50).Value = bookCoverUrl;
sqlCmd.Parameters.Add("@bookDate", SqlDbType.DateTime).Value = bookDate;
mycon.Open();
returnValue = sqlCmd.ExecuteNonQuery();
}
return returnValue;
}
public void insertok(string bookID, string bookTitle, string bookISBN, int bookPrice,
string bookPublisher, string bookAuthor, string bookCoverUrl,
DateTime bookDate)
{
if (bookID == null) return ;
if (bookID.ToString() == "") return ;
int returnValue;
SqlConnection mycon = new SqlConnection(constr);
using (mycon)
{
string sqlstr = "insert into Books(bookTitle,bookISBN,bookPrice,bookPublisher,bookAuthor,bookDate,bookID,bookCoverUrl) " +
" values(@bookTitle,@bookISBN,@bookPrice,@bookPublisher,@bookAuthor,@bookDate,@bookID,@bookCoverUrl)";
SqlCommand sqlCmd = new SqlCommand(sqlstr, mycon);
if (bookTitle == null) bookTitle = "";
if (bookISBN == null) bookISBN = "";
if (bookPublisher == null) bookPublisher = "";
if (bookAuthor == null) bookAuthor = "";
if (bookCoverUrl == null) bookCoverUrl = "";
if (bookPrice == null) bookPrice = 0;
sqlCmd.Parameters.Add("@bookID", SqlDbType.NChar, 10).Value = bookID;
sqlCmd.Parameters.Add("@bookTitle", SqlDbType.NChar, 50).Value = bookTitle;
sqlCmd.Parameters.Add("@bookISBN", SqlDbType.NChar, 20).Value = bookISBN;
sqlCmd.Parameters.Add("@bookPrice", SqlDbType.Int).Value = bookPrice;
sqlCmd.Parameters.Add("@bookPublisher", SqlDbType.NChar, 10).Value = bookPublisher;
sqlCmd.Parameters.Add("@bookAuthor", SqlDbType.NChar, 10).Value = bookAuthor;
sqlCmd.Parameters.Add("@bookCoverUrl", SqlDbType.NChar, 50).Value = bookDate;
sqlCmd.Parameters.Add("@bookDate", SqlDbType.DateTime).Value = dtt;
mycon.Open();
returnValue = sqlCmd.ExecuteNonQuery();
}
return returnValue;
}
}
public class bl
{
public bl()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public qds.BooksDataTable getdata(string bid)
{
qdsTableAdapters.BooksTableAdapter booktb = new qdsTableAdapters.BooksTableAdapter();
qds.BooksDataTable d1 = booktb.GetDataBy(bid);
return d1;
}
public int upblok(string bookTitle, int bookPrice, string original_bookID,string bookDate)
{
qdsTableAdapters.BooksTableAdapter booktb = new qdsTableAdapters.BooksTableAdapter();
int okre = booktb.upq(bookPrice, bookTitle, original_bookID);
return okre;
}
public void blinertok(string original_bookID, string bookDate,string bookID)
{
if (bookDate == null) { throw new Exception("no date!!"); }
if (bookID == null) { throw new Exception("no id!!"); }
DateTime dt = DateTime.Parse(bookDate);
if (dt == null) dt = DateTime.Now;
qdsTableAdapters.BooksTableAdapter qds = new qdsTableAdapters.BooksTableAdapter();
qds.InsertQuery(bookID,dt);
}
}
<textarea id="Content" runat ="server"></textarea>
<input type="button" id="Post" runat ="server" />
// ----------------------------------------
// 在外观层,当用户点击发送按钮后
// ----------------------------------------
private void Post_ServerClick(object sender, EventArgs e)
{
LeaveWord lword=new LeaveWord();
lword.Content=Content.Value;
lword.Post();
}
// ----------------------------------------
// 在商业逻辑层,定义 LeaveWord 类
// ----------------------------------------
public class LeaveWord
{
public string Content;
public void Post()
{
new LWordData().Post(this.Content);
}
}
// ----------------------------------------
// 数据库层,定义发送方法
// ----------------------------------------
public class LWordData
{
public void Post(string content)
{
// 打开数据库,将 content 插入到表中
}
}