Esempio n. 1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(BuysingooShop.Model.activity model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update activity set ");
            strSql.Append("fields=@fields,");
            strSql.Append("value=@value,");
            strSql.Append("remark=@remark,");
            strSql.Append("is_close=@is_close,");
            strSql.Append("start_time=@start_time,");
            strSql.Append("end_time=@end_time,");
            strSql.Append("category_id=@category_id");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@fields",      SqlDbType.NVarChar,   50),
                new SqlParameter("@value",       SqlDbType.NVarChar,   50),
                new SqlParameter("@remark",      SqlDbType.NVarChar,  100),
                new SqlParameter("@is_close",    SqlDbType.Int,         4),
                new SqlParameter("@start_time",  SqlDbType.DateTime),
                new SqlParameter("@end_time",    SqlDbType.DateTime),
                new SqlParameter("@category_id", SqlDbType.NVarChar,  100),
                new SqlParameter("@ID",          SqlDbType.Int, 4)
            };
            parameters[0].Value = model.fields;
            parameters[1].Value = model.value;
            parameters[2].Value = model.remark;
            parameters[3].Value = model.is_close;
            parameters[4].Value = model.start_time;
            parameters[5].Value = model.end_time;
            parameters[6].Value = model.category_id;
            parameters[7].Value = model.ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public BuysingooShop.Model.activity DataRowToModel(DataRow row)
 {
     BuysingooShop.Model.activity model = new BuysingooShop.Model.activity();
     if (row != null)
     {
         if (row["ID"] != null && row["ID"].ToString() != "")
         {
             model.ID = int.Parse(row["ID"].ToString());
         }
         if (row["fields"] != null)
         {
             model.fields = row["fields"].ToString();
         }
         if (row["value"] != null)
         {
             model.value = row["value"].ToString();
         }
         if (row["remark"] != null)
         {
             model.remark = row["remark"].ToString();
         }
         if (row["is_close"] != null && row["is_close"].ToString() != "")
         {
             model.is_close = int.Parse(row["is_close"].ToString());
         }
         if (row["start_time"] != null && row["start_time"].ToString() != "")
         {
             model.start_time = DateTime.Parse(row["start_time"].ToString());
         }
         if (row["end_time"] != null && row["end_time"].ToString() != "")
         {
             model.end_time = DateTime.Parse(row["end_time"].ToString());
         }
         if (row["category_id"] != null && row["category_id"].ToString() != "")
         {
             model.category_id = row["category_id"].ToString();
         }
     }
     return(model);
 }
Esempio n. 3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(BuysingooShop.Model.activity model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into activity(");
            strSql.Append("fields,value,remark,is_close,start_time,end_time,category_id)");
            strSql.Append(" values (");
            strSql.Append("@fields,@value,@remark,@is_close,@start_time,@end_time,@category_id)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@fields",      SqlDbType.NVarChar,   50),
                new SqlParameter("@value",       SqlDbType.NVarChar,   50),
                new SqlParameter("@remark",      SqlDbType.NVarChar,  100),
                new SqlParameter("@is_close",    SqlDbType.Int,         4),
                new SqlParameter("@start_time",  SqlDbType.DateTime),
                new SqlParameter("@end_time",    SqlDbType.DateTime),
                new SqlParameter("@category_id", SqlDbType.NVarChar, 100)
            };
            parameters[0].Value = model.fields;
            parameters[1].Value = model.value;
            parameters[2].Value = model.remark;
            parameters[3].Value = model.is_close;
            parameters[4].Value = model.start_time;
            parameters[5].Value = model.end_time;
            parameters[6].Value = model.category_id;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BuysingooShop.Model.activity GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ID,fields,value,remark,is_close,start_time,end_time,category_id from dt_activity ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ID;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }