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 customstr : System.Web.UI.Page
{
    public string uid = string.Empty;
    public string website = 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");
        }
        password.Visible = false;
        //DataSet dsname = DbHelperSQL.Query("select roleid from etw_admin where etwadminname='" + GetCookie["username"] + "'");
        //if (dsname.Tables[0].Rows.Count > 0)
        //{
        //    if (dsname.Tables[0].Rows[0]["roleid"].ToString() != "1")
        //    {
        //        password.Visible = false;
        //    }
        //}
        if (Request.QueryString["userid"] != null)
        {
            uid = Request.QueryString["userid"].ToString();
            userid.Visible = false;
            if (!IsPostBack)
            {
                BindDrpClass();
                BindLang();
                Binddata();
                etw.etw_user lead = new etw.etw_user();
                lead.userid = Convert.ToInt32(uid);
                lead.GetModel();
                company.Text = Fun.Fancode(lead.company);
                tel.Text = lead.tel;
                password.Text = lead.password;
                mail.Text = lead.mail;
                mainproduct.Text = Fun.Fancode(lead.mainproduct);
                beizhu.Text = Fun.Fancode(lead.beizhu);
                t_email.Text = Fun.Fancode(lead.t_emails);
                website = lead.username;
                userid.Text = uid;
                if (lead.istrade == 1)
                {
                    checktrade.Checked = true;
                }
                if (lead.isnews == 1)
                {
                    checknews.Checked = true;
                }
                webcontract.Text = Fun.Fancode(lead.webcontract);
                if (lead.material.ToString() == "0")
                {
                    RadioButtonList1.Items[0].Selected = true;
                }
                else
                {
                    RadioButtonList1.Items[1].Selected = true;
                }
                DropDownList1.SelectedValue = lead.industry.ToString();
            }
        }
    }
    private void BindDrpClass()
    {
        DropDownList1.Items.Add(new ListItem("-请选择行业--", ""));
        DataSet ds = DbHelperSQL.Query("select * from etw_industry");
        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            DropDownList1.Items.Add(new ListItem(ds.Tables[0].Rows[i]["industry"].ToString(), ds.Tables[0].Rows[i]["id"].ToString()));
        }
        DropDownList1.DataBind();
    }
    private void BindLang()
    {
        DataSet ds = DbHelperSQL.Query("select * from etw_language order by id");
        if (ds.Tables[0].Rows.Count > 0)
        {
            langlist.DataSource = ds.Tables[0].DefaultView;
            langlist.DataTextField = "language";
            langlist.DataValueField = "id";
            langlist.DataBind();
        }
    }
    public void Binddata()
    {
        DataSet ds = DbHelperSQL.Query("select * from etw_web where usernameid=" + uid + "");
        if (ds.Tables[0].Rows.Count > 0)
        {
            Repeater1.DataSource = ds.Tables[0].DefaultView;
            Repeater1.DataBind();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        userid.Visible = true;
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        etw.etw_user lead = new etw.etw_user();
        lead.userid = Convert.ToInt32(uid);
        lead.company = Fun.Encode(company.Text.Trim());
        lead.tel = Fun.Encode(tel.Text.Trim());
        lead.password = Fun.Encode(password.Text.Trim());
        lead.mail = Fun.Encode(mail.Text.Trim());
        lead.industry = DropDownList1.SelectedValue;
        lead.beizhu = Fun.Encode(beizhu.Text.ToString());
        lead.t_emails = Fun.Encode(t_email.Text.ToString());
        lead.mainproduct = Fun.Encode(mainproduct.Text.Trim());
        if (checktrade.Checked == true)
        {
            lead.istrade = 1;
        }
        if (checknews.Checked == true)
        {
            lead.isnews = 1;
        }
        for (int i = 0; i < RadioButtonList1.Items.Count; i++)
        {
            if (RadioButtonList1.Items[i].Selected == true)
            {
                lead.material = Convert.ToInt32(RadioButtonList1.Items[i].Value);
            }
        }
        lead.webcontract = Fun.Encode(webcontract.Text.Trim());
        lead.Update();
        Fun.JsAlerT("修改成功", "customstr.aspx?userid=" + uid + "");
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        if (websitestr.Text.ToString() != "" && websitestr.Text.ToString() != "www.")
        {
            etw.etw_web lead = new etw.etw_web();
            lead.website = Fun.Encode(websitestr.Text.Trim());
            lead.usernameid = Convert.ToInt32(uid);
            lead.jsqid = Convert.ToInt32(jsqid.Text.Trim());
            lead.langId = Convert.ToInt32(langlist.SelectedValue);
            lead.Add();
            Response.Write("<script language=javascript>window.open('customstr.aspx?userid=" + uid + "','mainFrame');</script>");
        }
    }
    public string CutLang(string str)
    {
        if (str != "" && str != null)
        {
            DataSet ds = DbHelperSQL.Query("select * from etw_language where id=" + str + "");
            if (ds.Tables[0].Rows.Count > 0)
            {
                str = ds.Tables[0].Rows[0]["language"].ToString();
            }
        }
        return str;
    }
    public string Cuttrue(string str, string cap)
    {
        string strbool = string.Empty;
        DataSet ds = DbHelperSQL.Query("select * from etw_web where webid=" + str + "");
        if (ds.Tables[0].Rows.Count > 0)
        {
            if (cap == "trade")
            {
                if (ds.Tables[0].Rows[0]["istrade"].ToString() == "1")
                {
                    strbool = "checked=\"true\"";
                }
            }
            else if (cap == "news")
            {
                if (ds.Tables[0].Rows[0]["isnews"].ToString() == "1")
                {
                    strbool = "checked=\"true\"";
                }
            }
        }
        return strbool;
    }
}
