📄 default.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
namespace comm
{
/// <summary>
/// _Default 的摘要说明。
/// </summary>
public class _Default : System.Web.UI.Page
{
protected System.Web.UI.WebControls.RadioButtonList RadioButtonList1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.TextBox txt_pwd;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox txt_user;
protected System.Web.UI.WebControls.Label Label1;
include.Db db=new comm.include.Db();
private void Page_Load(object sender, System.EventArgs e)
{
//清空session
this.Session["system"]=null;
this.Session["ip"]=null;
this.Session["usr"]=null;
this.Session["pwd"]=null;
this.Session["system_name"]=null;
this.Session["right"]=null;
// 在此处放置用户代码以初始化页面
db.DataBase=ConfigurationSettings.AppSettings["main_db"];
db.IP=ConfigurationSettings.AppSettings["IP"];
// db.IP ="";
db.Usr =ConfigurationSettings.AppSettings["usr"];
db.Pwd =ConfigurationSettings.AppSettings["pwd"];
if(!this.IsPostBack)
{
// this.Session.Timeout =9999;
string sql="select * from base_systems";
DataSet ds=db.GetDataSet(sql);
if(ds==null)
return;
this.RadioButtonList1.Items.Clear();
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
// System.Web.UI.WebControls.TableRow tr=new TableRow();
// System.Web.UI.WebControls.TableCell tc=new TableCell();
// System.Web.UI.WebControls.RadioButton chkbox=new RadioButton();
ListItem li=new ListItem();
li.Value =ds.Tables[0].Rows[i]["system_name_en"].ToString()+","+ds.Tables[0].Rows[i]["system_ip"].ToString().Trim()+","+ds.Tables[0].Rows[i]["system_admin"].ToString().Trim()+","+ds.Tables[0].Rows[i]["system_pwd"].ToString().Trim();
li.Text =ds.Tables[0].Rows[i]["system_name_cn"].ToString().Trim();
this.RadioButtonList1.Items.Add(li);
// tc.Controls.Add(chkbox);
// tr.Cells.Add(tc);
// this.tbl_systemname.Rows.Add(tr);
}
this.RadioButtonList1.Items[0].Selected=true;
// this.tbl_systemname.Visible =true;
//this.tbl_systemname.ID;
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
bool user_chk()
{
include.Db sub_db=new comm.include.Db();
string sql="select * from base_users where username='"+this.txt_user.Text.Trim()+"'";
sub_db.DataBase =this.RadioButtonList1.SelectedValue.Trim().Split(',')[0];
sub_db.IP =this.RadioButtonList1.SelectedValue.Trim().Split(',')[1];
sub_db.Usr =this.RadioButtonList1.SelectedValue.Trim().Split(',')[2];
sub_db.Pwd =this.RadioButtonList1.SelectedValue.Trim().Split(',')[3];
DataSet sub_ds=new DataSet();
try
{
sub_ds=sub_db.GetDataSet(sql);
}
catch
{
db.Msgbox("该系统无法进行用户验证","用户登录错误",this.Page);
return false;
}
if(sub_ds==null)
{
db.Msgbox("该系统无法进行用户验证","用户登录错误",this.Page);
return false;
}
if(sub_ds.Tables[0].Rows.Count==0)
{
db.Msgbox("用户名"+this.txt_user.Text+"不存在","用户登录错误",this.Page);
return false;
}
if(sub_ds.Tables[0].Rows.Count>1)
{
db.Msgbox("用户名"+this.txt_user.Text+"存在多个,不允许登入!","用户登录错误",this.Page);
return false;
}
if(sub_ds.Tables[0].Rows[0]["password"].ToString()!=this.txt_pwd.Text)
{
db.Msgbox("输入用户"+this.txt_user.Text+"密码错误!","用户登录错误",this.Page);
return false;
}
try //为兼容无权限
{
// this.Application["system"]=this.RadioButtonList1.SelectedValue.Trim().Split(',')[0];
// this.Application["ip"]=this.RadioButtonList1.SelectedValue.Trim().Split(',')[1];
// this.Application["usr"]=this.RadioButtonList1.SelectedValue.Trim().Split(',')[2];
// this.Application["pwd"]=this.RadioButtonList1.SelectedValue.Trim().Split(',')[3];
// this.Application["system_name"]=this.RadioButtonList1.SelectedItem.Text.Trim();
// this.Application["right"]=int.Parse(sub_ds.Tables[0].Rows[0]["access_right"].ToString());
this.Session["system"]=this.RadioButtonList1.SelectedValue.Trim().Split(',')[0];
this.Session["ip"]=this.RadioButtonList1.SelectedValue.Trim().Split(',')[1];
this.Session["usr"]=this.RadioButtonList1.SelectedValue.Trim().Split(',')[2];
this.Session["pwd"]=this.RadioButtonList1.SelectedValue.Trim().Split(',')[3];
this.Session["system_name"]=this.RadioButtonList1.SelectedItem.Text.Trim();
this.Session["right"]=int.Parse(sub_ds.Tables[0].Rows[0]["access_right"].ToString());
this.Session["user_namecn"]=sub_ds.Tables[0].Rows[0]["user_namecn"].ToString();
this.Session["username"]=this.txt_user.Text.Trim();
this.Session.Timeout=0;
}
catch
{
// this.Application["right"]=0;
this.Session["right"]=0;
}
return true;
}
private void Button1_Click(object sender, System.EventArgs e)
{
if(this.user_chk()==false)
{
return ;
}
this.Response.Redirect("index.aspx");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -