三層架構

Model層
using System;
namespace TSMS.Model
{
 /// <summary>
 /// 描述員工的在職狀態
 /// </summary>
 [Serializable]
 public partial class tb_potential
 {
  public tb_potential()
  {}
  #region Model
  private int _potstuid;
  private string _stuname;
  private string _stupho;
  private string _stuparentpho;
  private string _stuadress;
  private string _sturemarks;
  /// <summary>
  /// 
  /// </summary>
  public int potstuid
  {
   set{ _potstuid=value;}
   get{return _potstuid;}
  }
  /// <summary>
  /// 
  /// </summary>
  public string stuname
  {
   set{ _stuname=value;}
   get{return _stuname;}
  }
  /// <summary>
  /// 
  /// </summary>
  public string stupho
  {
   set{ _stupho=value;}
   get{return _stupho;}
  }
  /// <summary>
  /// 
  /// </summary>
  public string stuparentpho
  {
   set{ _stuparentpho=value;}
   get{return _stuparentpho;}
  }
  /// <summary>
  /// 
  /// </summary>
  public string stuadress
  {
   set{ _stuadress=value;}
   get{return _stuadress;}
  }
  /// <summary>
  /// 
  /// </summary>
  public string sturemarks
  {
   set{ _sturemarks=value;}
   get{return _sturemarks;}
  }
  #endregion Model
 }
}


Dal層

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TSMS.Model;
using TSMS.Common;
using System.Data.SqlClient;
using System.Data;
namespace TSMS.DAL
{
   public  class Dalpotential:IDalData<tb_potential>
   {
       SqlHelper _sqlhelper = new SqlHelper();
        /// <summary>
        /// 添加潛在學生
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public bool InsertItem(tb_potential t)
        {         
            SqlParameter[] parameters =
                {                             
                    new SqlParameter("@stuname",SqlDbType.NVarChar,12),
                    new SqlParameter("@stupho",SqlDbType.VarChar,11),
                    new SqlParameter("@stuparentpho",SqlDbType.VarChar,11),
                    new SqlParameter("@stuadress",SqlDbType.NVarChar,50),                  
                    new SqlParameter("@sturemarks",SqlDbType.NVarChar,120)
                };         
            parameters[0].Value = t.stuname;
            parameters[1].Value = t.stupho;
            parameters[2].Value = t.stuparentpho;
            parameters[3].Value = t.stuadress;
            parameters[4].Value = t.sturemarks;        
            string sql = @"INSERT INTO [tb_potential] ([stuname],[stupho],[stuparentpho],[stuadress],[sturemarks])
            VALUES (@stuname,@stupho,@stuparentpho,@stuadress,@sturemarks)";
            return _sqlhelper.ExecuteNonQurey(sql, CommandType.Text, parameters);         
        }
        /// <summary>
        /// 修改潛在學生信息
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public bool UpdateItem(tb_potential t)
        {
            SqlParameter[] parameters =
                {                             
                    new SqlParameter("@stuname",SqlDbType.NVarChar,12),
                    new SqlParameter("@stupho",SqlDbType.VarChar,11),
                    new SqlParameter("@stuparentpho",SqlDbType.VarChar,11),
                    new SqlParameter("@stuadress",SqlDbType.NVarChar,50),                  
                    new SqlParameter("@sturemarks",SqlDbType.NVarChar,120),
                    new SqlParameter("@potstuid",SqlDbType.Int)
                };
            parameters[0].Value = t.stuname;
            parameters[1].Value = t.stupho;
            parameters[2].Value = t.stuparentpho;
            parameters[3].Value = t.stuadress;
            parameters[4].Value = t.sturemarks;
            parameters[5].Value = t.potstuid;
            string sql = @"UPDATE tb_potential  SET stuname=@stuname,stupho =@stupho,
            stuparentpho= @stuparentpho,stuadress =@stuadress,sturemarks = @sturemarks
            WHERE potstuid = @potstuid";
            return _sqlhelper.ExecuteNonQurey(sql, CommandType.Text, parameters);     
        }
        /// <summary>
        /// 刪除潛在學生信息
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public bool DeleteItem(string strSelected)
        {
            
            strSelected = strSelected.Trim(new char[] { ',' });//重要細節,慢慢研究
            string sql = @"DELETE FROM [TSMS].[dbo].[tb_potential]
            WHERE [potstuid] in (" + strSelected + ")";
            return _sqlhelper.ExecuteNonQurey(sql, CommandType.Text);     
        }
        public List<tb_potential> GetListModel()
        {
            throw new NotImplementedException();
        }
        public tb_potential GetModel(int id)
        {
            throw new NotImplementedException();
        }
        /// <summary>
        /// 分頁按鈕
        /// </summary>
        /// <param name="condition"></param>
        /// <param name="pageCount"></param>
        /// <returns></returns>
        public DataTable GetAllVacation(Condition condition, out int pageCount)
        {
            SqlParameter[] parameters =
                {                             
                    new SqlParameter("@pageSize",SqlDbType.Int),
                    new SqlParameter("@pageIndex",SqlDbType.Int),
                    new SqlParameter("@tableName",SqlDbType.VarChar,50),
                    new SqlParameter("@priKey",SqlDbType.VarChar,20),                  
                    new SqlParameter("@condition",SqlDbType.VarChar,2000),
                    new SqlParameter("@sort",SqlDbType.VarChar,4),
                    new SqlParameter("@pageCount",SqlDbType.Int )
                };
            parameters[0].Value = condition.PageSize;
            parameters[1].Value = condition.PageIndex;
            parameters[2].Value = condition.TableName;
            parameters[3].Value = condition.Prikye;
            parameters[4].Value = condition.Condtion;
            parameters[5].Value = condition.Pagesort;
            parameters[6].Direction = ParameterDirection.Output;
            string sql = @"exec proc_CommonSinglePage @pageSize,@pageIndex,@tableName,@priKey,@condition,@sort,@pagecount out";
            DataTable db = _sqlhelper.GetDataTable(sql, CommandType.Text, parameters);
            pageCount = (int)parameters[6].Value;
            return db;          
        }

        public bool DeleteItem(tb_potential t)
        {
            throw new NotImplementedException();
        }
   }
}

Bll層

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TSMS.DAL;
using TSMS.Model;
using System.Data;
namespace TSMS.BLL
{
    public class Bllpotential
    {
        private Dalpotential dalpot = new Dalpotential();
        /// <summary>
        /// 新增一個潛在學生
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public bool InsertItem(tb_potential t)
        {
            return dalpot.InsertItem(t);
        }
        /// <summary>
        /// 更新潛在學生信息
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public bool UpdateItem(tb_potential t)
        {
            return dalpot.UpdateItem(t);
        }
        /// <summary>
        /// 刪除潛在學生信息
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public bool DeleteItem(string strSelected)
        {
            return dalpot.DeleteItem(strSelected);
        }
        public DataTable GetAllVacation(Condition condition, out int pageCount)
        {
            return dalpot.GetAllVacation(condition, out pageCount);
        }
    }
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章