コード例 #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(abc.Model.Model.Attribute model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Attribute(");
            strSql.Append("AttrCateId,AttrName,Enabled,OrderBy,CreateTime)");
            strSql.Append(" values (");
            strSql.Append("SQL2012AttrCateId,SQL2012AttrName,SQL2012Enabled,SQL2012OrderBy,SQL2012CreateTime)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("SQL2012AttrCateId", SqlDbType.Int,       4),
                new SqlParameter("SQL2012AttrName",   SqlDbType.VarChar, 255),
                new SqlParameter("SQL2012Enabled",    SqlDbType.Int,       4),
                new SqlParameter("SQL2012OrderBy",    SqlDbType.Int,       4),
                new SqlParameter("SQL2012CreateTime", SqlDbType.DateTime)
            };
            parameters[0].Value = model.AttrCateId;
            parameters[1].Value = model.AttrName;
            parameters[2].Value = model.Enabled;
            parameters[3].Value = model.OrderBy;
            parameters[4].Value = model.CreateTime;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
コード例 #2
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public abc.Model.Model.Attribute DataRowToModel(DataRow row)
 {
     abc.Model.Model.Attribute model = new abc.Model.Model.Attribute();
     if (row != null)
     {
         if (row["AttrId"] != null && row["AttrId"].ToString() != "")
         {
             model.AttrId = int.Parse(row["AttrId"].ToString());
         }
         if (row["AttrCateId"] != null && row["AttrCateId"].ToString() != "")
         {
             model.AttrCateId = int.Parse(row["AttrCateId"].ToString());
         }
         if (row["AttrName"] != null)
         {
             model.AttrName = row["AttrName"].ToString();
         }
         if (row["Enabled"] != null && row["Enabled"].ToString() != "")
         {
             model.Enabled = int.Parse(row["Enabled"].ToString());
         }
         if (row["OrderBy"] != null && row["OrderBy"].ToString() != "")
         {
             model.OrderBy = int.Parse(row["OrderBy"].ToString());
         }
         if (row["CreateTime"] != null && row["CreateTime"].ToString() != "")
         {
             model.CreateTime = DateTime.Parse(row["CreateTime"].ToString());
         }
     }
     return(model);
 }
コード例 #3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(abc.Model.Model.Attribute model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Attribute set ");
            strSql.Append("AttrCateId=SQL2012AttrCateId,");
            strSql.Append("AttrName=SQL2012AttrName,");
            strSql.Append("Enabled=SQL2012Enabled,");
            strSql.Append("OrderBy=SQL2012OrderBy,");
            strSql.Append("CreateTime=SQL2012CreateTime");
            strSql.Append(" where AttrId=SQL2012AttrId");
            SqlParameter[] parameters =
            {
                new SqlParameter("SQL2012AttrCateId", SqlDbType.Int,         4),
                new SqlParameter("SQL2012AttrName",   SqlDbType.VarChar,   255),
                new SqlParameter("SQL2012Enabled",    SqlDbType.Int,         4),
                new SqlParameter("SQL2012OrderBy",    SqlDbType.Int,         4),
                new SqlParameter("SQL2012CreateTime", SqlDbType.DateTime),
                new SqlParameter("SQL2012AttrId",     SqlDbType.Int, 4)
            };
            parameters[0].Value = model.AttrCateId;
            parameters[1].Value = model.AttrName;
            parameters[2].Value = model.Enabled;
            parameters[3].Value = model.OrderBy;
            parameters[4].Value = model.CreateTime;
            parameters[5].Value = model.AttrId;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public abc.Model.Model.Attribute GetModel(int AttrId)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 AttrId,AttrCateId,AttrName,Enabled,OrderBy,CreateTime from Attribute ");
            strSql.Append(" where AttrId=SQL2012AttrId");
            SqlParameter[] parameters =
            {
                new SqlParameter("SQL2012AttrId", SqlDbType.Int, 4)
            };
            parameters[0].Value = AttrId;

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

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