예제 #1
0
파일: Orders.cs 프로젝트: AckerlyXu/heima
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public cn.itcast.bookshop.Model.Orders DataRowToModel(DataRow row)
 {
     cn.itcast.bookshop.Model.Orders model = new cn.itcast.bookshop.Model.Orders();
     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);
 }
예제 #2
0
파일: Orders.cs 프로젝트: AckerlyXu/heima
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(cn.itcast.bookshop.Model.Orders 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);
            }
        }
예제 #3
0
파일: Orders.cs 프로젝트: AckerlyXu/heima
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(cn.itcast.bookshop.Model.Orders 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);
            }
        }
예제 #4
0
파일: Orders.cs 프로젝트: AckerlyXu/heima
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public cn.itcast.bookshop.Model.Orders 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;

            cn.itcast.bookshop.Model.Orders model = new cn.itcast.bookshop.Model.Orders();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

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