码迷,mamicode.com
首页 > 其他好文 > 详细

数据层

时间:2018-11-22 18:19:20      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:list   var   model   str   color   odi   first   return   desc   

技术分享图片
  1 using System;
  2 using System.Collections.Generic;
  3 using System.Linq;
  4 using System.Text;
  5 using System.Threading.Tasks;
  6 
  7 namespace VacationOA.DAL
  8 {
  9     using MODEL;
 10     using System.Data.Entity;
 11     public class LeaveDAL
 12     {
 13         VacationdbContext dbcontext = new VacationdbContext();
 14         /// <summary>
 15         /// 添加请假单
 16         /// </summary>
 17         /// <param name="l"></param>
 18         /// <returns></returns>
 19         public int AddLeave(Leave l)
 20         {
 21             dbcontext.Leaves.Add(l);
 22             int i = dbcontext.SaveChanges();
 23             if (i > 0)
 24             {
 25                 Leave leave = dbcontext.Leaves.Where(n => n.applyTime.Equals(l.applyTime) && n.staffID.Equals(l.staffID)).FirstOrDefault();
 26                 return leave.leaveID;
 27             }
 28             else
 29             {
 30                 return 0;
 31             }
 32 
 33         }
 34         /// <summary>
 35         /// 修改请假单
 36         /// </summary>
 37         /// <param name="l"></param>
 38         /// <returns></returns>
 39         public int updateleave(Leave l)
 40         {
 41             dbcontext.Entry(l).State = System.Data.Entity.EntityState.Modified;
 42             return dbcontext.SaveChanges();
 43         }
 44         /// <summary>
 45         /// 获取请假单 我的请假列表
 46         /// </summary>
 47         /// <returns></returns>
 48         public List<Leave> GetLeaves()
 49         {
 50             var list1 = from l in dbcontext.Leaves.ToList()
 51                         join s in dbcontext.Staffs.ToList()
 52                         on l.staffID equals s.staffID
 53                         orderby l.CheckTime descending,
 54                         l.applyTime descending
 55                         select new Leave
 56                         {
 57                             leaveID =l.leaveID,
 58                             state = l.state,
 59                             Department = s.Department,
 60                             staffID = s.staffID,
 61                             staffName = s.staffName,
 62                             applyTime = l.applyTime,
 63                             startTime = l.startTime,
 64                             endTime = l.endTime,
 65                             sumTime= l.sumTime,
 66                             CheckTime = l.CheckTime,
 67                             reason=l.reason,
 68                             remark=l.remark,
 69                             explain=l.explain
 70                         };
 71 
 72 
 73             return list1.ToList();
 74         }
 75         /// <summary>
 76         /// 获取请假单 我的审核列表
 77         /// </summary>
 78         /// <returns></returns>
 79         public List<Leave> GetLeavesCheck()
 80         {
 81             var list1 = from l in dbcontext.Leaves.ToList()
 82                         join s in dbcontext.Staffs.ToList()
 83                         on l.staffID equals s.staffID
 84                         orderby  l.applyTime ascending
 85                         select new Leave
 86                         {
 87                             leaveID = l.leaveID,
 88                             state = l.state,
 89                             Department = s.Department,
 90                             staffID = s.staffID,
 91                             staffName = s.staffName,
 92                             applyTime = l.applyTime,
 93                             startTime = l.startTime,
 94                             endTime = l.endTime,
 95                             sumTime = l.sumTime,
 96                             CheckTime = l.CheckTime,
 97                             reason = l.reason,
 98                             remark = l.remark,
 99                             explain = l.explain
100                         };
101             List<Leave> list2 = list1.Where(n=>n.state.Equals("待审核")).ToList();
102 
103             return list2;
104         }
105         /// <summary>
106         /// 修改请假单的状态,审核时间,说明,
107         /// </summary>
108         /// <param name="l"></param>
109         /// <returns></returns>
110         public int updateleaveState(int id,DateTime checktime,string explain,string state)
111         {
112             Leave l= dbcontext.Leaves.ToList().Where(n => n.leaveID.Equals(id)).FirstOrDefault();
113             l.CheckTime = checktime;
114             l.state = state;
115             l.explain = explain;
116             return updateleave(l);
117         }
118 
119 
120     }
121 }
LeaveDAL
技术分享图片
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace VacationOA.DAL
 8 {
 9     using VacationOA.MODEL;
10     public class StaffDAL
11     {
12         VacationdbContext dbcontext = new VacationdbContext();
13         public Staff LoginStaff(string name, string department)
14         {
15             List<Staff> list1 = dbcontext.Staffs.ToList();
16             list1 = list1.Where(n => n.staffName==name && n.Department==department).ToList();
17             return list1.FirstOrDefault();
18 
19 
20         }
21     }
22 }
StaffDAL
技术分享图片
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace VacationOA.DAL
 8 {
 9     using MODEL;
10   public  class TCheckDAL
11     {
12         VacationdbContext dbcontext = new VacationdbContext();
13 
14         /// <summary>
15         /// 添加审核清单
16         /// </summary>
17         /// <param name="tcheck"></param>
18         /// <returns></returns>
19         public int AddTcheck(TCheck tcheck)
20         {
21             dbcontext.checks.Add(tcheck);
22             return dbcontext.SaveChanges();
23         }
24         /// <summary>
25         /// 根据假条id查询是否有关于这个假条审核通过的审核单
26         /// </summary>
27         /// <param name="id"></param>
28         /// <returns></returns>
29         public int GetCheckbyid(int id)
30         {
31           return  dbcontext.checks.Where(n => n.leaveID == id).Where(n => n.checkState.Equals("已通过")).ToList().Count ;
32         }
33         /// <summary>
34         /// 根据id获取对应请假单的审核历史
35         /// </summary>
36         /// <returns></returns>
37         public List<TCheck> GetChecks(int id)
38         {
39             return dbcontext.checks.Where(n => n.leaveID.Equals(id)).ToList();
40         }
41 
42     }
43 }
TCheckDAL
技术分享图片
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace VacationOA.DAL
 8 {
 9     using MODEL;
10     using System.Data.Entity;
11   public  class VacationdbContext:DbContext
12     {
13         public VacationdbContext():base("name=VacationdbContext")
14         {
15 
16         }
17         public DbSet<TCheck> checks { get; set; }
18         public DbSet<Leave> Leaves { get; set; }
19         public DbSet<Staff> Staffs { get; set; }
20     }
21 }
VacationdbContext

 

数据层

标签:list   var   model   str   color   odi   first   return   desc   

原文地址:https://www.cnblogs.com/xcleowong/p/10002466.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!