/// <summary> /// 增加一条数据 /// </summary> public int Add(abc.Model.Model.MemberCardNum model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into MemberCardNum("); strSql.Append("MemberId,CardCategoryId,CardTypeId,CardTotalNum,CardRemainderNum)"); strSql.Append(" values ("); strSql.Append("SQL2012MemberId,SQL2012CardCategoryId,SQL2012CardTypeId,SQL2012CardTotalNum,SQL2012CardRemainderNum)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("SQL2012MemberId", SqlDbType.Int, 4), new SqlParameter("SQL2012CardCategoryId", SqlDbType.Int, 4), new SqlParameter("SQL2012CardTypeId", SqlDbType.Int, 4), new SqlParameter("SQL2012CardTotalNum", SqlDbType.Int, 4), new SqlParameter("SQL2012CardRemainderNum", SqlDbType.Int, 4) }; parameters[0].Value = model.MemberId; parameters[1].Value = model.CardCategoryId; parameters[2].Value = model.CardTypeId; parameters[3].Value = model.CardTotalNum; parameters[4].Value = model.CardRemainderNum; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public abc.Model.Model.MemberCardNum DataRowToModel(DataRow row) { abc.Model.Model.MemberCardNum model = new abc.Model.Model.MemberCardNum(); if (row != null) { if (row["MemberCardId"] != null && row["MemberCardId"].ToString() != "") { model.MemberCardId = int.Parse(row["MemberCardId"].ToString()); } if (row["MemberId"] != null && row["MemberId"].ToString() != "") { model.MemberId = int.Parse(row["MemberId"].ToString()); } if (row["CardCategoryId"] != null && row["CardCategoryId"].ToString() != "") { model.CardCategoryId = int.Parse(row["CardCategoryId"].ToString()); } if (row["CardTypeId"] != null && row["CardTypeId"].ToString() != "") { model.CardTypeId = int.Parse(row["CardTypeId"].ToString()); } if (row["CardTotalNum"] != null && row["CardTotalNum"].ToString() != "") { model.CardTotalNum = int.Parse(row["CardTotalNum"].ToString()); } if (row["CardRemainderNum"] != null && row["CardRemainderNum"].ToString() != "") { model.CardRemainderNum = int.Parse(row["CardRemainderNum"].ToString()); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(abc.Model.Model.MemberCardNum model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update MemberCardNum set "); strSql.Append("CardCategoryId=SQL2012CardCategoryId,"); strSql.Append("CardTypeId=SQL2012CardTypeId,"); strSql.Append("CardTotalNum=SQL2012CardTotalNum,"); strSql.Append("CardRemainderNum=SQL2012CardRemainderNum"); strSql.Append(" where MemberCardId=SQL2012MemberCardId"); SqlParameter[] parameters = { new SqlParameter("SQL2012CardCategoryId", SqlDbType.Int, 4), new SqlParameter("SQL2012CardTypeId", SqlDbType.Int, 4), new SqlParameter("SQL2012CardTotalNum", SqlDbType.Int, 4), new SqlParameter("SQL2012CardRemainderNum", SqlDbType.Int, 4), new SqlParameter("SQL2012MemberCardId", SqlDbType.Int, 4), new SqlParameter("SQL2012MemberId", SqlDbType.Int, 4) }; parameters[0].Value = model.CardCategoryId; parameters[1].Value = model.CardTypeId; parameters[2].Value = model.CardTotalNum; parameters[3].Value = model.CardRemainderNum; parameters[4].Value = model.MemberCardId; parameters[5].Value = model.MemberId; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public abc.Model.Model.MemberCardNum GetModel(int MemberCardId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 MemberCardId,MemberId,CardCategoryId,CardTypeId,CardTotalNum,CardRemainderNum from MemberCardNum "); strSql.Append(" where MemberCardId=SQL2012MemberCardId"); SqlParameter[] parameters = { new SqlParameter("SQL2012MemberCardId", SqlDbType.Int, 4) }; parameters[0].Value = MemberCardId; abc.Model.Model.MemberCardNum model = new abc.Model.Model.MemberCardNum(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }