EF数据持久化(三层架构,公司查,改)

   效果图

 

 

 

 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();
        
        }
    }
}

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

W少年没有乌托邦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值