예제 #1
0
        void OrderOptionsList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            XmlNode orderOptionNode = e.Item.DataItem as XmlNode;
            int     counter         = 0;

            if (orderOptionNode != null &&
                int.TryParse(orderOptionNode["Counter"].InnerText, out counter))
            {
                string itemCode        = orderOptionNode["ItemCode"].InnerText;
                string itemName        = orderOptionNode["ItemName"].InnerText;
                string itemDescription = orderOptionNode["ItemDescription"].InnerText;
                string popupTitle      = string.Empty;

                Label lblDisplayName = e.Item.FindControl("OrderOptionName") as Label;
                if (!CommonLogic.IsStringNullOrEmpty(itemDescription))
                {
                    lblDisplayName.Text = Security.HtmlEncode(itemDescription);
                    popupTitle          = CommonLogic.Left(Security.UrlEncode(SE.MungeName(itemDescription)), 90);
                }
                else
                {
                    lblDisplayName.Text = Security.HtmlEncode(itemName);
                    popupTitle          = CommonLogic.Left(Security.UrlEncode(SE.MungeName(itemName)), 90);
                }

                if (AppLogic.AppConfigBool("ShowPicsInCart"))
                {
                    String ImgUrl = InterpriseHelper.LookUpImageByItemCode(itemCode, "icon", SkinID, ThisCustomer.LocaleSetting);
                    if (!string.IsNullOrEmpty(ImgUrl) && ImgUrl.IndexOf("nopicture") == -1)
                    {
                        Image imgControl = (Image)e.Item.FindControl("OptionImage");
                        imgControl.ImageUrl = ImgUrl;
                        imgControl.Visible  = true;
                    }
                }

                var helpCircle = (Image)e.Item.FindControl("helpcircle_gif");
                helpCircle.ImageUrl = AppLogic.LocateImageURL(SkinImagePath + "helpcircle.gif");
                helpCircle.Attributes.Add("onclick", "popuporderoptionwh('Order Option " + popupTitle + "', " + counter.ToString() + ",650,550,'yes');");

                // 2 Control choices for drop down list
                var cboUnitMeasureCode    = e.Item.FindControl("cboUnitMeasureCode") as DropDownList;
                var lblUnitMeasureCode    = e.Item.FindControl("lblUnitMeasureCode") as Label;
                var availableUnitMeasures = ProductDA.GetProductUnitMeasureAvailability(ThisCustomer.CustomerCode, itemCode,
                                                                                        AppLogic.AppConfigBool("ShowInventoryFromAllWarehouses"),
                                                                                        ThisCustomer.IsNotRegistered);
                if (availableUnitMeasures.Count() > 1)
                {
                    // render as drop down list
                    lblUnitMeasureCode.Visible = false;

                    foreach (string unitMeasureCode in availableUnitMeasures)
                    {
                        cboUnitMeasureCode.Items.Add(new ListItem(HttpUtility.HtmlEncode(unitMeasureCode), HttpUtility.HtmlEncode(unitMeasureCode)));
                    }
                }
                else
                {
                    // The only unit measure the item is configured for is the default
                    // which we are guaranteed to be in the first index..
                    cboUnitMeasureCode.Visible = false;
                    lblUnitMeasureCode.Text    = availableUnitMeasures.First().ToHtmlEncode();
                }

                bool withVat = AppLogic.AppConfigBool("VAT.Enabled") && ThisCustomer.VATSettingReconciled == VatDefaultSetting.Inclusive;
                var  um      = UnitMeasureInfo.ForItem(itemCode, UnitMeasureInfo.ITEM_DEFAULT);

                decimal promotionalPrice = Decimal.Zero;
                decimal price            = InterpriseHelper.GetSalesPriceAndTax(ThisCustomer.CustomerCode,
                                                                                itemCode,
                                                                                ThisCustomer.CurrencyCode,
                                                                                Decimal.One,
                                                                                um.Code, withVat,
                                                                                ref promotionalPrice);

                if (promotionalPrice != Decimal.Zero)
                {
                    price = promotionalPrice;
                }

                string vatDisplay = String.Empty;
                if (AppLogic.AppConfigBool("VAT.Enabled"))
                {
                    vatDisplay = (ThisCustomer.VATSettingReconciled == VatDefaultSetting.Inclusive)?
                                 " <span class=\"VATLabel\">" + AppLogic.GetString("showproduct.aspx.38", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</span>\n":
                                 " <span class=\"VATLabel\">" + AppLogic.GetString("showproduct.aspx.37", ThisCustomer.SkinID, ThisCustomer.LocaleSetting) + "</span>\n";
                }

                var lblPrice = e.Item.FindControl("OrderOptionPrice") as Label;
                lblPrice.Text = InterpriseHelper.FormatCurrencyForCustomer(price, ThisCustomer.CurrencyCode) + vatDisplay;

                var hfCounter = e.Item.FindControl("hfItemCounter") as HiddenField;
                hfCounter.Value = counter.ToString();

                var cbk = (DataCheckBox)e.Item.FindControl("OrderOptions");
                cbk.Checked = false;

                bool shouldBeAbleToEnterNotes = orderOptionNode["CheckOutOptionAddMessage"].InnerText.TryParseBool().Value;
                var  lblNotes = e.Item.FindControl("lblNotes") as Label;
                var  txtNotes = e.Item.FindControl("txtOrderOptionNotes") as TextBox;
                lblNotes.Visible = txtNotes.Visible = shouldBeAbleToEnterNotes;
                txtNotes.Attributes.Add("onkeyup", "return imposeMaxLength(this, 1000);");
            }
        }