-
Notifications
You must be signed in to change notification settings - Fork 0
/
typeList.aspx.cs
156 lines (137 loc) · 4.08 KB
/
typeList.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class typeList : System.Web.UI.Page
{
private void Query ()
{
string where = " 1=1 ";
if (query_lb.Value != "0")
{
where += " and lx='" + query_lb.Value + "'";
}
if (query_zl.Value != "0")
{
where += " and zl='" + query_zl.Value + "' ";
}
DataSet ds = DBHelperAccess.GetList("select * from type where " + where);
Repeater1.DataSource = ds;
Repeater1.DataBind();
}
protected void Page_Load (object sender, EventArgs e)
{
if (Session["userName"] == null)
{
Response.Write("<script>alert('登录超时,请从新登录!')</script>");
Response.Redirect("login.aspx");
return;
}
if (!IsPostBack)
{
InitData();
InitData2();
Query();
}
}
private void InitData ()
{
string sql = "select * from type where lx='0'";
DataSet ds = DBHelperAccess.GetList(sql);
if (ds != null && ds.Tables.Count > 0)
{
DataTable dt = InsertTotal(ds.Tables[0]);
query_lb.DataSource = ds.Tables[0];
query_lb.DataValueField = "id";
query_lb.DataTextField = "lxmc";
query_lb.DataBind();
}
}
private void InitData2 ()
{
DataTable dt = new DataTable();
dt.Columns.Add("id");
dt.Columns.Add("lxmc");
DataRow dr1 = dt.NewRow();
dr1["id"] = "0";
dr1["lxmc"] = "全部";
dt.Rows.Add(dr1);
if (query_lb.Value != "0")
{
DataRow dr2 = dt.NewRow();
dr2["id"] = "1";
dr2["lxmc"] = "系列";
dt.Rows.Add(dr2);
DataRow dr3 = dt.NewRow();
dr3["id"] = "2";
dr3["lxmc"] = "级别";
dt.Rows.Add(dr3);
}
query_zl.DataSource = dt;
query_zl.DataValueField = "id";
query_zl.DataTextField = "lxmc";
query_zl.DataBind();
}
/// <summary>
/// 添加全部项
/// </summary>
/// <returns></returns>
private DataTable InsertTotal (DataTable dt)
{
DataRow dr = dt.NewRow();
dr["id"] = "0";
dr["lxmc"] = "全部";
dt.Rows.InsertAt(dr, 0);
return dt;
}
protected void btn_query_Click (object sender, EventArgs e)
{
InitData2();
Query();
}
#region Repeater1_ItemCommand事件
protected void Repeater1_ItemCommand (object source, RepeaterCommandEventArgs e)
{
string id = e.CommandArgument.ToString();
if (e.CommandName == "Edit" && !String.IsNullOrEmpty(id))
{
Response.Redirect("addType.aspx?id=" + id);
}
else if (e.CommandName == "Delete" && !String.IsNullOrEmpty(id))
{
string deleteSql = "delete from type where id=" + id;
string useSql = "select count(1) from flower where lx="+id +" or zl="+id+" ";
string usedSql2 = "select * from price where dj = '" + id + "'";
int count=Convert.ToInt32( DBHelperAccess.GetSingle(useSql));
count = count + Convert.ToInt32(DBHelperAccess.GetSingle(usedSql2));
if (count > 0)
{
Response.Write("<script>alert('数据被引用,不能被删除!')</script>");
return;
}
int i = DBHelperAccess.ExecuteSql(deleteSql);
if (i == 0)
{
Response.Write("<script>alert('删除失败!')</script>");
}
else
{
// 删除相关数据
DBHelperAccess.ExecuteSql("delete from type where lx='" + id+"'");
Query();
}
}
else
{
return;
}
}
#endregion
protected void btn_query2_Click (object sender, EventArgs e)
{
Query();
}
}