/// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Mofang.Model.TravelDestination model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update TravelDestination set ");

            strSql.Append(" Value = @Value , ");
            strSql.Append(" Name = @Name , ");
            strSql.Append(" Status = @Status , ");
            strSql.Append(" Sort = @Sort  ");
            strSql.Append(" where Id=@Id ");

            SqlParameter[] parameters =
            {
                new SqlParameter("@Id",     model.Id),
                new SqlParameter("@Value",  model.Value),
                new SqlParameter("@Name",   model.Name),
                new SqlParameter("@Status", model.Status),
                new SqlParameter("@Sort",   model.Sort)
            };

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Mofang.Model.TravelDestination model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into TravelDestination(");
            strSql.Append("Value,Name,Status,Sort");
            strSql.Append(") values (");
            strSql.Append("@Value,@Name,@Status,@Sort");
            strSql.Append(") ");
            strSql.Append(";select SCOPE_IDENTITY()");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Value",  model.Value),
                new SqlParameter("@Name",   model.Name),
                new SqlParameter("@Status", model.Status),
                new SqlParameter("@Sort",   model.Sort)
            };


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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Beispiel #3
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List <Mofang.Model.TravelDestination> DataTableToList(DataTable dt)
        {
            List <Mofang.Model.TravelDestination> modelList = new List <Mofang.Model.TravelDestination>();
            int rowsCount = dt.Rows.Count;

            if (rowsCount > 0)
            {
                Mofang.Model.TravelDestination model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Mofang.Model.TravelDestination();
                    if (dt.Rows[n]["Id"].ToString() != "")
                    {
                        model.Id = int.Parse(dt.Rows[n]["Id"].ToString());
                    }
                    if (dt.Rows[n]["Value"].ToString() != "")
                    {
                        model.Value = int.Parse(dt.Rows[n]["Value"].ToString());
                    }
                    model.Name = dt.Rows[n]["Name"].ToString();
                    if (dt.Rows[n]["Status"].ToString() != "")
                    {
                        model.Status = int.Parse(dt.Rows[n]["Status"].ToString());
                    }
                    if (dt.Rows[n]["Sort"].ToString() != "")
                    {
                        model.Sort = int.Parse(dt.Rows[n]["Sort"].ToString());
                    }


                    modelList.Add(model);
                }
            }
            return(modelList);
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Mofang.Model.TravelDestination GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select Id, Value, Name, Status, Sort  ");
            strSql.Append("  from TravelDestination ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Id", SqlDbType.Int, 4)
            };
            parameters[0].Value = Id;


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

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Id"].ToString() != "")
                {
                    model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Value"].ToString() != "")
                {
                    model.Value = int.Parse(ds.Tables[0].Rows[0]["Value"].ToString());
                }
                model.Name = ds.Tables[0].Rows[0]["Name"].ToString();
                if (ds.Tables[0].Rows[0]["Status"].ToString() != "")
                {
                    model.Status = int.Parse(ds.Tables[0].Rows[0]["Status"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Sort"].ToString() != "")
                {
                    model.Sort = int.Parse(ds.Tables[0].Rows[0]["Sort"].ToString());
                }

                return(model);
            }
            else
            {
                return(null);
            }
        }
Beispiel #5
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Mofang.Model.TravelDestination model)
 {
     return(dal.Update(model));
 }
Beispiel #6
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(Mofang.Model.TravelDestination model)
 {
     return(dal.Add(model));
 }