Пример #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Maticsoft.Model.T_Menu model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update T_Menu set ");
            strSql.Append("name=@name,");
            strSql.Append("url=@url,");
            strSql.Append("icon=@icon,");
            strSql.Append("description=@description,");
            strSql.Append("pid=@pid,");
            strSql.Append("isDeleted=@isDeleted,");
            strSql.Append("_sort=@_sort");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@name",        SqlDbType.VarChar,  40),
                new SqlParameter("@url",         SqlDbType.VarChar, 200),
                new SqlParameter("@icon",        SqlDbType.VarChar,  30),
                new SqlParameter("@description", SqlDbType.VarChar, 200),
                new SqlParameter("@pid",         SqlDbType.Int,       4),
                new SqlParameter("@isDeleted",   SqlDbType.Int,       4),
                new SqlParameter("@_sort",       SqlDbType.Int,       4),
                new SqlParameter("@id",          SqlDbType.Int, 4)
            };
            parameters[0].Value = model.name;
            parameters[1].Value = model.url;
            parameters[2].Value = model.icon;
            parameters[3].Value = model.description;
            parameters[4].Value = model.pid;
            parameters[5].Value = model.isDeleted;
            parameters[6].Value = model._sort;
            parameters[7].Value = model.id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Maticsoft.Model.T_Menu DataRowToModel(DataRow row)
 {
     Maticsoft.Model.T_Menu model = new Maticsoft.Model.T_Menu();
     if (row != null)
     {
         if (row["id"] != null && row["id"].ToString() != "")
         {
             model.id = int.Parse(row["id"].ToString());
         }
         if (row["name"] != null)
         {
             model.name = row["name"].ToString();
         }
         if (row["url"] != null)
         {
             model.url = row["url"].ToString();
         }
         if (row["icon"] != null)
         {
             model.icon = row["icon"].ToString();
         }
         if (row["description"] != null)
         {
             model.description = row["description"].ToString();
         }
         if (row["pid"] != null && row["pid"].ToString() != "")
         {
             model.pid = int.Parse(row["pid"].ToString());
         }
         if (row["isDeleted"] != null && row["isDeleted"].ToString() != "")
         {
             model.isDeleted = int.Parse(row["isDeleted"].ToString());
         }
         if (row["_sort"] != null && row["_sort"].ToString() != "")
         {
             model._sort = int.Parse(row["_sort"].ToString());
         }
     }
     return model;
 }
Пример #3
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Maticsoft.Model.T_Menu DataRowToModel(DataRow row)
 {
     Maticsoft.Model.T_Menu model = new Maticsoft.Model.T_Menu();
     if (row != null)
     {
         if (row["id"] != null && row["id"].ToString() != "")
         {
             model.id = int.Parse(row["id"].ToString());
         }
         if (row["name"] != null)
         {
             model.name = row["name"].ToString();
         }
         if (row["url"] != null)
         {
             model.url = row["url"].ToString();
         }
         if (row["icon"] != null)
         {
             model.icon = row["icon"].ToString();
         }
         if (row["description"] != null)
         {
             model.description = row["description"].ToString();
         }
         if (row["pid"] != null && row["pid"].ToString() != "")
         {
             model.pid = int.Parse(row["pid"].ToString());
         }
         if (row["isDeleted"] != null && row["isDeleted"].ToString() != "")
         {
             model.isDeleted = int.Parse(row["isDeleted"].ToString());
         }
         if (row["_sort"] != null && row["_sort"].ToString() != "")
         {
             model._sort = int.Parse(row["_sort"].ToString());
         }
     }
     return(model);
 }
Пример #4
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Maticsoft.Model.T_Menu model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into T_Menu(");
            strSql.Append("name,url,icon,description,pid,isDeleted,_sort)");
            strSql.Append(" values (");
            strSql.Append("@name,@url,@icon,@description,@pid,@isDeleted,@_sort)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@name",        SqlDbType.VarChar,  40),
                new SqlParameter("@url",         SqlDbType.VarChar, 200),
                new SqlParameter("@icon",        SqlDbType.VarChar,  30),
                new SqlParameter("@description", SqlDbType.VarChar, 200),
                new SqlParameter("@pid",         SqlDbType.Int,       4),
                new SqlParameter("@isDeleted",   SqlDbType.Int,       4),
                new SqlParameter("@_sort",       SqlDbType.Int, 4)
            };
            parameters[0].Value = model.name;
            parameters[1].Value = model.url;
            parameters[2].Value = model.icon;
            parameters[3].Value = model.description;
            parameters[4].Value = model.pid;
            parameters[5].Value = model.isDeleted;
            parameters[6].Value = model._sort;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Пример #5
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.T_Menu GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 * from T_Menu ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.T_Menu GetModel(int id)
        {
            StringBuilder strSql=new StringBuilder();
            strSql.Append("select  top 1 * from T_Menu ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int,4)
            };
            parameters[0].Value = id;

            Maticsoft.Model.T_Menu model=new Maticsoft.Model.T_Menu();
            DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
            if(ds.Tables[0].Rows.Count>0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }