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;
using System.Data.SqlClient;

public partial class SystemManage_AddArea : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Convert.ToString(Session["username"]) == "")
        {
            Response.Write("<script language=javascript>alert('请登录');location='../login.aspx'</script>");
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string name = Request["name"];
        string mome = Request["mome"];
        if (Tools.validate(name))
        {
            Response.Write("<script>alert('区域名中不能含有非法字符');history.back()</script>");
            return;
        }
        if (Tools.validate(mome))
        {
            Response.Write("<script>alert('备注中不能含有非法字符');histort.back()</script>");
        }
        string sqlcmd1 = "select count(*) as ff from CLIENT_AREA where name='" + name + "'";
        using (SqlConnection sqlconn = new SqlConnection(Tools.strConn))
        {
            sqlconn.Open();
            SqlCommand cmd = new SqlCommand(sqlcmd1, sqlconn);
            int count = Convert.ToInt32(cmd.ExecuteScalar());
            if (count > 0)
            {
                Response.Write("<script>alert('区域名已经存在，请重新输入！');history.back()</script>");
                return;
            }
            try
            {
                string sqlcmd2 = "insert into CLIENT_AREA (name,mome)values(@name,@mome)";
                cmd.CommandText = sqlcmd2;
                cmd.Parameters.Add("@name", SqlDbType.VarChar, 10).Value = name;
                cmd.Parameters.Add("@mome", SqlDbType.VarChar, 10).Value = mome;
                cmd.ExecuteNonQuery();
                Response.Write("<script>alert('区域添加成功');location='AreaManage.aspx'</script>");
            }
            catch
            {
                Response.Write("<script>alert('操作失败');location='AddArea.aspx'</script>");
            }
        }
    }
}
