📄 seasondiscount.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;
public partial class seasonDiscount : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SeasonDBConn dbConn = new SeasonDBConn();
ArrayList rooms = dbConn.getAllRoomType();
TableRow row = null;
TableCell cell = null;
ImageButton imgEdit = null;
TextBox txtDiscount = null;
Label lblPercent = null;
int rowNum = 0;
foreach (string[] room in rooms)
{
rowNum++;
row = new TableRow();
//房间类型
cell = new TableCell();
cell.Text = room[1];
cell.HorizontalAlign = HorizontalAlign.Center;
row.Cells.Add(cell);
//价格
cell = new TableCell();
cell.Text = room[0];
cell.HorizontalAlign = HorizontalAlign.Center;
row.Cells.Add(cell);
//数量
cell = new TableCell();
cell.Text = room[2];
cell.HorizontalAlign = HorizontalAlign.Center;
row.Cells.Add(cell);
//折扣
cell = new TableCell();
txtDiscount = new TextBox();
txtDiscount.Enabled = false;
txtDiscount.Text = room[3];
txtDiscount.Width = 25;
cell.Controls.Add(txtDiscount);
lblPercent = new Label();
lblPercent.Text = "%";
cell.Controls.Add(lblPercent);
cell.HorizontalAlign = HorizontalAlign.Center;
row.Cells.Add(cell);
//编辑
cell = new TableCell();
imgEdit = new ImageButton();
imgEdit.ID = rowNum.ToString();
imgEdit.ImageUrl = "pic/edit.gif";
imgEdit.Click += new ImageClickEventHandler(imgEdit_Click);
cell.Controls.Add(imgEdit);
cell.HorizontalAlign = HorizontalAlign.Center;
row.Cells.Add(cell);
Table1.Rows.Add(row);
}
}
protected void imgEdit_Click(object sender, ImageClickEventArgs e)
{
int rowNum = Convert.ToInt32(((ImageButton)sender).ID);
if (((ImageButton)sender).ImageUrl == "pic/edit.gif")
{
//折扣
foreach (Control txt in Table1.Rows[rowNum].Cells[3].Controls)
{
if (txt is TextBox)
{
((TextBox)txt).Enabled = true;
}
}
//保存
((ImageButton)sender).ImageUrl = "pic/save.bmp";
}
else
{
double discount = 0.0;
string roomType = null;
//房间类型
roomType = Table1.Rows[rowNum].Cells[0].Text;
//折扣
try
{
foreach (Control txt in Table1.Rows[rowNum].Cells[3].Controls)
{
if (txt is TextBox)
{
((TextBox)txt).Enabled = false;
discount = Convert.ToDouble(((TextBox)txt).Text) / 100;
}
}
}
catch
{
Response.Write("<script>window.alert('折扣输入格式出错!');</script>");
}
//编辑
((ImageButton)sender).ImageUrl = "pic/edit.gif";
//保存记录
try
{
if (discount > 1 || discount < 0)
{
foreach (Control txt in Table1.Rows[rowNum].Cells[3].Controls)
{
if (txt is TextBox)
{
discount = 1.0;
((TextBox)txt).Text = "100";
}
}
Response.Write("<script>window.alert('折扣超出范围!');</script>");
}
SeasonDBConn dbConn = new SeasonDBConn();
dbConn.updateRoomDiscount(roomType, discount);
}
catch
{
Response.Write("<script>window.alert('更新房间折扣信息出错!');</script>");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -