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 DailyFeePaymentContentService
{
///
/// 查询所有
///
/// sql语句
/// 可变参数数组
/// 返回集合
List excuteSql(string sql, params SqlParameter[] param)
{
return ServiceBase.excuteSql(new DailyFeePaymentContent(), "DailyFeePaymentContent", sql, CommandType.Text, param);
}
///
/// 获取单个对象
///
/// sql语句
/// 可变参数数组
/// 返回空或者单个对象
DailyFeePaymentContent excuteType(string sql, params SqlParameter[] param)
{
//查询结果放入对象集合
List cdList = excuteSql(sql, param);
//判断集合是否为空
if (cdList == null || cdList.Count == 0)
//返回null
return null;
//返回单个对象
return cdList[0];
}
///
/// 根据编号查询对象信息
///
/// 对象编号
/// 返回空或者单个对象信息
public DailyFeePaymentContent GetDailyFeePaymentContentByID(int id)
{
//调用获取单个对象的方法
return excuteType("select * from DailyFeePaymentContent where Id = @id", new SqlParameter("@id", id));
}
///
/// 根据编号查询对象信息
///
/// 对象编号
/// 返回空或者单个对象信息
public List GetDailyFeePaymentContentByDFPID(int DFPID)
{
//调用获取单个对象的方法
return excuteSql("select * from DailyFeePaymentContent where DFPID = @DFPID ORDER BY ID", new SqlParameter("@DFPID", DFPID));
}
///
/// 增加
///
///
///
public bool AddDailyFeePaymentContent(List list)
{
SqlCommand cmd = SqlHelper.createCon().CreateCommand();
cmd.Connection.Open();
SqlTransaction trans = cmd.Connection.BeginTransaction();
try
{
foreach (DailyFeePaymentContent dfpc in list)
{
cmd.CommandText = "insert into DailyFeePaymentContent values(" + dfpc.DFPID + ",'" + dfpc.PriceName + "'," + dfpc.Count + "," + dfpc.Price + "," + dfpc.ItemSumPrice + ",'" + dfpc.Remark + "')";
cmd.ExecuteNonQuery();
}
trans.Commit();
cmd.Connection.Close();
return true;
}
catch
{
trans.Rollback();
cmd.Connection.Close();
return false;
}
}
///
/// 编辑
///
///
///
public bool EditDailyFeePaymentContent(DailyFeePaymentContent dfpc)
{
string sql = "update DailyFeePaymentContent set PriceName = @PriceName,Count = @Count,Price = @Price,ItemSumPrice = @ItemSumPrice,Remark = @Remark where Id = @Id";
SqlParameter[] parameter = new SqlParameter[] {
new SqlParameter("@PriceName",dfpc.PriceName),
new SqlParameter("@Count",dfpc.Count),
new SqlParameter("@Price",dfpc.Price),
new SqlParameter("@ItemSumPrice",dfpc.ItemSumPrice),
new SqlParameter("@Remark",dfpc.Remark),
new SqlParameter("@Id",dfpc.Id)
};
if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
return true;
return false;
}
///
/// 删除
///
///
///
public bool DelDailyFeePaymentContent(int id)
{
if (SqlHelper.ExecuteNonQuery("delete DailyFeePaymentContent where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
return true;
return false;
}
///
/// 删除
///
///
///
public bool DelDailyFeePaymentContentByDFPID(int DFPID)
{
if (SqlHelper.ExecuteNonQuery("delete DailyFeePaymentContent where DFPID = @DFPID", CommandType.Text, new SqlParameter("@DFPID", DFPID)) > 0)
return true;
return false;
}
///
/// LiuChengYi 2014/4/25
/// 日常支付金额
///
///
///
///
public Double DelDailyFeePaymentContentByDateTime(string startTime, string endTime)
{
double DailyExpensesMoney;
SqlParameter[] pars =
{
new SqlParameter("@startTime",startTime),
new SqlParameter("@endTime",endTime)
};
DataTable dt = SqlHelper.TransferProcedure("dailyFeePaymentContent_Report", CommandType.StoredProcedure, pars);
if (dt.Rows.Count > 0)
{
if (dt.Rows[0][0].ToString() != null && dt.Rows[0][0].ToString() != "")
{
DailyExpensesMoney = Convert.ToDouble(dt.Rows[0][0].ToString());
}
else
{
DailyExpensesMoney = 0;
}
}
else
{
DailyExpensesMoney = 0;
}
return DailyExpensesMoney;
}
}
}