首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 其他相关 >

应用三层架构,实现页面中输入学生id,单机按钮后使该学生的年龄加

2012-12-25 
使用三层架构,实现页面中输入学生id,单机按钮后使该学生的年龄加UI文件夹/ui1.aspx前台:bodyform idf

使用三层架构,实现页面中输入学生id,单机按钮后使该学生的年龄加
UI文件夹/ui1.aspx前台:
<body>
    <form id="form1" runat="server">
    <div>
          请输入要修改学生年龄的id:<asp:TextBox ID="txtId" runat="server"></asp:TextBox>
        <br /><br />
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="学生年龄加1" />
    </div>
    </form>
</body>

UI文件夹/ui1.aspx后台:
  protected void Button1_Click(object sender, EventArgs e)
        {
            int fid = Convert.ToInt32(txtId.Text.Trim());
            MyStudentsBll bll = new MyStudentsBll();
            bool b = bll.AgeAddById(fid);
            if (b)
            {
                Response.Write("修改成功!");
            }
            else
            {
                Response.Write("修改失败!");
            }
        }

DAL/MyStudentsDal类:
public class MyStudentsDal
    {
        public int AgeAddById(int Fid)
        {
            string sql = "update MyStudents set FAge=FAge+1 where FId=@Fid";
            SqlParameter pms = new SqlParameter("@Fid",Fid);
            return SQLHelper.ExecuteNoQuery(sql, pms);
        }
    }

Bll/MyStudentsBll类:
  public class MyStudentsBll
    {
        public bool AgeAddById(int fid)
        {
            MyStudentsDal dal = new MyStudentsDal();
          int r=dal.AgeAddById(fid);
          if (r > 0)
          {
              return true;
          }
          else
          { 
          return false;
          }
        }
    }

热点排行