效果图
Model设置具体流程在下面链接中
https://blog.csdn.net/Mr_wangzu/article/details/136805824?spm=1001.2014.3001.5501
DAL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebApplication2.Models;
namespace WebApplication2.DAL
{public class CompanyListDAL{public static List<CompanyList> Show(){AdvertisesEntities db = new AdvertisesEntities();return db.CompanyLists.ToList();}public static List<CompanyList> Find(string gangwei){AdvertisesEntities db = new AdvertisesEntities();return db.CompanyLists.Where(x => x.CompanyJobs.Contains(gangwei)).ToList();}public static bool Apply(int id){AdvertisesEntities db = new AdvertisesEntities();var v= db.CompanyLists.FirstOrDefault(s => s.CompanyID == id);if (v!=null&&v.CompanyCount>0){v.CompanyCount --;db.SaveChanges();return true;}else{return false;}}}
}
BLL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebApplication2.Models;
namespace WebApplication2.BLL
{public class CompanyListBLL{public static List<CompanyList> Show(){return DAL.CompanyListDAL.Show();}public static List<CompanyList> Find(string gangwei){return DAL.CompanyListDAL.Find(gangwei);}public static bool Apply(int id){return DAL.CompanyListDAL.Apply(id);}}
}
WebForm1.aspx
前端部分
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title></title>
</head>
<body><form id="form1" runat="server"><div><asp:Label ID="Label1" runat="server" Text="岗位:"></asp:Label><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:Button ID="Button1" runat="server" Text="查询" OnClick="Button1_Click" /><table border="1"><tr><th>公司名称</th><th>招募岗位</th><th>招募人数</th><th>岗位申请</th></tr><asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand"><ItemTemplate><tr><td><%#Eval("CompanyName") %></td><td><%#Eval("CompanyJobs") %></td><td><%#Eval("CompanyCount") %></td><td><asp:LinkButton ID="LinkButton1" runat="server" CommandArgument='<%#Eval("CompanyID") %>' OnClientClick="return confirm('确定申请岗位?')">申请岗位</asp:LinkButton></td></tr></ItemTemplate></asp:Repeater></table></div></form>
</body>
</html>
后端部分
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;namespace WebApplication2
{public partial class WebForm1 : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){Repeater1.DataSource= BLL.CompanyListBLL.Show();Repeater1.DataBind();}protected void Button1_Click(object sender, EventArgs e){Repeater1.DataSource = BLL.CompanyListBLL.Find(TextBox1.Text);Repeater1.DataBind();}protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e){int id=Convert.ToInt32(e.CommandArgument); bool sta = BLL.CompanyListBLL.Apply(id);if (sta){ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('成功')", true);}else{ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('名额满了')", true);} Repeater1.DataSource = BLL.CompanyListBLL.Show();Repeater1.DataBind();}}
}