| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 929 人关注过本帖
标题:看过后,两层架构的网站基本都可以做了
只看楼主 加入收藏
shuijiashui
Rank: 2
等 级:论坛游民
帖 子:43
专家分:85
注 册:2009-9-1
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:1 
看过后,两层架构的网站基本都可以做了
个人学习的总结:
学习重要就是学习对空间的使用:
一下是个人学习笔记,看过后2层架构的网站都可以做了:
留言板
一、    登录页面的设置login.aspx
        
       检验用户名和数据库的配对 select count(*) from admin where adminName='" + TextBox1.Text + "' and adminPwd='" + TextBox2.Text + "' 采用查找数量的方法,   
借助于命令的属性comm.ExecuteScalar()这个命令,是返回找到的数目,若真则可以进入到留言主页。


二、留言主页的设置index.aspx:
1、datalist控件: 除了可以将数据依照用户制定的样式显示之外,还可以对数据进行修改。
2、分页的处理
3、主要内容:
 1)用datalist控件中的编辑模板的itemteplate进行页面设计,布局(用到了html中的div,该标记相当于容器);然后进行和数据库的连接!连接完成后进行数据的绑定(Eval(“字段名”)对于图片的绑定有空格,注意Eval(“字段名”).ToString().Trim)
 2)发表留言:linkbutton,进入发表留言的页面---留言板.aspx
 3)回复:linkbutton     进入回复页面——replys.aspx
 4)删除:linkbutton     不需要换页面

三、发表留言(留言板.aspx):
1、主要是DropDownList控件的应用,此控件和image控件的结合,可以根据选择来改变图片的变化
2、首先要判断是不是加载dropdownlist的项目;使用ispostback ;
         for (int i = 1; i <= 10; i++)
            {
                DropDownList1.Items.Add("pic"+i.ToString()+".gif");
       }
   再DropDownList1属性中的ispostback设置true
    DropDownList1中的事件selectindexchaged更改索引后激发
this.Image1.ImageUrl = "images/face/" + DropDownList1.SelectedValue;

四、replys.aspx设置
       1、这个需要设置反升事件:(和新闻系统的主页的datalist的传递字符区别)
a、在主页中datalist控件“回复按钮”的属性中的commandname中设置命令reply,
b、在bind()中写datalist. DataKeyFild=”id”,或在datalist控件的属性DataKeyFild中设置id
c、然后再datalist事件中的itemcommand写事件,if ( == "reply")
用DataList1.DataKeys[e.Item.ItemIndex]获取要回复的id,然后用Response.Redirect("replys.aspx?id="+id)传递字符串
       2、replys.aspx中用Request.QueryString["id"].ToString() 接受传过来的字符串
五、删除的设置
       1、这个和回复一样都需要固定的id,因此可以用反升事件,但是还有一种方法,直接发挥删除按钮的作用(注意和新闻系统的主页datalist中获取主键的区别: 新闻中是在datalist控件的itemcommand事件中获取主键,而此处是在删除按钮的command事件处理)
          1)首先再datalist属性中的datakeys设置字段ID,用来获取数据源的主键,
2)在删除按钮的属性CommandArgument中设置<%#Eval(“字段名”)%>
3)在删除按钮中的事件command中()获取当前的字段id
         

      2、删除时注意提醒,用了DataList1事件中的ItemDataBound事件
         LinkButton dele = (LinkButton)(e.Item.FindControl("LinkButton3"));
        if (dele != null)
        {
            dele.Attributes.Add("onclick","return confirm('确定要删除吗?')");}
e.Item.FindControl作用是再当前命名的容器中获取指定id的服务器控件
六、对于div中的设置
      1、发布时间:再源中加入代码
:发布时间:<%#DataBinder.Eval(Container.DataItem,"posttime")%>
      2、管理员回复:再源中加入代码
         管理员回复:<%#DataBinder.Eval(Container.DataItem,"reply")%>
七、分页
     1、分页和总页数的设置
        PagedDataSource ps=new PagedDataSource();
        ps.DataSource = ds.Tables["guest"].DefaultView;
        ps.AllowPaging = true;
        ps.CurrentPageIndex=current-1;//================================当前页的索引
        ps.PageSize=3;
        Button1.Enabled = true;
        Button2.Enabled = true;
        if (ps.IsFirstPage)
        {
            Button1.Enabled = false;
        }
        if (ps.IsLastPage)
        {
            Button2.Enabled = false;
        }
        DataList1.DataSource = ps;
        DataList1.DataBind();
        this.Label5.Text = ps.PageCount.ToString();//================共几页,需要注意位置
        conn.Close();
     2.总共的留言条数的设置
        string sql1 = "select count(*) from guest ";//===========写sql语句计算共多少条留言
        SqlCommand comm1 = new SqlCommand(sql1, conn);
        Label3.Text=comm1.ExecuteScalar().ToString();
学生管理系统
一 、专业管理里使用: gridview控件:
   1: 删除:A、在gridview外使用Button按钮
循环从gridview控件的行对象集合找到指定id的服务器控件,再找到项目模板中的主键。
(注释:由于循环找到的是一行,所以只要找到此行的指定的id服务器就可以找到要删除的id了)
for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            CheckBox x = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
            if (x.Checked)
            {
                string id =((Label)GridView1.Rows[i].FindControl("Label1")).Text;
                SqlConnection conn = DB.getconnection();
                string sql = "delete from speciality where specialityid='" + id + "'";
                SqlCommand comm = new SqlCommand(sql, conn);
                if (comm.ExecuteNonQuery() > 0)
                                    Response.Write("<script>alert('删除成功!');</script>");
                else
                                    Response.Write("<script>alert('删除失败!');</script>");
             }  
bind();
            conn.Close();
               B、确认删除的处理:再page事件中处理!
LinkButton3.Attributes.Add("onclick", "javascript:return confirm('你确认要删除吗?')");
1、    删除(使用commandfield建立删除按钮)
   在数据bind()中加入
       GridView1.DataKeyNames = new string[]{"id"};
         在gridview控件的delete事件中
          string id=GridView1.DataKeys[e.RowIndex].Value.ToString();

   2: 编辑:使用commandfield建立编辑按钮
      对gridview的事件RowEditing,RowUpdating,RowCancelingEdit即编辑,更新,取消事件处理。
     //=======编辑
        GridView1.EditIndex = e.NewEditIndex;
        bind();
//=======更新找到编辑模板中的主键
string specialname = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox1")).Text.Trim();
        string id = ((Label)GridView1.Rows[e.RowIndex].FindControl("Label7")).Text.Trim();
        string str = "update speciality set specialityname='"+specialname+"' where specialityid='" + id + "'";
        SqlConnection conn = DB.getconnection();
        SqlCommand comm = new SqlCommand(str,conn);
        comm.ExecuteNonQuery();
        bind();
        conn.Close();
//=======取消
        GridView1.EditIndex = -1;
        bind();
二、课程管理使用:gridview和datalist控件的结合:
1、结合作用和目的:在gridview中点击一组数据可以在datalist中显示详细信息并对它进行编辑处理。
             2、删除:同专业管理的删除处理

           3、gridview和datalist的结合:
protected void LinkButton2_Click(object sender, EventArgs e)
        int x = 0;
        LinkButton lb = (LinkButton)sender;//=============标记点击gridview中要显示详细信息的数据超连接按钮
        //===============从gridview里找到标记的超链接按钮的行,读出行号
for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            if ((LinkButton)(GridView1.Rows[i].FindControl("LinkButton2")) == lb)
            {
                x = i;
            }
        }
      //=================找到要处理的行的主键。
        string id = ((HyperLink)(GridView1.Rows[x].FindControl("HyperLink2"))).Text.ToString();//===========获取要更改的id,然后在datalist中显示bind()。

           4、datalist中处理:a、在itemtemplate项目模板中建表用来显示gridview中某一个的详细信息,并建立编辑的超链按钮命名edit。
                             b、在edittemplate编辑模板中建表用来显示要更改的信息,并建立更新和取消的超链接按钮 命名 update 和cancel
                             c、分别对datalist控件的editcommand、cancelcommand、updatecommand三个事件处理。
                             d、datalist控件中的控件不能直接使用要获取【重要】
                             //======更新
        TextBox total = (TextBox)e.Item.FindControl("TextBox5");
        TextBox remark = (TextBox)e.Item.FindControl("TextBox8");
        DropDownList cred = (DropDownList)e.Item.FindControl("DropDownList3");
        DropDownList week = (DropDownList)e.Item.FindControl("DropDownList4");
        string str = "update course set totalperiod='" + total.Text + "',remark='" + remark.Text + "',credithour='" + cred.Text + "',weekperiod='" + week.Text + "' where courseid='"+Label22.Text+"'";
        SqlConnection conn = DB.getconnection();
        SqlCommand comm = new SqlCommand(str,conn);
        comm.ExecuteNonQuery();
        bindlist();
      //=======================编辑======
        DataList1.EditItemIndex = e.Item.ItemIndex;
        DataList1.SelectedIndex = -1;//============================================重要:屏蔽已选的
        bindlist();


三、系部管理使用repeater控件:
            1、首先建立一个表格,并加入编辑、更新、取消、删除四个超链接按钮(同datalist的区别)对他们命名edit、update、cancel、delete其中要处理四个按钮的显示和隐藏。最后套入repeater控件。
            2、对repeater控件中itemcommand事件处理,注意其里面的控件也要获取才可以使用,注意和datalist控件的区别:


protected void Repeater2_ItemCommand(object source, RepeaterCommandEventArgs e)
//==============label,linkbutton等也就是repeater中的控件必须获取,否则没有
{
     System.Web.UI.WebControls.LinkButton update=(LinkButton)e.Item.FindControl("LinkButton3");
        System.Web.UI.WebControls.LinkButton cancle=(LinkButton)e.Item.FindControl("LinkButton4");
        System.Web.UI.WebControls.LinkButton edit=(LinkButton)e.Item.FindControl("LinkButton1");
        System.Web.UI.WebControls.LinkButton dele=(LinkButton)e.Item.FindControl("LinkButton2");
        System.Web.UI.WebControls.Label departanme=(Label)e.Item.FindControl("Label5");
        System.Web.UI.WebControls.Label departid = (Label)e.Item.FindControl("Label3");
        System.Web.UI.WebControls.Label departhead=(Label)e.Item.FindControl("Label4");
        System.Web.UI.WebControls.TextBox tdepartanme=(TextBox)e.Item.FindControl("TextBox3");
        System.Web.UI.WebControls.TextBox tdeparthead=(TextBox)e.Item.FindControl("TextBox2");

        if()
        {
            edit.Visible = false;
            dele.Visible = false;
            update.Visible = true;
            cancle.Visible = true;
            departanme.Visible = false;
            departhead.Visible = false;
            tdepartanme.Visible = true;
            tdeparthead.Visible = true;
        }
        if ( == "update")
        {
            SqlConnection conn = DB.getconnection();
            string str = "update department set departmentname='"+tdepartanme.Text+"',departmenthead='"+tdeparthead.Text+"' where departmentid='"+departid.Text+"'";
            SqlCommand comm = new SqlCommand(str, conn);
            comm.ExecuteNonQuery();
            bind();
            conn.Close();
        }
        if ( == "delete")
        {
            SqlConnection conn = DB.getconnection();
            string str = "delete from department  where departmentid='" + departid.Text + "'";
            SqlCommand comm = new SqlCommand(str, conn);
            comm.ExecuteNonQuery();
            bind();
            conn.Close();
        }
        if ( == "cancle")
        {
            bind();
        }
    }

                                
                                                                                      
系部管理里使用repeater控件,重要:自己写代码定义编辑
                                 先做好控件,再itemscommand事件中 处理



四、成绩管理同专业管理:
             1、使用datalist控件来做导航
             2、分页使用pagetemplate模板:
设置4个超链接按钮 首页、上一页、下一页、尾页 分别设置命令名page参数first、prev、next、last多gridview的pageindexchanging事件处理:
try
        {
            GridView1.PageIndex = e.NewPageIndex;
            bind();
        }
        catch { }

3、当前页和总页的设置:
建立label控件,在源中设置:当前页<%# ((GridView)Container.NamingContainer).PageIndex + 1 %>
                                 总页<%# ((GridView)Container.NamingContainer).PageCount %>

五、学生管理使用gridview控件,同专业管理相同,但通过对字符的传递来编辑:
在超链接按钮中的Navigateurl中传递字符Eval("studentID","editstu.aspx?id={0}")
六、教师管理 同学生管理
七、班级管理同课程管理中的datalist控件处理相同。

八 、公用处理
  1、鼠标移动在行之间的变色
      protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)  
     {    if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='RED'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
        }
}

2、在传递字符编辑时dropdownlist的使用
   添加项目,获取主键的id
for (int i = 0; i < ds.Tables["department"].Rows.Count; i++)
            {
                DropDownList1.Items.Add(new ListItem(ds.Tables["department"].Rows[i]["departmentname"].ToString(), ds.Tables["department"].Rows[i]["departmentid"].ToString()));
            }
用于编辑时获得指定的项----这个是指定的id中的内容
  string t = ds.Tables["department"].Rows[0]["departmentname"].ToString();
该项是否是再dropdownlist中显示
  DropDownList1.Items.FindByText(t).Selected = true;





新闻管理系统
主页(Index.aspx)datalist控件:
1、     用户控件head.aspx:
a、导航使用的自定义的字符串传递: NavigateUrl="news.aspx?id=1"用来传给新闻标题的显示(news.aspx)。
b、查找:用sessoin[]记录查找命令,再search.aspx中调用。
 2、 模板:使用用户控件建立模板

3、index.aspx使用了8个datalist控件,并分别设置了键字段,且进行了字符串的传递,用来在shownews.aspx中显现该标题的详细信息。
4、在datalist控件中显示前5个新闻标题
 string strSZ = "select top 5 * from tb_News where Style='时政要闻' order by issueDate desc";、


一、    新闻标题的显示(news.aspx)datalist控件:
 1、使用模板,在编辑模块使用datalist控件显示。

2、    使用switch cash 循环处理导航传递的字符并设置键字段,在datalist控件中的itemcommand事件中获取单击该标题时的主键号,传递给新闻内容的网页
(注意和gridview传递字符的区别)
    int id = Convert.ToInt32(DataList1.DataKeys[e.Item.ItemIndex].ToString());//======获取每条记录的键值
        Response.Redirect("shownews.aspx?id="+id+"");

    sql x = new sql();
        int n = Convert.ToInt32(Request.QueryString["id"]);
        switch(n)
        {
            case 1:
                strStyle = "时政要闻";
                Label1.Text="新闻类型 :时政要闻";
                Image1.ImageUrl="Images/szywbar.jpg";
                this.Image2.ImageUrl="Images/szywtp.jpg";
                break;
            case 2:
                strStyle = "经济动向";
                this.Label1.Text = "新闻类别->经济动向";
                this.Image1.ImageUrl = "~/Images/jjdxbar.jpg";
                this.Image2.ImageUrl = "~/Images/jjdxtp.jpg";
                this.Page.Title = "经济动向";
                break;
                              
                              
                              
             case 8:
                strStyle = "时尚娱乐";
                this.Label1.Text = "新闻类别->时尚娱乐";
                this.Image1.ImageUrl = "~/Images/ssylbar.jpg";
                this.Image2.ImageUrl = "~/Images/ssyltp.jpg";
                this.Page.Title = "时尚娱乐";
                break;
           }
        DataList1.DataKeyField = "id";//===============设置键字段


  
二、    查找的新闻标题的显示(search.aspx)datalist控件:
  
1、在bind()中同样设置主键:DataList1.DataKeyField = "id";
   在datalist控件itemcommand事件中获取点击标题的id,传递给shownews.aspx:
    int id = Convert.ToInt32(DataList1.DataKeys[e.Item.ItemIndex].ToString());//======获取每条记录的键值
        Response.Redirect("shownews.aspx?id="+id+"");


三、    显示标题的详细信息(shownews.aspx)表格:
1、    表格不可以使用<%#Eval("content") %>,表达式是和控件一起使用的,
要使用表达式,可以这样使用:
shownews中先定义数据源,然后用数组的方式来读取:
string conntent;
    sql x = new sql();
        string str = "select * from tb_News";
        DataSet ds = x.dataset(str, "news");
        DataRow[] row = ds.Tables["news"].Select("id=" + Request.QueryString["id"]);

        foreach (DataRow rw in row)
        {
            this.Page.Title = rw["title"].ToString();
            Label1.Text = rw["title"].ToString();
            conntent = rw["content"].ToString();
}
2.数据绑定:通过写函数进行数据绑定
        public string getcontent()
        {
         string s = conntent;
         return s;
     }
在表的源中<%=getcontent()%>--%>



后台管理

一、    主页(index.aspx):
1、    使用了框架
a、    main.aspx
b、    menu.aspx
c、    top.aspx
2、    menu.aspx:
a、    JavaScript折叠代码,在head中:
          <script language="javascript" type="text/jscript">
    <!--
   
    function MenuChange(obj,menu)
    {
       if(menu.style.display=="none")
       {
        menu.style.display="block";
        obj.background="../Images/admin_menubar2.gif";
       }
       else if(menu.style.display != "none")
       {
        menu.style.display="none";
        obj.background="../Images/admin_menubar.gif";
       }
              
    }
    function HideMenu(menu)
    {
        menu.style.display="none";
    }
    -->
</script>

应用:
<%--经济动向--%>
    <table style="width:160px; margin-left:auto; margin-right:auto;" cellSpacing="0" cellPadding="0">
        <tr style="cursor:hand;">
            <td style="background-image:url(../Images/admin_menubar.gif); height:25px; text-align:center;" onclick="MenuChange(this,menu2)">经济动向</td>
        </tr>
        <tr>
            <td style="background-color:#BCD1F8;">
                <div id="menu2" >
                <table  style="text-align:center; width:150px; height:25px;" cellSpacing="0" cellPadding="0">
                    <tr>
                        <td><a href="Add.aspx?id=2" target="right">添加 </a>| <a href="Manage.aspx?id=2" target="right">管理</a></td>
                    </tr>
                </table>
                </div>
            </td>
        </tr>
    </table>
    <script>HideMenu(menu2)</script>


二、    添加(Add.aspx)表:
通过menu.aspx传递的字符可以知道是向那种类型的新闻添加。同主页中的导航。


三、    管理(manage.Aspx)
1、    删除(使用commandfield建立删除按钮):
   在数据bind()中加入
       GridView1.DataKeyNames = new string[]{"id"};
         在gridview控件的delete事件中
          string id=GridView1.DataKeys[e.RowIndex].Value.ToString();
2、    编辑(使用超链接):链接到edit.aspx。



四、    编辑(edit.aspx):
1、    dropdownlist的设置:
   DataSet ds = da.ExceDS2("select * from tb_News where id='" + Request["id"] + "'", "tbNews");
            DataRow[] rows = ds.Tables["tbNews"].Select();
            foreach (DataRow dr in rows)
            {
                this.txtNewsTitle.Text = dr["title"].ToString();
                this.txtNewsContent.Text = dr["content"].ToString();
                this.labTitle.Text = dr["Style"].ToString();

                switch (dr["type"].ToString())
                {
                    case "国内新闻":
                        this.ddlNewsType.SelectedIndex = 1;
                        break;
                    case "国际新闻":
                        this.ddlNewsType.SelectedIndex = 0;
                        break;
                    default:
                        break;
                }
                        }

  五、用户登录(admin.aspx):
      1、验证码的获取:
            public int getcode()
    {
        Random rand = new Random();
        int code = rand.Next(1000, 9999);
        return code;
               }
2、    验证过程:
  先判断用户名和密码,再判断验证码。
  六、用户管理(adminedit.aspx):
       使用gridview的智能标签。

搜索更多相关主题的帖子: 架构 
2010-05-07 12:15
zongshi123
Rank: 5Rank: 5
等 级:职业侠客
威 望:1
帖 子:50
专家分:310
注 册:2009-9-13
收藏
得分:20 
这么大一串

一个没房没车没钱没权没头没脑没心没肺没脸没皮的穷鬼垃圾小流氓外带人妖大尾(yi)巴狼
2010-05-12 20:43
快速回复:看过后,两层架构的网站基本都可以做了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033575 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved