using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; public partial class SysAdmin_NewSort : System.Web.UI.Page { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString.ToString()); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.DropDownList2.Items.Insert(0, new ListItem("请选择", "0")); } } private void BindDDl() { this.DropDownList1.Items.Clear(); string DDLSource = null; if (this.DropDownList2.SelectedIndex == 0) { this.DropDownList1.Items.Insert(0, new ListItem("请选择","0")); } else if (this.DropDownList2.SelectedIndex == 1) { DDLSource = "select * from v3_m_category where ParentId = 0 and ( visiable =1 or visiable =3)"; ReadDdl(DDLSource); DropDownList1.Items.Insert(0, new ListItem("一级类别", "0")); } else { DDLSource = "select * from v3_m_category where ParentId = 0 and( visiable =2 or visiable =3)"; ReadDdl(DDLSource); DropDownList1.Items.Insert(0, new ListItem("一级类别", "0")); } } private void ReadDdl(string sqlstr) { DataSet ds = new common().ExcuteReader(sqlstr); this.DropDownList1.DataSource = ds; DropDownList1.DataTextField = "name_cn"; DropDownList1.DataValueField = "ID"; DropDownList1.DataBind(); } public bool TextBoxIsNull() { bool IsNull = false; foreach (Control c in Form.Controls) { if (c.GetType().Name == "TextBox") { TextBox tb = new TextBox(); tb = (TextBox)this.FindControl(c.ID); if (string.IsNullOrEmpty(tb.Text.Trim())) { IsNull = false; } else { IsNull = true; } } } return IsNull; } protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { if (Convert.ToInt32(DropDownList1.SelectedItem.Value) == 0) { if (TextBoxIsNull()) { string sqlstr = " insert into v3_m_category (name_cn,name_en,descrip_cn,descrip_en,titlebgi_cn,titlebgi_en,ParentId,visiable) values ('" + txtSortCN.Text.Trim() + "','" + txtSortEN.Text.Trim() + "','" + TextBox2.Text.Trim() + "','" + TextBox2.Text.Trim() + "','背景图中文版','背景图英文版',0,2)"; bool b = new common().ExcuteNoneQuery(sqlstr, null); if (b) { Methods1.Methods1.MsgBox("新建类别成功!", Request.Url.ToString()); } else { Methods1.Methods1.Alert(this, "新建类别失败!"); } } } else { if (TextBoxIsNull()) { string sqlstr = " insert into v3_m_category (name_cn,name_en,descrip_cn,descrip_en,titlebgi_cn,titlebgi_en,ParentId,visiable) values ('" + txtSortCN.Text.Trim() + "','" + txtSortEN.Text.Trim() + "','" + TextBox2.Text.Trim() + "','" + TextBox2.Text.Trim() + "','背景图中文版','背景图英文版'," + this.DropDownList1.SelectedItem.Value + ",2)"; bool b = new common().ExcuteNoneQuery(sqlstr, null); if (b) { Methods1.Methods1.Alert(this, "新建类别成功!"); } else { Methods1.Methods1.Alert(this, "新建类别失败!"); } } } } protected void ImageButton2_Click(object sender, ImageClickEventArgs e) { Response.Redirect("SortMain.aspx"); } protected void ImageButton3_Click(object sender, ImageClickEventArgs e) { foreach (Control c in this.Form.Controls) { if (c.GetType().ToString() == "System.Web.UI.WebControls.TextBox") { TextBox txt = (TextBox)c; txt.Text = null; } } } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { BindDDl(); } }