温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:海南岛旅游网全站源码
当前文件:
HaiNanDaoTravel/admin/hotel_room_add.aspx.cs,打开代码结构图
HaiNanDaoTravel/admin/hotel_room_add.aspx.cs,打开代码结构图1using System; 2
using System.Text; 3
using System.Data; 4
using System.Data.SqlClient; 5
using System.Configuration; 6
using System.Collections; 7
using System.Web; 8
using System.Web.Security; 9
using System.Web.UI; 10
using System.Web.UI.WebControls; 11
using System.Web.UI.WebControls.WebParts; 12
using System.Web.UI.HtmlControls; 13
14
public partial class admin_hotel_room_add : Sper.baseadmin 15
{ 16
protected void Page_Load(object sender, EventArgs e) 17
{ 18
19
} 20
protected void Button1_Click(object sender, EventArgs e) 21
{ 22
Add(); 23
} 24
protected void myGridView_RowUpdating(object sender, GridViewUpdateEventArgs e) 25
{ 26
DropDownList dr = ((DropDownList)GridView1.Rows[e.RowIndex].Cells[3].FindControl("txtbreakfast2")); 27
string str = dr.SelectedValue; 28
e.NewValues["breakfast"] = str; 29
30
DropDownList dr2 = ((DropDownList)GridView1.Rows[e.RowIndex].Cells[4].FindControl("txtbedtype2")); 31
string str2 = dr2.SelectedValue; 32
e.NewValues["bedtype"] = str2; 33
34
DropDownList dr3 = ((DropDownList)GridView1.Rows[e.RowIndex].Cells[5].FindControl("txtBroadBand2")); 35
string str3 = dr3.SelectedValue; 36
e.NewValues["BroadBand"] = str3; 37
38
} 39
protected void myGridView_RowDataBound(object sender, GridViewRowEventArgs e) 40
{ 41
//e.Row.Cells[0].Attributes.Add("onclick", "return confirm('确定删除吗?')"); 42
if (((DropDownList)e.Row.FindControl("txtbreakfast2")) != null) 43
{ 44
DropDownList ddlstate = (DropDownList)e.Row.FindControl("txtbreakfast2"); 45
ddlstate.SelectedValue = ((HiddenField)e.Row.FindControl("hdstate")).Value; 46
47
DropDownList ddlstate2 = (DropDownList)e.Row.FindControl("txtbedtype2"); 48
ddlstate2.SelectedValue = ((HiddenField)e.Row.FindControl("hdstatebedtype")).Value; 49
50
DropDownList ddlstate3 = (DropDownList)e.Row.FindControl("txtBroadBand2"); 51
ddlstate3.SelectedValue = ((HiddenField)e.Row.FindControl("hdstateBroadBand")).Value; 52
} 53
54
} 55
/// <summary> 56
/// 增加一条数据 57
/// </summary> 58
public void Add() 59
{ 60
string roomtpye = this.txtroomtpye.Text; 61
int priceA = int.Parse(this.txtpriceA.Text); 62
int priceB = int.Parse(this.txtpriceB.Text); 63
string breakfast = this.txtbreakfast.SelectedValue; 64
string bedtype = this.txtbedtype.SelectedValue; 65
string BroadBand = this.txtBroadBand.SelectedValue; 66
int hotelid = int.Parse(Request.QueryString["id"]); 67
68
69
string strErr = ""; 70
if (roomtpye == "") 71
{ 72
strErr += "房型不能为空!\\n"; 73
} 74
if (!PageValidate.IsNumber(txtpriceA.Text)) 75
{ 76
strErr += "门市价不是数字!\\n"; 77
} 78
if (!PageValidate.IsNumber(txtpriceB.Text)) 79
{ 80
strErr += "本站会员价不是数字!\\n"; 81
} 82
if (breakfast == "") 83
{ 84
strErr += "早餐不能为空!\\n"; 85
} 86
if (bedtype == "") 87
{ 88
strErr += "床型不能为空!\\n"; 89
} 90
if (BroadBand == "") 91
{ 92
strErr += "宽带不能为空!\\n"; 93
} 94
95
if (strErr != "") 96
{ 97
MessageBox.Show(this, strErr); 98
return; 99
} 100
101
102
StringBuilder strSql = new StringBuilder(); 103
strSql.Append("insert into hotel_room("); 104
strSql.Append("roomtpye,priceA,priceB,breakfast,bedtype,BroadBand,hotelid)"); 105
strSql.Append(" values ("); 106
strSql.Append("@roomtpye,@priceA,@priceB,@breakfast,@bedtype,@BroadBand,@hotelid)"); 107
SqlParameter[] parameters = { 108
new SqlParameter("@roomtpye", SqlDbType.VarChar,50), 109
new SqlParameter("@priceA", SqlDbType.Int,4), 110
new SqlParameter("@priceB", SqlDbType.Int,4), 111
new SqlParameter("@breakfast", SqlDbType.VarChar,50), 112
new SqlParameter("@bedtype", SqlDbType.VarChar,50), 113
new SqlParameter("@BroadBand", SqlDbType.VarChar,50), 114
new SqlParameter("@hotelid", SqlDbType.Int,4)}; 115
parameters[0].Value = roomtpye; 116
parameters[1].Value = priceA; 117
parameters[2].Value = priceB; 118
parameters[3].Value = breakfast; 119
parameters[4].Value = bedtype; 120
parameters[5].Value = BroadBand; 121
parameters[6].Value = hotelid; 122
123
DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); 124
GridView1.DataBind(); 125
} 126
} 127





}
}