?? st_roomordermodule.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_RoomOrderModule 的摘要說明。
/// </summary>
public partial class ST_RoomOrderModule : ST_ModuleBase
{
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack){
RoomIdLabel.Text=Request.QueryString["RoomId"].ToString();
NowTimeLabel.Text=DateTime.Now.ToString();
}
}
#region Web 窗體設計器生成的代碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調用是 ASP.NET Web 窗體設計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器
/// 修改此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.Order.Click += new System.EventHandler(this.Order_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Order_Click(object sender, System.EventArgs e)
{
if(Page.IsValid)
{
//從文件Web.config中讀取連接字符串
string ST_sqldb= ConfigurationSettings.AppSettings["ConnectionString"];
//連接ST_GinShopManage數據庫
SqlConnection ST_Conn= new SqlConnection (ST_sqldb);
ST_Conn.Open ();
//利用Command對象調用存儲過程
SqlCommand ST_mycommand=new SqlCommand ("ST_AddOrder",ST_Conn);
//將命令類型轉為存儲類型
ST_mycommand.CommandType =CommandType.StoredProcedure ;
//往存儲過程中添加參數
ST_mycommand.Parameters .Add ("@RoomId",SqlDbType.Int);
ST_mycommand.Parameters .Add ("@CName",SqlDbType.NVarChar);
ST_mycommand.Parameters .Add ("@CIdentityId",SqlDbType.NVarChar);
ST_mycommand.Parameters .Add ("@CPhone",SqlDbType.NVarChar);
ST_mycommand.Parameters .Add ("@BeginTime",SqlDbType.DateTime);
ST_mycommand.Parameters .Add ("@Remarks",SqlDbType.NVarChar);
//給存儲過程的參數付值
ST_mycommand.Parameters ["@RoomId"].Value =int.Parse(RoomIdLabel.Text.Trim());
ST_mycommand.Parameters ["@CName"].Value = NameTextBox.Text.Trim();
ST_mycommand.Parameters ["@CIdentityId"].Value =IdentityTextBox.Text.Trim();
ST_mycommand.Parameters ["@CPhone"].Value =PhoneTextBox.Text.Trim();
ST_mycommand.Parameters ["@BeginTime"].Value =NowTimeLabel.Text;
ST_mycommand.Parameters ["@Remarks"].Value =RemarksTextBox.Text.Trim();
try
{
ST_mycommand.ExecuteNonQuery();
ShowMsg.Text="房間"+ RoomIdLabel.Text+"已成功訂出";
ShowMsg.Style["color"]="green";}
catch(SqlException error)
{
ShowMsg.Text="訂房未成功,請稍后再試。原因:"+error.Message;
ShowMsg.Style["color"]="red";
}
//關閉連接
ST_Conn.Close();
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -