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

            strSql.Append("update area set ");
            strSql.Append("areaID=@areaID,");
            strSql.Append("area=@area,");
            strSql.Append("fatherID=@fatherID");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@areaID",   SqlDbType.Int,       4),
                new SqlParameter("@area",     SqlDbType.VarChar, 200),
                new SqlParameter("@fatherID", SqlDbType.Int,       4),
                new SqlParameter("@id",       SqlDbType.Int, 4)
            };
            parameters[0].Value = model.areaID;
            parameters[1].Value = model.area;
            parameters[2].Value = model.fatherID;
            parameters[3].Value = model.id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(M_area model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into area(");
            strSql.Append("areaID,area,fatherID)");
            strSql.Append(" values (");
            strSql.Append("@areaID,@area,@fatherID)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@areaID",   SqlDbType.Int,       4),
                new SqlParameter("@area",     SqlDbType.VarChar, 200),
                new SqlParameter("@fatherID", SqlDbType.Int, 4)
            };
            parameters[0].Value = model.areaID;
            parameters[1].Value = model.area;
            parameters[2].Value = model.fatherID;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Пример #3
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public M_area DataRowToModel(DataRow row)
        {
            M_area model = new M_area();

            if (row != null)
            {
                if (row["id"] != null && row["id"].ToString() != "")
                {
                    model.id = int.Parse(row["id"].ToString());
                }
                if (row["areaID"] != null && row["areaID"].ToString() != "")
                {
                    model.areaID = int.Parse(row["areaID"].ToString());
                }
                if (row["area"] != null)
                {
                    model.area = row["area"].ToString();
                }
                if (row["fatherID"] != null && row["fatherID"].ToString() != "")
                {
                    model.fatherID = int.Parse(row["fatherID"].ToString());
                }
            }
            return(model);
        }
Пример #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public M_area GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

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

            M_area  model = new M_area();
            DataSet ds    = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Пример #5
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(M_area model)
 {
     return(dal.Update(model));
 }
Пример #6
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int  Add(M_area model)
 {
     return(dal.Add(model));
 }