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_ShebeiWeixiuDAL : IOA_ShebeiWeixiuDAL
|
{
|
private Database _dataBase = null;
|
|
public OA_ShebeiWeixiuDAL()
|
{
|
_dataBase = new Database();
|
}
|
|
public OA_ShebeiWeixiuDAL(Database dataBase)
|
{
|
_dataBase = dataBase;
|
}
|
|
/// <summary>
|
/// 新增
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool InserModel(Infrastructure.Domain.IAggregateRoot model)
|
{
|
Model.OA_ShebeiWeixiu trueModel = model as Model.OA_ShebeiWeixiu;
|
if (trueModel == null)
|
{
|
return false;
|
}
|
SqlParameter WeixiuTime = null;
|
if (trueModel.WeixiuTime.HasValue)
|
{
|
WeixiuTime = new SqlParameter("@WeixiuTime", trueModel.WeixiuTime.Value);
|
}
|
else
|
{
|
WeixiuTime = new SqlParameter("@WeixiuTime", DBNull.Value);
|
}
|
|
IList<SqlParameter> sqlParms = new List<SqlParameter>()
|
{ new SqlParameter("@MemberId", trueModel.MemberId) ,
|
new SqlParameter("@ShebeiId", trueModel.ShebeiId) ,
|
WeixiuTime,
|
new SqlParameter("@CateId", trueModel.CateId) ,
|
new SqlParameter("@Anzhuangdidian", string.IsNullOrEmpty(trueModel.Anzhuangdidian)?"":trueModel.Anzhuangdidian) ,
|
new SqlParameter("@Name", trueModel.Name) ,
|
new SqlParameter("@Remark",string.IsNullOrEmpty(trueModel.Remark)?"":trueModel.Remark ),
|
new SqlParameter("@WeixiuPrice", trueModel.WeixiuPrice.HasValue?trueModel.WeixiuPrice.Value:0) ,
|
new SqlParameter("@Zerenren",trueModel.Zerenren.HasValue?trueModel.Zerenren.Value:0 ) ,
|
new SqlParameter("@ZerenrenName", string.IsNullOrEmpty(trueModel.ZerenrenName)?"":trueModel.ZerenrenName) ,
|
new SqlParameter("@DanzePrice", trueModel.DanzePrice.HasValue?trueModel.DanzePrice.Value:0) ,
|
|
new SqlParameter("@WeixiuShebeiId", trueModel.WeixiuShebeiId.HasValue?trueModel.WeixiuShebeiId.Value:0) ,
|
new SqlParameter("@FukuanShebeiId", trueModel.FukuanShebeiId.HasValue?trueModel.FukuanShebeiId.Value:0) ,
|
new SqlParameter("@FukuanshenqingId", trueModel.FukuanshenqingId.HasValue?trueModel.FukuanshenqingId.Value:0) ,
|
new SqlParameter("@Shifoufufei", trueModel.Shifoufufei.HasValue?trueModel.Shifoufufei.Value:0) ,
|
|
|
new SqlParameter("@CreateTime", trueModel.CreateTime) ,
|
new SqlParameter("@Creator", trueModel.Creator) ,
|
new SqlParameter("@LastUpdateTime", trueModel.LastUpdateTime) ,
|
new SqlParameter("@Operator", trueModel.Operator) ,
|
new SqlParameter("@ApprovalStatus", trueModel.ApprovalStatus.HasValue?trueModel.ApprovalStatus.Value:0) ,
|
new SqlParameter("@Fukuanfangshi", string.IsNullOrEmpty(trueModel.Fukuanfangshi)?"":trueModel.Fukuanfangshi) ,
|
|
};
|
string sql = "Insert Into OA_ShebeiWeixiu ([MemberId],[ShebeiId],[WeixiuTime],[CateId],[Name],[Anzhuangdidian],[Remark],[WeixiuPrice],[Zerenren],[ZerenrenName],[DanzePrice],[WeixiuShebeiId],[FukuanShebeiId],[FukuanshenqingId],[Shifoufufei],[CreateTime],[Creator],[LastUpdateTime],[Operator],[ApprovalStatus],[Fukuanfangshi])"
|
+ " Values (@MemberId,@ShebeiId,@WeixiuTime,@CateId,@Name,@Anzhuangdidian,@Remark ,@WeixiuPrice,@Zerenren,@ZerenrenName,@DanzePrice,@WeixiuShebeiId,@FukuanShebeiId,@FukuanshenqingId,@Shifoufufei,@CreateTime,@Creator,@LastUpdateTime,@Operator,@ApprovalStatus,@Fukuanfangshi)";
|
|
try
|
{
|
_dataBase.ExecuteSql(sql, sqlParms.ToArray<SqlParameter>());
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 修改
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model)
|
{
|
Model.OA_ShebeiWeixiu trueModel = model as Model.OA_ShebeiWeixiu;
|
if (trueModel == null)
|
{
|
return false;
|
}
|
SqlParameter WeixiuTime = null;
|
if (trueModel.WeixiuTime.HasValue)
|
{
|
WeixiuTime = new SqlParameter("@WeixiuTime", trueModel.WeixiuTime.Value);
|
}
|
else
|
{
|
WeixiuTime = new SqlParameter("@WeixiuTime", DBNull.Value);
|
}
|
|
|
IList<SqlParameter> sqlParms = new List<SqlParameter>()
|
{ new SqlParameter("@Keyid", trueModel.Keyid) ,
|
new SqlParameter("@MemberId", trueModel.MemberId) ,
|
new SqlParameter("@ShebeiId", trueModel.ShebeiId) ,
|
WeixiuTime,
|
new SqlParameter("@CateId", trueModel.CateId) ,
|
new SqlParameter("@Anzhuangdidian", string.IsNullOrEmpty(trueModel.Anzhuangdidian)?"":trueModel.Anzhuangdidian) ,
|
new SqlParameter("@Name", trueModel.Name) ,
|
new SqlParameter("@Remark",string.IsNullOrEmpty(trueModel.Remark)?"":trueModel.Remark ),
|
new SqlParameter("@WeixiuPrice", trueModel.WeixiuPrice.HasValue?trueModel.WeixiuPrice.Value:0) ,
|
new SqlParameter("@Zerenren",trueModel.Zerenren.HasValue?trueModel.Zerenren.Value:0 ) ,
|
new SqlParameter("@ZerenrenName", string.IsNullOrEmpty(trueModel.ZerenrenName)?"":trueModel.ZerenrenName) ,
|
new SqlParameter("@DanzePrice", trueModel.DanzePrice.HasValue?trueModel.DanzePrice.Value:0) ,
|
|
new SqlParameter("@WeixiuShebeiId", trueModel.WeixiuShebeiId.HasValue?trueModel.WeixiuShebeiId.Value:0) ,
|
new SqlParameter("@FukuanShebeiId", trueModel.FukuanShebeiId.HasValue?trueModel.FukuanShebeiId.Value:0) ,
|
new SqlParameter("@FukuanshenqingId", trueModel.FukuanshenqingId.HasValue?trueModel.FukuanshenqingId.Value:0) ,
|
new SqlParameter("@Shifoufufei", trueModel.Shifoufufei.HasValue?trueModel.Shifoufufei.Value:0) ,
|
|
new SqlParameter("@LastUpdateTime", trueModel.LastUpdateTime) ,
|
new SqlParameter("@Operator", trueModel.Operator) ,
|
new SqlParameter("@ApprovalStatus", trueModel.ApprovalStatus.HasValue?trueModel.ApprovalStatus.Value:0) ,
|
new SqlParameter("@Fukuanfangshi", string.IsNullOrEmpty(trueModel.Fukuanfangshi)?"":trueModel.Fukuanfangshi) ,
|
};
|
string sql = "Update OA_ShebeiWeixiu Set [MemberId]=@MemberId,[ShebeiId]=@ShebeiId,[WeixiuTime]=@WeixiuTime,[CateId]=@CateId,[Name]=@Name,[Anzhuangdidian]=@Anzhuangdidian,[Remark]=@Remark,[WeixiuPrice]=@WeixiuPrice,[Zerenren]=@Zerenren,[ZerenrenName]=@ZerenrenName,[DanzePrice]=@DanzePrice, [WeixiuShebeiId]=@WeixiuShebeiId,[FukuanShebeiId]=@FukuanShebeiId,[FukuanshenqingId]=@FukuanshenqingId,[Shifoufufei]=@Shifoufufei,[LastUpdateTime]=@LastUpdateTime, [Operator]=@Operator,ApprovalStatus=@ApprovalStatus,Fukuanfangshi=@Fukuanfangshi where [Keyid] =@Keyid ";
|
|
try
|
{
|
_dataBase.ExecuteSql(sql, sqlParms.ToArray<SqlParameter>());
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 删除
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model)
|
{
|
Model.OA_ShebeiWeixiu trueModel = model as Model.OA_ShebeiWeixiu;
|
if (trueModel == null)
|
{
|
return false;
|
}
|
IList<SqlParameter> sqlParms = new List<SqlParameter>()
|
{
|
new SqlParameter("@Keyid",trueModel.Keyid)
|
};
|
string sql = "Delete OA_ShebeiWeixiu Where [Keyid] = @Keyid ";
|
|
|
try
|
{
|
_dataBase.ExecuteSql(sql, sqlParms.ToArray<SqlParameter>());
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
|
return true;
|
}
|
|
/// <summary>
|
/// 分页查询
|
/// </summary>
|
/// <param name="query"></param>
|
/// <param name="pagination"></param>
|
/// <returns></returns>
|
public IEnumerable<Model.OA_ShebeiWeixiu> SelectModelPage(Infrastructure.Query.Query query, Infrastructure.Query.Pagination pagination)
|
{
|
throw new NotImplementedException();
|
}
|
|
/// <summary>
|
/// 单个查询
|
/// </summary>
|
/// <param name="query"></param>
|
/// <returns></returns>
|
public IEnumerable<Model.OA_ShebeiWeixiu> SelectAllModel(Infrastructure.Query.Query query)
|
{
|
return _dataBase.SelectModel<Model.OA_ShebeiWeixiu>(" * ", " OA_ShebeiWeixiu ") as IList<Model.OA_ShebeiWeixiu>;//执行查询
|
}
|
|
/// <summary>
|
/// 根据编号获得信息
|
/// </summary>
|
/// <param name="Keyid">编号</param>
|
/// <returns></returns>
|
public OA_ShebeiWeixiu GetModelByKeyid(int? Keyid)
|
{
|
try
|
{
|
if (Keyid == null || Keyid < 0)
|
return null;//错误数据返会空
|
|
IList<OA_ShebeiWeixiu> result = _dataBase.SelectModel<OA_ShebeiWeixiu>(" * ", " OA_ShebeiWeixiu ", string.Format(" Keyid='{0}'", Keyid)) as IList<OA_ShebeiWeixiu>;//执行查询
|
|
return (null == result || result.Count == 0) ? null : result[0];//返回结果
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
|
|
/// <summary>
|
/// 根据编号获得信息
|
/// </summary>
|
/// <param name="Keyid">编号</param>
|
/// <returns></returns>
|
public OA_ShebeiWeixiu GetModelBytiaojian(int? WeixiuShebeiId, int? FukuanShebeiId, int? FukuanshenqingId)
|
{
|
try
|
{
|
string tiaojian = "";
|
if (WeixiuShebeiId.HasValue)
|
{
|
tiaojian += "WeixiuShebeiId=" + WeixiuShebeiId.Value;
|
}
|
else if (FukuanShebeiId.HasValue)
|
{
|
tiaojian += "FukuanShebeiId=" + FukuanShebeiId.Value;
|
}
|
else if (FukuanshenqingId.HasValue)
|
{
|
tiaojian += "FukuanshenqingId=" + FukuanshenqingId.Value;
|
}
|
|
|
IList<OA_ShebeiWeixiu> result = _dataBase.SelectModel<OA_ShebeiWeixiu>(" * ", " OA_ShebeiWeixiu ", tiaojian ) as IList<OA_ShebeiWeixiu>;//执行查询
|
|
return (null == result || result.Count == 0) ? null : result[0];//返回结果
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
|
/// <summary>
|
/// 根据编号获得信息
|
/// </summary>
|
/// <param name="Keyid">编号</param>
|
/// <returns></returns>
|
public Model.OA_ShebeiWeixiu GetModelBytiaojian(int ShebeiId)
|
{
|
try
|
{
|
|
|
string from = "( SELECT sum(WeixiuPrice) WeixiuPrice,0 as DanzePrice FROM OA_ShebeiWeixiu where ShebeiId="+ ShebeiId + " and Shifoufufei = 1 and DATEDIFF(MONTH,'"+DateTime.Now.ToString("yyyy-MM-dd")+"',WeixiuTime) =0 "
|
+ " UNION ALL "
|
+ " SELECT 0 as WeixiuPrice,sum(WeixiuPrice) DanzePrice FROM OA_ShebeiWeixiu where ShebeiId=" + ShebeiId + " and Shifoufufei = 1 and DATEDIFF(YEAR,'" + DateTime.Now.ToString("yyyy-MM-dd") + "',WeixiuTime) =0 "
|
+ " ) AS subquery ";
|
|
IList<OA_ShebeiWeixiu> result = _dataBase.SelectModel<OA_ShebeiWeixiu>(" sum(WeixiuPrice) WeixiuPrice,sum(DanzePrice) DanzePrice ", from) as IList<OA_ShebeiWeixiu>;//执行查询
|
|
|
|
return (null == result || result.Count == 0) ? null : result[0];//返回结果
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
/// <summary>
|
/// 分页查询
|
/// </summary>
|
/// <param name="pagination"></param>
|
/// <returns></returns>
|
public IEnumerable<Model.OA_ShebeiWeixiu> SelectModelPage(Infrastructure.Query.Pagination pagination, Guid _MemberId, int? _CateId, string _Name, int? _Status, string Anzhuangdidian, int? Zerenren, int? Shifoufufei, int? guanliZerenren)
|
{
|
try
|
{
|
string condition = " ApprovalStatus=1 ";
|
|
if (_MemberId != Guid.Empty)
|
condition += " and a.MemberId = '" + _MemberId + "'";
|
|
if (_CateId.HasValue)
|
condition += " and a.CateId = '" + _CateId + "'";
|
|
if (!string.IsNullOrEmpty(_Name))
|
condition += " and a.Name = '" + _Name + "'";
|
|
if (!string.IsNullOrEmpty(Anzhuangdidian))
|
condition += " and a.Anzhuangdidian = '" + Anzhuangdidian + "'";
|
|
if (_Status.HasValue)
|
condition += " and a.Status = '" + _Status + "'";
|
|
if (Zerenren.HasValue)
|
condition += " and a.Zerenren = '" + Zerenren + "'";
|
|
if (guanliZerenren.HasValue)
|
condition += " and c.Zerenren = '" + guanliZerenren + "'";
|
|
|
|
if (Shifoufufei.HasValue)
|
condition += " and a.Shifoufufei = '" + Shifoufufei + "'";
|
|
|
|
/// <summary>
|
/// 查询来源
|
/// </summary>
|
string fromss = " OA_ShebeiWeixiu as a left join OA_ShebeiCate as b on a.CateId = b.Keyid left join OA_ShebeiManage as c on a.ShebeiId = c.Keyid " +
|
|
|
|
|
|
" where " + condition;
|
|
var ssss = _dataBase.SelectModel<Model.OA_ShebeiWeixiu>(" sum(a.WeixiuPrice) as WeixiuPrice,sum(a.DanzePrice) as DanzePrice ", fromss);
|
if (ssss.Count > 0)
|
{
|
var aaaaa = ssss.First();
|
pagination.heji1 = aaaaa.WeixiuPrice;
|
pagination.heji3 = aaaaa.DanzePrice;
|
}
|
|
|
|
|
|
return _dataBase.SelectModelPage<Model.OA_ShebeiWeixiu>(pagination, " a.*,b.Name as CateName, c.ZerenrenName as ShebeiZerenrenName ", " OA_ShebeiWeixiu as a left join OA_ShebeiCate as b on a.CateId = b.Keyid left join OA_ShebeiManage as c on a.ShebeiId = c.Keyid ", " a.WeixiuTime DESC", " Keyid desc ", condition);
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
|
|
|
|
|
}
|
}
|