此处设置文本框多行
下图是三层架构列表,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 SeaFoodTypeModel { private string infoTitle; private string infoID; public string InfoID { get { return infoID; } set { infoID = value; } } private string pubTime; public string PubTime { get { return pubTime; } set { pubTime = value; } } public string InfoTitle { get { return infoTitle; } set { infoTitle = value; } } private string infoPic; public string InfoPic { get { return infoPic; } set { infoPic = value; } } private string type; public string Type { get { return type; } set { type = value; } } private string infoDetail; public string InfoDetail { get { return infoDetail; } set { infoDetail = value; } } private string price; public string Price { get { return price; } set { price = 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=SeaFoodDB;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) {
try
{
Connect();
SqlCommand cmd = new SqlCommand(sql,conn);
int temp= cmd.ExecuteNonQuery();
conn.Close();
return temp > 0;
}
catch (Exception ex)
{
return false;
}
}
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 Zhanshi() {
List list = new List();
string sql = "select * from SeaFoodInfo";
SqlDataReader read= Dal.DBHelper.Reader(sql);
while (read.Read())
{
Models.SeaFoodTypeModel model = new Models.SeaFoodTypeModel();
model.InfoID = read["InfoID"].ToString();
model.PubTime = read["PubTime"].ToString();
model.Type = read["Type"].ToString();
model.Price = read["Price"].ToString();
model.InfoPic = read["InfoPic"].ToString();
model.InfoTitle = read["InfoTitle"].ToString();
model.InfoDetail = read["InfoDetail"].ToString();
list.Add(model);
}
return list;
}
public static bool Tianjia(string InfoTitle, string TypeName, string InfoDetail, string Price)
{
string sql = string.Format("insert SeaFoodInfo values('{0}', 'yu.jpg', '{1}', '{2}', '{3}', GETDATE())", InfoTitle, TypeName, InfoDetail, Price);
return DBHelper.NoQuery(sql);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bll
{
public class BllManager
{
public static List Zhanshi() {
return Dal.DalService.Zhanshi();
}
public static bool Tianjia(string InfoTitle, string TypeName, string InfoDetail, string Price)
{
return Dal.DalService.Tianjia( InfoTitle, TypeName, InfoDetail, Price);
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.Repeater1.DataSource = Bll.BllManager.Zhanshi();
this.Repeater1.DataBind();
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Tianjia.aspx.cs" Inherits="WebApplication2.Tianjia" %>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class Tianjia : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
UnobtrusiveValidationMode = UnobtrusiveValidationMode.None;
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Bll.BllManager.Tianjia(TextBox1.Text.ToString(), TextBox2.Text.ToString(), TextBox3.Text.ToString(), TextBox4.Text.ToString()))
{
ClientScript.RegisterStartupScript(GetType(),"success", "alert('正确!');location.href='WebForm1.aspx'",true);
}
else
{
ClientScript.RegisterStartupScript(GetType(), "success", "alert('错误!')", true);
};
}
}
}