123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- 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
- {
- /// <summary>
- /// 查询所有
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回集合</returns>
- List<UpCardAuditContent> excuteSql(string sql, params SqlParameter[] param)
- {
- return ServiceBase<UpCardAuditContent>.excuteSql(new UpCardAuditContent(), "UpCardAuditContent", sql, CommandType.Text, param);
- }
- /// <summary>
- /// 获取单个对象
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回空或者单个对象</returns>
- UpCardAuditContent excuteType(string sql, params SqlParameter[] param)
- {
- //查询结果放入对象集合
- List<UpCardAuditContent> cList = excuteSql(sql, param);
- //判断集合是否为空
- if (cList == null || cList.Count == 0)
- //返回null
- return null;
- //返回单个对象
- return cList[0];
- }
- /// <summary>
- /// 根据编号查询对象信息
- /// </summary>
- /// <param name="id">对象编号</param>
- /// <returns>返回空或者单个对象信息</returns>
- public UpCardAuditContent GetUpCardAuditContentByID(int id)
- {
- //调用获取单个对象的方法
- return excuteType("select * from UpCardAuditContent where Id = @id and IsDel = 0", new SqlParameter("@id", id));
- }
- /// <summary>
- /// 根据外键编号查询数据集合
- /// </summary>
- /// <param name="uCAid"></param>
- /// <returns></returns>
- public List<UpCardAuditContent> GetUpCardAuditContent(int uCAid)
- {
- return excuteSql("select * from UpCardAuditContent where IsDel = 0 and UCAid = @UCAid", new SqlParameter("@UCAid", uCAid));
- }
- /// <summary>
- /// 根据外键编号查询数据集合
- /// </summary>
- /// <param name="uCAid"></param>
- /// <returns></returns>
- public UpCardAuditContent GetByUCAID(int uCAid)
- {
- return excuteType("select * from UpCardAuditContent where IsDel = 0 and UCAid = @UCAid", new SqlParameter("@UCAid", uCAid));
- }
- /// <summary>
- /// 根据条件查询数据
- /// </summary>
- /// <param name="upCardDate"></param>
- /// <returns></returns>
- public UpCardAuditContent GetUpCardAuditContent(string upCardDate)
- {
- return excuteType("select * from UpCardAuditContent where IsDel = 0 and UpCardDate = @upCardDate", new SqlParameter("@UpCardDate", upCardDate));
- }
- /// <summary>
- /// 根据条件查询数据集合
- /// </summary>
- /// <param name="upCardDate"></param>
- /// <returns></returns>
- public List<UpCardAuditContent> GetUpCardAuditContentList(string upCardDate)
- {
- return excuteSql("select * from UpCardAuditContent where IsDel = 0 and UpCardDate = @upCardDate", new SqlParameter("@UpCardDate", upCardDate));
- }
- /// <summary>
- /// 根据条件查询数据集合
- /// </summary>
- /// <param name="upCardDate"></param>
- /// <returns></returns>
- public List<UpCardAuditContent> 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");
- }
- /// <summary>
- /// 批量添加方法
- /// </summary>
- /// <param name="list"></param>
- /// <returns></returns>
- public bool AddUpCardAuditContent(List<UpCardAuditContent> 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;
- }
- }
- /// <summary>
- /// 批量编辑方法
- /// </summary>
- /// <param name="list"></param>
- /// <returns></returns>
- public bool UpdateUpCardAuditContent(List<UpCardAuditContent> 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;
- }
- }
- /// <summary>
- /// 删除方法
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- 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;
- }
- }
- }
|