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 OA_WorkPlan_attachmentDAL : IOA_WorkPlan_attachmentDAL
{
private Database _dataBase = null;
#region 常量
///
/// 查询目标
///
const string SELECTTARGET = " t.* ";
///
/// 查询来源
///
const string FROMSOUCEBEFORE = " ( select distinct ok.*,d_kaipiaoshenqing.Name as KaipiaoshenqingName,d_fapiaoqianshou.Name as KehuqianshouName, " +
" oe.CompanyName as BuyerName,eo.shuliang,eo.jine, os.Name as BusinessManager " +
" from [OA_WorkPlan_attachment] ok inner join [OA_CorporateClients] oe on oe.Keyid = ok.[BuyerId] " +
" left join (select count(*) as shuliang,sum(eo.[SumPrice]) as jine,eoe.KaipiaoshenqingId from [EC_OrderBasic] eo ,[EC_OrderExtend] eoe where eoe.Keyid=eo.Keyid group by eoe.KaipiaoshenqingId ) eo on ok.Keyid =eo.KaipiaoshenqingId " +
" left join [OA_Staff] os on ok.BusinessManagerId = os.Keyid " +
" Left Join Sys_Dictionary as d_kaipiaoshenqing On(d_kaipiaoshenqing.DicType= 'EC_开票申请' and ok.[Kaipiaoshenqing]= d_kaipiaoshenqing.MeanValue) " +
" Left Join Sys_Dictionary as d_fapiaoqianshou On(d_fapiaoqianshou.DicType= 'EC_发票签收' and ok.[Kehuqianshou]= d_fapiaoqianshou.MeanValue) where 0=0 ";
const string FROMSOUCEEND = ") as t ";
///
/// 分页默认排序字段
///
const string ORDERBY = " SellerOrderId desc ";
#endregion
public OA_WorkPlan_attachmentDAL()
{
_dataBase = new Database();
}
///
/// 新增
///
///
///
public bool InserModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.OA_WorkPlan_attachment trueModel = model as Model.OA_WorkPlan_attachment;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{
new SqlParameter("@OA_WorkPlanId",trueModel.OA_WorkPlanId),
new SqlParameter("@CreateTime",trueModel.CreateTime),
new SqlParameter("@PlanAttachment",trueModel.PlanAttachment),
new SqlParameter("@AttachmentType",trueModel.AttachmentType),
new SqlParameter("@Operator",string.IsNullOrWhiteSpace(trueModel.Operator)?"":trueModel.Operator),
};
string sql = "Insert Into OA_WorkPlan_attachment ( [OA_WorkPlanId] , [PlanAttachment],[AttachmentType],[CreateTime],[Operator] )"
+ " Values ( @OA_WorkPlanId, @PlanAttachment,@AttachmentType,@CreateTime,@Operator )";
try
{
_dataBase.ExecuteSql(sql, sqlParms.ToArray());
}
catch (Exception ex)
{
throw ex;
}
return true;
}
///
/// 修改
///
///
///
public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.OA_WorkPlan_attachment trueModel = model as Model.OA_WorkPlan_attachment;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{
new SqlParameter("@Keyid",trueModel.Keyid),
new SqlParameter("@OA_WorkPlanId",trueModel.OA_WorkPlanId),
new SqlParameter("@CreateTime",trueModel.CreateTime),
new SqlParameter("@PlanAttachment",trueModel.PlanAttachment),
new SqlParameter("@AttachmentType",trueModel.AttachmentType),
new SqlParameter("@Operator",string.IsNullOrWhiteSpace(trueModel.Operator)?"":trueModel.Operator),
};
string sql = "Update OA_WorkPlan_attachment Set [OA_WorkPlanId]=@OA_WorkPlanId,[CreateTime]=@CreateTime,[PlanAttachment]=@PlanAttachment,[AttachmentType]=@AttachmentType ,[Operator]=@Operator where [Keyid] =@Keyid ";
try
{
_dataBase.ExecuteSql(sql, sqlParms.ToArray());
}
catch (Exception ex)
{
throw ex;
}
return true;
}
///
/// 根据编号获得信息
///
/// 编号
///
public OA_WorkPlan_attachment GetModelByKeyid(int keyid)
{
try
{
string condition = " ";
if (keyid > 0)
{
condition = " Keyid=" + keyid + "";
}
else
{
return null;
}
// return null;//错误数据返会空
IList result = _dataBase.SelectModel("*", "OA_WorkPlan_attachment", condition) as IList;//执行查询
return (null == result || result.Count == 0) ? null : result[0];//返回结果
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 全部查询
///
///
///
public IEnumerable SelectAllModel(Infrastructure.Query.Query query)
{
return _dataBase.SelectModel(" * ", " OA_WorkPlan_attachment ") as IList;//执行查询
}
///
/// 全部查询
///
///
///
public IEnumerable GetModelByKaipiaoId(int OA_WorkPlanId)
{
return _dataBase.SelectModel(" * ", " OA_WorkPlan_attachment ", " OA_WorkPlanId = '" + OA_WorkPlanId + "' and [AttachmentType] in (1,2) order by CreateTime desc ") as IList;//执行查询
}
///
/// 全部查询
///
///
///
public IEnumerable GetModelByKaipiaoIdandType(int OA_WorkPlanId, int AttachmentType)
{
return _dataBase.SelectModel(" * ", " OA_WorkPlan_attachment ", " OA_WorkPlanId = '" + OA_WorkPlanId + "' and [AttachmentType] = '" + AttachmentType + "' order by CreateTime desc ") as IList;//执行查询
}
///
/// 分页查询
///
///
///
///
public IEnumerable SelectModelPage(Infrastructure.Query.Query query, Infrastructure.Query.Pagination pagination)
{
if (null == pagination || null == query || null == query.Criteria || 1 > query.Criteria.Count)
return null;
//query.Criteria 首个元素必须是排序字段,其值为结果排序字段
int maxParamIndex = query.Criteria.Count - 1;//最大索引
string[] orderbys = new string[] { ORDERBY };
string resultOrderBy = "";//结果集排序方式
if ("@orderBy".Equals(query.Criteria[maxParamIndex].PropertyName))
{
orderbys = string.Format("{0}", query.Criteria[maxParamIndex].Value).Split(',');
resultOrderBy = query.Criteria[maxParamIndex].Value.ToString();//= 1 == orderbys.Length ? resultOrderBy : orderbys[1];
}
string fromSouce = string.Format("{0}{1}{2}", FROMSOUCEBEFORE, query.Criteria[0].Value, FROMSOUCEEND);//拼装条件
return _dataBase.SelectModelPage(pagination, SELECTTARGET, fromSouce, orderbys[0], resultOrderBy);
}
///
/// 删除
///
///
///
public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.OA_WorkPlan_attachment trueModel = model as Model.OA_WorkPlan_attachment;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{
new SqlParameter("@Keyid",trueModel.Keyid)
};
string sql = "Delete OA_WorkPlan_attachment Where [Keyid] = @Keyid ";
try
{
_dataBase.ExecuteSql(sql, sqlParms.ToArray());
}
catch (Exception ex)
{
throw ex;
}
return true;
}
}
}