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 newcustom : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpCookie GetCookie = Request.Cookies["cook_admin"];
        if (Request.Cookies["cook_admin"] == null)
        {
            Response.Redirect("index.aspx");
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Random rnd = new Random();
        int rndNum = rnd.Next(2, 20);
        DataSet dss = DbHelperSQL.Query("select top 1 userid from etw_user order by userid desc");
        if (dss.Tables[0].Rows.Count > 0)
        {
            rndNum = rndNum + Convert.ToInt32(dss.Tables[0].Rows[0]["userid"].ToString());
        }
        if (company.Text.Trim().ToString() != "" && username.Text.ToString() != "")
        {
            DataSet ds = DbHelperSQL.Query("select userid from etw_user where username='" + Fun.Encode(username.Text.Trim()) + "'");
            if (ds.Tables[0].Rows.Count > 0)
            {
                Fun.JsAlerT("用户名已存在！！", "newcustom.aspx");
            }
            else
            {
                etw.etw_user lead = new etw.etw_user();
                lead.userid = rndNum;
                lead.company = Fun.Encode(company.Text.Trim());
                lead.password = Fun.Encode(password.Text.Trim());
                lead.tel = Fun.Encode(tel.Text.Trim());
                lead.username = Fun.Encode(username.Text.Trim());
                lead.mail = Fun.Encode(email.Text.Trim());
                lead.edittime = System.DateTime.Now.ToString();
                for (int i = 0; i < RadioButtonList1.Items.Count; i++)
                {
                    if (RadioButtonList1.Items[i].Selected == true)
                    {
                        lead.material = Convert.ToInt32(RadioButtonList1.Items[i].Value);
                    }
                }
                lead.Add();
                Fun.JsAlerT("添加成功", "newcustom.aspx");
            }
        }
        else
        {
            Fun.JsAlerT("用户名和公司名字不能为空！", "newcustom.aspx");
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        company.Text = "";
        username.Text = "";
        tel.Text = "";
        password.Text = "";
        email.Text = "";
    }
}
