-
Notifications
You must be signed in to change notification settings - Fork 0
/
addType.aspx.cs
184 lines (162 loc) · 4.84 KB
/
addType.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
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 addType : System.Web.UI.Page
{
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();
string id = Request.QueryString["id"];
if (!string.IsNullOrEmpty(id))
{
DataSet ds = DBHelperAccess.GetList("select * from type where id =" + id);
string lx= ds.Tables[0].Rows[0]["lx"].ToString();
drp1.SelectedValue = lx;
if (lx!="0")
{
drp2.Visible = true;
}
drp2.SelectedValue = (ds.Tables[0].Rows[0]["zl"]).ToString();
ipt_lxmc.Value = (ds.Tables[0].Rows[0]["lxmc"]).ToString();
drp1.Enabled = false;
}
drp1_SelectedIndexChanged(null, null);
}
}
protected void InitData ()
{
BindDDL();
}
private void BindDDL ()
{
string sql = "select * from type where lx='0'"; // 查询出所有一级节点
DataSet ds = DBHelperAccess.GetList(sql);
if (ds != null && ds.Tables.Count > 0)
{
drp1.DataValueField = "id";
drp1.DataTextField = "lxmc";
drp1.DataSource = InsertTotal(ds.Tables[0]);
drp1.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_save_Click (object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(Request.QueryString["id"]))
{
Update();
}
else
{
Add();
}
}
private void Update ()
{
if (ipt_lxmc.Value == "")
{
Response.Write("<script>alert('请填写类型名称!')</script>");
return;
}
string lxmc = ipt_lxmc.Value;
string lx = drp1.SelectedValue;
string zl = GetZL();
string sql = "update type set lxmc='" + lxmc + "',lx='" + lx + "',zl='" + zl + "' where id =" + Request.QueryString["id"];
object include = DBHelperAccess.GetSingle("select * from type where lxmc='" + lxmc + "' and lx='" + lx + "' and zl='" + zl + "' and id<>" + Request.QueryString["id"]);
if (include != null)
{
Response.Write("<script>alert('类别已存在,不能添加!')</script>");
return;
}
int i = DBHelperAccess.ExecuteSql(sql);
if (i > 0)
{
Response.Redirect("typeList.aspx");
}
else
{
Response.Write("<script>alert('修改失败!')</script>");
}
}
private void Add ()
{
if (ipt_lxmc.Value == "")
{
Response.Write("<script>alert('请填写类型名称!')</script>");
return;
}
string lxmc = ipt_lxmc.Value;
string lx = drp1.SelectedValue;
string zl = GetZL();
string sql = "insert into type(lxmc,lx,zl) values('" + ipt_lxmc.Value + "','" + lx + "','" + zl + "')";
object include = DBHelperAccess.GetSingle("select * from type where lxmc='" + lxmc + "' and lx='" + lx + "' and zl='" + zl + "'");
if (include != null)
{
Response.Write("<script>alert('类别已存在,不能添加!')</script>");
return;
}
int i = DBHelperAccess.ExecuteSql(sql);
if (i > 0)
{
Response.Write("<script>alert('添加成功')</script>");
Response.Redirect("typeList.aspx");
}
else
{
Response.Write("<script>alert('添加失败')</script>");
}
}
/// <summary>
/// 获取系列字段
/// </summary>
/// <returns></returns>
private string GetZL ()
{
if (drp1.SelectedValue == "0")
{
return "0";
}
else
{
return drp2.SelectedValue;
}
}
protected void drp1_SelectedIndexChanged (object sender, EventArgs e)
{
string drp1value = drp1.SelectedValue;
if(drp1value=="0")
{
leveSelect.Visible = false;
drp2.Visible = false;
}
else
{
leveSelect.Visible = true;
drp2.Visible = true;
}
}
}