Example #1
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public book_shop.Model.OrdersModel DataRowToModel(DataRow row)
 {
     book_shop.Model.OrdersModel model = new book_shop.Model.OrdersModel();
     if (row != null)
     {
         if (row["OrderId"] != null)
         {
             model.OrderId = row["OrderId"].ToString();
         }
         if (row["OrderDate"] != null && row["OrderDate"].ToString() != "")
         {
             model.OrderDate = DateTime.Parse(row["OrderDate"].ToString());
         }
         if (row["UserId"] != null && row["UserId"].ToString() != "")
         {
             model.UserId = int.Parse(row["UserId"].ToString());
         }
         if (row["TotalPrice"] != null && row["TotalPrice"].ToString() != "")
         {
             model.TotalPrice = decimal.Parse(row["TotalPrice"].ToString());
         }
         if (row["PostAddress"] != null)
         {
             model.PostAddress = row["PostAddress"].ToString();
         }
         if (row["state"] != null && row["state"].ToString() != "")
         {
             model.state = int.Parse(row["state"].ToString());
         }
     }
     return(model);
 }
Example #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(book_shop.Model.OrdersModel model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Orders(");
            strSql.Append("OrderId,OrderDate,UserId,TotalPrice,PostAddress,state)");
            strSql.Append(" values (");
            strSql.Append("@OrderId,@OrderDate,@UserId,@TotalPrice,@PostAddress,@state)");
            SqlParameter[] parameters =
            {
                new SqlParameter("@OrderId",     SqlDbType.NVarChar,   50),
                new SqlParameter("@OrderDate",   SqlDbType.DateTime),
                new SqlParameter("@UserId",      SqlDbType.Int,         4),
                new SqlParameter("@TotalPrice",  SqlDbType.Decimal,     9),
                new SqlParameter("@PostAddress", SqlDbType.NVarChar,  255),
                new SqlParameter("@state",       SqlDbType.Int, 4)
            };
            parameters[0].Value = model.OrderId;
            parameters[1].Value = model.OrderDate;
            parameters[2].Value = model.UserId;
            parameters[3].Value = model.TotalPrice;
            parameters[4].Value = model.PostAddress;
            parameters[5].Value = model.state;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(book_shop.Model.OrdersModel model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Orders set ");
            strSql.Append("OrderDate=@OrderDate,");
            strSql.Append("UserId=@UserId,");
            strSql.Append("TotalPrice=@TotalPrice,");
            strSql.Append("PostAddress=@PostAddress,");
            strSql.Append("state=@state");
            strSql.Append(" where OrderId=@OrderId ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@OrderDate",   SqlDbType.DateTime),
                new SqlParameter("@UserId",      SqlDbType.Int,         4),
                new SqlParameter("@TotalPrice",  SqlDbType.Decimal,     9),
                new SqlParameter("@PostAddress", SqlDbType.NVarChar,  255),
                new SqlParameter("@state",       SqlDbType.Int,         4),
                new SqlParameter("@OrderId",     SqlDbType.NVarChar, 50)
            };
            parameters[0].Value = model.OrderDate;
            parameters[1].Value = model.UserId;
            parameters[2].Value = model.TotalPrice;
            parameters[3].Value = model.PostAddress;
            parameters[4].Value = model.state;
            parameters[5].Value = model.OrderId;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public book_shop.Model.OrdersModel GetModel(string OrderId)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 OrderId,OrderDate,UserId,TotalPrice,PostAddress,state from Orders ");
            strSql.Append(" where OrderId=@OrderId ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@OrderId", SqlDbType.NVarChar, 50)
            };
            parameters[0].Value = OrderId;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }