Esempio n. 1
0
        /// <summary>
        /// Read an order from the database
        /// </summary>
        /// <param name="orderId">Order Id</param>
        /// <returns>All information about the order</returns>
        public OrderInfo GetOrder(int orderId)
        {
            OrderInfo order = new OrderInfo();

            //Create a parameter
            SqlParameter parm = new SqlParameter(PARM_ORDER_ID, SqlDbType.Int);
            parm.Value = orderId;

            //Execute a query to read the order
            using (SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringOrderDistributedTransaction, CommandType.Text, SQL_SELECT_ORDER, parm)) {

                if (rdr.Read()) {

                    //Generate an order header from the first row
                    AddressInfo billingAddress = new AddressInfo(rdr.GetString(5), rdr.GetString(6), rdr.GetString(7), rdr.GetString(8), rdr.GetString(9), rdr.GetString(10), rdr.GetString(11), rdr.GetString(12), null, "email");
                    AddressInfo shippingAddress = new AddressInfo(rdr.GetString(13), rdr.GetString(14), rdr.GetString(15), rdr.GetString(16), rdr.GetString(17), rdr.GetString(18), rdr.GetString(19), rdr.GetString(20), null, "email");

                    order = new OrderInfo(orderId, rdr.GetDateTime(0), rdr.GetString(1), null, billingAddress, shippingAddress, rdr.GetDecimal(21), null, null);

                    IList<LineItemInfo> lineItems = new List<LineItemInfo>();
                    LineItemInfo item = null;

                    //Create the lineitems from the first row and subsequent rows
                    do {
                        item = new LineItemInfo(rdr.GetString(22), string.Empty, rdr.GetInt32(23), rdr.GetInt32(24), rdr.GetDecimal(25));
                        lineItems.Add(item);
                    } while (rdr.Read());

                    order.LineItems = new LineItemInfo[lineItems.Count];
                    lineItems.CopyTo(order.LineItems, 0);
                }
            }

            return order;
        }
Esempio n. 2
0
 /// <summary>
 /// Constructor with specified initial values
 /// </summary>
 /// <param name="orderid">Unique identifier</param>
 /// <param name="date">Order date</param>
 /// <param name="userid">User placing order</param>
 /// <param name="creditCard">Credit card used for order</param>
 /// <param name="billing">Billing address for the order</param>
 /// <param name="shipping">Shipping address for the order</param>
 /// <param name="total">Order total value</param>
 /// <param name="line">Ordered items</param>
 /// <param name="authorization">Credit card authorization number</param>
 public OrderInfo(int orderid, DateTime date, string userid, CreditCardInfo creditCard, AddressInfo billing, AddressInfo shipping, decimal total, LineItemInfo[] line, Nullable<int> authorization)
 {
     this.orderid = orderid;
     this.date = date;
     this.userid = userid;
     this.creditCard = creditCard;
     this.billingAddress = billing;
     this.shippingAddress = shipping;
     this.orderTotal = total;
     this.lineItems = line;
     this.authorizationNumber = authorization;
 }