Example #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(LPWeb.Model.UserGoals model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into UserGoals(");
            strSql.Append("UserId,LowRange,MediumRange,HighRange,Month)");
            strSql.Append(" values (");
            strSql.Append("@UserId,@LowRange,@MediumRange,@HighRange,@Month)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserId",      SqlDbType.Int,      4),
                new SqlParameter("@LowRange",    SqlDbType.Money,    8),
                new SqlParameter("@MediumRange", SqlDbType.Money,    8),
                new SqlParameter("@HighRange",   SqlDbType.Money,    8),
                new SqlParameter("@Month",       SqlDbType.SmallInt, 2)
            };
            parameters[0].Value = model.UserId;
            parameters[1].Value = model.LowRange;
            parameters[2].Value = model.MediumRange;
            parameters[3].Value = model.HighRange;
            parameters[4].Value = model.Month;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(1);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Example #2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(LPWeb.Model.UserGoals model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update UserGoals set ");
            strSql.Append("GoalId=@GoalId,");
            strSql.Append("UserId=@UserId,");
            strSql.Append("LowRange=@LowRange,");
            strSql.Append("MediumRange=@MediumRange,");
            strSql.Append("HighRange=@HighRange,");
            strSql.Append("Month=@Month");
            strSql.Append(" where GoalId=@GoalId ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@GoalId",      SqlDbType.Int,      4),
                new SqlParameter("@UserId",      SqlDbType.Int,      4),
                new SqlParameter("@LowRange",    SqlDbType.Money,    8),
                new SqlParameter("@MediumRange", SqlDbType.Money,    8),
                new SqlParameter("@HighRange",   SqlDbType.Money,    8),
                new SqlParameter("@Month",       SqlDbType.SmallInt, 2)
            };
            parameters[0].Value = model.GoalId;
            parameters[1].Value = model.UserId;
            parameters[2].Value = model.LowRange;
            parameters[3].Value = model.MediumRange;
            parameters[4].Value = model.HighRange;
            parameters[5].Value = model.Month;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
Example #3
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public LPWeb.Model.UserGoals GetModel(int GoalId)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 GoalId,UserId,LowRange,MediumRange,HighRange,Month from UserGoals ");
            strSql.Append(" where GoalId=@GoalId ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@GoalId", SqlDbType.Int, 4)
            };
            parameters[0].Value = GoalId;

            LPWeb.Model.UserGoals model = new LPWeb.Model.UserGoals();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["GoalId"].ToString() != "")
                {
                    model.GoalId = int.Parse(ds.Tables[0].Rows[0]["GoalId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UserId"].ToString() != "")
                {
                    model.UserId = int.Parse(ds.Tables[0].Rows[0]["UserId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LowRange"].ToString() != "")
                {
                    model.LowRange = decimal.Parse(ds.Tables[0].Rows[0]["LowRange"].ToString());
                }
                if (ds.Tables[0].Rows[0]["MediumRange"].ToString() != "")
                {
                    model.MediumRange = decimal.Parse(ds.Tables[0].Rows[0]["MediumRange"].ToString());
                }
                if (ds.Tables[0].Rows[0]["HighRange"].ToString() != "")
                {
                    model.HighRange = decimal.Parse(ds.Tables[0].Rows[0]["HighRange"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Month"].ToString() != "")
                {
                    model.Month = int.Parse(ds.Tables[0].Rows[0]["Month"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }