Пример #1
0
        // ReSharper restore UnusedMethodReturnValue.Global
        // ReSharper restore UnusedMember.Global
        // ReSharper restore MemberCanBeProtected.Global
        // ReSharper restore MemberCanBePrivate.Global

        #endregion Public

        #region Event handlers and overrides

        protected void Page_Load(object sender, EventArgs e)
        {
            // ReSharper disable InvertIf
            if (!IsPostBack)
            {
                var table = Counties.GetCacheDataByStateCode(StateCode);

                int columns;
                if (table.Count == 0)
                {
                    columns = 0;
                }
                else if (table.Count <= 17)
                {
                    columns = 1;
                }
                else if (table.Count <= 34)
                {
                    columns = 2;
                }
                else if (table.Count <= 90)
                {
                    columns = 3;
                }
                else if (table.Count <= 120)
                {
                    columns = 4;
                }
                else if (table.Count <= 160)
                {
                    columns = 5;
                }
                else
                {
                    columns = 6;
                }

                CountiesMenu.AddCssClasses("has-" + columns.ToString(CultureInfo.InvariantCulture) +
                                           "-cols");

                if (columns < 6)
                {
                    CountiesBlock6.Visible = false;
                }
                if (columns < 5)
                {
                    CountiesBlock5.Visible = false;
                }
                if (columns < 4)
                {
                    CountiesBlock4.Visible = false;
                }
                if (columns < 3)
                {
                    CountiesBlock3.Visible = false;
                }
                if (columns < 2)
                {
                    CountiesBlock2.Visible = false;
                }

                if (columns == 0)
                {
                    var span = new HtmlSpan();
                    CountiesBlock1.Controls.Add(span);
                    span.InnerText = "No counties found for " + StateCode;
                }
                else
                {
                    var blockControls = new[]
                    {
                        CountiesBlock1, CountiesBlock2, CountiesBlock3, CountiesBlock4, CountiesBlock5,
                        CountiesBlock6
                    };
                    var blockIndex       = -1;
                    var countiesPerBlock = (table.Count - 1) / columns + 1;
                    for (var inx = 0; inx < table.Count; inx++)
                    {
                        var row = table[inx];
                        if (inx % countiesPerBlock == 0)
                        {
                            blockIndex++;
                        }
                        AddCounty(blockControls[blockIndex], row.CountyCode, row.County);
                    }
                }
            }
            // ReSharper restore InvertIf
        }