1. using System; 
  2. using System.Collections.Generic; 
  3. using System.Linq; 
  4. using System.Text; 
  5. using LyqModels; 
  6. using System.Data.SqlClient; 
  7. using System.Data.Common; 
  8. using System.Data; 
  9.  
  10. namespace LyqDAL 
  11.    public class CustomService 
  12.     { 
  13.        public static bool Add( Custom custom) 
  14.        { 
  15.            string sql = "INSERT INTO custom (id, cname, departID, age, ename, password) VALUES (@id, @cname, @departID, @age, @ename, @password) "
  16.            Dictionary<stringobject> dic = new Dictionary<stringobject>(); 
  17.            dic.Add("@id", custom.id); 
  18.            dic.Add("@cname", custom.cname); 
  19.            dic.Add("@departID", custom.departID); 
  20.            dic.Add("@age", custom.age); 
  21.            dic.Add("@ename", custom.ename); 
  22.            dic.Add("@password", custom.password); 
  23.            return DBHelper.ExecuteNonQuery(sql, dic) > 0 ? true : false
  24.  
  25.  
  26.        } 
  27.        public static bool Delete(int id) 
  28.        { 
  29.             
  30.            string sql = " DELETE FROM custom WHERE id = @id "
  31.            Dictionary<stringobject> dic = new Dictionary<stringobject>(); 
  32.            dic.Add("@id", id); 
  33.  
  34.            return DBHelper.ExecuteNonQuery(sql, dic) > 0 ? true : false
  35.        } 
  36.        public static bool Modify(Custom custom ) 
  37.        { 
  38.            string sql = "UPDATE custom SET cname = @cname, departID = @departID, age = @age, ename = @ename, password = @password WHERE id = @id; "
  39.            Dictionary<stringobject> dic = new Dictionary<stringobject>(); 
  40.            dic.Add("@id", custom.id); 
  41.            dic.Add("@cname", custom.cname); 
  42.            dic.Add("@departID", custom.departID); 
  43.            dic.Add("@age", custom.age); 
  44.            dic.Add("@ename", custom.ename); 
  45.            dic.Add("@password", custom.password); 
  46.            return DBHelper.ExecuteNonQuery(sql, dic) > 0 ? true : false
  47.        } 
  48.        public static List GetAllCustom() 
  49.        { 
  50.            string sql ="select * from custom"
  51.            DataTable dt = DBHelper.GetDataSet(sql); 
  52.            List list = new List(); 
  53.            foreach (DataRow dr in dt.Rows) 
  54.            { 
  55.                Custom  custom= new Custom(); 
  56.                custom.id = (int)dr["id"]; 
  57.                custom.cname = (string)dr["cname"]; 
  58.                custom.ename = (string)dr["ename"]; 
  59.                custom.age = (int)dr["age"]; 
  60.                custom.departID = (int)dr["departID"]; 
  61.                custom.password = (string)dr["password"]; 
  62.                list.Add(custom); 
  63.  
  64.            } 
  65.            return list; 
  66.            
  67.           
  68.  
  69.  
  70.        } 
  71.        public static List GetCustom(int id,string cname,string ename,int departID,int age,string password) 
  72.        { 
  73.  
  74.  
  75.            string sql = "SELECT * FROM custom WHERE 1=1"
  76.           
  77.            if (departID>-1) 
  78.            { 
  79.                 sql += "and departID=@departID"
  80.  
  81.                if (id > 0) 
  82.                { 
  83.                    sql += " or id=@id"
  84.  
  85.                } 
  86.                
  87.                else if (!Equals(cname, "")) 
  88.               { 
  89.                   sql += " or cname like '%'+@cname+'%'"
  90.               
  91.               } 
  92.                else if (age>0) 
  93.               { 
  94.                sql += " or age=@age"
  95.               } 
  96.                  
  97.                else if (!Equals(ename, "")) 
  98.               { 
  99.                    sql += " or ename like '%'+@ename+'%'"
  100.               
  101.               } 
  102.               else if (!Equals(password, "")) 
  103.               { 
  104.                    sql += " or password like '%'+@password+'%'"
  105.               
  106.               } 
  107.            } 
  108.          
  109.   
  110.            SqlParameter[] arr = new SqlParameter[] 
  111.            { 
  112.                new SqlParameter("@id", id), 
  113.                new SqlParameter("@cname", cname), 
  114.                new SqlParameter("@departID", departID), 
  115.                new SqlParameter("@age", age), 
  116.                new SqlParameter("@ename", ename), 
  117.                new SqlParameter("@password", password), 
  118.                               
  119.            }; 
  120.  
  121.            DataTable dt = DBHelper.GetDataTable(sql, arr); 
  122.            List list = new List(); 
  123.            foreach (DataRow dr in dt.Rows) 
  124.            { 
  125.                Custom custom= new Custom(); 
  126.                custom.id = (int)dr["id"]; 
  127.                custom.cname = (string)dr["cname"]; 
  128.                custom.departID = (int)dr["departID"]; 
  129.                custom.age = (int)dr["age"]; 
  130.                custom.ename = (string)dr["ename"]; 
  131.                custom.password = (string)dr["password"]; 
  132.  
  133.                list.Add(custom); 
  134.  
  135.            } 
  136.            return list; 
  137.  
  138.        } 
  139.     }