using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Models;
using System.Data.SqlClient;
using System.Data;
namespace DAL
{
///
/// 考勤补卡数据访问类
///
public class UpCardAuditService
{
///
/// 查询所有
///
/// sql语句
/// 可变参数数组
/// 返回集合
List excuteSql(string sql, params SqlParameter[] param)
{
return ServiceBase.excuteSql(new UpCardAudit(), "UpCardAudit", sql, CommandType.Text, param);
}
///
/// 获取单个对象
///
/// sql语句
/// 可变参数数组
/// 返回空或者单个对象
UpCardAudit excuteType(string sql, params SqlParameter[] param)
{
//查询结果放入对象集合
List ucaList = excuteSql(sql, param);
//判断集合是否为空
if (ucaList == null || ucaList.Count == 0)
//返回null
return null;
//返回单个对象
return ucaList[0];
}
///
/// 根据编号查询对象信息
///
/// 对象编号
/// 返回空或者单个对象信息
public List GetUpCardAuditByYearMonth(int uid, string YearMonth)
{
//调用获取单个对象的方法
return excuteSql("select * from UpCardAudit where uid = @uid and YearMonth = @YearMonth and IsDel = 0 order by Id", new SqlParameter("@uid", uid), new SqlParameter("@YearMonth", YearMonth));
}
///
/// 根据编号查询对象信息
///
/// 对象编号
/// 返回空或者单个对象信息
public List GetYearMonth()
{
//调用获取单个对象的方法
return excuteSql("select * from UpCardAudit where IsDel = 0 order by Id desc");
}
///
/// 根据编号查询对象信息
///
/// 对象编号
/// 返回空或者单个对象信息
public UpCardAudit GetUpCardAuditByID(int id)
{
//调用获取单个对象的方法
return excuteType("select * from UpCardAudit where Id = @id and IsDel = 0", new SqlParameter("@id", id));
}
///
/// 根据条件获取数据集合
///
///
///
///
///
public List GetUpCardAudit(int pageIndex, out int sumPage, out int totalRecord, string yearMonth, string isAudit, string userid)
{
string sqlwhere = "YearMonth = '" + yearMonth + "' and IsDel = 0 and uid = " + userid + "";
if (isAudit == "0")
sqlwhere += " and (IsAudit = " + isAudit + " or IsAudit = 2)";
else
sqlwhere += " and IsAudit = 1";
return PageBase.excutePageSql(new UpCardAudit(), "UpCardAudit", "UpCardAudit", "*", "id desc", sqlwhere, 15, pageIndex, out sumPage, out totalRecord);
}
///
/// 新增
///
/// 对象
public bool AddUpCardAudit(UpCardAudit u, out int id)
{
string sql = "insert into UpCardAudit([Uid],[YearMonth],[ApplicationPeriod],[Attachment],[Subject],[IsAudit],[IsDel]) values(" + u.Uid + ",'" + u.YearMonth + "','" + u.ApplicationPeriod + "','" + u.Attachment + "','" + u.Subject + "'," + u.IsAudit + "," + u.IsDel + ");SELECT @@IDENTITY";
int obj = Convert.ToInt32(SqlHelper.ExecuteScalar(sql, CommandType.Text));
if (obj > 0)
{
id = obj;
return true;
}
id = 0;
return false;
}
///
/// 编辑
///
///
///
public bool UpdateUpCardAudit(UpCardAudit uca)
{
string Attachment = "";
if (!string.IsNullOrEmpty(uca.Attachment))
Attachment = ", Attachment = '" + uca.Attachment + "'";
string sql = "update UpCardAudit set ApplicationPeriod = @ApplicationPeriod " + Attachment + " , Subject = @Subject where id = @Id";
if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, new SqlParameter("@ApplicationPeriod", uca.ApplicationPeriod), new SqlParameter("@Subject", uca.Subject), new SqlParameter("@Id", uca.Id)) > 0)
return true;
return false;
}
///
/// 删除
///
///
///
public bool DelUpCardAudit(int id)
{
if (SqlHelper.ExecuteNonQuery("update UpCardAudit set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
return true;
return false;
}
///
/// 更改审核状态
///
///
///
///
///
///
///
public bool UpdeteIsAudit(int isAudit, string auditRemark, int operate, string operateTime, int id)
{
string sql = "update UpCardAudit set IsAudit = @IsAudit,AuditRemark=@AuditRemark,Operate=@Operate,OperateTime=@OperateTime where Id = @Id";
SqlParameter[] parameter = new SqlParameter[]{
new SqlParameter("@IsAudit",isAudit),
new SqlParameter("@AuditRemark",auditRemark),
new SqlParameter("@Operate",operate),
new SqlParameter("@OperateTime",operateTime),
new SqlParameter("@Id",id)
};
if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
return true;
return false;
}
public List GetError(int userId, string yearMonth)
{
string sql = "select * from UpCardAudit where uid = " + userId + " and YearMonth = '" + yearMonth + "' and Isdel=0 "
+ "AND Id NOT IN (select UCAid from UpCardAuditContent where Isdel=0 "
+ "AND UCAid IN (select Id from UpCardAudit where uid = " + userId + " and YearMonth = '" + yearMonth + "' and IsDel = 0))";
return excuteSql(sql);
}
}
}