Пример #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(BookShop.Model.Settings model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Settings(");
            strSql.Append("Name,Value)");
            strSql.Append(" values (");
            strSql.Append("@Name,@Value)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Name",  SqlDbType.NVarChar, 50),
                new SqlParameter("@Value", SqlDbType.NVarChar, 50)
            };
            parameters[0].Value = model.Name;
            parameters[1].Value = model.Value;

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

            if (obj == null)
            {
                return(1);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Пример #2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(BookShop.Model.Settings model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Settings set ");
            strSql.Append("Name=@Name,");
            strSql.Append("Value=@Value");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Name",  SqlDbType.NVarChar, 50),
                new SqlParameter("@Value", SqlDbType.NVarChar, 50),
                new SqlParameter("@Id",    SqlDbType.Int, 4)
            };
            parameters[0].Value = model.Name;
            parameters[1].Value = model.Value;
            parameters[2].Value = model.Id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #3
0
        //--------------------------------------------
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BookShop.Model.Settings GetModel(string name)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Id,Name,Value from Settings ");
            strSql.Append(" where Name=@Name ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Name", SqlDbType.NVarChar, 50)
            };
            parameters[0].Value = name;

            BookShop.Model.Settings model = new BookShop.Model.Settings();
            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());
                }
                model.Name  = ds.Tables[0].Rows[0]["Name"].ToString();
                model.Value = ds.Tables[0].Rows[0]["Value"].ToString();
                return(model);
            }
            else
            {
                return(null);
            }
        }
Пример #4
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(BookShop.Model.Settings model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Settings set ");
            strSql.Append("Name=@Name,");
            strSql.Append("Value=@Value");
            strSql.Append(" where Id=@Id ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Id",    SqlDbType.Int,       4),
                new SqlParameter("@Name",  SqlDbType.NVarChar, 50),
                new SqlParameter("@Value", SqlDbType.NVarChar, 50)
            };
            parameters[0].Value = model.Id;
            parameters[1].Value = model.Name;
            parameters[2].Value = model.Value;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
Пример #5
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public BookShop.Model.Settings DataRowToModel(DataRow row)
 {
     BookShop.Model.Settings model=new BookShop.Model.Settings();
     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["Value"]!=null)
         {
             model.Value=row["Value"].ToString();
         }
     }
     return model;
 }
Пример #6
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public BookShop.Model.Settings DataRowToModel(DataRow row)
 {
     BookShop.Model.Settings model = new BookShop.Model.Settings();
     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["Value"] != null)
         {
             model.Value = row["Value"].ToString();
         }
     }
     return(model);
 }
Пример #7
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BookShop.Model.Settings GetModel(string name)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 Id,Name,Value from Settings ");
            strSql.Append(" where Name=@Name");
            SqlParameter[] parameters = {
                    new SqlParameter("@Name", SqlDbType.NVarChar,50)
            };
            parameters[0].Value = name;

            BookShop.Model.Settings model = new BookShop.Model.Settings();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }
Пример #8
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List <BookShop.Model.Settings> DataTableToList(DataTable dt)
        {
            List <BookShop.Model.Settings> modelList = new List <BookShop.Model.Settings>();
            int rowsCount = dt.Rows.Count;

            if (rowsCount > 0)
            {
                BookShop.Model.Settings model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new BookShop.Model.Settings();
                    if (dt.Rows[n]["Id"].ToString() != "")
                    {
                        model.Id = int.Parse(dt.Rows[n]["Id"].ToString());
                    }
                    model.Name  = dt.Rows[n]["Name"].ToString();
                    model.Value = dt.Rows[n]["Value"].ToString();
                    modelList.Add(model);
                }
            }
            return(modelList);
        }
Пример #9
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BookShop.Model.Settings GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

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

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

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