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_GongzuozhizeDAL : IOA_GongzuozhizeDAL
{
private Database _dataBase = null;
public OA_GongzuozhizeDAL()
{
_dataBase = new Database();
}
public OA_GongzuozhizeDAL(Database dataBase)
{
_dataBase = dataBase;
}
///
/// 新增
///
///
///
public bool InserModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.OA_Gongzuozhize trueModel = model as Model.OA_Gongzuozhize;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{ new SqlParameter("@MemberId", trueModel.MemberId) ,
new SqlParameter("@Gongzuozhize", trueModel.Gongzuozhize) ,
new SqlParameter("@Zerenren",trueModel.Zerenren.HasValue?trueModel.Zerenren.Value:0 ) ,
new SqlParameter("@ZerenrenName", string.IsNullOrEmpty(trueModel.ZerenrenName)?"":trueModel.ZerenrenName) ,
new SqlParameter("@CreateTime", trueModel.CreateTime) ,
new SqlParameter("@Creator", trueModel.Creator) ,
new SqlParameter("@LastUpdateTime", trueModel.LastUpdateTime) ,
new SqlParameter("@Updator", trueModel.Updator) ,
};
string sql = "Insert Into OA_Gongzuozhize ([MemberId],[Gongzuozhize],[Zerenren],[ZerenrenName],[CreateTime],[Creator],[LastUpdateTime],[Updator])"
+ " Values (@MemberId,@Gongzuozhize,@Zerenren,@ZerenrenName,@CreateTime,@Creator,@LastUpdateTime,@Updator )";
try
{
_dataBase.ExecuteSql(sql, sqlParms.ToArray());
}
catch (Exception ex)
{
throw ex;
}
return true;
}
///
/// 修改
///
///
///
public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.OA_Gongzuozhize trueModel = model as Model.OA_Gongzuozhize;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{ new SqlParameter("@Keyid", trueModel.Keyid) ,
new SqlParameter("@MemberId", trueModel.MemberId) ,
new SqlParameter("@Gongzuozhize", trueModel.Gongzuozhize) ,
new SqlParameter("@Zerenren",trueModel.Zerenren.HasValue?trueModel.Zerenren.Value:0 ) ,
new SqlParameter("@ZerenrenName", string.IsNullOrEmpty(trueModel.ZerenrenName)?"":trueModel.ZerenrenName) ,
new SqlParameter("@LastUpdateTime", trueModel.LastUpdateTime) ,
new SqlParameter("@Updator", trueModel.Updator) ,
};
string sql = "Update OA_Gongzuozhize Set [MemberId]=@MemberId,[Gongzuozhize]=@Gongzuozhize,[Zerenren]=@Zerenren,[ZerenrenName]=@ZerenrenName, [LastUpdateTime]=@LastUpdateTime, [Updator]=@Updator where [Keyid] =@Keyid ";
try
{
_dataBase.ExecuteSql(sql, sqlParms.ToArray());
}
catch (Exception ex)
{
throw ex;
}
return true;
}
///
/// 删除
///
///
///
public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model)
{
Model.OA_Gongzuozhize trueModel = model as Model.OA_Gongzuozhize;
if (trueModel == null)
{
return false;
}
IList sqlParms = new List()
{
new SqlParameter("@Keyid",trueModel.Keyid)
};
string sql = "Delete OA_Gongzuozhize Where [Keyid] = @Keyid ";
try
{
_dataBase.ExecuteSql(sql, 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)
{
return _dataBase.SelectModel(" * ", " OA_Gongzuozhize ") as IList;//执行查询
}
///
/// 根据编号获得信息
///
/// 编号
///
public OA_Gongzuozhize GetModelByKeyid(int? Keyid)
{
try
{
if (Keyid == null || Keyid < 0)
return null;//错误数据返会空
IList result = _dataBase.SelectModel(" * ", " OA_Gongzuozhize ", string.Format(" Keyid='{0}'", Keyid)) as IList;//执行查询
return (null == result || result.Count == 0) ? null : result[0];//返回结果
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 分页查询
///
///
///
public IEnumerable SelectModelPage(Infrastructure.Query.Pagination pagination, Guid _MemberId, string Gongzuozhize, int? Zerenren)
{
try
{
string condition = " 1=1 ";
if (_MemberId != Guid.Empty)
condition += " and a.MemberId = '" + _MemberId + "'";
if (!string.IsNullOrEmpty(Gongzuozhize))
condition += " and a.Gongzuozhize like '%" + Gongzuozhize + "%'";
if (Zerenren.HasValue)
condition += " and a.Zerenren = '" + Zerenren + "'";
return _dataBase.SelectModelPage(pagination, " a.* ", " OA_Gongzuozhize a ", " a.Keyid DESC", " Keyid desc ", condition);
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 检测物品是否重复
///
///
///
///
///
public int IsExitsName(int? Zerenren, int? Keyid)
{
try
{
string where = " Zerenren = " + Zerenren + " ";
if (Keyid.HasValue)
{
where += " and Keyid <> " + Keyid + " ";
}
IList result = _dataBase.SelectModel("*", "OA_Gongzuozhize", where) as IList;//执行查询
if (null == result || result.Count == 0)
return 0;
else
return 1;
}
catch (Exception ex)
{
throw ex;
}
}
}
}