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

            strSql.Append("update S_Role set ");
            strSql.Append("RoleName=@RoleName,");
            strSql.Append("ParentCode=@ParentCode,");
            strSql.Append("RoleSeq=@RoleSeq,");
            strSql.Append("Description=@Description,");
            strSql.Append("CreateUser=@CreateUser,");
            strSql.Append("CreateDate=@CreateDate,");
            strSql.Append("UpdateUser=@UpdateUser,");
            strSql.Append("UpdateDate=@UpdateDate");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@RoleName",    SqlDbType.NVarChar,   50),
                new SqlParameter("@ParentCode",  SqlDbType.VarChar,    20),
                new SqlParameter("@RoleSeq",     SqlDbType.Int,         4),
                new SqlParameter("@Description", SqlDbType.NVarChar,  100),
                new SqlParameter("@CreateUser",  SqlDbType.VarChar,    20),
                new SqlParameter("@CreateDate",  SqlDbType.DateTime),
                new SqlParameter("@UpdateUser",  SqlDbType.VarChar,    20),
                new SqlParameter("@UpdateDate",  SqlDbType.DateTime),
                new SqlParameter("@ID",          SqlDbType.Int,         4),
                new SqlParameter("@RoleCode",    SqlDbType.VarChar, 20)
            };
            parameters[0].Value = model.RoleName;
            parameters[1].Value = model.ParentCode;
            parameters[2].Value = model.RoleSeq;
            parameters[3].Value = model.Description;
            parameters[4].Value = model.CreateUser;
            parameters[5].Value = model.CreateDate;
            parameters[6].Value = model.UpdateUser;
            parameters[7].Value = model.UpdateDate;
            parameters[8].Value = model.ID;
            parameters[9].Value = model.RoleCode;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public ML.Model.S_Role DataRowToModel(DataRow row)
 {
     ML.Model.S_Role model = new ML.Model.S_Role();
     if (row != null)
     {
         if (row["ID"] != null && row["ID"].ToString() != "")
         {
             model.ID = int.Parse(row["ID"].ToString());
         }
         if (row["RoleCode"] != null)
         {
             model.RoleCode = row["RoleCode"].ToString();
         }
         if (row["RoleName"] != null)
         {
             model.RoleName = row["RoleName"].ToString();
         }
         if (row["ParentCode"] != null)
         {
             model.ParentCode = row["ParentCode"].ToString();
         }
         if (row["RoleSeq"] != null && row["RoleSeq"].ToString() != "")
         {
             model.RoleSeq = int.Parse(row["RoleSeq"].ToString());
         }
         if (row["Description"] != null)
         {
             model.Description = row["Description"].ToString();
         }
         if (row["CreateUser"] != null)
         {
             model.CreateUser = row["CreateUser"].ToString();
         }
         if (row["CreateDate"] != null && row["CreateDate"].ToString() != "")
         {
             model.CreateDate = DateTime.Parse(row["CreateDate"].ToString());
         }
         if (row["UpdateUser"] != null)
         {
             model.UpdateUser = row["UpdateUser"].ToString();
         }
         if (row["UpdateDate"] != null && row["UpdateDate"].ToString() != "")
         {
             model.UpdateDate = DateTime.Parse(row["UpdateDate"].ToString());
         }
     }
     return(model);
 }
Пример #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(ML.Model.S_Role model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into S_Role(");
            strSql.Append("RoleCode,RoleName,ParentCode,RoleSeq,Description,CreateUser,CreateDate,UpdateUser,UpdateDate)");
            strSql.Append(" values (");
            strSql.Append("@RoleCode,@RoleName,@ParentCode,@RoleSeq,@Description,@CreateUser,@CreateDate,@UpdateUser,@UpdateDate)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@RoleCode",    SqlDbType.VarChar,    20),
                new SqlParameter("@RoleName",    SqlDbType.NVarChar,   50),
                new SqlParameter("@ParentCode",  SqlDbType.VarChar,    20),
                new SqlParameter("@RoleSeq",     SqlDbType.Int,         4),
                new SqlParameter("@Description", SqlDbType.NVarChar,  100),
                new SqlParameter("@CreateUser",  SqlDbType.VarChar,    20),
                new SqlParameter("@CreateDate",  SqlDbType.DateTime),
                new SqlParameter("@UpdateUser",  SqlDbType.VarChar,    20),
                new SqlParameter("@UpdateDate",  SqlDbType.DateTime)
            };
            parameters[0].Value = model.RoleCode;
            parameters[1].Value = model.RoleName;
            parameters[2].Value = model.ParentCode;
            parameters[3].Value = model.RoleSeq;
            parameters[4].Value = model.Description;
            parameters[5].Value = model.CreateUser;
            parameters[6].Value = model.CreateDate;
            parameters[7].Value = model.UpdateUser;
            parameters[8].Value = model.UpdateDate;

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

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

            strSql.Append("select  top 1 ID,RoleCode,RoleName,ParentCode,RoleSeq,Description,CreateUser,CreateDate,UpdateUser,UpdateDate from S_Role ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ID;

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

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