📄 st_rcategoryadd.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class ST_RCategoryAdd : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.lblInfo.Visible = false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
SqlConnection ST_myCon = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand ST_mycommand = new SqlCommand();
ST_mycommand.Connection = ST_myCon;
ST_mycommand.CommandType = CommandType.StoredProcedure;
ST_mycommand.CommandText = "ST_InsertRoomCategory";
ST_mycommand.Parameters.Add("@Name", SqlDbType.VarChar, 50);
ST_mycommand.Parameters.Add("@Area", SqlDbType.Float);
ST_mycommand.Parameters.Add("@BedNum", SqlDbType.Int);
ST_mycommand.Parameters.Add("@Price", SqlDbType.Money);
ST_mycommand.Parameters.Add("@AirCondition", SqlDbType.Int);
ST_mycommand.Parameters.Add("@TV", SqlDbType.Int);
ST_mycommand.Parameters["@Name"].Value = this.txtName.Text.ToString();
ST_mycommand.Parameters["@Area"].Value = System.Convert.ToDouble(this.txtArea.Text);
ST_mycommand.Parameters["@BedNum"].Value = int.Parse(this.txtBedNum.Text);
ST_mycommand.Parameters["@Price"].Value = System.Convert.ToDouble(this.txtPrice.Text);
ST_mycommand.Parameters["@AirCondition"].Value = this.radAirCondition.SelectedIndex;
ST_mycommand.Parameters["@TV"].Value = this.radTv.SelectedIndex;
try
{
ST_myCon.Open();
ST_mycommand.ExecuteNonQuery();
this.lblInfo.Visible = true;
this.lblInfo.Text = "添加成功";
}
catch (SqlException exx)
{
this.lblInfo.Visible = true;
this.lblInfo.Text = "出错了:" + exx.Message;
}
finally
{
ST_myCon.Close();
}
}
}
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)/////判断添加的类型是否存在
{
SqlConnection ST_myCon = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand ST_mycommand = new SqlCommand();
ST_mycommand.Connection = ST_myCon;
string Name = this.txtName.Text;
ST_mycommand.CommandText = "select * from ST_RoomCategory where ST_Name='" + Name + "'";
ST_myCon.Open();
SqlDataReader dr = ST_mycommand.ExecuteReader();
if (dr.Read())
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
dr.Close();
ST_myCon.Close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -