/// <summary> Handles the Load event of the Page control. </summary> /// <param name="sender"> The source of the event. </param> /// <param name="e"> The <see cref="System.EventArgs"/> instance containing the event data. </param> protected void Page_Load(object sender, EventArgs e) { string useOtherOrderSection = "Use Other Order Section"; // Initializes the OrderSections this.ProductsListView.DisplayMode = this.CurrentOrderDisplayMode; if (this.DataEntity != null) { if (this.DataEntity is Order) { Order order = this.DataEntity as Order; this.ProductsListView.ProductLines = order.OrderLines; this.ProductsListView.Currency = order.Currency; this.summary.Totals = order.Totals; this.summary.Currency = order.Currency; this.delivery.ShippingProvider = order.ShippingProvider; this.delivery.Currency = order.Currency; this.lblOrderNumber.InnerText = string.Format("{0}: {1}", Translate.Text(Sitecore.Ecommerce.Examples.Texts.OrderNumber), order.OrderNumber); string cardType = order.CustomerInfo.CustomProperties[TransactionConstants.CardType]; if (!string.IsNullOrEmpty(cardType)) { this.lblCardType.InnerText = string.Format("{0}: {1}", Translate.Text(Sitecore.Ecommerce.Examples.Texts.CardType), cardType); } } } else { return; } Item[] rowItems = Sitecore.Context.Item.Axes.SelectItems(TemplateNameOrderSectionsAndRowQuery); if (rowItems == null) { Item orderSectionItem = Sitecore.Context.Item.Axes.SelectSingleItem(TemplateNameOrderSectionsQuery); string id = orderSectionItem[useOtherOrderSection]; Assert.IsTrue(Sitecore.Data.ID.IsID(id), string.Format("The '{0}' is not a valid id.", useOtherOrderSection)); Item useOtherOrderSectionItem = Sitecore.Context.Database.GetItem(Sitecore.Data.ID.Parse(id)); rowItems = useOtherOrderSectionItem.Axes.SelectItems(TemplateNameOrderSectionRowQuery); } if (rowItems == null) { return; } for (int i = 0; i < rowItems.Length; i++) { string cssClass = "content2"; Item rowItem = rowItems[i]; // Set the CSS class on the row div. string cssClassID = rowItem["Css Class"]; if (Sitecore.Data.ID.IsID(cssClassID)) { Item cssClassItem = Sitecore.Context.Database.GetItem(Sitecore.Data.ID.Parse(cssClassID)); if (cssClassItem != null) { cssClass = cssClassItem.Name; } } string attributeClass = "class"; if (i == 0) { this.divRow1.Attributes.Add(attributeClass, cssClass); } else { this.divRow2.Attributes.Add(attributeClass, cssClass); } // Find max height string maxHeightForSections = "Max height for sections"; string maxHeight = rowItem[maxHeightForSections]; int height = -1; if (!string.IsNullOrEmpty(maxHeight) && !int.TryParse(maxHeight, out height)) { #if DEBUG throw new ConfigurationException(string.Format("The field '{0}' wasn't a valid integer to be used as height", maxHeightForSections)); #else height = 188; #endif } int addedSectionItems = 0; switch (i) { case 0: addedSectionItems = 0; break; case 1: addedSectionItems = 3; break; } // Set each OrderSections foreach (Item orderSectionItem in rowItem.Children) { List <SectionTableRow> tableRows = SectionFactory.GetSection(orderSectionItem, this.DataEntity); string title = Utils.ItemUtil.GetTitleOrDictionaryEntry(orderSectionItem, true); // try // { // title = ItemUtil.GetTitleOrDictionaryEntry(orderSectionItem, true); // } // catch (Exception) // { // // Do nothing since it's okay with a empty title of a section. // } bool hideSection = orderSectionItem["Hide Section"] == "1"; bool showLabelColumn = orderSectionItem["Show Label Column"] == "1"; if (!hideSection) { addedSectionItems += 1; string heightFormat = "height: {0}px;"; string classLabels = "labels"; string classNoLabels = "noLabels"; string attributeStyle = "style"; switch (addedSectionItems) { case 1: this.litTitleSection1.Text = title; this.repeaterOrderSection1.DataSource = tableRows; this.repeaterOrderSection1.DataBind(); this.divSection1.Visible = true; if (height != -1) { this.divSection1.Attributes.Add(attributeStyle, string.Format(heightFormat, height)); } if (showLabelColumn) { this.ddSection1.Attributes.Add(attributeClass, classLabels); } else { this.ddSection1.Attributes.Add(attributeClass, classNoLabels); } break; case 2: this.litTitleSection2.Text = title; this.repeaterOrderSection2.DataSource = tableRows; this.repeaterOrderSection2.DataBind(); this.divSection2.Visible = true; if (height != -1) { this.divSection2.Attributes.Add(attributeStyle, string.Format(heightFormat, height)); } if (showLabelColumn) { this.ddSection2.Attributes.Add(attributeClass, classLabels); } else { this.ddSection2.Attributes.Add(attributeClass, classNoLabels); } break; case 3: this.litTitleSection3.Text = title; this.repeaterOrderSection3.DataSource = tableRows; this.repeaterOrderSection3.DataBind(); this.divSection3.Visible = true; if (height != -1) { this.divSection3.Attributes.Add(attributeStyle, string.Format(heightFormat, height)); } if (showLabelColumn) { this.ddSection3.Attributes.Add(attributeClass, classLabels); } else { this.ddSection3.Attributes.Add(attributeClass, classNoLabels); } break; case 4: this.litTitleSection4.Text = title; this.repeaterOrderSection4.DataSource = tableRows; this.repeaterOrderSection4.DataBind(); this.divSection4.Visible = true; if (height != -1) { this.divSection4.Attributes.Add(attributeStyle, string.Format(heightFormat, height)); } if (showLabelColumn) { this.ddSection4.Attributes.Add(attributeClass, classLabels); } else { this.ddSection4.Attributes.Add(attributeClass, classNoLabels); } break; case 5: this.litTitleSetion5.Text = title; this.repeaterOrderSection5.DataSource = tableRows; this.repeaterOrderSection5.DataBind(); this.divSection5.Visible = true; if (height != -1) { this.divSection5.Attributes.Add(attributeStyle, string.Format(heightFormat, height)); } if (showLabelColumn) { this.ddSection5.Attributes.Add(attributeClass, classLabels); } else { this.ddSection5.Attributes.Add(attributeClass, classNoLabels); } break; case 6: this.litTitleSection6.Text = title; this.repeaterOrderSection6.DataSource = tableRows; this.repeaterOrderSection6.DataBind(); this.divSection6.Visible = true; if (height != -1) { this.divSection6.Attributes.Add(attributeStyle, string.Format(heightFormat, height)); } if (showLabelColumn) { this.ddSection6.Attributes.Add(attributeClass, classLabels); } else { this.ddSection6.Attributes.Add(attributeClass, classNoLabels); } break; default: break; } } } } }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void Page_Load(object sender, EventArgs e) { const string useOtherOrderSection = "Use Other Order Section"; if (!IsPostBack) { // Initializes the OrderSections this.ProductsListView.DisplayMode = CurrentOrderDisplayMode; var rowItems = Sitecore.Context.Item.Axes.SelectItems(TemplateNameOrderSectionsAndRowQuery); if (rowItems == null) { var orderSectionItem = Sitecore.Context.Item.Axes.SelectSingleItem( TemplateNameOrderSectionsQuery); var id = orderSectionItem[useOtherOrderSection]; Assert.IsTrue(Sitecore.Data.ID.IsID(id), string.Format("The '{0}' is not a valid id.", useOtherOrderSection)); var useOtherOrderSectionItem = Sitecore.Context.Database.GetItem(Sitecore.Data.ID.Parse(id)); rowItems = useOtherOrderSectionItem.Axes.SelectItems(TemplateNameOrderSectionRowQuery); } if (rowItems != null) { for (var i = 0; i < rowItems.Length; i++) { const string classContent = "content"; const string classContent2 = "content2"; const string classContent3 = "content3"; const string attributeClass = "class"; var cssClass = classContent2; var rowItem = rowItems[i]; // Set the CSS class on the row div. var cssClassID = rowItem["Css Class"]; var id = new ID(cssClassID); var cssClassItem = Sitecore.Context.Database.GetItem(id); if (cssClassItem != null) { cssClass = cssClassItem.Name; } //try //{ // ID id = new ID(cssClassID); // Item cssClassItem = Sitecore.Context.Database.GetItem(id); // if (cssClassItem != null) // { // cssClass = cssClassItem.Name; // } //} //catch (Exception) //{ //} if (i == 0) { divRow1.Attributes.Add(attributeClass, cssClass); } else { divRow2.Attributes.Add(attributeClass, cssClass); } // Find max height const string maxHeightForSections = "Max height for sections"; var maxHeight = rowItem[maxHeightForSections]; var height = -1; if (!string.IsNullOrEmpty(maxHeight) && !int.TryParse(maxHeight, out height)) { throw new ConfigurationException(string.Format("The field '{0}' wasn't a valid integer to be used as height", maxHeightForSections)); } var addedSectionItems = 0; if (i == 0) { // The first row addedSectionItems = 0; } else if (i == 1) { // The second row addedSectionItems = 3; } //else //{ // // Not implemented in ascx file. //} // Set each OrderSections foreach (Item orderSectionItem in rowItem.Children) { var tableRows = SectionFactory.GetSection(orderSectionItem, this.DataEntity); var title = Utils.ItemUtil.GetTitleOrDictionaryEntry(orderSectionItem, true); //try //{ // title = ItemUtil.GetTitleOrDictionaryEntry(orderSectionItem, true); //} //catch (Exception) //{ // // Do nothing since it's okay with a empty title of a section. //} var hideSection = orderSectionItem["Hide Section"] == "1"; var showLabelColumn = orderSectionItem["Show Label Column"] == "1"; if (!hideSection) { addedSectionItems += 1; const string classLabels = "labels"; const string classNoLabels = "noLabels"; const string widthFormat = "width: {0}%;"; const string heightFormat = "height: {0}px;"; const string attributeStyle = "style"; const string emptyTr = "</tr><tr>"; const int widthA = 50; const int widthB = 33; switch (addedSectionItems) { case 1: if (cssClass == classContent2) { divSection1.Attributes.Add(attributeStyle, string.Format(widthFormat, widthA)); } else if (cssClass == classContent3) { divSection1.Attributes.Add(attributeStyle, string.Format(widthFormat, widthB)); } litTitleSection1.Text = title; repeaterOrderSection1.DataSource = tableRows; repeaterOrderSection1.DataBind(); divSection1.Visible = true; //if(height!=-1) //{ // divSection1.Attributes.Add("style", string.Format("height: {0}px;", height)); //} if (showLabelColumn) { ddSection1.Attributes.Add(attributeClass, classLabels); } else { ddSection1.Attributes.Add(attributeClass, classNoLabels); } break; case 2: if (cssClass == classContent) { phSection1.Controls.Add(new LiteralControl(emptyTr)); } if (cssClass == classContent2) { divSection2.Attributes.Add(attributeStyle, string.Format(widthFormat, widthA)); } else if (cssClass == classContent3) { divSection2.Attributes.Add(attributeStyle, string.Format(widthFormat, widthB)); } litTitleSection2.Text = title; repeaterOrderSection2.DataSource = tableRows; repeaterOrderSection2.DataBind(); divSection2.Visible = true; //if (height != -1) //{ // divSection2.Attributes.Add("style", string.Format("height: {0}px;", height)); //} if (showLabelColumn) { ddSection2.Attributes.Add(attributeClass, classLabels); } else { ddSection2.Attributes.Add(attributeClass, classNoLabels); } break; case 3: if (cssClass == classContent) { phSection2.Controls.Add(new LiteralControl(emptyTr)); } if (cssClass == classContent2) { divSection3.Attributes.Add(attributeStyle, string.Format(widthFormat, widthA)); } else if (cssClass == classContent3) { divSection3.Attributes.Add(attributeStyle, string.Format(widthFormat, widthB)); } litTitleSection3.Text = title; repeaterOrderSection3.DataSource = tableRows; repeaterOrderSection3.DataBind(); divSection3.Visible = true; //if (height != -1) //{ // divSection3.Attributes.Add("style", string.Format("height: {0}px;", height)); //} if (showLabelColumn) { ddSection3.Attributes.Add(attributeClass, classLabels); } else { ddSection3.Attributes.Add(attributeClass, classNoLabels); } break; case 4: if (cssClass == classContent2) { divSection4.Attributes.Add(attributeStyle, string.Format(widthFormat, widthA)); } else if (cssClass == classContent3) { divSection4.Attributes.Add(attributeStyle, string.Format(widthFormat, widthB)); } litTitleSection4.Text = title; repeaterOrderSection4.DataSource = tableRows; repeaterOrderSection4.DataBind(); divSection4.Visible = true; //if (height != -1) //{ // divSection4.Attributes.Add("style", string.Format("height: {0}px;", height)); //} if (showLabelColumn) { ddSection4.Attributes.Add(attributeClass, classLabels); } else { ddSection4.Attributes.Add(attributeClass, classNoLabels); } break; case 5: if (cssClass == classContent) { phSection4.Controls.Add(new LiteralControl(emptyTr)); } if (cssClass == classContent2) { divSection5.Attributes.Add(attributeStyle, string.Format(widthFormat, widthA)); } else if (cssClass == classContent3) { divSection5.Attributes.Add(attributeStyle, string.Format(widthFormat, widthB)); } litTitleSetion5.Text = title; repeaterOrderSection5.DataSource = tableRows; repeaterOrderSection5.DataBind(); divSection5.Visible = true; //if (height != -1) //{ // divSection5.Attributes.Add("style", string.Format("height: {0}px;", height)); //} if (showLabelColumn) { ddSection5.Attributes.Add(attributeClass, classLabels); } else { ddSection5.Attributes.Add(attributeClass, classNoLabels); } break; case 6: if (cssClass == classContent) { phSection5.Controls.Add(new LiteralControl(emptyTr)); } if (cssClass == classContent2) { divSection6.Attributes.Add(attributeStyle, string.Format(widthFormat, widthA)); } else if (cssClass == classContent3) { divSection6.Attributes.Add(attributeStyle, string.Format(widthFormat, widthB)); } litTitleSection6.Text = title; repeaterOrderSection6.DataSource = tableRows; repeaterOrderSection6.DataBind(); divSection6.Visible = true; if (height != -1) { divSection6.Attributes.Add(attributeStyle, string.Format(heightFormat, height)); } if (showLabelColumn) { ddSection6.Attributes.Add(attributeClass, classLabels); } else { ddSection6.Attributes.Add(attributeClass, classNoLabels); } break; default: break; } } } } } } }