using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CY.IDAL;
using System.Data.SqlClient;
using System.Data;
using CY.Model;
using System.Transactions;
namespace CY.SQLDAL
{
public class EC_PaymentRecordDAL : IEC_PaymentRecordDAL
{
private Database _dataBase = null;
public EC_PaymentRecordDAL()
{
_dataBase = new Database();
}
public EC_PaymentRecordDAL(Database dDatabase)
{
_dataBase = dDatabase;
}
///
/// 新增
///
///
///
public bool InserModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.EC_PaymentRecord trueModel = model as Model.EC_PaymentRecord;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{
new SqlParameter("@PayType",trueModel.PayType),
new SqlParameter("@Operator",trueModel.Operator),
new SqlParameter("@MemberId",trueModel.MemberId),
new SqlParameter("@MemberName",trueModel.MemberName),
new SqlParameter("@BusinessManagerId",trueModel.BusinessManagerId),
new SqlParameter("@AccountManagerId",trueModel.AccountManagerId),
new SqlParameter("@Contact",trueModel.Contact),
new SqlParameter("@CompanyPhone",trueModel.CompanyPhone),
new SqlParameter("@Email",trueModel.Email),
new SqlParameter("@QQ",trueModel.QQ),
new SqlParameter("@PayMoney",trueModel.PayMoney),
new SqlParameter("@PayAllMoney",trueModel.PayAllMoney),
new SqlParameter("@PayStartTime",trueModel.PayStartTime),
new SqlParameter("@PayEndTime",trueModel.PayEndTime),
new SqlParameter("@PayRole",trueModel.PayRole),
new SqlParameter("@LastUpdateTime",trueModel.LastUpdateTime),
new SqlParameter("@Remark",trueModel.Remark),
new SqlParameter("@SoftwarePermissions",trueModel.SoftwarePermissions),
new SqlParameter("@AdForum",trueModel.AdForum),
new SqlParameter("@AdLocation",trueModel.AdLocation),
new SqlParameter("@AdSize",trueModel.AdSize),
new SqlParameter("@AdImg",trueModel.AdImg),
new SqlParameter("@AdInstallments",trueModel.AdInstallments)
};
try
{
_dataBase.Query("sp_EC_PaymentRecord_Insert", CommandType.StoredProcedure, sqlParms.ToArray());
}
catch (Exception ex)
{
throw ex;
}
return true;
}
///
/// 修改
///
///
///
public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.EC_PaymentRecord trueModel = model as Model.EC_PaymentRecord;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{
new SqlParameter("@Keyid",trueModel.Keyid),
new SqlParameter("@PayType",trueModel.PayType),
new SqlParameter("@Operator",trueModel.Operator),
new SqlParameter("@MemberId",trueModel.MemberId),
new SqlParameter("@MemberName",trueModel.MemberName),
new SqlParameter("@BusinessManagerId",trueModel.BusinessManagerId),
new SqlParameter("@AccountManagerId",trueModel.AccountManagerId),
new SqlParameter("@Contact",trueModel.Contact),
new SqlParameter("@CompanyPhone",trueModel.CompanyPhone),
new SqlParameter("@Email",trueModel.Email),
new SqlParameter("@QQ",trueModel.QQ),
new SqlParameter("@PayMoney",trueModel.PayMoney),
new SqlParameter("@PayAllMoney",trueModel.PayAllMoney),
new SqlParameter("@PayStartTime",trueModel.PayStartTime),
new SqlParameter("@PayEndTime",trueModel.PayEndTime),
new SqlParameter("@PayRole",trueModel.PayRole),
new SqlParameter("@LastUpdateTime",trueModel.LastUpdateTime),
new SqlParameter("@Remark",trueModel.Remark),
new SqlParameter("@SoftwarePermissions",trueModel.SoftwarePermissions),
new SqlParameter("@AdForum",trueModel.AdForum),
new SqlParameter("@AdLocation",trueModel.AdLocation),
new SqlParameter("@AdSize",trueModel.AdSize),
new SqlParameter("@AdImg",trueModel.AdImg),
new SqlParameter("@AdInstallments",trueModel.AdInstallments)
};
try
{
_dataBase.Query("sp_EC_PaymentRecord_Update", CommandType.StoredProcedure, sqlParms.ToArray());
}
catch (Exception ex)
{
throw ex;
}
return true;
}
///
/// 删除
///
///
///
public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.EC_PaymentRecord trueModel = model as Model.EC_PaymentRecord;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{
new SqlParameter("@Keyid",trueModel.Keyid)
};
try
{
_dataBase.Query("sp_EC_PaymentRecord_DeleteRow", CommandType.StoredProcedure, sqlParms.ToArray());
}
catch (Exception ex)
{
throw ex;
}
return true;
}
///
/// 分页查询
///
///
///
///
public IEnumerable SelectModelPage(Infrastructure.Query.Query query, Infrastructure.Query.Pagination pagination)
{
throw new NotImplementedException();
}
///
/// 单个查询
///
///
///
public IEnumerable SelectAllModel(Infrastructure.Query.Query query)
{
throw new NotImplementedException();
}
///
/// 分页查询
///
///
///
///
///
///
///
///
///
///
///
public IEnumerable SelectAllModelPage(Infrastructure.Query.Pagination pagination, DateTime? StartTime, DateTime? EndTime, string Name, string MemberType, string OrderType, string Province, string City, string Country)
{
try
{
string condition = " 1=1 ";
if (StartTime != null)
condition += " And a.PayStartTime >= '" + StartTime + "' ";
if (EndTime != null)
condition += " And a.PayStartTime <= '" + EndTime.Value.AddDays(1) + "' ";
if (!string.IsNullOrEmpty(Name))
condition += " And a.MemberName like '%" + Name + "%' ";
if (!string.IsNullOrEmpty(MemberType))
condition += " And a.PayRole = '" + MemberType + "' ";
if (!string.IsNullOrEmpty(OrderType))
condition += " And a.PayType = '" + OrderType + "' ";
if (!string.IsNullOrEmpty(Province))
condition += " And b.Province = '" + Province + "' ";
if (!string.IsNullOrEmpty(City))
condition += " And b.City = '" + City + "' ";
if (!string.IsNullOrEmpty(Country))
condition += " And b.County = '" + Country + "' ";
IList result = _dataBase.SelectModelPage(pagination, " a.* ", " dbo.EC_PaymentRecord AS a LEFT JOIN dbo.EC_MemberBasic AS b ON a.MemberId=b.MemberId ", " a.LastUpdateTime desc ", " LastUpdateTime desc ", condition) as IList;//执行查询
return result;//返回结果
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 分页查询
///
///
///
///
///
///
///
///
public IEnumerable SelectAllModelPage(Infrastructure.Query.Pagination pagination, string StartTime, string EndTime, string OrderType, string selectProvince, string selectCity, string selectCounty)
{
IEnumerable list = null;
string selectTarget = " a.* ";
string fromSouce = " dbo.EC_PaymentRecord a INNER JOIN EC_MemberBasic b ON a.MemberId=b.MemberId ";
fromSouce += " where 1=1 and a.PayMoney>0 ";
if (!string.IsNullOrEmpty(OrderType))
fromSouce += " And a.PayType = '" + OrderType + "' ";
if (!string.IsNullOrEmpty(StartTime))
fromSouce += " And a.PayStartTime >= '" + StartTime + "' ";
if (!string.IsNullOrEmpty(EndTime))
fromSouce += " And a.PayStartTime < '" + EndTime + "' ";
if (!string.IsNullOrEmpty(selectProvince))
{
fromSouce += " and b.Province='" + selectProvince + "'";
}
if (!string.IsNullOrEmpty(selectCity))
{
fromSouce += " and b.City='" + selectCity + "'";
}
if (!string.IsNullOrEmpty(selectCounty))
{
fromSouce += " and b.County='" + selectCounty + "'";
}
list = _dataBase.SelectModelPage(pagination, selectTarget, fromSouce, " a.LastUpdateTime desc ", " LastUpdateTime desc ", string.Empty);
return list;
}
///
/// 新增
///
///
///
///
///
public bool AddModel(EC_PaymentRecord m_EC_PaymentRecord, EC_MemberBasic m_EC_MemberBasic, Sys_Permissions_UserRoleRelation m_Sys_Permissions_UserRoleRelation)
{
try
{
EC_PaymentRecordDAL dal_EC_PaymentRecordDAL = new EC_PaymentRecordDAL(_dataBase);
Sys_Permissions_UserRoleRelationDAL dal_Sys_Permissions_UserRoleRelation = new Sys_Permissions_UserRoleRelationDAL(_dataBase);
EC_MemberBasicDAL dal_EC_MemberBasicDAL = new EC_MemberBasicDAL(_dataBase);
Sys_Permissions_UserRoleRelation m_Sys_Permissions_UserRoleRelation_del = new Sys_Permissions_UserRoleRelation();
m_Sys_Permissions_UserRoleRelation_del = dal_Sys_Permissions_UserRoleRelation.SelectModel(m_EC_MemberBasic.MemberId);
bool result = false;
using (TransactionScope t_TransactionScope = new TransactionScope())
{
result = this.InserModel(m_EC_PaymentRecord);
if (result)
{
result = dal_EC_MemberBasicDAL.UpdateModel(m_EC_MemberBasic);
if (result)
{
if (m_Sys_Permissions_UserRoleRelation_del != null)
{
result = dal_Sys_Permissions_UserRoleRelation.DeleteModel(m_Sys_Permissions_UserRoleRelation_del);
}
if (result)
{
result = dal_Sys_Permissions_UserRoleRelation.InserModel(m_Sys_Permissions_UserRoleRelation);
if (result)
{
t_TransactionScope.Complete();
}
}
}
}
}
return result;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 根据编号获得信息
///
/// 编号
///
public EC_PaymentRecord GetModelByKeyid(int? Keyid)
{
try
{
if (Keyid == null || Keyid < 0)
return null;//错误数据返会空
IList result = _dataBase.SelectModel("*", "EC_PaymentRecord", string.Format(" Keyid='{0}'", Keyid)) as IList;//执行查询
return (null == result || result.Count == 0) ? null : result[0];//返回结果
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 获取新的订单编号
///
///
public string GetNewOrderId()
{
try
{
string OldNum = DateTime.Now.ToString("yyyyMMdd");
string NewNum = "";
IList result = _dataBase.SelectModel(" Top(1) * ", " EC_PaymentRecord ", string.Format(" Remark like '%{0}%' order by Keyid DESC ", OldNum)) as IList;//执行查询
if (result == null || result.Count == 0)
NewNum = DateTime.Now.ToString("yyyyMMdd") + "001";
else
NewNum = OldNum + (int.Parse(result[0].Remark.Replace(OldNum, "")) + 1).ToString("000");
return NewNum;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 更新已付费用,并且修改会员状态
///
///
///
public bool UpdateModel(Model.EC_PaymentRecord model, CY.Model.Pay.Pay_Request m_Pay_Request, EC_MemberBasic memberBasic)
{
try
{
Pay_PaymentAccountDAL _pay_PaymentAccount = new Pay_PaymentAccountDAL(_dataBase);
EC_MemberBasicDAL _EC_MemberBasicDAL = new EC_MemberBasicDAL(_dataBase);
bool IsSuccess = true;
using (TransactionScope t_TransactionScope = new TransactionScope())
{
IsSuccess = UpdateModel(model);
if (IsSuccess)
{
IsSuccess = _pay_PaymentAccount.Pay(m_Pay_Request);
if (IsSuccess)
{
if (model.PayType == "个人网店押金" || model.PayType == "印刷厂商注册费" || model.PayType == "印刷厂商续费")
{
IsSuccess = _EC_MemberBasicDAL.UpdateModel(memberBasic);
}
if (IsSuccess)
{
t_TransactionScope.Complete();
}
}
}
}
return IsSuccess;
}
catch (Exception ex)
{
throw ex;
}
}
}
}