123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Models;
- using System.Data.SqlClient;
- using System.Data;
- using System.Data.Common;
- namespace DAL
- {
- /// <summary>
- /// 考勤数据数据访问类
- /// </summary>
- public class AttendanceDataService
- {
- /// <summary>
- /// 查询所有
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回集合</returns>
- List<AttendanceData> excuteSql(string sql, params SqlParameter[] param)
- {
- return ServiceBase<AttendanceData>.excuteSql(new AttendanceData(), "AttendanceData", sql, CommandType.Text, param);
- }
- /// <summary>
- /// 获取单个对象
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回空或者单个对象</returns>
- AttendanceData excuteType(string sql, params SqlParameter[] param)
- {
- //查询结果放入对象集合
- List<AttendanceData> adList = excuteSql(sql, param);
- //判断集合是否为空
- if (adList == null || adList.Count == 0)
- //返回null
- return null;
- //返回单个对象
- return adList[0];
- }
- /// <summary>
- /// 根据编号查询对象信息
- /// </summary>
- /// <param name="id">对象编号</param>
- /// <returns>返回空或者单个对象信息</returns>
- public AttendanceData GetAttendanceDataByID(int id)
- {
- //调用获取单个对象的方法
- return excuteType("select * from AttendanceData where Id = @id", new SqlParameter("@id", id));
- }
- /// <summary>
- /// 根据员工号和日期获取数据集合
- /// </summary>
- /// <param name="userNumber"></param>
- /// <param name="swipeDate"></param>
- /// <returns></returns>
- public List<AttendanceData> GetByUserNumberAndSwipeDate(string userNumber, string swipeDate)
- {
- string sql = "select * from AttendanceData where UserNumber = @UserNumber and SwipeDate = @SwipeDate order by SwipeTime";
- SqlParameter[] parameter = new SqlParameter[]{
- new SqlParameter("@UserNumber",userNumber),
- new SqlParameter("@SwipeDate",swipeDate)
- };
- return excuteSql(sql, parameter);
- }
- /// <summary>
- /// 根据员工号和日期获取数据
- /// </summary>
- /// <param name="userNumber"></param>
- /// <param name="swipeDate"></param>
- /// <returns></returns>
- public AttendanceData GetByUserNumberAndSwipeDateEntity(string userNumber, string swipeDate, string swipeTime)
- {
- string sql = "select * from AttendanceData where UserNumber = @UserNumber and SwipeDate = @SwipeDate and InitSwipeTime = @SwipeTime";
- SqlParameter[] parameter = new SqlParameter[]{
- new SqlParameter("@UserNumber",userNumber),
- new SqlParameter("@SwipeDate",swipeDate),
- new SqlParameter("@SwipeTime",swipeTime)
- };
- return excuteType(sql, parameter);
- }
- /// <summary>
- /// 根据条件获取单个数据
- /// </summary>
- /// <param name="userNumber"></param>
- /// <param name="swipeDate"></param>
- /// <param name="startTime"></param>
- /// <param name="endTime"></param>
- /// <returns></returns>
- public AttendanceData GetByUserNumberAndSwipeDateEntity(string userNumber, string swipeDate, string startTime, string endTime)
- {
- string sql = "select * from AttendanceData where UserNumber = @UserNumber and SwipeDate = @SwipeDate and swipeTime between @StartTime and @EndTime";
- SqlParameter[] parameter = new SqlParameter[]{
- new SqlParameter("@UserNumber",userNumber),
- new SqlParameter("@SwipeDate",swipeDate),
- new SqlParameter("@StartTime",startTime),
- new SqlParameter("@EndTime",endTime)
- };
- return excuteType(sql, parameter);
- }
- /// <summary>
- /// 多条数据添加
- /// </summary>
- /// <param name="ad"></param>
- public bool AddAttendanceData(List<AttendanceData> adList)
- {
- SqlCommand cmd = SqlHelper.createCon().CreateCommand();
- cmd.Connection.Open();
- SqlTransaction trans = cmd.Connection.BeginTransaction();
- try
- {
- foreach (AttendanceData ad in adList)
- {
- string sql = string.Format("insert into AttendanceData values('" + ad.UserNumber + "','" + ad.SwipeDate + "','" + ad.SwipeTime + "','" + ad.SwipeTime + "')");
- cmd.CommandText = sql;
- cmd.ExecuteNonQuery();
- }
- trans.Commit();
- cmd.Connection.Close();
- return true;
- }
- catch
- {
- trans.Rollback();
- cmd.Connection.Close();
- return false;
- }
- }
- /// <summary>
- /// 更改打卡时间
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public bool UpdateSwipeDate(int id, string swipeTime)
- {
- string sql = "update AttendanceData set SwipeTime = '" + swipeTime + "' where id = " + id + "";
- if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text) > 0)
- return true;
- return false;
- }
- /// <summary>
- /// 添加
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public bool AddAttendanceData(AttendanceData ad)
- {
- string sql = "insert into AttendanceData values('" + ad.UserNumber + "','" + ad.SwipeDate + "','" + ad.SwipeTime + "','')";
- if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text) > 0)
- return true;
- return false;
- }
- /// <summary>
- /// 更改打卡时间
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public bool DelAttendanceData(int id)
- {
- string sql = "Delete AttendanceData where Id = @Id";
- if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, new SqlParameter("@Id", id)) > 0)
- return true;
- return false;
- }
- /// <summary>
- /// 获取所有请假列表
- /// </summary>
- /// <param name="uid"></param>
- /// <param name="yearMonth"></param>
- /// <param name="UpCardType"></param>
- /// <returns></returns>
- public DataTable GetLeaveList(int uid, string yearMonth, int UpCardType, int pageIndex, int pageSize, out int sumPage, out int totalRecord)
- {
- SqlParameter[] parameters = new SqlParameter[] {
- new SqlParameter("@pageIndex", pageIndex),
- new SqlParameter("@pageSize", pageSize),
- new SqlParameter("@uid",uid),
- new SqlParameter("@yearMonth",yearMonth),
- new SqlParameter("@UpCardType",UpCardType)
- };
- DataTable dt = SqlHelper.TransferProcedure("[dbo].[UpCard_Hourse]", CommandType.StoredProcedure, parameters);
- parameters = null;
- //查询总条数
- SqlParameter[] para = new SqlParameter[] {
- new SqlParameter("@pageIndex", pageIndex),
- new SqlParameter("@pageSize", pageSize),
- new SqlParameter("@uid",uid),
- new SqlParameter("@yearMonth",yearMonth),
- new SqlParameter("@UpCardType",UpCardType)
- };
- DataTable counts = SqlHelper.TransferProcedure("[dbo].[UpCard_Hourse_count]", CommandType.StoredProcedure, para);
- if (counts != null && counts.Rows.Count > 0)
- totalRecord = Convert.ToInt32(counts.Rows[0]["c"]);
- else
- totalRecord = 0;
- //计算出总页数
- sumPage = totalRecord % 15 == 0 ? totalRecord / 15 : totalRecord / 15 + 1;
- return dt;
- }
- /// <summary>
- /// 查询该年度请假次数
- /// </summary>
- /// <param name="uid"></param>
- /// <param name="yearMonth"></param>
- /// <param name="UpCardType"></param>
- /// <returns></returns>
- public string GetLeaveCountY(int uid, string yearMonth, int UpCardType)
- {
- SqlParameter[] parameters = new SqlParameter[] {
- new SqlParameter("@uid",uid),
- new SqlParameter("@yearMonth",yearMonth),
- new SqlParameter("@UpCardType",UpCardType)
- };
- DataTable dt = SqlHelper.TransferProcedure("[dbo].[UpCard_Years_count]", CommandType.StoredProcedure, parameters);
- if (dt != null && dt.Rows.Count > 0)
- return dt.Rows[0]["c"].ToString();
- else
- return "0";
- }
- /// <summary>
- /// 查询考勤日
- /// </summary>
- /// <param name="userNumber"></param>
- /// <param name="start"></param>
- /// <param name="end"></param>
- /// <returns></returns>
- public List<AttendanceData> GetByZB(string userNumber, string start, string end)
- {
- string sql = "select * from AttendanceData where UserNumber=@UserNumber and (SwipeDate between @start and @end) order by SwipeDate asc";
- SqlParameter[] parameter = new SqlParameter[]{
- new SqlParameter("@UserNumber",userNumber),
- new SqlParameter("@start",start),
- new SqlParameter("@end",end)
- };
- return excuteSql(sql, parameter);
- }
- }
- }
|