asp.Net 3階層アーキテクチャの削除と変更

11193 ワード

データベース#データベース#
use master
if exists (select * from sysdatabases where name='bond')
drop database bond
create database bond
on PRIMARY
(
name='bond_data',
FILENAME='F:\asp\    \management\bond.mdf',
filegrowth=20%,
size=10MB
)
LOG ON
(
name='bond_log',
FILENAME='F:\asp\    \management\bond_log.ldf',
size=3MB,
MAXSIZE=20MB
)




use bond
--     (  )
if exists (select * from sys.objects where name='jjlx')
drop table jjlx
create table jjlx
(
id int primary key identity(1,1),                     --id
jjlx varchar(50) not null                            --    
)

--           
if exists(select * from sys.objects where name='jjlx_add')
drop procedure jjlx_add
go
create proc jjlx_add
@jjlx varchar(50) 
as
insert into jjlx values (@jjlx)
go
--           
if exists(select * from sys.objects where name='p_jjlx')
drop procedure p_jjlx
go
create proc p_jjlx
as
select * from jjlx
go
--           
if exists(select * from sys.objects where name='jjlx_gai')
drop procedure jjlx_gai
go
create proc jjlx_gai
@id int,
@jjlx varchar(50)
as
UPDATE jjlx SET jjlx=@jjlx where  id=@id 
go
--           
if exists(select * from sys.objects where name='jjlx_delete')
drop procedure jjlx_delete
go
create proc jjlx_delete
@id int,
@jjlx varchar(50)
as
delete from jjlx where id=@id and jjlx=@jjlx
go


リンクデータベースWeb.config
	
  
 

Model層managementModelクラス
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace managementModel
{
    public class jjlxs//     
    {
        public int id { set; get; }//id
        public string jjlx { set; get; } //    

    }
}



DAL層追加参照Model層追加プログラムセット参照using System.Configuration; managementDALクラス
 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
using managementModel;
namespace managementDAL
{
    public class jjlxdal
    {
        DBHelper db = new DBHelper();
        /// 
        ///       
        /// 
        /// 
        public DataSet Searchjjlx()
        {
            string sql = "p_jjlx";
            return db.Search(sql);
        }
        /// 
        ///       
        /// 
        /// 
        /// 
        public int Insertjjlx(jjlxs stujjlx)
        {
            string sql = "jjlx_add";
            SqlParameter[] para ={
                           new SqlParameter("@jjlx",stujjlx.jjlx)   
                           };
            return db.IUD(sql, para);
        }
        /// 
        ///       
        /// 
        /// 
        /// 
        public int Udatejjlx(jjlxs stujjlx)
        {
            string sql = "jjlx_gai";
            SqlParameter[] para ={
                           new SqlParameter("@id",stujjlx.id),
                           new SqlParameter("@jjlx",stujjlx.jjlx)
                           };
            return db.IUD(sql, para);
        }
        /// 
        ///       
        /// 
        /// 
        /// 
        public int Deletejjlx(jjlxs stujjlx)
        {
            string sql = "jjlx_delete";
            SqlParameter[] para ={
                          new SqlParameter("@id",stujjlx.id),
                           new SqlParameter("@jjlx",stujjlx.jjlx)
                           };
            return db.IUD(sql, para);
        }
    }
}


DBHelperクラス
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace managementDAL
{
    public class DBHelper
    {
        public static string conn = ConfigurationManager.ConnectionStrings["conn"].ToString();
        /// 
        ///       
        /// 
        ///         
        ///          
        /// 
        public int IUD(string sql, SqlParameter[] param)
        {
            int count = 0;
            SqlConnection con = new SqlConnection(conn);
            con.Open();
            SqlCommand com = new SqlCommand(sql, con);
            com.CommandType = CommandType.StoredProcedure;
            com.Parameters.AddRange(param);
            count = com.ExecuteNonQuery();
            con.Close();
            return count;
        }
        /// 
        ///     DATASET
        /// 
        /// 
        /// 
        public DataSet Search(string sql)
        {
            DataSet ds = new DataSet();
            SqlConnection con = new SqlConnection(conn);
            SqlDataAdapter adapter = new SqlDataAdapter(sql, con);
            adapter.Fill(ds);
            return ds;
        }
      
    }
}


BLLレイヤリファレンスModelレイヤリファレンスDALレイヤを追加
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using managementDAL;
using managementModel;
using System.Data;
namespace managementBLL
{
   public  class jjlxbll
    {
       jjlxdal dal = new jjlxdal();
       /// 
       ///       
       /// 
       /// 
       public DataSet Searchjjlx() {
           return dal.Searchjjlx();
       }
       /// 
       ///       
       /// 
       /// 
       /// 
       public bool Insertjjlx(jjlxs stujjlx)
       {
           bool flag = false;
           if (stujjlx.jjlx.Length != 0)
           {
               int count = dal.Insertjjlx(stujjlx);
               if (count > 0)
               {
                   flag = true;
               }
           }
           return flag;
       }
       /// 
       ///       
       /// 
       /// 
       /// 
       public bool Udatejjlx(jjlxs stujjlx)
       {
           bool flag = false;
           if (stujjlx.jjlx.Length != 0&&stujjlx.id!=0)
           {
               int count = dal.Udatejjlx(stujjlx);
               if (count > 0)
               {
                   flag = true;
               }
           }
           return flag;
       }
       /// 
       ///       
       /// 
       /// 
       /// 
       public bool Deletejjlx(jjlxs stujjlx)
       {
           bool flag = false;
           if (stujjlx.jjlx.Length != 0 && stujjlx.id != 0)
           {
               int count = dal.Deletejjlx(stujjlx);
               if (count > 0)
               {
                   flag = true;
               }
           }
           return flag;
       }
    }
}


UI層に参照Model層を追加参照BLL層基金タイプを追加する.aspx







    


    <form id="form1" runat="server">
        <label id="Label2" runat="server" text="  id:"/>
 
        <textbox id="txtid" runat="server"/>
    <div>
    
    </div>
        <label id="Label1" runat="server" text="    :"/>
        <textbox id="txtjjlx" runat="server"/>
        <br/>
        <br/>
        <button id="btnadd" runat="server" onclick="btnadd_Click" text="  "/>
        <button id="btndelete" runat="server" onclick="btndelete_Click" text="  "/>
        <button id="btngai" runat="server" onclick="btngai_Click" text="  "/>
        <br/>
        <table border="1">
            <tr><th>  id</th><th>    </th></tr>
        <repeater id="repjjlx" runat="server">
            <itemtemplate>
                <tr>
                    <td/>
                    <td/>
                </tr>
            </itemtemplate>
        </repeater>
        </table>
    </form>



</code></pre> 
  <p><strong>    .aspx.cs</strong><br/> <em>    .aspx.cs</em></p> 
  <pre><code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; 
using managementBLL;
using System.Data;
using managementModel;
namespace management
{
    public partial class index : System.Web.UI.Page
    {
        jjlxbll bll = new jjlxbll();
        protected void Page_Load(object sender, EventArgs e)
        {
            Bind();
        }
        public void Bind() {

            this.repjjlx.DataSource = bll.Searchjjlx().Tables[0];
            this.repjjlx.DataBind();
        }
        protected void btnadd_Click(object sender, EventArgs e)
        {
            jjlxs stujjlx = new jjlxs {jjlx=txtjjlx.Text };
            if (bll.Insertjjlx(stujjlx))
            {
                Bind();
                Response.Write("<script>alert('    !')</script>");
            }
            else {
                Response.Write("<script>alert('    !')</script>");
            }
        }

        protected void btndelete_Click(object sender, EventArgs e)
        {
            jjlxs stujjlx = new jjlxs();
            stujjlx.id = Convert.ToInt32(txtid.Text);
            stujjlx.jjlx = txtjjlx.Text;
            if (bll.Deletejjlx(stujjlx))
            {
                Bind();
                Response.Write("<script>alert('    !')</script>");
            }
            else
            {
                Response.Write("<script>alert('    !')</script>");
            }
        }

        protected void btngai_Click(object sender, EventArgs e)
        {
            jjlxs stujjlx = new jjlxs();
            stujjlx.id = Convert.ToInt32(txtid.Text);
            stujjlx.jjlx = txtjjlx.Text;
            if (bll.Udatejjlx(stujjlx))
            {
                Bind();
                Response.Write("<script>alert('    !')</script>");
            }
            else
            {
                Response.Write("<script>alert('    !')</script>");
            }
            
        }
    }
}
</code></pre> 
 </div> 
</div>
                            </div>
                        </div>