?? st_rcatgaddmodule.ascx.cs
字號:
namespace ST_GROUP.Modules
{
using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
/// <summary>
/// ST_RCatgAddModule 的摘要說明。
/// </summary>
public partial class ST_RCatgAddModule : ST_ModuleBase
{
private void Page_Load(object sender, System.EventArgs e)
{
// 在此處放置用戶代碼以初始化頁面
}
//驗證房間類型是否已存在
public void IsNameValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
{
//從文件Web.config中讀取連接字符串
string ST_sqldb= ConfigurationSettings.AppSettings["ConnectionString"];
//連接ST_GinShopManage數(shù)據(jù)庫
SqlConnection ST_Conn= new SqlConnection (ST_sqldb);
ST_Conn.Open ();
//構(gòu)造SQL語句,該語句在RoomCategory表中檢查房間類型是否已存在
string ST_checksql= "select * from ST_RoomCategory where ST_Name='"+RCatgNameTextBox.Text.Trim() +"'";
//創(chuàng)建Command對象
SqlCommand ST_mycommand=new SqlCommand (ST_checksql,ST_Conn);
//執(zhí)行ExecuteReader ()方法
SqlDataReader dr=ST_mycommand.ExecuteReader ();
if(dr.Read ())
{
args.IsValid =false;//房間類型已存在
}
else
{
args.IsValid =true;//房間類型未存在
}
//關(guān)閉連接
ST_Conn.Close();
}
#region Web 窗體設(shè)計器生成的代碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調(diào)用是 ASP.NET Web 窗體設(shè)計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設(shè)計器支持所需的方法 - 不要使用代碼編輯器
/// 修改此方法的內(nèi)容。
/// </summary>
private void InitializeComponent()
{
this.SubmitButton.Click += new System.EventHandler(this.SubmitButton_Click);
this.ReturnButton.Click += new System.EventHandler(this.ReturnButton_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void SubmitButton_Click(object sender, System.EventArgs e)
{
if(Page.IsValid)
{
//從文件Web.config中讀取連接字符串
string ST_sqldb= ConfigurationSettings.AppSettings["ConnectionString"];
//連接ST_GinShopManage數(shù)據(jù)庫
SqlConnection ST_Conn= new SqlConnection (ST_sqldb);
ST_Conn.Open ();
//利用Command對象調(diào)用存儲過程
SqlCommand ST_mycommand=new SqlCommand ("ST_InsertRoomCategory",ST_Conn);
//將命令類型轉(zhuǎn)為存儲類型
ST_mycommand.CommandType =CommandType.StoredProcedure ;
//往存儲過程中添加參數(shù)
ST_mycommand.Parameters .Add ("@Name",SqlDbType.VarChar);
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);
//給存儲過程的參數(shù)賦值
ST_mycommand.Parameters ["@Name"].Value =RCatgNameTextBox.Text.Trim();
ST_mycommand.Parameters ["@Area"].Value =Convert.ToDouble(AreaTextBox.Text.Trim());
ST_mycommand.Parameters ["@BedNum"].Value =int.Parse(BedNumTextBox.Text.Trim());
ST_mycommand.Parameters ["@Price"].Value =Convert.ToDouble(PriceTextBox.Text.Trim());
ST_mycommand.Parameters ["@AirCondition"].Value =AirConditionList.SelectedIndex;
ST_mycommand.Parameters ["@TV"].Value =TvList.SelectedIndex;
try
{
ST_mycommand.ExecuteNonQuery();
ShowMsg.Text="新房間類型添加成功";
ShowMsg.Style["color"]="green";}
catch(SqlException error)
{
ShowMsg.Text="添加未成功,請稍后再試。原因:"+error.Message;
ShowMsg.Style["color"]="red";
}
//關(guān)閉連接
ST_Conn.Close();
}
}
private void ReturnButton_Click(object sender, System.EventArgs e)
{
Response.Redirect(PathPrefix+"/ST_RCategoryMan.aspx");
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -