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.DropDownList1.DataSource = BindDDl(); DropDownList1.DataTextField = "name_cn"; DropDownList1.DataValueField = "ID"; DropDownList1.DataBind(); DropDownList1.Items.Insert(0, new ListItem("一级类别", "0")); } } private DataSet BindDDl() { string DDLSource = "select * from v3_m_category where ParentId = 0 and visiable =1 or visiable =3"; DataSet ds = new common().ExcuteReader(DDLSource); return ds; } 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, 1)"; 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 + ",1)"; 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; } } } }