📄 groupdiscount.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 groupDiscount : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GroupDBConn dbConn = new GroupDBConn();
ArrayList groups = dbConn.getAllGroup();
TableRow row = null;
TableCell cell = null;
ImageButton imgEdit = null;
ImageButton imgDel = null;
TextBox txt = null;
Label lbl = null;
int rowNum = 0;
foreach (Group group in groups)
{
row = new TableRow();
rowNum++;
//编号
cell = new TableCell();
cell.Text = group.ID.ToString();
row.Cells.Add(cell);
//单位名称
cell = new TableCell();
txt = new TextBox();
txt.Text = group.Name;
txt.Enabled = false;
cell.Controls.Add(txt);
row.Cells.Add(cell);
//联系人
cell = new TableCell();
txt = new TextBox();
txt.Text = group.Contact;
txt.Enabled = false;
cell.Controls.Add(txt);
row.Cells.Add(cell);
//电话
cell = new TableCell();
txt = new TextBox();
txt.Text = group.Telphone;
txt.Enabled = false;
cell.Controls.Add(txt);
row.Cells.Add(cell);
//地址
cell = new TableCell();
txt = new TextBox();
txt.Text = group.Address;
txt.Enabled = false;
cell.Controls.Add(txt);
row.Cells.Add(cell);
//折扣
cell = new TableCell();
txt = new TextBox();
if (group.Discount != null)
{
double discount = group.Discount;
discount = discount * 100;
txt.Text = discount.ToString();
}
txt.Enabled = false;
txt.Width = 25;
lbl = new Label();
lbl.Text = "%";
cell.Controls.Add(txt);
cell.Controls.Add(lbl);
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);
row.Cells.Add(cell);
//删除
cell = new TableCell();
imgDel = new ImageButton();
imgDel.ID = "del_" + group.ID;
imgDel.ImageUrl = "pic/del.gif";
imgDel.Click += new ImageClickEventHandler(imgDel_Click);
cell.Controls.Add(imgDel);
row.Cells.Add(cell);
Table2.Rows.Add(row);
}
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
Group group = new Group();
//单位名称
foreach (Control txt in Table1.Rows[1].Cells[0].Controls)
{
if (txt is TextBox)
{
group.Name = ((TextBox)txt).Text;
}
}
//联系人
foreach (TextBox txt in Table1.Rows[1].Cells[1].Controls)
{
group.Contact = txt.Text;
}
//电话
foreach (TextBox txt in Table1.Rows[1].Cells[2].Controls)
{
group.Telphone = txt.Text;
}
//地址
foreach (TextBox txt in Table1.Rows[1].Cells[3].Controls)
{
group.Address = txt.Text;
}
//折扣
try
{
foreach (Control txt in Table1.Rows[1].Cells[4].Controls)
{
if (txt is TextBox)
{
group.Discount = Convert.ToDouble(((TextBox)txt).Text) / 100;
}
}
}
catch
{
Response.Write("<script>window.alert('折扣输入格式出错!');</script>");
}
if (group.Name == "")
{
Response.Write("<script>window.alert('单位名称为空');</script>");
}
else
{
try
{
if (group.Discount > 1 || group.Discount < 0)
{
foreach (Control txt in Table1.Rows[1].Cells[4].Controls)
{
if (txt is TextBox)
{
group.Discount = 1.0;
((TextBox)txt).Text = "100";
}
}
Response.Write("<script>window.alert('折扣超出范围!');</script>");
}
else
{
GroupDBConn dbConn = new GroupDBConn();
dbConn.insertGroup(group);
Response.Redirect("groupDiscount.aspx");
}
}
catch (System.Exception err)
{
Response.Write("<script>window.alert('添加新团体/单位出错!');</script>");
}
}
}
protected void imgDel_Click(object sender, ImageClickEventArgs e)
{
GroupDBConn dbConn = new GroupDBConn();
int id = Convert.ToInt32(((ImageButton)sender).ID.Substring(4));
dbConn.delGroup(id);
Response.Redirect("groupDiscount.aspx");
}
protected void imgEdit_Click(object sender, ImageClickEventArgs e)
{
int rowNum = Convert.ToInt32(((ImageButton)sender).ID);
if (((ImageButton)sender).ImageUrl == "pic/edit.gif")
{
//单位名称
foreach (TextBox txt in Table2.Rows[rowNum].Cells[1].Controls)
{
txt.Enabled = true;
}
//联系人
foreach (TextBox txt in Table2.Rows[rowNum].Cells[2].Controls)
{
txt.Enabled = true;
}
//电话
foreach (TextBox txt in Table2.Rows[rowNum].Cells[3].Controls)
{
txt.Enabled = true;
}
//地址
foreach (TextBox txt in Table2.Rows[rowNum].Cells[4].Controls)
{
txt.Enabled = true;
}
//折扣
foreach (Control txt in Table2.Rows[rowNum].Cells[5].Controls)
{
if (txt is TextBox)
{
((TextBox)txt).Enabled = true;
}
}
//保存
((ImageButton)sender).ImageUrl = "pic/save.bmp";
}
else
{
Group group = new Group();
group.ID = Convert.ToInt32(Table2.Rows[rowNum].Cells[0].Text);
//单位名称
foreach (TextBox txt in Table2.Rows[rowNum].Cells[1].Controls)
{
txt.Enabled = false;
group.Name = txt.Text;
}
//联系人
foreach (TextBox txt in Table2.Rows[rowNum].Cells[2].Controls)
{
txt.Enabled = false;
group.Contact = txt.Text;
}
//电话
foreach (TextBox txt in Table2.Rows[rowNum].Cells[3].Controls)
{
txt.Enabled = false;
group.Telphone = txt.Text;
}
//地址
foreach (TextBox txt in Table2.Rows[rowNum].Cells[4].Controls)
{
txt.Enabled = false;
group.Address = txt.Text;
}
//折扣
try
{
foreach (Control txt in Table2.Rows[rowNum].Cells[5].Controls)
{
if (txt is TextBox)
{
((TextBox)txt).Enabled = false;
group.Discount = Convert.ToDouble(((TextBox)txt).Text) / 100;
}
}
}
catch
{
Response.Write("<script>window.alert('折扣输入格式出错!');</script>");
}
((ImageButton)sender).ImageUrl = "pic/edit.gif";
//保存记录
try
{
if (group.Discount > 1 || group.Discount < 0)
{
foreach (Control txt in Table2.Rows[rowNum].Cells[5].Controls)
{
if (txt is TextBox)
{
group.Discount = 1.0;
((TextBox)txt).Text = "100";
}
}
Response.Write("<script>window.alert('折扣超出范围!');</script>");
}
GroupDBConn dbConn = new GroupDBConn();
dbConn.updateGroup(group);
}
catch
{
Response.Write("<script>window.alert('更新团体/单位出错!');</script>");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -