//下面的代码是对登录界面的账户(CODE), 密码(PASSWORD)进行判断。 看能不能登陆的。前台的ASPX文件就没什么好发的了
//下面的是MSDN对DICTIONARY的介绍
//Dictionary<(Of <(TKey, TValue>)>) 泛型类提供了从一组键到一组值的映射。
//字典中的每个添加项都由一个值及其相关联的键组成。
//通过键来检索值的速度是非常快的,接近于 O(1),
//这是因为 Dictionary<(Of <(TKey, TValue>)>) 类是作为一个哈希表来实现的。
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using llano.web;
using score.Data;namespace score.Web
{
    public partial class checkLogin : System.Web.UI.Page  //在代码隐藏页模型中使用 Page 类
    {
        //TUser:score.Data.TUser
        //facade创建的类型
        BaseFacade<TUser, TUser, string> facade = new BaseFacade<TUser, TUser, string>();
        protected void Page_Load(object sender, EventArgs e)
        {
            string code = Request.Params["code"];
            string pwd = Request.Params["password"];   //本来的2个输入框
            Dictionary<string,object> dict = new Dictionary<string,object>(); 
            dict["code"]=code;
            dict["pwd"]=pwd;  //怎么DICT是数组了???
            //IdataAccess<TUser, string> BaseService
            //这个LIST应该是用来保存合适的记录的
            List<TUser> users = facade.Service.EntityDAO.Load("s.code=:code and s.pwd=:pwd", dict);  
            if (users.Count > 0)
            {
                Session["cur_user"] = users[0];
                Response.Redirect("~/index.aspx");
            }
            else { 
                
            }   
        }
    }
}
//facade.Service.EntityDAO.Load 这句应该是跟数据库连接相关的吧?可是后面的STRING按不是很懂什么意思。 
//还有这些数据结构是怎样跟数据库相连接的俺不懂~
//Dictionary结构俺也不是很懂怎么创建了模板以后, 会成为数组的了??

解决方案 »

  1.   

     dict["code"]=code;
     dict["pwd"]=pwd; 这两句应该是通过键(key)给dictionary赋值!
      

  2.   

     Dictionary<string,object> dict = new Dictionary<string,object>();
    dict中的键类型是string,值类型是object
    所有的类都继承自object,所以dict["pwd"]=pwd;成立。就是在dict中放一个<"pwd",pwd>的键值对。//facade.Service.EntityDAO.Load 这句应该是跟数据库连接相关的吧?可是后面的STRING按不是很懂什么意思。
    这个拿到EntityDAO.Load的实现不就可以看到为啥传此种格式的string了嘛
      

  3.   

    Dictionary 泛型类提供了从一组键到一组值的映射。字典中的每个添加项都由一个值及其相关联的键组成
    。用Dictionary<TKey,TValue>集合类来存储数据
    facade.Service.EntityDAO.Load通过值查询用户数据
      

  4.   

            private void button1_Click(object sender, EventArgs e)
            {
                string a = this.textBox1.Text;
                string b = this.textBox2.Text;
                string c = this.comboBox1.Text;            
                SqlConnection sqlconn = new SqlConnection(con.SqlCon) ;
                SqlCommand sqlcomm = new SqlCommand(con.SqlSelectEnter, sqlconn);
                sqlconn.Open();
                sqlcomm.Parameters.Add(new SqlParameter("@a", a));
                sqlcomm.Parameters.Add(new SqlParameter("@b", b));
                sqlcomm.Parameters.Add(new SqlParameter("@c", c));
                SqlDataReader read = sqlcomm.ExecuteReader();
                if (!read.Read())
                {
                    MessageBox.Show("用户名或密码或用户角色输入错误!");
                }
                else if (c == "标准维护人")
                {
                    this.Hide();
                    FormAdmin formadmin = new FormAdmin();
                    formadmin.Show();
                }
                else if (c == "普通用户")
                {
                    this.Hide();
                    FormAdmin fomadmin = new FormAdmin("1");
                    fomadmin.Show();            }
                else if (c == "标准发布人")
                {
                    this.Hide();
                    FormAdmin fa = new FormAdmin(1);
                    fa.Show();
                }        }
    我的登录窗体是这样做的 我还没看懂你是怎么弄的!
      

  5.   

    拿到EntityDAO.Load的实现??
    俺还是不懂
    不好意思, 俺今天是第二天看C#, ASP.NET。 很多都不懂。不过现在俺要尽快掌握这些东西
    所以麻烦了
      

  6.   

    facade.Service.EntityDAO.Load("s.code=:code and s.pwd=:pwd", dict); 
    实际上就是返回的就是一个泛型类型(就是TUser类型)
    好像是从业务层获得
    与数据库相关的已经在数据访问层封装了
      

  7.   

    List<TUser> users = facade.Service.EntityDAO.Load("s.code=:code and s.pwd=:pwd", dict);  s.code,s.pwd 是表里面的字段;:code,:pwd ,对应的是dict 里面的key的alue,code,pwd是key,冒号是分隔符号。
      

  8.   

    先谢谢各位大大的帮助了!
    俺现在最大的问题是不知道数据库的连接在哪里了。
    facade.Service.EntityDAO.Load("s.code=:code and s.pwd=:pwd", dict);
    数据库封装得太深了
      

  9.   

    数据库是不是ORACLE? 
    s.code =: code
    第一个code 是字段,第二个code 是变量,听说这样写效率高,听说啊.
      

  10.   

    字典的value获取方式之一,是通过key来获取
      

  11.   

    这里用泛型构造的类,用字典存储有效用户,用当前输入的用户名和密码到有效用户字典中搜寻,有匹配的就允许登陆,否则不允许。这是典型的MVC设计模式。