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 IncreasePaymentsService
{
///
/// 查询所有
///
/// sql语句
/// 可变参数数组
/// 返回集合
List excuteSql(string sql, params SqlParameter[] param)
{
return ServiceBase.excuteSql(new IncreasePayments(), "IncreasePayments", sql, CommandType.Text, param);
}
///
/// 获取单个对象
///
/// sql语句
/// 可变参数数组
/// 返回空或者单个对象
IncreasePayments excuteType(string sql, params SqlParameter[] param)
{
//查询结果放入对象集合
List IncreasePaymentsList = excuteSql(sql, param);
//判断集合是否为空
if (IncreasePaymentsList == null || IncreasePaymentsList.Count == 0)
//返回null
return null;
//返回单个对象
return IncreasePaymentsList[0];
}
///
/// 根据编号查询对象信息
///
/// 对象编号
/// 返回空或者单个对象信息
public IncreasePayments GetIncreasePaymentsByID(int id)
{
//调用获取单个对象的方法
return excuteType("select * from IncreasePayments where Id = @id", new SqlParameter("@id", id));
}
///
/// 获取全部有效数据
///
///
public List GetAll()
{
return excuteSql("select * from IncreasePayments Where IsDel = 0");
}
///
/// 获取信息
///
///
public double GetSumMoney(int uid, string yearMonth)
{
object obj = SqlHelper.ExecuteScalar("select sum([money]) from IncreasePayments where isDel = 0 and userId = " + uid + " and yearMonth = '" + yearMonth + "'", CommandType.Text);
double sumMoney = 0;
if(obj!=null && !string.IsNullOrEmpty(obj.ToString()))
sumMoney = Convert.ToDouble(obj);
//调用获取单个对象的方法
return sumMoney;
}
///
/// 根据条件查询条件获取 - 分页
///
///
///
///
///
///
///
public List GetAll(int pageIndex, out int sumPage, out int totalRecord, string yearMonth, string increaseType,string userId)
{
string sqlwhere;
if (userId != "0")
{
sqlwhere = "YearMonth = '" + yearMonth + "' and Sid = " + increaseType + " and UserId = " + userId + " and IsDel = 0";
}else
{
sqlwhere = "YearMonth = '" + yearMonth + "' and Sid = " + increaseType + " and IsDel = 0";
}
return PageBase.excutePageSql(new IncreasePayments(), "IncreasePayments", "IncreasePayments", "*", "id desc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
}
///
/// 新增
///
/// 对象
public bool AddIncreasePayments(IncreasePayments ip)
{
string sql = "insert into IncreasePayments values(@YearMonth,@UserId,@Sid,@OccurrenceDate,@Money,@Remark,@Operator,@OperatorDate,@IsDel)";
SqlParameter[] parameter = new SqlParameter[]{
new SqlParameter("@YearMonth",ip.YearMonths),
new SqlParameter("@UserId",ip.UserId),
new SqlParameter("@Sid",ip.Sid),
new SqlParameter("@OccurrenceDate",ip.OccurrenceDate),
new SqlParameter("@Money", ip.Money),
new SqlParameter("@Remark",ip.Remark),
new SqlParameter("@Operator",ip.Operators),
new SqlParameter("@OperatorDate",ip.OperatorsDate),
new SqlParameter("@IsDel",ip.IsDel)
};
if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
return true;
return false;
}
///
/// 编辑
///
///
///
public bool EditIncreasePayments(IncreasePayments ip)
{
string sql = "update IncreasePayments set YearMonth = @YearMonth,UserId = @UserId,Sid = @Sid,OccurrenceDate = @OccurrenceDate,Money = @Money,Remark = @Remark,Operator = @Operator,OperatorDate = @OperatorDate where Id = @Id";
SqlParameter[] parameter = new SqlParameter[]{
new SqlParameter("@YearMonth",ip.YearMonths),
new SqlParameter("@UserId",ip.UserId),
new SqlParameter("@Sid",ip.Sid),
new SqlParameter("@OccurrenceDate",ip.OccurrenceDate),
new SqlParameter("@Money", ip.Money),
new SqlParameter("@Remark",ip.Remark),
new SqlParameter("@Operator",ip.Operators),
new SqlParameter("@OperatorDate",ip.OperatorsDate),
new SqlParameter("@Id",ip.Id)
};
if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
return true;
return false;
}
///
/// 删除
///
///
///
public bool DelIncreasePayments(int id)
{
if (SqlHelper.ExecuteNonQuery("update IncreasePayments set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
return true;
return false;
}
}
}