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 ForeignReceivablesService
{
///
/// 查询所有
///
/// sql语句
/// 可变参数数组
/// 返回集合
List excuteSql(string sql, params SqlParameter[] param)
{
return ServiceBase.excuteSql(new ForeignReceivables(), "ForeignReceivables", sql, CommandType.Text, param);
}
///
/// 获取单个对象
///
/// sql语句
/// 可变参数数组
/// 返回空或者单个对象
ForeignReceivables excuteType(string sql, params SqlParameter[] param)
{
//查询结果放入对象集合
List ioaList = excuteSql(sql, param);
//判断集合是否为空
if (ioaList == null || ioaList.Count == 0)
//返回null
return null;
//返回单个对象
return ioaList[0];
}
///
/// 根据编号查询对象信息
///
/// 对象编号
/// 返回空或者单个对象信息
public ForeignReceivables GetForeignReceivablesByDIId(int DIId)
{
//调用获取单个对象的方法
return excuteType("select * from ForeignReceivables where DIId = @DIId and isdel = 0", new SqlParameter("@DIId", DIId));
}
///
/// 根据编号和添加模块 查询对象信息
///
/// 对象编号
/// 返回空或者单个对象信息
public ForeignReceivables GetForeignReceivablesByDIId(int DIId,int AddingWay)
{
//调用获取单个对象的方法
return excuteType("select * from ForeignReceivables where DIId = @DIId and AddingWay = @AddingWay and isdel = 0", new SqlParameter("@DIId", DIId), new SqlParameter("@AddingWay", AddingWay));
}
///
/// 根据编号查询对象信息 - 集合
///
/// 对象编号
/// 返回空或者对象集合信息
public List GetAllByDIId(int DIId)
{
//调用获取单个对象的方法
return excuteSql("select * from ForeignReceivables where DIId = @DIId", new SqlParameter("@DIId", DIId));
}
///
/// 批量添加方法
///
///
///
public bool AddUpCardAuditContent(List list)
{
SqlCommand cmd = SqlHelper.createCon().CreateCommand();
cmd.Connection.Open();
//SqlTransaction trans = cmd.Connection.BeginTransaction();
try
{
foreach (ForeignReceivables fr in list)
{
cmd.CommandText = "insert into ForeignReceivables values("+fr.Id+"," + fr.DIId + ",'" + fr.PriceName + "'," + fr.Price + "," + fr.Count + ",'" + fr.Unit + "'," + fr.ItemSumPrice + ",'" + fr.To + "','" + fr.ToTel + "','" + fr.PayDate + "','" + fr.Attention + "'," + fr.Operators + ",'" + fr.OperatorsDate + "'," + fr.IsDel +","+fr.Rate+",'"+fr.Currency+ "','" + fr.AddingWay + "')";
cmd.ExecuteNonQuery();
}
//trans.Commit();
cmd.Connection.Close();
return true;
}
catch
{
//trans.Rollback();
cmd.Connection.Close();
return false;
}
}
///
/// 删除
///
///
///
public bool DelForeignReceivables(int DIId)
{
if (SqlHelper.ExecuteNonQuery("delete ForeignReceivables where DIId = @DIId", CommandType.Text, new SqlParameter("@DIId", DIId)) > 0)
return true;
return false;
}
public float GetSumForForeignReceivables(int diid)
{
object o=SqlHelper.ExecuteScalar("select sum(ItemSumPrice) from ForeignReceivables where isdel = 0 and diid="+diid,CommandType.Text,null);
if (o != null && o.ToString()!="")
return float.Parse(o.ToString());
else
return 0;
}
///
/// 获取所有收款信息(应收、已收)
///
///
///
public DataTable getAllForReceivables(int diid)
{
DataTable dt = SqlHelper.TransferProcedure("[dbo].[exec_ReceviedAccount]", CommandType.StoredProcedure, new SqlParameter("@diid", diid));
if (dt != null)
return dt;
return null;
}
///
/// 查询应收款项最大id
///
///
public int GetMaxID()
{
object result = SqlHelper.ExecuteScalar("select max(id) from ForeignReceivables", CommandType.Text, null);
if (result != null)
return Convert.ToInt32(result);
else
return 0;
}
}
}