using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Models;
using System.Data;
using System.Data.SqlClient;
namespace DAL
{
///
/// 团组客户保险数据访问类
///
public class GroupsCustomersService
{
///
/// 查询所有
///
/// sql语句
/// 可变参数数组
/// 返回集合
List excuteSql(string sql, params SqlParameter[] param)
{
return ServiceBase.excuteSql(new GroupsCustomers(), "GroupsCustomers", sql, CommandType.Text, param);
}
///
/// 获取单个对象
///
/// sql语句
/// 可变参数数组
/// 返回空或者单个对象
GroupsCustomers excuteType(string sql, params SqlParameter[] param)
{
//查询结果放入对象集合
List gcList = excuteSql(sql, param);
//判断集合是否为空
if (gcList == null || gcList.Count == 0)
//返回null
return null;
//返回单个对象
return gcList[0];
}
///
/// 根据编号查询对象信息
///
/// 对象编号
/// 返回空或者单个对象信息
public GroupsCustomers GetGroupsCustomersByID(int id)
{
//调用获取单个对象的方法
return excuteType("select * from GroupsCustomers where Id = @id and isdel=0", new SqlParameter("@id", id));
}
///
/// 获取全部 - 分页
///
///
public List GetGroupsCustomers(int pageIndex, out int sumPage, out int totalRecord, string tourCode, string clientName)
{
string sqlwhere = "IsDel = 0 and DIId = '" + tourCode + "' and ClientName like '%" + clientName + "%'";
return PageBase.excutePageSql(new GroupsCustomers(), "GroupsCustomers", "GroupsCustomers", "*", "id desc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
}
///
/// 增加
///
///
public bool AddGroupsCustomers(GroupsCustomers v, out int id)
{
string sql = "insert into GroupsCustomers values(@DIId,@ClientName,@InsuranceCosts,@Currency,@Attachment,@Remark,@Operator,@OperatorDate,@IsDel,@Iid);SELECT @@IDENTITY";
SqlParameter[] parameter = new SqlParameter[]{
new SqlParameter("@DIId",v.DIId),
new SqlParameter("@ClientName",v.ClientName),
new SqlParameter("@InsuranceCosts",v.InsuranceCosts),
new SqlParameter("@Currency",v.Currency),
new SqlParameter("@Attachment",v.Attachment),
new SqlParameter("@Remark",v.Remark),
new SqlParameter("@Operator",v.Operators),
new SqlParameter("@OperatorDate",v.OperatorsDate),
new SqlParameter("@IsDel",v.IsDel),
new SqlParameter("@Iid",v.Iid)
};
int obj = Convert.ToInt32(SqlHelper.ExecuteScalar(sql, CommandType.Text, parameter));
if (obj > 0)
{
id = obj;
return true;
}
id = 0;
return false;
}
///
/// 编辑
///
///
public bool EditGroupsCustomers(GroupsCustomers v)
{
string sql = "update GroupsCustomers set DIId = @DIId,ClientName = @ClientName,InsuranceCosts = @InsuranceCosts,Currency = @Currency,Attachment = @Attachment,Remark = @Remark,Operator = @Operator,OperatorDate = @OperatorDate,Iid =@Iid where Id = @Id";
SqlParameter[] parameter = new SqlParameter[]{
new SqlParameter("@DIId",v.DIId),
new SqlParameter("@ClientName",v.ClientName),
new SqlParameter("@InsuranceCosts",v.InsuranceCosts),
new SqlParameter("@Currency",v.Currency),
new SqlParameter("@Attachment",v.Attachment),
new SqlParameter("@Remark",v.Remark),
new SqlParameter("@Operator",v.Operators),
new SqlParameter("@OperatorDate",v.OperatorsDate),
new SqlParameter("@Iid",v.Iid),
new SqlParameter("@Id",v.Id)
};
if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
return true;
return false;
}
///
/// 删除
///
///
///
public bool DelGroupsCustomers(int id)
{
if (SqlHelper.ExecuteNonQuery("update GroupsCustomers set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
return true;
return false;
}
public double GetByIid(int Iid)
{
string sql = "select sum(InsuranceCosts) from GroupsCustomers where Iid = " + Iid + "";
object obj = SqlHelper.ExecuteScalar(sql, CommandType.Text);
if (obj != null)
{
if (!string.IsNullOrEmpty(obj.ToString()))
{
double value = (double)obj;
return value;
}
else
return 0;
}
else
return 0;
}
///
/// 保险费用 - 分页
///
///
public List GetGroupsCustomersByDid(int pageIndex, out int sumPage, out int totalRecord, string tourCode)
{
string sqlwhere = "IsDel = 0 and Iid = '" + tourCode + "'";
return PageBase.excutePageSql(new GroupsCustomers(), "GroupsCustomers", "GroupsCustomers", "*", "id desc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
}
}
}