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 login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        GlobalEBTLink.Text = "Copyright (C)2008 <b>WANcome</b> All rights reserved.";
        GlobalEBTLink.NavigateUrl = "http://www.wancome.com";
        GlobalEBTLogo.AlternateText = "wanCome 网购系统管理登录";

        SqlConnection custemer = CDatabase.wtoconn();
        custemer.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = custemer;
        cmd.CommandText = "select IsOpen,setdo from UserAdmin";
        SqlDataReader sdr = cmd.ExecuteReader();
        sdr.Read();
        string isopen = sdr.GetString(0);
        string setdo = sdr.GetString(1);
        if (isopen == "close" || setdo == "no")
        {
            Response.Redirect("main/error.aspx?err=网站未开通!");
            sdr.Close();
            Response.End();
        }
        sdr.Close();
        string hidden = Request.Form["hidden1"];
        if (hidden == "yes")
        {
            string UserName = Request.Form["UserName"];
            string PassWord = Request.Form["PassWord"];
            string CheckCode = Request.Form["CheckCode"];
            if (wtodo.checkUser(UserName, PassWord))
            {
                if (ValidentCode(CheckCode))
                {
                    SqlCommand scd2 = new SqlCommand("select linkpeaplo,id,userlx from UserAdmin where UserName='" + UserName + "' and UserPwd='" + PassWord + "'", custemer);
                    SqlDataReader sdr2 = scd2.ExecuteReader();
                    sdr2.Read();
                    Session["WtoRightName"] = sdr2["linkpeaplo"].ToString();
                    Session["WtoRightid"] = sdr2["id"].ToString();
                    Session["WtoRightLX"] = sdr2["userlx"].ToString().Trim();
                    Session["UserName_Back"] = UserName;
                    new Cls_Operation().SaveLog("成功登入后台!");
                    sdr2.Close();
                    //功能设置值获取
                    SqlCommand cmdset = new SqlCommand();
                    cmdset.Connection = custemer;
                    Session.Timeout = Convert.ToInt32(ConfigurationManager.AppSettings["systemtimeout"]);
                    Response.Redirect("default.aspx");
                }
                else
                {
                    Response.Redirect("main/error.aspx?err=对不起,验证码错误!");
                }
            }
            else
            {
                Response.Redirect("main/error.aspx?err=对不起,登陆信息不合法!");
            }
            custemer.Close();
        }
    }

    public bool ValidentCode(string CheckCode)
    {
        bool str = CheckCode == Session["ValidateCode"].ToString() ? true : false;
        return str;
    }
}

