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