/// <summary> /// 钱包实体转参数 /// </summary> public static SqlParameter[] ModelToParms(CardInfo card) { SqlParameter[] parms = { new SqlParameter("@CardID", SqlDbType.Int), new SqlParameter("@CardName", SqlDbType.NVarChar, 20), new SqlParameter("@CardNumber", SqlDbType.NVarChar, 50), new SqlParameter("@CardImage", SqlDbType.NVarChar, 50), new SqlParameter("@CardMoney", SqlDbType.Decimal), new SqlParameter("@CardLive", SqlDbType.TinyInt), new SqlParameter("@Synchronize", SqlDbType.TinyInt), new SqlParameter("@ModifyDate", SqlDbType.DateTime), new SqlParameter("@CDID", SqlDbType.Int), new SqlParameter("@UserID", SqlDbType.Int), new SqlParameter("@MoneyStart", SqlDbType.Decimal), new SqlParameter("@CardShow", SqlDbType.TinyInt) }; parms[0].Value = card.CardID; parms[1].Value = card.CardName; parms[2].Value = card.CardNumber; parms[3].Value = card.CardImage; parms[4].Value = card.CardMoney; parms[5].Value = card.CardLive; parms[6].Value = card.Synchronize; parms[7].Value = card.ModifyDate; parms[8].Value = card.CDID; parms[9].Value = card.UserID; parms[10].Value = card.MoneyStart; parms[11].Value = card.CardShow; return parms; }
/// <summary> /// 数据转钱包实体 /// </summary> public static CardInfo DataToModel(SqlDataReader rdr) { CardInfo card = new CardInfo(); if (!rdr.IsDBNull(0)) card.CardID = rdr.GetInt32(0); if (!rdr.IsDBNull(1)) card.CardName = rdr.GetString(1); if (!rdr.IsDBNull(2)) card.CardNumber = rdr.GetString(2); if (!rdr.IsDBNull(3)) card.CardImage = rdr.GetString(3); if (!rdr.IsDBNull(4)) card.CardMoney = rdr.GetDecimal(4); if (!rdr.IsDBNull(5)) card.CardLive = rdr.GetByte(5); if (!rdr.IsDBNull(6)) card.Synchronize = rdr.GetByte(6); if (!rdr.IsDBNull(7)) card.ModifyDate = rdr.GetDateTime(7); if (!rdr.IsDBNull(8)) card.CDID = rdr.GetInt32(8); if (!rdr.IsDBNull(9)) card.UserID = rdr.GetInt32(9); if (!rdr.IsDBNull(10)) card.MoneyStart = rdr.GetDecimal(10); if (!rdr.IsDBNull(11)) card.CardShow = rdr.GetByte(11); return card; }
/// <summary> /// 根据钱包ID取钱包,返回CardInfo /// </summary> public CardInfo GetCardByCardId(int userId, int cardId) { CardInfo card = new CardInfo(); SqlParameter[] parms = { new SqlParameter(PARM_USER_ID, SqlDbType.Int), new SqlParameter(PARM_CARD_ID, SqlDbType.Int) }; parms[0].Value = userId; parms[1].Value = cardId; using (SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, CommandType.Text, SQL_SELECT_CARD_BY_CARD_ID, parms)) { while (rdr.Read()) { card = DataToModel(rdr); } } return card; }
/// <summary> /// 修改钱包 /// </summary> public bool UpdateCard(CardInfo card) { SqlParameter[] parms = ModelToParms(card); int result = SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionString, CommandType.StoredProcedure, SQL_UPDATE_CARD, parms); return result > 0; }
/// <summary> /// 修改钱包 /// </summary> public bool UpdateCard(CardInfo card) { return dal.UpdateCard(card); }
/// <summary> /// 插入钱包 /// </summary> public bool InsertCard(CardInfo card) { return dal.InsertCard(card); }