⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 toolbar.cs

📁 浏览器端看到树型目录结构,用户可以完整地看到像windows资源管理器一样的效果
💻 CS
📖 第 1 页 / 共 3 页
字号:
            if (bBubble && (item is ToolbarCheckButton))
            {
                ToolbarCheckGroup group = ((ToolbarCheckButton)item).Group;
                if (group != null)
                {
                    bBubble = group.OnButtonClick(item, eventArgs);
                }
            }

            if (bBubble)
            {
                OnButtonClick(item, eventArgs);
            }
        }

        /// <summary>
        /// Perform the bubbling necessary in firing the CheckChange event.
        /// </summary>
        /// <param name="btn">The source ToolbarCheckButton.</param>
        protected void PostCheckChangeEvent(ToolbarCheckButton btn)
        {
            bool bBubble = true;
            EventArgs eventArgs = new EventArgs();

            bBubble = btn.OnCheckChange(eventArgs);

            if (bBubble && (btn.Group != null))
            {
                bBubble = btn.Group.OnCheckChange(btn, eventArgs);
            }

            if (bBubble)
            {
                OnCheckChange(btn, eventArgs);
            }
        }

        /// <summary>
        /// Parses the posted data string and returns an ArrayList of indexes in string format.
        /// </summary>
        /// <param name="szData">The postback string.</param>
        /// <returns>An ArrayList of indexes.</returns>
        private ArrayList ParseDataString(string szData)
        {
            ArrayList list = new ArrayList();
            int start = 0;
            int end;

            while (start < szData.Length)
            {
                end = szData.IndexOf(';', start);
                if (end > start)
                {
                    string szParam = szData.Substring(start, end - start);
                    list.Add(szParam);

                    start = end + 1;
                }
                else
                {
                    break;
                }
            }

            return list;
        }

        /// <summary>
        /// Processes post back data for the server control given the data from the hidden helper.
        /// </summary>
        /// <param name="szData">The data from the hidden helper</param>
        /// <returns>true if the server control's state changes as a result of the post back; otherwise false.</returns>
        protected override bool ProcessData(string szData)
        {
            if ((szData == null) || (szData == String.Empty))
                return false;

            ArrayList eventList = ParseDataString(szData);
            ArrayList changedBtns = new ArrayList();
            ArrayList oldVals = new ArrayList();

            // Apply the changes
            foreach (string szParam in eventList)
            {
                int flatIndex = Convert.ToInt32(szParam.Substring(1, szParam.Length - 1));
                ToolbarItem item = Items.FlatIndexItem(flatIndex);
                if ((item != null) && (item is ToolbarCheckButton))
                {
                    ToolbarCheckButton btn = (ToolbarCheckButton)item;

                    // If the button affects other buttons, then store those values
                    if (btn.Group != null)
                    {
                        ToolbarCheckButton affectedBtn = btn.Group.SelectedCheckButton;
                        if ((affectedBtn != null) && !changedBtns.Contains(affectedBtn))
                        {
                            changedBtns.Add(affectedBtn);
                            oldVals.Add(affectedBtn.Selected);
                        }
                    }

                    // If we haven't stored the original value, then store it
                    if (!changedBtns.Contains(btn))
                    {
                        changedBtns.Add(btn);
                        oldVals.Add(btn.Selected);
                    }

                    // Apply the change (+ means selected, - means not selected)
                    btn.Selected = ((szParam.Length > 0) && (szParam[0] == '+'));
                }
            }

            // Determine which items changed
            for (int i = 0; i < changedBtns.Count; i++)
            {
                ToolbarCheckButton btn = (ToolbarCheckButton)changedBtns[i];
                if (btn.Selected != (bool)oldVals[i])
                {
                    _Changed.Add(btn);
                }
            }

            return (_Changed.Count > 0);
        }

        /// <summary>
        /// Processes post back data for a server control.
        /// </summary>
        /// <param name="postDataKey">The key identifier for the control.</param>
        /// <param name="postCollection">The collection of all incoming name values.</param>
        /// <returns>true if the server control's state changes as a result of the post back; otherwise false.</returns>
        protected override bool LoadPostData(string postDataKey, NameValueCollection postCollection)
        {
            bool changed = base.LoadPostData(postDataKey, postCollection);

            // Find IPostBackDataHandlers and invoke the interface
            // NOTE: Does not recurse into CheckGroups because they should only have
            // CheckButtons which don't implement the interface.
            foreach (ToolbarItem item in Items)
            {
                if (item is IPostBackDataHandler)
                {
                    if (((IPostBackDataHandler)item).LoadPostData(postDataKey, postCollection))
                    {
                        _DataChanged.Add(item);
                    }
                }
            }

            return (changed || (_DataChanged.Count > 0));
        }

        /// <summary>
        /// Signals the server control object to notify the ASP.NET application that the state of the control has changed.
        /// </summary>
        protected override void RaisePostDataChangedEvent()
        {
            foreach (ToolbarCheckButton btn in _Changed)
            {
                PostCheckChangeEvent(btn);
            }

            _Changed.Clear();

            foreach (IPostBackDataHandler item in _DataChanged)
            {
                item.RaisePostDataChangedEvent();
            }
        }

        /// <summary>
        /// Enables a server control to process an event raised when a form is posted to the server.
        /// </summary>
        /// <param name="eventArgument">A String that represents an optional event argument to be passed to the event handler.</param>
        protected override void RaisePostBackEvent(string eventArgument)
        {
            if ((eventArgument != null) && (eventArgument != String.Empty))
            {
                ToolbarItem item = Items.FlatIndexItem(Convert.ToInt32(eventArgument));
                if (item != null)
                {
                    PostButtonClickEvent(item);
                }
            }
        }

        /// <summary>
        /// Initializes the control.
        /// </summary>
        /// <param name="e">Event data.</param>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            foreach (ToolbarItem item in Items)
            {
                if (item is ToolbarCheckGroup)
                {
                    ((ToolbarCheckGroup)item).ResolveSelectedItems();
                }
            }
        }

        /// <summary>
        /// Raises the PreRender event.
        /// </summary>
        /// <param name="e">The event data.</param>
        protected override void OnPreRender(EventArgs e)
        {
            bool isUpLevel = (RenderPath == RenderPathID.UpLevelPath);

            foreach (ToolbarItem item in Items)
            {
                if (item is ToolbarDropDownList)
                {
                    ((ToolbarDropDownList)item).SetupHiddenHelper(isUpLevel);
                }
                else if (item is ToolbarTextBox)
                {
                    ((ToolbarTextBox)item).SetupHiddenHelper(isUpLevel);
                }
            }

            if (ID == null)
            {
                ID = UniqueID;
            }

            base.OnPreRender(e);
        }

        /// <summary>
        /// Renders the contents of the control into the specified writer.
        /// </summary>
        /// <param name="writer">The output stream that renders HTML content to the client.</param>
        protected override void RenderContents(HtmlTextWriter writer)
        {
            foreach (ToolbarItem item in Items)
            {
                item.Render(writer, RenderPath);
            }
        }

        /// <summary>
        /// Renders the control for an uplevel browser.
        /// </summary>
        /// <param name="writer">The HtmlTextWriter object that receives the control content.</param>
        protected override void RenderUpLevelPath(HtmlTextWriter writer)
        {
            writer.Write("<?XML:NAMESPACE PREFIX=\"" + TagNamespace
                + "\" /><?IMPORT NAMESPACE=\"" + TagNamespace + "\" IMPLEMENTATION=\""
                + AddPathToFilename("toolbar.htc") + "\" />");
            writer.WriteLine();

            AddAttributesToRender(writer);

            if (Orientation == Orientation.Vertical)
                writer.AddAttribute("orientation", "vertical");

            if (Page != null)
            {
                // We replace the '<replaceme>' with event.flatIndex so that we get the actual value 
                // of the variable at runtime and not the string 'event.flatIndex'
                string postBack = "{setAttribute('_submitting', 'true');try{" + Page.GetPostBackEventReference(this, "<replaceme>").Replace("'<replaceme>'", "event.flatIndex") + ";}catch(e){setAttribute('_submitting', 'false');}}";
                string checkNode = "if (event.srcNode != null) ";
                string checkPostBack = "if ((event.srcNode.getType() != 'checkbutton') || (event.srcNode.getAttribute('_autopostback') != null)) if (getAttribute('_submitting') != 'true')";
                string setHelper = HelperID + ".value+=((event.srcNode.getAttribute('selected')=='true')?'+':'-')+event.flatIndex+';';";

                writer.AddAttribute("oncheckchange", "JScript:" + checkNode + setHelper);
                writer.AddAttribute("onbuttonclick", "JScript:" + checkNode + checkPostBack + postBack);

                string readyScript = "JScript:try{" + HelperID + ".value = ''}catch(e){}";
                foreach (ToolbarItem item in Items)
                {
                    ToolbarDropDownList ddl = item as ToolbarDropDownList;
                    ToolbarTextBox tbox = item as ToolbarTextBox;
                    if (ddl != null)
                    {
                        ListItem selItem = ddl.SelectedItem;
                        readyScript += "try{" + ddl.HelperID + ".value = getItem(" + ddl.Index + ").getAttribute('value');}catch(e){}";
                    }
                    else if (tbox != null)
                    {
                        readyScript += "try{" + tbox.HelperID + ".value = getItem(" + tbox.Index + ").getAttribute('value');}catch(e){}";
                    }
                }
                writer.AddAttribute("onwcready", readyScript);
            }

            string style = DefaultStyle.CssText;
            if (style != String.Empty)
                writer.AddAttribute("defaultstyle", style);
            style = HoverStyle.CssText;
            if (style != String.Empty)
                writer.AddAttribute("hoverstyle", style);
            style = SelectedStyle.CssText;
            if (style != String.Empty)
                writer.AddAttribute("selectedstyle", style);

            writer.RenderBeginTag(TagNamespace + ":" + ToolbarTagName);
            writer.WriteLine();

            base.RenderUpLevelPath(writer);

            writer.RenderEndTag();
        }

        /// <summary>
        /// Performs a case insensitive check of the Style collection by looping through it.
        /// CssStyleCollection is case sensitive unlike CssCollection.
        /// </summary>
        /// <param name="name">The name to search for.</param>
        /// <returns>The value or null.</returns>
        private string GetStyle(string name)
        {
            // First try it in case it works
            string val = Style[name];
            if (val != null)
                return val;

            // Go for a case insensitive search
            foreach (string key in Style.Keys)
            {
                if (String.Compare(key, name, true) == 0)
                {
                    return Style[key];
                }
            }

            return null;
        }

        /// <summary>
        /// Tests for the existence of a border style being set.
        /// </summary>
        /// <param name="type">The type of border setting (color, width, style).</param>
        /// <returns>true if nothing was set.</returns>
        private bool NotExistBorder(string type)
        {
            return ((GetStyle("border") == null) && (GetStyle("border-" + type) == null) &&
                (GetStyle("border-top") == null) && (GetStyle("border-top-" + type) == null) &&
                (GetStyle("border-bottom") == null) && (GetStyle("border-bottom-" + type) == null) &&
                (GetStyle("border-left") == null) && (GetStyle("border-left-" + type) == null) &&
                (GetStyle("border-right") == null) && (GetStyle("border-right-" + type) == null));
        }

        /// <summary>
        /// Opens the downlevel table.
        /// </summary>
        /// <param name="writer">The HtmlTextWriter object that receives the control content.</param>
        /// <param name="isDesignMode">Indicates whether this is design mode.</param>
        private void RenderBeginTable(HtmlTextWriter writer, bool isDesignMode)
        {
            bool resetBorderWidth = false;
            bool resetBorderStyle = false;
            bool resetBorderColor = false;

            if ((BackColor == Color.Empty) && (GetStyle("background-color") == null))
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, "#D0D0D0");
            }

            if (!isDesignMode &&
                (Width == Unit.Empty) && (GetStyle("width") == null) && 
                (String.Compare(GetStyle("position"), "absolute", true) != 0))
                
            {
                writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "100%");
            }

            if ((BorderWidth == Unit.Empty) && NotExistBorder("width"))
            {
                Style["border-width"] = "1";
                resetBorderWidth = true;
            }

            if ((BorderStyle == BorderStyle.NotSet) && NotExistBorder("style"))
            {
                Style["border-style"] = "solid";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -