Ejemplo n.º 1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Models.mobile_model GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

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

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
 ///<summary>
 /// 将对象转换为实体
 /// </summary>
 private Models.mobile_model DataRowToModel(DataRow row)
 {
     Models.mobile_model model = new Models.mobile_model();
     if (row != null)
     {
         if (row["id"] != null && row["id"].ToString() != "")
         {
             model.id = int.Parse(row["id"].ToString());
         }
         if (row["model_name"] != null && row["model_name"].ToString() != "")
         {
             model.model_name = row["model_name"].ToString();
         }
     }
     return(model);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Models.mobile_model model)
        {
            using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
            {
                conn.Open();
                StringBuilder strSql = new StringBuilder();
                strSql.Append("insert into tb_mobile_model(model_name)");
                strSql.Append(" values (@model_name)");
                SqlParameter[] parameters = {
                        new SqlParameter("@model_name", SqlDbType.VarChar,50)};
                parameters[0].Value = model.model_name;

                object obj = DbHelperSQL.ExecuteSql(strSql.ToString(),parameters); //带事务
                model.id = Convert.ToInt32(obj);

            return model.id;
        }
        public HttpResponseMessage Post([FromBody] Models.mobile_model value)
        {
            int addId    = db.Add(value);
            var response = Request.CreateResponse();

            if (addId > 0)
            {
                response         = Request.CreateResponse(HttpStatusCode.OK);
                response.Content = new StringContent("添加成功!", Encoding.Unicode);
                return(response);
            }
            else
            {
                response         = Request.CreateResponse(HttpStatusCode.InternalServerError);
                response.Content = new StringContent("未知错误", Encoding.Unicode);
                return(response);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Models.mobile_model model)
        {
            using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        StringBuilder strSql = new StringBuilder();

                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        return false;
                    }
                }
            }
            return true;
        }
 public Models.mobile_model GetById(int id)
 {
     Models.mobile_model model = db.GetModel(id);
     return(model);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Models.mobile_model model)
 {
     return(true);
 }