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 newindustry : System.Web.UI.Page
{
    public string id = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpCookie GetCookie = Request.Cookies["cook_admin"];
        if (Request.Cookies["cook_admin"] == null)
        {
            Response.Redirect("index.aspx");
        }
        if (Request.QueryString["id"] != null)
        {
            id = Request.QueryString["id"].ToString();
            etw.etw_industry lead = new etw.etw_industry();
            lead.id = Convert.ToInt32(id);
            lead.GetModel();
            if (!IsPostBack)
            {
                industry.Text = Fun.Fancode(lead.industry);
                Button1.Text = "修改";
            }
        }
        data();
    }
    public void data()
    {
        DataSet ds = DbHelperSQL.Query("select * from etw_industry");
        if (ds.Tables[0].Rows.Count > 0)
        {
            Repeater1.DataSource = ds.Tables[0].DefaultView;
            Repeater1.DataBind();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (industry.Text.ToString() != "")
        {
            DataSet ds = DbHelperSQL.Query("select * from etw_industry where industry='" + Fun.Encode(industry.Text.Trim()) + "'");
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (id != "")
                {
                    Fun.JsAlerT("该行业名已经存在！ ", "newindustry.aspx?id=" + id + "");
                }
                else
                {
                    Fun.JsAlerT("该行业名已经存在！ ", "newindustry.aspx");
                }
            }
            else
            {
                etw.etw_industry lead = new etw.etw_industry();
                lead.industry = Fun.Encode(industry.Text.Trim());
                if (id != "")
                {
                    lead.id = Convert.ToInt32(id);
                    lead.Update();
                    Fun.JsAlerT("修改成功", "newindustry.aspx");
                }
                else
                {
                    lead.Add();
                    Fun.JsAlerT("添加成功", "newindustry.aspx");
                }
            }
        }
        else
        {
            if (id != "")
            {
                Fun.JsAlerT("行业名称不能为空！ ", "newindustry.aspx?id=" + id + "");
            }
            else
            {
                Fun.JsAlerT("行业名称不能为空！ ", "newindustry.aspx");
            }
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        industry.Text = "";
    }
}
