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 UpCardAuditContentService { /// /// 查询所有 /// /// sql语句 /// 可变参数数组 /// 返回集合 List excuteSql(string sql, params SqlParameter[] param) { return ServiceBase.excuteSql(new UpCardAuditContent(), "UpCardAuditContent", sql, CommandType.Text, param); } /// /// 获取单个对象 /// /// sql语句 /// 可变参数数组 /// 返回空或者单个对象 UpCardAuditContent excuteType(string sql, params SqlParameter[] param) { //查询结果放入对象集合 List cList = excuteSql(sql, param); //判断集合是否为空 if (cList == null || cList.Count == 0) //返回null return null; //返回单个对象 return cList[0]; } /// /// 根据编号查询对象信息 /// /// 对象编号 /// 返回空或者单个对象信息 public UpCardAuditContent GetUpCardAuditContentByID(int id) { //调用获取单个对象的方法 return excuteType("select * from UpCardAuditContent where Id = @id and IsDel = 0", new SqlParameter("@id", id)); } /// /// 根据外键编号查询数据集合 /// /// /// public List GetUpCardAuditContent(int uCAid) { return excuteSql("select * from UpCardAuditContent where IsDel = 0 and UCAid = @UCAid", new SqlParameter("@UCAid", uCAid)); } /// /// 根据外键编号查询数据集合 /// /// /// public UpCardAuditContent GetByUCAID(int uCAid) { return excuteType("select * from UpCardAuditContent where IsDel = 0 and UCAid = @UCAid", new SqlParameter("@UCAid", uCAid)); } /// /// 根据条件查询数据 /// /// /// public UpCardAuditContent GetUpCardAuditContent(string upCardDate) { return excuteType("select * from UpCardAuditContent where IsDel = 0 and UpCardDate = @upCardDate", new SqlParameter("@UpCardDate", upCardDate)); } /// /// 根据条件查询数据集合 /// /// /// public List GetUpCardAuditContentList(string upCardDate) { return excuteSql("select * from UpCardAuditContent where IsDel = 0 and UpCardDate = @upCardDate", new SqlParameter("@UpCardDate", upCardDate)); } /// /// 根据条件查询数据集合 /// /// /// public List GetContentList(string yearmonth, string number,string date) { return excuteSql("SELECT ucc.* FROM UpCardAuditContent ucc JOIN UpCardAudit uc ON ucc.UCAid=uc.Id JOIN Users us ON us.Id=uc.uid where ucc.IsDel=0 AND uc.IsDel=0 and us.Number=" + number + " AND uc.YearMonth='" + yearmonth + "' And ucc.UpCardDate='" + date + "' ORDER BY ucc.UpCardDate"); } /// /// 批量添加方法 /// /// /// public bool AddUpCardAuditContent(List list) { SqlCommand cmd = SqlHelper.createCon().CreateCommand(); cmd.Connection.Open(); SqlTransaction trans = cmd.Connection.BeginTransaction(); try { foreach (UpCardAuditContent u in list) { cmd.CommandText = "insert into UpCardAuditContent values(" + u.UCAid + "," + u.Did + ",'" + u.UpCardDate + "','" + u.UpCardPeriod + "'," + u.UpCardHours + "," + u.IsDel + ")"; cmd.ExecuteNonQuery(); } trans.Commit(); cmd.Connection.Close(); return true; } catch { trans.Rollback(); cmd.Connection.Close(); return false; } } /// /// 批量编辑方法 /// /// /// public bool UpdateUpCardAuditContent(List list) { SqlCommand cmd = SqlHelper.createCon().CreateCommand(); cmd.Connection.Open(); SqlTransaction trans = cmd.Connection.BeginTransaction(); try { foreach (UpCardAuditContent u in list) { cmd.CommandText = "update UpCardAuditContent set Did = " + u.Did + " , UpCardDate = '" + u.UpCardDate + "' , UpCardPeriod = '" + u.UpCardPeriod + "' , UpCardHours= " + u.UpCardHours + " where id = " + u.Id + ""; cmd.ExecuteNonQuery(); } trans.Commit(); cmd.Connection.Close(); return true; } catch { trans.Rollback(); cmd.Connection.Close(); return false; } } /// /// 删除方法 /// /// /// public bool DelUpcardAuditContent(int id) { if (SqlHelper.ExecuteNonQuery("update UpcardAuditContent set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0) return true; return false; } public bool add(UpCardAuditContent u) { if (SqlHelper.ExecuteNonQuery("insert into UpCardAuditContent values(" + u.UCAid + "," + u.Did + ",'" + u.UpCardDate + "','" + u.UpCardPeriod + "'," + u.UpCardHours + "," + u.IsDel + ")", CommandType.Text) > 0) return true; return false; } } }