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 etwuser_Customize : System.Web.UI.Page
{
    public string usernameid = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpCookie ChatCookie = Request.Cookies["cookChatuser"];
        HttpCookie GetCookie = Request.Cookies["cookEtwuser"];
        if (Request.Cookies["cookChatuser"] == null)
        {
            if (Request.Cookies["cookEtwuser"] == null)
            {
                Response.Redirect("../index.aspx");
            }
            else
            {
                DataSet ds = DbHelperSQL.Query("select * from etw_user where username='" + GetCookie["username"] + "'");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    usernameid = ds.Tables[0].Rows[0]["userid"].ToString();
                }
            }
        }
        else
        {
            DataSet dss = DbHelperSQL.Query("select * from chat_user where username='" + ChatCookie["username"] + "'");
            if (dss.Tables[0].Rows.Count > 0)
            {
                usernameid = dss.Tables[0].Rows[0]["userid"].ToString();
            }
        }
        if (!IsPostBack)
        {
            Fun.Funrecord(Request.Url.AbsoluteUri,Page.Request.UserHostAddress, usernameid);
            Bind();
        }
    }
    private void Bind()
    {
        DataSet ds = DbHelperSQL.Query("select * from etw_Customize where usernameid=" + usernameid + "");
        if (ds.Tables[0].Rows.Count > 0)
        {
            dlstType.DataSource = ds.Tables[0].DefaultView;
            dlstType.DataBind();
        }
    }
    protected void dlstType_CancelCommand(object source, DataListCommandEventArgs e)
    {
        dlstType.EditItemIndex = -1;
        Bind();
    }
    protected void dlstType_DeleteCommand(object source, DataListCommandEventArgs e)
    {
        int id = Convert.ToInt32(dlstType.DataKeys[e.Item.ItemIndex]);
        etw.etw_Customize lead = new etw.etw_Customize();
        lead.id = id;
        lead.Delete();
        Fun.JsAlerT("删除成功", "Customizeadd.aspx");
    }
    protected void dlstType_EditCommand(object source, DataListCommandEventArgs e)
    {
        dlstType.EditItemIndex = e.Item.ItemIndex;
        Bind();
    }
    protected void dlstType_UpdateCommand(object source, DataListCommandEventArgs e)
    {
        int id = Convert.ToInt32(dlstType.DataKeys[e.Item.ItemIndex]);
        string name = ((TextBox)e.Item.FindControl("txtName")).Text;
        etw.etw_Customize lead = new etw.etw_Customize();
        lead.id = id;
        lead.name = name;
        lead.Upname();
        dlstType.EditItemIndex = -1;
        Fun.JsAlerT("修改成功", "Customizeadd.aspx");
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        etw.etw_Customize lead = new etw.etw_Customize();
        lead.name = Fun.Encode(txtname.Text);
        lead.usernameid = Convert.ToInt32(usernameid);
        lead.Add();
        Response.Write("<script language=\"javascript\">window.location='Customizeadd.aspx'</" + "script>");
    }
}
