Web层

表现层:由需求网页构成,调用业务逻辑层的方法。该层一般不出现SQL语句相关的内容,就算出现,也不能出现能执行的SQL语句。
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using HotelManager.Models;
using HotelManager.BLL;

namespace HotelManager
{
    public partial class RoomTypeAdd : System.Web.UI.Page
    {
        RoomTypeManager roomTypeManager = new RoomTypeManager();
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {

            RoomType addRoomType = new RoomType();
            addRoomType.TypeName = txtTypeName.Text.Trim();
            addRoomType.Price = Convert.ToDecimal(txtPrice.Text.Trim());
            addRoomType.AddBed = rbtnYes.Checked ? true : false;
            addRoomType.BedPrice = Convert.ToDecimal

(txtAddPrice.Text.Trim());
            addRoomType.Remark = txtRemark.Text;


            try
            {
                roomTypeManager.AddRoomType(addRoomType);

		///添加javaScript代码的方式
                ////在<form>标签前部输出脚本
                Page.ClientScript.RegisterClientScriptBlock

(this.GetType(), Guid.NewGuid().ToString(), "alert('添加成功!')", true);

            }
            catch (Exception ex)
            {
                //在<form>标签后部输出脚本
                Page.ClientScript.RegisterStartupScript(this.GetType(), 

Guid.NewGuid().ToString(), "alert('添加失败!"+ex.Message+"')", true);
            }



            
        }
    }
}

  

注意:如何向网页中集成javaScript代码!

原文地址:https://www.cnblogs.com/yaoxc/p/3134399.html