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

            strSql.Append("insert into Dirtory(");
            strSql.Append("ParentDirId,UId,DirName,DirDesc)");
            strSql.Append(" values (");
            strSql.Append("@ParentDirId,@UId,@DirName,@DirDesc)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ParentDirId", SqlDbType.Int,      4),
                new SqlParameter("@UId",         SqlDbType.Int,      4),
                new SqlParameter("@DirName",     SqlDbType.VarChar, 50),
                new SqlParameter("@DirDesc",     SqlDbType.VarChar, 100)
            };
            parameters[0].Value = model.ParentDirId;
            parameters[1].Value = model.UId;
            parameters[2].Value = model.DirName;
            parameters[3].Value = model.DirDesc;

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

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

            strSql.Append("update Dirtory set ");
            strSql.Append("ParentDirId=@ParentDirId,");
            strSql.Append("UId=@UId,");
            strSql.Append("DirName=@DirName,");
            strSql.Append("DirDesc=@DirDesc");
            strSql.Append(" where DirId=@DirId");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ParentDirId", SqlDbType.Int,       4),
                new SqlParameter("@UId",         SqlDbType.Int,       4),
                new SqlParameter("@DirName",     SqlDbType.VarChar,  50),
                new SqlParameter("@DirDesc",     SqlDbType.VarChar, 100),
                new SqlParameter("@DirId",       SqlDbType.Int, 4)
            };
            parameters[0].Value = model.ParentDirId;
            parameters[1].Value = model.UId;
            parameters[2].Value = model.DirName;
            parameters[3].Value = model.DirDesc;
            parameters[4].Value = model.DirId;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #3
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Hch.iDisk.Model.Dirtory GetModel(int DirId)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 DirId,ParentDirId,UId,DirName,DirDesc from Dirtory ");
            strSql.Append(" where DirId=@DirId");
            SqlParameter[] parameters =
            {
                new SqlParameter("@DirId", SqlDbType.Int, 4)
            };
            parameters[0].Value = DirId;

            Hch.iDisk.Model.Dirtory model = new Hch.iDisk.Model.Dirtory();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["DirId"].ToString() != "")
                {
                    model.DirId = int.Parse(ds.Tables[0].Rows[0]["DirId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ParentDirId"].ToString() != "")
                {
                    model.ParentDirId = int.Parse(ds.Tables[0].Rows[0]["ParentDirId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UId"].ToString() != "")
                {
                    model.UId = int.Parse(ds.Tables[0].Rows[0]["UId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["DirName"] != null)
                {
                    model.DirName = ds.Tables[0].Rows[0]["DirName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["DirDesc"] != null)
                {
                    model.DirDesc = ds.Tables[0].Rows[0]["DirDesc"].ToString();
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }