OOP典型应用:实体类

(1)实体类是业务对象的基础,它用面向对象的思想消除了关系数据与对象之间的差异

   实体类:

 public class Department
    {
        public int BId { get; set; }
        public int BName{ get; set; }
    
    }

  

public class Employee
    {
        public int YId{ get; set; }
        public int YName{ get; set; }
        public int BId{ get; set; }
        public int ZId{ get; set; }
    }

  

 public class Task
    {
        public string Contents {get;set;}
        public int RId {get;set;}
        public int YId {get;set;}
        public DateTime Time {get;set;}
        public int Hours {get;set;}
        public string Type { get; set; }
    }

  数据访问层:

public  class InfoAddDAL
    {

        public bool Add(string name)
        {
            bool falg = false;
            string sql = "insert into ProgramInfo(pname) values('"+name+"')";
            int num=SQLHelper.ExecuteNonQuery(sql);
            if(num==1)
            {
                falg= true;
            }
            return falg;
        }

        public DataTable SelectInfo()
        {
            List<string> list = new List<string>();
          
            try
            {   
                string sql = "select pname from ProgramInfo";
                DataTable table=SQLHelper.ExecuteDataTable(sql);         
                return table;
            
            }
            catch (SqlException ex)
            {

                throw ex;
            }
            catch(Exception ex)
            {
                throw ex;
            }  
        }

        public bool DeleteInfo(string name)
        {
            bool falg = false;
            try
            {
                string sql = "delete ProgramInfo where pname='" + name + "'";
                int num=SQLHelper.ExecuteNonQuery(sql);
                if (num == 1)
                {
                    falg= true;
                }
                return falg;
            }
            catch (SqlException ex)
            {

                throw ex;
            }
            catch(Exception ex)
            {
                throw ex;

            }
          
        }

        public bool UpdateInfo(string name,string names)
        {
            bool falg = false;       
            string sql = "Update  ProgramInfo set pname='"+name+"'where pname='"+names+"'";
            int num=SQLHelper.ExecuteNonQuery(sql);
            if(num==1)
            {
                falg= true;
            }
            return falg;
        }
    }

  在这里再引用一个App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings>
    <add name="constr" connectionString="data source=.; initial catalog=AddInfo; uid=sa;">  
    </add>
  </connectionStrings>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
    </startup>
</configuration>

  

(2)const和readonly的区别

   (1)readonly只能修饰类变量   const修饰成员变量和局部变量

   (2)readonly在运行时赋值,const在编译时赋值

   (3)const只能修饰值类型和特殊的引用类型  readonly可以修饰任何类型

原文地址:https://www.cnblogs.com/sunbin123/p/6661349.html