using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; using Models; using System.Data; using System.Runtime.InteropServices.ComTypes; using System.Security.Cryptography; namespace DAL { /// /// 加班申请数据访问层 /// public class OvertimeApplicationService { /// /// 新增考勤补卡 /// /// /// public bool AddOvertimeApplication(OvertimeApplication ota) { string sql = "INSERT INTO OvertimeApplication(UID,OverDate,StardTime,EndTime,ObjectiveTime,SubjectiveTime,Reason,MAudio,IsAudio,AudioMan,AudioTime,Remark,IsDel,Did,OvertimeType)" + " VALUES(@UID,@OverDate,@StardTime,@EndTime,@ObjectiveTime,@SubjectiveTime,@Reason,@MAudio,@IsAudio,@AudioMan,@AudioTime,@Remark,@IsDel,@Did,@OvertimeType)"; SqlParameter[] parameter = new SqlParameter[]{ new SqlParameter("@UID",ota.UID), new SqlParameter("@OverDate",ota.OverDate), new SqlParameter("@StardTime",ota.StardTime), new SqlParameter("@EndTime",ota.EndTime), new SqlParameter("@ObjectiveTime",ota.ObjectiveTime), new SqlParameter("@SubjectiveTime",ota.SubjectiveTime), new SqlParameter("@Reason",ota.Reason), new SqlParameter("@MAudio",ota.MAudio), new SqlParameter("@IsAudio",ota.IsAudio), new SqlParameter("@AudioMan",ota.AudioMan), new SqlParameter("@AudioTime",ota.AudioTime), new SqlParameter("@Remark",ota.Remark), new SqlParameter("@IsDel",ota.IsDel), new SqlParameter("@Did",ota.Did), new SqlParameter("@OvertimeType",ota.OvertimeType) }; if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) <= 0) return false; return true; } /// /// 根据用户ID,人事审核状态查询 /// 获取全部有效新增考勤补卡数据 /// /// public List GetAll(int UID, DateTime StartDate, DateTime EndDate, int IsAudio, int MAudit, int Did, int OvertimeType) { string sql = "select * from OvertimeApplication Where Uid = '" + UID + "' and (OverDate >= '" + StartDate + "' and OverDate <='" + EndDate + "') " + "and IsAudio=" + IsAudio + " and MAudio =" + MAudit + " and IsDel = 0"; if (OvertimeType != 0) sql = sql + " and OvertimeType = " + OvertimeType; return excuteSql(sql); } /// /// 根据用户ID,起止时间,人事审核状态,经理审核状态,团组did查询 /// 根据条件查询条件获取 - 分页 /// /// /// /// /// /// public List GetAll(int pageIndex, out int sumPage, out int totalRecord, int UID, DateTime StartDate, DateTime EndDate, int IsAudio, int MAudit, int Did, int userID, int OvertimeType) { string sqlcmd = "select * from OvertimeApplication where MAudio=" + MAudit + " and IsAudio=" + IsAudio + " and (OverDate between '" + StartDate + "' and '" + EndDate + "')" + " and IsDel=0"; if (UID > 0) { sqlcmd = sqlcmd + " and UID = " + UID; } if (Did > 0 && Did != 99 && Did != 3) { sqlcmd = sqlcmd + " and Did=" + Did; } string sqlwhere = ""; //"1=1 and OverDate >= '"+StartDate+"' and OverDate <='"+EndDate+"' and IsAudio="+IsAudio; //if (UID > 0 && UID!=21 && UID!=41) // sqlwhere = sqlwhere+" and UID = "+UID; //if (Did > 0 && Did!=99 && Did!=3) // sqlwhere = sqlwhere + " and Did=" + Did; //if (userID == 21) // sqlwhere = sqlwhere + " and UID in (10,16,18,22,37,5,11,41)"; //sqlwhere =sqlwhere+ " and IsDel = 0"; //if (Status == "Maudit") //{ sqlwhere = sqlwhere + "1=1 and OverDate >= '" + StartDate + "' and OverDate <='" + EndDate + "' and MAudio=" + MAudit + "and IsAudio=" + IsAudio; //} //else //{ //sqlwhere = sqlwhere + "1=1 and OverDate >= '" + StartDate + "' and OverDate <='" + EndDate + "'and IsAudio=" + IsAudio; //} if (UID > 0) { sqlwhere = sqlwhere + " and UID = " + UID; } if (Did > 0 && Did != 99 && Did != 3) { sqlwhere = sqlwhere + " and Did=" + Did; } if (OvertimeType != 0) { sqlwhere = sqlwhere + " and OvertimeType=" + OvertimeType; } sqlwhere = sqlwhere + " and IsDel = 0"; return PageBase.excutePageSql(new OvertimeApplication(), "OvertimeApplication", "OvertimeApplication", "*", "id desc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord); } /// /// 根据用户ID,起止时间,人事审核状态,未知status,未知did查询 /// 根据条件查询条件获取 - 分页 /// /// /// /// /// /// public List GetAll(int pageIndex, out int sumPage, out int totalRecord, int UID, DateTime StartDate, DateTime EndDate, int IsAudio, int Did, int userID) { string sqlwhere = "1=1 and OverDate >= '" + StartDate + "' and OverDate <='" + EndDate + "' and IsAudio=" + IsAudio; //if (UID > 0 && UID!=21 && UID!=41) // sqlwhere = sqlwhere+" and UID = "+UID; //if (Did > 0 && Did!=99 && Did!=3) // sqlwhere = sqlwhere + " and Did=" + Did; //if (userID == 21) // sqlwhere = sqlwhere + " and UID in (10,16,18,22,37,5,11,41)"; //sqlwhere =sqlwhere+ " and IsDel = 0"; if (UID > 0) { sqlwhere = sqlwhere + " and UID = " + UID; } if (Did > 0 && Did != 99 && Did != 3) sqlwhere = sqlwhere + " and Did=" + Did; sqlwhere = sqlwhere + " and IsDel = 0"; return PageBase.excutePageSql(new OvertimeApplication(), "OvertimeApplication", "OvertimeApplication", "*", "id desc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord); } /// /// 根据用户ID,起止时间查询 /// 根据条件查询条件获取 - 所有 /// /// /// /// /// /// public double GetAll(int did, int uid, string startDate, string endDate) { SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("@did",did), new SqlParameter("@uid",uid), new SqlParameter("@startTime",startDate), new SqlParameter("@endTime",endDate) }; DataTable dt = SqlHelper.TransferProcedure("Leavel_Hourse_Count", CommandType.StoredProcedure, parameter); if (dt != null && dt.Rows.Count > 0) { try { return Convert.ToDouble(dt.Rows[0]["Hourse"]); } catch { return 0.00; } } else return 0.00; } //public double GetJBDX(int uid, string startDate, string endDate) { // string sql="select sum(ucac.UpCardHours) as JBDXT from UpCardAudit ucajoin UpCardAuditContent ucac on uca.id = ucac.UCAid where uca.isDel = 0 and ucac.isdel=0 and ucac.Did = 281 and isAudit = 1 and uid ="+ uid +"and (uca.YearMonth between '"+ startDate +" and '"+ endDate +"')"; // SqlHelper.ExecuteNonQuery(sql, CommandType.Text, null); // return 0.00; //} /// ///加班抵休或者年假抵休的时间 /// /// 抵休原因 /// 用户ID /// 起始日 /// 终止日 /// public double GetDX(int did, int uid, string startDate, string endDate) { SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("@did",did), new SqlParameter("@uid",uid), new SqlParameter("@startTime",startDate), new SqlParameter("@endTime",endDate) }; DataTable dt = SqlHelper.TransferProcedure("JBDX_Count", CommandType.StoredProcedure, parameter); if (dt != null && dt.Rows.Count > 0) { try { return Convert.ToDouble(dt.Rows[0]["Xtime"]); } catch { return 0.00; } } else return 0.00; } /// /// 逻辑删除 /// /// public bool DelOvertimeApplication(int id) { string sql = "delete from OvertimeApplication where id=" + id; if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, null) > 0) return true; return false; } /// /// 根据数据ID查询 /// /// /// public OvertimeApplication GetAllByID(int id) { string sql = "select * from OvertimeApplication where id=" + id; return excuteType(sql, null); } /// /// 查询所有 /// /// sql语句 /// 可变参数数组 /// 返回集合 List excuteSql(string sql, params SqlParameter[] param) { return ServiceBase.excuteSql(new OvertimeApplication(), "OvertimeApplication", sql, CommandType.Text, param); } /// /// 获取单个对象 /// /// sql语句 /// 可变参数数组 /// 返回空或者单个对象 OvertimeApplication excuteType(string sql, params SqlParameter[] param) { //查询结果放入对象集合 List cList = excuteSql(sql, param); //判断集合是否为空 if (cList == null || cList.Count == 0) //返回null return null; //返回单个对象 return cList[0]; } /// /// 修改加班申请 /// /// /// public bool EditOvertimeApplication(OvertimeApplication oat, int id) { string sql = "update OvertimeApplication set OverDate=@OverDate,StardTime=@StardTime,EndTime=@EndTime,ObjectiveTime=@ObjectiveTime,SubjectiveTime=@SubjectiveTime,Reason=@Reason,Remark=@Remark,Did=@Did,OvertimeType=@OvertimeType where ID=" + id; SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("@OverDate",oat.OverDate), new SqlParameter("@StardTime",oat.StardTime), new SqlParameter("@ObjectiveTime",oat.ObjectiveTime), new SqlParameter("@SubjectiveTime",oat.SubjectiveTime), new SqlParameter("@EndTime",oat.EndTime), new SqlParameter("@Reason",oat.Reason), new SqlParameter("@Remark",oat.Remark), new SqlParameter("@Did",oat.Did), new SqlParameter("@OvertimeType",oat.OvertimeType) }; if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0) return true; return false; } /// /// 人事审核 /// /// /// /// public bool AuditOvertimeApplication(int state, int id, string name, DateTime Now) { string sql = "update OvertimeApplication set IsAudio=" + state + " ,AudioMan='" + name + "',AudioTime='" + Now + "' where ID=" + id; if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, null) > 0) return true; return false; } /// /// 部门经理审核 /// /// /// /// /// /// public bool Maudit(int state, int id, string name, DateTime Now) { string sql = "update OvertimeApplication set MAudio=" + state + " ,AudioMan='" + name + "',AudioTime='" + Now + "' where ID=" + id; if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, null) > 0) return true; return false; } public List GetAfterSixMonth() { return excuteSql("select * from OvertimeApplication WHERE iSDEL = 0 and OverDate>= '2021-06-01' order by OverDate"); //return excuteSql("select * from OvertimeApplication Where (OverDate >= '" + StartDate + "' and OverDate <='" + EndDate + "') " + "and IsAudio=" + IsAudio + " and MAudio =" + MAudit + " and IsDel = 0"); } public List GetUnreviewedOvertime(string uids) { string sql = " select * from OvertimeApplication where isdel = 0 and isAudio = 0 and uid in("+ uids +")"; return excuteSql(sql); } } }