⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 login1.aspx.cs

📁 新闻管理后台源码,包括添加,删除,修改新闻
💻 CS
字号:

using System;
using System.Data;
using System.Configuration;
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 login1 : System.Web.UI.Page
{
    //连接数据库
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["news_manageConnectionString"].ConnectionString);
    string name;   //用户名
    string pwd;//用户密码
    int idd;  //用户ID
    string ip1;  //远程客户端的IP地址
    clsLogin userlogin;   //三层架构调用
    protected void Page_Load(object sender, EventArgs e)
    {
        //连接数据库
        
        userlogin = new clsLogin();

    }
    //
    public void cc()
    {
        bool b = userlogin.Login(name, pwd);
        if (b)
        {
            //Session变量存储用户名称
            Session["UserName"] = this.txtName.Text;
            //取得远程客户端的IP地址
            ip1 = Request.UserHostAddress.ToString();

            this.insert();
            Response.Redirect("AddUser.aspx");

        }
        else
        {
            //Session变量存储用户名称
            Session["UserName"] = this.txtName.Text;
            //取得远程客户端的IP地址
            ip1 = Request.UserHostAddress.ToString();
            //调用插入日志表
            this.insert();
            Response.Redirect("houtaiziliao.aspx");
        }

    }
    //插入到日志用
    public void insert()
    {
        //取出用户ID
        string s = "select userid from t_news_user where userName='" + name + "' and userPassword= '" + pwd + "'";
        conn.Open();
        SqlCommand cmd = new SqlCommand(s, conn);
        idd = Convert.ToInt32(cmd.ExecuteScalar());
        conn.Close();
        //取出现在时间
        DateTime d = Convert.ToDateTime(DateTime.Now);
        string ss = "insert into t_log(LOGINIP,LOGINDATE,USERID) values( '" + ip1 + "','" + d + "'    ,'" + idd + "')";
        SqlCommand cc = new SqlCommand(ss, conn);
        conn.Open();
        cc.ExecuteNonQuery();
        conn.Close();
    }
    // 判断用户是否存在
    public bool check()
    {
        string str = "select count(*) from t_news_user where userName='" + name + "' and userPassword= '" + pwd + "'";
        conn.Open();
        SqlCommand com = new SqlCommand(str, conn);
        int i = Convert.ToInt32(com.ExecuteScalar());
        conn.Close();
        if (i > 0)
        {
            return false;
        }
        else
        {
            return true;
        }
    }
    //登录代码
    protected void btnLogin_Click1(object sender, EventArgs e)
    {
        name = this.txtName.Text;
        pwd = this.txtPwd.Text;
        bool b = false;
        b = check();
        //用户如果存在,则弹出对话框
        if (b)
        {
            Response.Write("<script language=javascript> window.alert('对不起,用户名不存在或者密码不正确!')</script>");
        }
        else
        {
            cc();
        }

    }
    //取消按钮 
    protected void btnCancle_Click(object sender, EventArgs e)
    {
        this.txtName.Text = "";
        this.txtPwd.Text = "";
    }
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -