/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.MemberAccount model) { StringBuilder strSql = new StringBuilder(); strSql.Append("if(not exists(select 1 from memberaccount where (@UserId<>'' and UserId=@UserId) or (@MobilePhone<>'' and MobilePhone=@MobilePhone) or (@Email<>'' and Email=@Email))) begin insert into memberaccount("); strSql.Append("UserType, UserGroup, UserId, MobilePhone, Email, Email_QQ, PassWord, Question, Answer, State, RegisterDate, RegisterIP, Capital, Coupons, Points, PeriodOfValidity, CompanyClass)"); strSql.Append(" values ("); strSql.Append("@UserType, @UserGroup, @UserId, @MobilePhone, @Email, @Email_QQ, @PassWord, @Question, @Answer, @State, @RegisterDate, @RegisterIP, @Capital, @Coupons, @Points, @PeriodOfValidity, @CompanyClass)"); strSql.Append(" SELECT SCOPE_IDENTITY() end"); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "UserType", DbType.Int32, model.UserType); db.AddInParameter(dbCommand, "UserGroup", DbType.Int32, model.UserGroup); db.AddInParameter(dbCommand, "UserId", DbType.AnsiString, model.UserId); db.AddInParameter(dbCommand, "MobilePhone", DbType.AnsiString, model.MobilePhone); db.AddInParameter(dbCommand, "Email", DbType.AnsiString, model.Email); db.AddInParameter(dbCommand, "Email_QQ", DbType.AnsiString, model.Email_QQ); db.AddInParameter(dbCommand, "PassWord", DbType.AnsiString, model.PassWord); db.AddInParameter(dbCommand, "Question", DbType.AnsiString, model.Question); db.AddInParameter(dbCommand, "Answer", DbType.AnsiString, model.Answer); db.AddInParameter(dbCommand, "State", DbType.Int32, model.State); db.AddInParameter(dbCommand, "RegisterDate", DbType.DateTime, model.RegisterDate); db.AddInParameter(dbCommand, "RegisterIP", DbType.AnsiString, model.RegisterIP); db.AddInParameter(dbCommand, "Capital", DbType.Decimal, model.Capital); db.AddInParameter(dbCommand, "Coupons", DbType.Int32, model.Coupons); db.AddInParameter(dbCommand, "Points", DbType.Int32, model.Points); db.AddInParameter(dbCommand, "PeriodOfValidity", DbType.DateTime, model.PeriodOfValidity); db.AddInParameter(dbCommand, "CompanyClass", DbType.String, model.CompanyClass); object obj = db.ExecuteScalar(dbCommand); return(obj != null?Convert.ToInt32(obj) : 0); }
private Model.MemberAccount GetModelByDataSet(DataSet ds) { Model.MemberAccount model = null; if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { model = GetModelByDataRow(ds.Tables[0].Rows[0]); } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.MemberAccount model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update memberaccount set "); strSql.Append("UserType=@UserType,"); strSql.Append("UserGroup=@UserGroup,"); strSql.Append("UserId=@UserId,"); strSql.Append("MobilePhone=@MobilePhone,"); strSql.Append("Email=@Email,"); strSql.Append("Email_QQ=@Email_QQ,"); if (model.PassWord.Length > 0) { strSql.Append("PassWord=@PassWord,"); } strSql.Append("Question=@Question,"); strSql.Append("Answer=@Answer,"); strSql.Append("State=@State,"); strSql.Append("Coupons=@Coupons,"); strSql.Append("Capital=@Capital,"); strSql.Append("Points=@Points,"); strSql.Append("PeriodOfValidity=@PeriodOfValidity,"); strSql.Append("CompanyClass=@CompanyClass"); strSql.Append(" where UID=@UID "); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "UID", DbType.Int32, model.UID); db.AddInParameter(dbCommand, "UserType", DbType.Int32, model.UserType); db.AddInParameter(dbCommand, "UserGroup", DbType.Int32, model.UserGroup); db.AddInParameter(dbCommand, "UserId", DbType.AnsiString, model.UserId); db.AddInParameter(dbCommand, "MobilePhone", DbType.AnsiString, model.MobilePhone); db.AddInParameter(dbCommand, "Email", DbType.AnsiString, model.Email); db.AddInParameter(dbCommand, "Email_QQ", DbType.AnsiString, model.Email_QQ); db.AddInParameter(dbCommand, "PassWord", DbType.AnsiString, model.PassWord); db.AddInParameter(dbCommand, "Question", DbType.AnsiString, model.Question); db.AddInParameter(dbCommand, "Answer", DbType.AnsiString, model.Answer); db.AddInParameter(dbCommand, "State", DbType.Int32, model.State); db.AddInParameter(dbCommand, "RegisterDate", DbType.DateTime, model.RegisterDate); db.AddInParameter(dbCommand, "RegisterIP", DbType.AnsiString, model.RegisterIP); db.AddInParameter(dbCommand, "Capital", DbType.Decimal, model.Capital); db.AddInParameter(dbCommand, "Coupons", DbType.Int32, model.Coupons); db.AddInParameter(dbCommand, "Points", DbType.Int32, model.Points); db.AddInParameter(dbCommand, "PeriodOfValidity", DbType.DateTime, model.PeriodOfValidity); db.AddInParameter(dbCommand, "CompanyClass", DbType.String, model.CompanyClass); return(0 < db.ExecuteNonQuery(dbCommand)); }
private Model.MemberAccount GetModelByDataRow(DataRow dr) { Model.MemberAccount model = new Model.MemberAccount(); model.UID = int.Parse(dr["UID"].ToString()); model.UserType = int.Parse(dr["UserType"].ToString()); model.UserGroup = int.Parse(dr["UserGroup"].ToString()); model.UserId = dr["UserId"].ToString(); model.PassWord = dr["PassWord"].ToString(); model.MobilePhone = dr["MobilePhone"].ToString(); model.Question = dr["Question"].ToString(); model.Answer = dr["Answer"].ToString(); model.Email = dr["Email"].ToString(); model.Email_QQ = dr["Email_QQ"].ToString(); model.State = int.Parse(dr["State"].ToString()); model.RegisterDate = DateTime.Parse(dr["RegisterDate"].ToString()); model.RegisterIP = dr["RegisterIP"].ToString(); model.Capital = decimal.Parse(dr["Capital"].ToString()); model.Coupons = int.Parse(dr["Coupons"].ToString()); model.Points = int.Parse(dr["Points"].ToString()); model.PeriodOfValidity = DateTime.Parse(dr["PeriodOfValidity"].ToString()); model.CompanyClass = dr["CompanyClass"].ToString(); return(model); }