• 属性扩展


    类中:

    using System;
    using System.Collections.Generic;
    using System.Data.SqlClient;
    using System.Linq;
    using System.Text;
    
    namespace 实体类_数据访问类.App_Code
    {
        public class Users
        {
            SqlConnection conn = null;
            SqlCommand cmd = null;
    
            public Users()
            {
                conn = new SqlConnection("server=.;database=Data0928;user=sa;pwd=123");
                cmd = conn.CreateCommand();
            }
    
    
            private int _Ids;
    
            /// <summary>
            /// ids
            /// </summary>
            public int Ids
            {
                get { return _Ids; }
                set { _Ids = value; }
            }
            private string _UserName;
    
            /// <summary>
            /// 用户名
            /// </summary>
            public string UserName
            {
                get { return _UserName; }
                set { _UserName = value; }
            }
            private string _PassWord;
    
            /// <summary>
            /// 密码
            /// </summary>
            public string PassWord
            {
                get { return _PassWord; }
                set { _PassWord = value; }
            }
            private string _NickName;
    
            /// <summary>
            /// 昵称
            /// </summary>
            public string NickName
            {
                get { return _NickName; }
                set { _NickName = value; }
            }
    
            public string NickAndUser
            {
                get
                {
                    return _NickName + "(" + _UserName + ")";
                }
            }
    
    
            private bool _Sex;
    
            /// <summary>
            /// 性别
            /// </summary>
            public bool Sex
            {
                get { return _Sex; }
                set { _Sex = value; }
            }
            //判断是男是女
            public string SexStr
            {
                get
                {
                    return _Sex ? "" : "";
                }
            }
    
    
            private DateTime _Birthday;
    
            /// <summary>
            /// 生日
            /// </summary>
            public DateTime Birthday
            {
                get { return _Birthday; }
                set { _Birthday = value; }
            }
            //将datetime类型转换为string类型
            public string BirthdayStr
            {
                get
                {
                    return _Birthday.ToString("yyyy年MM月dd日");
                }
            }
    
    
            private string _Nation;
    
            /// <summary>
            /// 民族
            /// </summary>
            public string Nation
            {
                get { return _Nation; }
                set { _Nation = value; }
            }
            //将民族用字符串显示出来
            public string NationName
            {
                get
                {
                    string end = "<未填>";
                    cmd.CommandText = "select *from Nation where NationCode = @a";
                    cmd.Parameters.Clear();
                    cmd.Parameters.Add("@a",_Nation);
                    conn.Open();
                    SqlDataReader dr = cmd.ExecuteReader();
                    if (dr.HasRows)
                    {
                        dr.Read();
                        end=dr["NationName"].ToString();
                    }
                    conn.Close();
    
                    return end;
                }
            }
            private string _Class;
    
            /// <summary>
            /// 班级
            /// </summary>
            public string Class
            {
                get { return _Class; }
                set { _Class = value; }
            }
            //将班级用字符串展示出来
            public string ClassName
            {
                get
                {
                    string end = "<无班级>";
    
                    cmd.CommandText = "select *from Class where ClassCode = @a";
                    cmd.Parameters.Clear();
                    cmd.Parameters.Add("@a",_Class);
                    conn.Open();
                    SqlDataReader dr = cmd.ExecuteReader();
                    if (dr.HasRows)
                    {
                        dr.Read();
                        end = dr["ClassName"].ToString();
                    }
                    conn.Close();
                    return end;
                }
            }
        }
    }

    主程序中:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using 实体类_数据访问类.App_Code;
    
    namespace 属性扩展
    {
        class Program
        {
            static void Main(string[] args)
            {
                List<Users> ulist = new UsersData().Select();
    
                Console.WriteLine("序号   密码   昵称   性别   生日   民族   班级");
                foreach (var u in ulist)
                {
                    Console.WriteLine(u.Ids + "   " + u.PassWord + "   " + u.NickAndUser + "   " + u.SexStr + "   " + u.BirthdayStr + "   " + u.NationName + "   " + u.ClassName);
                }
                Console.ReadKey();
            }
        }
    }

  • 相关阅读:
    性能学习-了解前端性能测试
    Python变量类型说明
    Python 标识符说明
    极验验证码-判断需要移动的距离
    极验验证码-userresponse.js
    转载系列
    loadrunner java vuser
    java DES
    java AES
    极验验证码流程-4字段加密
  • 原文地址:https://www.cnblogs.com/wy1992/p/6126396.html
Copyright © 2020-2023  润新知