此处设置文本框多行
下图是三层架构列表,Models里面有模拟数据库中列的类,DAL中有DBHelper和service,BLL中有BllManager文件用于ui界面直接调用
建照片文件图片,数据夹用于展示库存地址
DAL引用Models文件,BLL引用DAL和Models文件,主文件WebApplication1引用Bll和Models
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Models { public class ModelsCarInfo { private string infoID; public string InfoID { get { return infoID; } set { infoID = value; } } private string infoTitle; public string InfoTitle { get { return infoTitle; } set { infoTitle = value; } } private string infoPic; public string InfoPic { get { return infoPic; } set { infoPic = value; } } private string carPrice; public string CarPrice { get { return carPrice; } set { carPrice = value; } } private string pubTime; public string PubTime { get { return pubTime; } set { pubTime = value; } } } }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
namespace DAL
{
public class DBHelper
{
public static string connstr = "server=.;database=CarDB;uid=sa;pwd=123123";
public static SqlConnection conn = null;
public static void Connect() {
if (conn==null)
{
conn = new SqlConnection(connstr);
}
conn.Close();
conn.Open();
}
public static bool NoQuery(string sql) {
Connect();
SqlCommand cmd = new SqlCommand(sql,conn);
int temp= cmd.ExecuteNonQuery();
return temp > 0;
}
public static SqlDataReader Reader(string sql){
Connect();
SqlCommand cmd = new SqlCommand(sql, conn);
return cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
namespace DAL
{
public class DalService
{
public static List Query()
{
string cha = "select * from CarInfo";
List list = new List();
SqlDataReader read= DBHelper.Reader(cha);
while (read.Read())
{
Models.ModelsCarInfo model = new Models.ModelsCarInfo();
model.InfoID = read["InfoID"].ToString();
model.InfoPic = read["InfoPic"].ToString();
model.InfoTitle = read["InfoTitle"].ToString();
model.PubTime = read["PubTime"].ToString();
model.CarPrice = read["CarPrice"].ToString();
list.Add(model);
} ;
return list;
}
public static bool Tianjia(string title,string price) {
string sql = string.Format("insert CarInfo values('{0}','Desert.jpg',{1},GETDATE())",title,price);
if ( DBHelper.NoQuery(sql))
{
return true;
}
else
{
return false;
};
}
public static List Sou(string title)
{
string cha = string.Format("select * from CarInfo where InfoTitle like '%{0}%'", title);
List list = new List();
SqlDataReader read = DBHelper.Reader(cha);
while (read.Read())
{
Models.ModelsCarInfo model = new Models.ModelsCarInfo();
model.InfoID = read["InfoID"].ToString();
model.InfoPic = read["InfoPic"].ToString();
model.InfoTitle = read["InfoTitle"].ToString();
model.PubTime = read["PubTime"].ToString();
model.CarPrice = read["CarPrice"].ToString();
list.Add(model);
};
return list;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BLL
{
public class BLLManager
{
public static List Query() {
return DAL.DalService.Query();
}
public static bool Tianjia(string title, string price) {
return DAL.DalService.Tianjia(title, price);
}
public static List Sou(string title) {
return DAL.DalService.Sou(title);
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Index.WebForm1" %>
新闻ID 新闻标题 新闻内容 新闻照片 新闻类型 发布人 发布时间 <%#Eval("NewsID") %> <%#Eval("NewsTitle") %> <%#Eval("NewsContent") %> " height="50px" width="50px"/> <%#Eval("Type") %> <%#Eval("Publisher") %> <%#Eval("PubTime") %>