/// <summary> /// 根据主键值读取记录。如果数据库不存在这条数据将返回null /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param> public CGOrderEntity GetCGOrder(int id) { string sql = @"SELECT [Id],[Code],[Title],[SourceCode],[CreateTime], [TransFee],[Status], [SendTime],[Remark] FROM dbo.[CGOrder] WITH(NOLOCK) WHERE [Id]=@id" ; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@Id", DbType.Int32, id); CGOrderEntity entity = new CGOrderEntity(); using (IDataReader reader = db.ExecuteReader(cmd)) { if (reader.Read()) { entity.Id = StringUtils.GetDbInt(reader["Id"]); entity.Code = StringUtils.GetDbLong(reader["Code"]); entity.Title = StringUtils.GetDbString(reader["Title"]); entity.SourceCode = StringUtils.GetDbLong(reader["SourceCode"]); entity.CreateTime = StringUtils.GetDbDateTime(reader["CreateTime"]); entity.TransFee = StringUtils.GetDbDecimal(reader["TransFee"]); entity.Status = StringUtils.GetDbInt(reader["Status"]); entity.SendTime = StringUtils.GetDbDateTime(reader["SendTime"]); entity.Remark = StringUtils.GetDbString(reader["Remark"]); } } return(entity); }
/// <summary> /// 读取记录列表。 /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param> public IList <CGOrderEntity> GetCGOrderAll() { string sql = @"SELECT [Id],[Code],[Title],[SourceCode],[CreateTime], [TransFee],[Status], [SendTime],[Remark] from dbo.[CGOrder] WITH(NOLOCK) "; IList <CGOrderEntity> entityList = new List <CGOrderEntity>(); DbCommand cmd = db.GetSqlStringCommand(sql); using (IDataReader reader = db.ExecuteReader(cmd)) { while (reader.Read()) { CGOrderEntity entity = new CGOrderEntity(); entity.Id = StringUtils.GetDbInt(reader["Id"]); entity.Code = StringUtils.GetDbLong(reader["Code"]); entity.Title = StringUtils.GetDbString(reader["Title"]); entity.SourceCode = StringUtils.GetDbLong(reader["SourceCode"]); entity.CreateTime = StringUtils.GetDbDateTime(reader["CreateTime"]); entity.TransFee = StringUtils.GetDbDecimal(reader["TransFee"]); entity.Status = StringUtils.GetDbInt(reader["Status"]); entity.SendTime = StringUtils.GetDbDateTime(reader["SendTime"]); entity.Remark = StringUtils.GetDbString(reader["Remark"]); entityList.Add(entity); } } return(entityList); }
public IList <CGOrderEntity> GetCGOrderBySourceCode(long sourceCode) { string sql = @"SELECT [Id],[Code],[Title],[SourceCode],[CreateTime], [TransFee],[Status], [SendTime],[Remark],OrderStyle FROM dbo.[CGOrder] WITH(NOLOCK) WHERE [SourceCode]=@SourceCode" ; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@SourceCode", DbType.Int64, sourceCode); IList <CGOrderEntity> entityList = new List <CGOrderEntity>(); using (IDataReader reader = db.ExecuteReader(cmd)) { while (reader.Read()) { CGOrderEntity entity = new CGOrderEntity(); entity.Id = StringUtils.GetDbInt(reader["Id"]); entity.Code = StringUtils.GetDbLong(reader["Code"]); entity.Title = StringUtils.GetDbString(reader["Title"]); entity.SourceCode = StringUtils.GetDbLong(reader["SourceCode"]); entity.CreateTime = StringUtils.GetDbDateTime(reader["CreateTime"]); entity.TransFee = StringUtils.GetDbDecimal(reader["TransFee"]); entity.Status = StringUtils.GetDbInt(reader["Status"]); entity.SendTime = StringUtils.GetDbDateTime(reader["SendTime"]); entity.Remark = StringUtils.GetDbString(reader["Remark"]); entity.OrderStyle = StringUtils.GetDbInt(reader["OrderStyle"]); entityList.Add(entity); } } return(entityList); }
/// <summary> /// 插入一条记录到表CGOrder,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0。 /// 该方法提供给界面等UI层调用 /// </summary> /// <param name="cGOrder">要添加的CGOrder数据实体对象</param> public int AddCGOrder(CGOrderEntity cGOrder) { if (cGOrder.Id > 0) { return(UpdateCGOrder(cGOrder)); } else if (CGOrderBLL.Instance.IsExist(cGOrder)) { return((int)CommonStatus.ADD_Fail_Exist); } else { return(CGOrderDA.Instance.AddCGOrder(cGOrder)); } }
/// <summary> /// 判断当前节点是否已存在相同的 /// </summary> /// <param name="entity"></param> /// <returns></returns> public int ExistNum(CGOrderEntity entity) { ///id=0,判断总数,ID>0判断除自己之外的总数 string sql = @"Select count(1) from dbo.[CGOrder] WITH(NOLOCK) "; string where = "where (Code=@Code) "; sql = sql + where; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@Code", DbType.Int32, entity.Code); object identity = db.ExecuteScalar(cmd); if (identity == null || identity == DBNull.Value) { return(0); } return(Convert.ToInt32(identity)); }
/// <summary> /// 根据主键值更新记录的全部字段(注意:该方法不会对自增字段、timestamp类型字段以及主键字段更新!如果要更新主键字段,请使用Update方法)。 /// 如果数据库有数据被更新了则返回True,否则返回False /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="cGOrder">待更新的实体对象</param> public int UpdateCGOrder(CGOrderEntity entity) { string sql = @" UPDATE dbo.[CGOrder] SET [Code]=@Code,[Title]=@Title,[SourceCode]=@SourceCode,[CreateTime]=@CreateTime, [TransFee]=@TransFee,[Status]=@Status, [SendTime]=@SendTime,[Remark]=@Remark WHERE [Id]=@id"; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@Id", DbType.Int32, entity.Id); db.AddInParameter(cmd, "@Code", DbType.Int64, entity.Code); db.AddInParameter(cmd, "@Title", DbType.String, entity.Title); db.AddInParameter(cmd, "@SourceCode", DbType.Int64, entity.SourceCode); db.AddInParameter(cmd, "@CreateTime", DbType.DateTime, entity.CreateTime); db.AddInParameter(cmd, "@TransFee", DbType.Decimal, entity.TransFee); db.AddInParameter(cmd, "@Status", DbType.Int32, entity.Status); db.AddInParameter(cmd, "@SendTime", DbType.DateTime, entity.SendTime); db.AddInParameter(cmd, "@Remark", DbType.String, entity.Remark); return(db.ExecuteNonQuery(cmd)); }
public CGOrderEntity GetCGOrderByCode(long cgcode, int memid) { CGOrderEntity entity = new CGOrderEntity(); string where = " where Code=@Code "; if (memid != -1) { where += "and CGMemId=@CGMemId "; } string sql = @" SELECT a.[Id],a.[Code],CGMemId,a.[Title],a.[SourceCode],a.[CreateTime],a.[TransFee],a.[Status], a.[SendTime],a.[Remark] FROM dbo.[CGOrder] a WITH(NOLOCK) " + where; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@Code", DbType.Int64, cgcode); if (memid != -1) { db.AddInParameter(cmd, "@CGMemId", DbType.Int32, memid); } using (IDataReader reader = db.ExecuteReader(cmd)) { if (reader.Read()) { entity.Id = StringUtils.GetDbInt(reader["Id"]); entity.Code = StringUtils.GetDbLong(reader["Code"]); entity.CGMemId = StringUtils.GetDbInt(reader["CGMemId"]); entity.Title = StringUtils.GetDbString(reader["Title"]); entity.SourceCode = StringUtils.GetDbLong(reader["SourceCode"]); entity.CreateTime = StringUtils.GetDbDateTime(reader["CreateTime"]); entity.TransFee = StringUtils.GetDbDecimal(reader["TransFee"]); entity.Status = StringUtils.GetDbInt(reader["Status"]); entity.SendTime = StringUtils.GetDbDateTime(reader["SendTime"]); entity.Remark = StringUtils.GetDbString(reader["Remark"]); } } return(entity); }
/// <summary> /// 插入一条记录到表CGOrder,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0 /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="cGOrder">待插入的实体对象</param> public int AddCGOrder(CGOrderEntity entity) { string sql = @"insert into CGOrder( [Code],[Title],[SourceCode],[CreateTime], [TransFee],[Status], [SendTime],[Remark])VALUES ( @Code,@Title,@SourceCode,@CreateTime, @TransFee,@Status, @SendTime,@Remark); SELECT SCOPE_IDENTITY();" ; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@Code", DbType.Int64, entity.Code); db.AddInParameter(cmd, "@Title", DbType.String, entity.Title); db.AddInParameter(cmd, "@SourceCode", DbType.Int64, entity.SourceCode); db.AddInParameter(cmd, "@CreateTime", DbType.DateTime, entity.CreateTime); db.AddInParameter(cmd, "@TransFee", DbType.Decimal, entity.TransFee); db.AddInParameter(cmd, "@Status", DbType.Int32, entity.Status); db.AddInParameter(cmd, "@SendTime", DbType.DateTime, entity.SendTime); db.AddInParameter(cmd, "@Remark", DbType.String, entity.Remark); object identity = db.ExecuteScalar(cmd); if (identity == null || identity == DBNull.Value) { return(0); } return(Convert.ToInt32(identity)); }
/// <summary> /// 更新一条CGOrder记录。 /// 该方法提供给界面等UI层调用 /// </summary> /// <param name="cGOrder">待更新的实体对象</param> /// <param name="columns">要更新的列名,不提供任何列名时默认将更新主键之外的所有列</param> public int UpdateCGOrder(CGOrderEntity cGOrder) { return(CGOrderDA.Instance.UpdateCGOrder(cGOrder)); }
/// <summary> /// 判断对象是否存在 /// </summary> /// <param name="dicEnum"></param> /// <returns></returns> public bool IsExist(CGOrderEntity cGOrder) { return(CGOrderDA.Instance.ExistNum(cGOrder) > 0); }
/// <summary> /// 读取记录列表。 /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param> public IList <CGOrderEntity> GetCGOrderList(int pagesize, int pageindex, ref int recordCount, int status, int orderstyle, long sourceCode, string keyword) { string where = " where 1=1"; if (!string.IsNullOrEmpty(keyword)) { where += " And Code like @keyword"; } if (orderstyle != -1) { where += " And OrderStyle=@OrderStyle"; } if (status != -1) { where += " And Status=@Status"; } if (sourceCode > 0) { where += " And SourceCode = @SourceCode"; } string sql = @"SELECT [Id],[Code],[Title],[SourceCode],[CreateTime], [TransFee],[Status], [SendTime],[Remark] FROM (SELECT ROW_NUMBER() OVER (ORDER BY Id desc) AS ROWNUMBER, [Id],[Code],[Title],[SourceCode],[CreateTime], [TransFee],[Status], [SendTime],[Remark] from dbo.[CGOrder] WITH(NOLOCK) " + where + @") as temp where rownumber BETWEEN ((@PageIndex - 1) * @PageSize + 1) AND @PageIndex * @PageSize" ; string sql2 = @"Select count(1) from dbo.[CGOrder] with (nolock) " + where; IList <CGOrderEntity> entityList = new List <CGOrderEntity>(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@PageIndex", DbType.Int32, pageindex); db.AddInParameter(cmd, "@PageSize", DbType.Int32, pagesize); if (!string.IsNullOrEmpty(keyword)) { db.AddInParameter(cmd, "@keyword", DbType.String, "%" + keyword + "%"); } if (orderstyle != -1) { db.AddInParameter(cmd, "@OrderStyle", DbType.Int32, orderstyle); } if (status != -1) { db.AddInParameter(cmd, "@Status", DbType.Int32, status); } if (sourceCode > 0) { db.AddInParameter(cmd, "@SourceCode", DbType.Int64, sourceCode); } using (IDataReader reader = db.ExecuteReader(cmd)) { while (reader.Read()) { CGOrderEntity entity = new CGOrderEntity(); entity.Id = StringUtils.GetDbInt(reader["Id"]); entity.Code = StringUtils.GetDbLong(reader["Code"]); entity.Title = StringUtils.GetDbString(reader["Title"]); entity.SourceCode = StringUtils.GetDbLong(reader["SourceCode"]); entity.CreateTime = StringUtils.GetDbDateTime(reader["CreateTime"]); entity.TransFee = StringUtils.GetDbDecimal(reader["TransFee"]); entity.Status = StringUtils.GetDbInt(reader["Status"]); entity.SendTime = StringUtils.GetDbDateTime(reader["SendTime"]); entity.Remark = StringUtils.GetDbString(reader["Remark"]); entityList.Add(entity); } } cmd = db.GetSqlStringCommand(sql2); if (!string.IsNullOrEmpty(keyword)) { db.AddInParameter(cmd, "@keyword", DbType.String, "%" + keyword + "%"); } if (orderstyle != -1) { db.AddInParameter(cmd, "@OrderStyle", DbType.Int32, orderstyle); } if (status != -1) { db.AddInParameter(cmd, "@Status", DbType.Int32, status); } if (sourceCode > 0) { db.AddInParameter(cmd, "@SourceCode", DbType.Int64, sourceCode); } using (IDataReader reader = db.ExecuteReader(cmd)) { if (reader.Read()) { recordCount = StringUtils.GetDbInt(reader[0]); } else { recordCount = 0; } } return(entityList); }