Esempio n. 1
0
    protected void LoadDeliveryTypes()
    {
        ddlDeliveryTypes.Items.Clear();

        //Calculating order total and other offers to populate delivery options
        OrdersBAL deliveryOptions = new OrdersBAL();

        deliveryOptions.orderId = Convert.ToInt32(Session[enumSessions.OrderId.ToString()].ToString());

        //Set the lowest priced as selected.
        int     i = 0; int selectedIndex = 0;
        decimal leastPriceItem = decimal.MaxValue;


        try
        {
            //List<DeliveryType> shippingOptions = deliveryOptions.GetShippingOptions();
            LinqToSqlDataContext db = new LinqToSqlDataContext();
            List <USP_GetShippingOptionsResult> shippingOptions = new List <USP_GetShippingOptionsResult>();

            shippingOptions = db.USP_GetShippingOptions(Convert.ToInt32(Session[enumSessions.ARC_Id.ToString()].ToString()), new Guid(Session[enumSessions.InstallerCompanyID.ToString()].ToString()), Convert.ToInt32(Session[enumSessions.OrderId.ToString()])).ToList();

            foreach (USP_GetShippingOptionsResult delivery in shippingOptions)
            {
                System.Web.UI.WebControls.ListItem item = new System.Web.UI.WebControls.ListItem();
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-GB", false);
                item.Text  = delivery.DeliveryShortDesc + " - " + delivery.DeliveryPrice.Value.ToString("c");
                item.Value = delivery.DeliveryTypeId.ToString();

                if (leastPriceItem != decimal.Zero && delivery.DeliveryPrice < leastPriceItem)
                {
                    leastPriceItem = delivery.DeliveryPrice.Value;
                    ddlDeliveryTypes.ClearSelection();
                    ddlDeliveryTypes.SelectedIndex = i;
                    selectedIndex = i;
                }
                ddlDeliveryTypes.Items.Add(item);
                i++;
            }
            ddlDeliveryTypes.DataBind();
            ddlDeliveryTypes.SelectedIndex = selectedIndex;

            bool?isAncillary = false;
            db.USP_IsAncillaryOnlyOrders(Convert.ToInt32(Session[enumSessions.OrderId.ToString()]), ref isAncillary);
            if (isAncillary.Value == true)
            {
                lblIsAncillary.Visible = true;
            }
            else
            {
                lblIsAncillary.Visible = false;
            }
        }
        catch (Exception objException)
        {
            CSLOrderingARCBAL.LinqToSqlDataContext db;
            db = new CSLOrderingARCBAL.LinqToSqlDataContext();
            db.USP_SaveErrorDetails(Request.Url.ToString(), "LoadDeliveryTypes", Convert.ToString(objException.Message), Convert.ToString(objException.InnerException), Convert.ToString(objException.StackTrace), "", HttpContext.Current.Request.UserHostAddress, false, Convert.ToString(HttpContext.Current.Session[enumSessions.User_Id.ToString()]));
            db.Dispose();
        }
    }