www.pudn.com > Fetion.rar > GroupCategory.cs


namespace Imps.Client.Pc 
{ 
    using Imps.Client.Core; 
    using Imps.Client.Pc.Controls; 
    using Imps.Client.Resource; 
    using System; 
    using System.Collections.Generic; 
    using System.ComponentModel; 
    using System.Drawing; 
    using System.Windows.Forms; 
 
    public class GroupCategory : UserControl 
    { 
        private Dictionary> _categorys; 
        private IFrameworkWindow _framework; 
        private bool _unselected; 
        private IContainer components; 
        public XComboBox xcmbCategoryOne; 
        public XComboBox xcmbCategoryTwo; 
 
        public GroupCategory() 
        { 
            this.InitializeComponent(); 
        } 
 
        protected override void Dispose(bool disposing) 
        { 
            if (disposing && (this.components != null)) 
            { 
                this.components.Dispose(); 
            } 
            base.Dispose(disposing); 
        } 
 
        private void InitializeComponent() 
        { 
            this.xcmbCategoryTwo = new XComboBox(); 
            this.xcmbCategoryOne = new XComboBox(); 
            base.SuspendLayout(); 
            this.xcmbCategoryTwo.BackColor = Color.White; 
            this.xcmbCategoryTwo.DisplayMember = "Name"; 
            this.xcmbCategoryTwo.DropDownStyle = ComboBoxStyle.DropDownList; 
            this.xcmbCategoryTwo.EmptyTextTip = ""; 
            this.xcmbCategoryTwo.EmptyTextTipColor = Color.DarkGray; 
            this.xcmbCategoryTwo.FormattingEnabled = true; 
            this.xcmbCategoryTwo.Location = new System.Drawing.Point(0x4f, 3); 
            this.xcmbCategoryTwo.Name = "xcmbCategoryTwo"; 
            this.xcmbCategoryTwo.Size = new Size(100, 0x15); 
            this.xcmbCategoryTwo.TabIndex = 6; 
            this.xcmbCategoryOne.BackColor = Color.White; 
            this.xcmbCategoryOne.DisplayMember = "Name"; 
            this.xcmbCategoryOne.DropDownStyle = ComboBoxStyle.DropDownList; 
            this.xcmbCategoryOne.EmptyTextTip = ""; 
            this.xcmbCategoryOne.EmptyTextTipColor = Color.DarkGray; 
            this.xcmbCategoryOne.FormattingEnabled = true; 
            this.xcmbCategoryOne.Location = new System.Drawing.Point(0, 3); 
            this.xcmbCategoryOne.Name = "xcmbCategoryOne"; 
            this.xcmbCategoryOne.Size = new Size(70, 0x15); 
            this.xcmbCategoryOne.TabIndex = 5; 
            this.xcmbCategoryOne.SelectedIndexChanged += new EventHandler(this.xcmbCategoryOne_SelectedIndexChanged); 
            base.AutoScaleDimensions = new SizeF(6f, 13f); 
            base.AutoScaleMode = AutoScaleMode.Font; 
            this.BackColor = Color.Transparent; 
            base.Controls.Add(this.xcmbCategoryTwo); 
            base.Controls.Add(this.xcmbCategoryOne); 
            base.Name = "GroupCategory"; 
            base.Size = new Size(0xb5, 0x23); 
            base.ResumeLayout(false); 
        } 
 
        private void xcmbCategoryOne_SelectedIndexChanged(object sender, EventArgs e) 
        { 
            if (this.xcmbCategoryOne.SelectedItem != null) 
            { 
                this.xcmbCategoryTwo.Items.Clear(); 
                PersonalGroupCategory.Category selectedItem = this.xcmbCategoryOne.SelectedItem as PersonalGroupCategory.Category; 
                if (this._unselected) 
                { 
                    PersonalGroupCategory.Category item = new PersonalGroupCategory.Category(); 
                    item.Id = "-1"; 
                    item.Name = "-请选择-"; 
                    item.Parent = selectedItem; 
                    this.xcmbCategoryTwo.Items.Add(item); 
                } 
                if (this._categorys.ContainsKey(selectedItem)) 
                { 
                    foreach (PersonalGroupCategory.Category category3 in this._categorys[this.xcmbCategoryOne.SelectedItem as PersonalGroupCategory.Category]) 
                    { 
                        this.xcmbCategoryTwo.Items.Add(category3); 
                    } 
                } 
                if (this.xcmbCategoryTwo.Items.Count > 0) 
                { 
                    this.xcmbCategoryTwo.SelectedIndex = 0; 
                } 
            } 
        } 
 
        public Dictionary> Categorys 
        { 
            set 
            { 
                this._categorys = value; 
                this.xcmbCategoryOne.DataSource = null; 
                this.xcmbCategoryTwo.DataSource = null; 
                this.xcmbCategoryOne.Items.Clear(); 
                this.xcmbCategoryTwo.Items.Clear(); 
                new List(); 
                if (this._unselected) 
                { 
                    PersonalGroupCategory.Category item = new PersonalGroupCategory.Category(); 
                    item.Id = "-1"; 
                    item.Name = "-请选择-"; 
                    this.xcmbCategoryOne.Items.Add(item); 
                } 
                int length = 1; 
                foreach (PersonalGroupCategory.Category category2 in value.Keys) 
                { 
                    this.xcmbCategoryOne.Items.Add(category2); 
                    if (category2.Name.Length > length) 
                    { 
                        length = category2.Name.Length; 
                    } 
                } 
                if (this.xcmbCategoryOne.Items.Count > 0) 
                { 
                    this.xcmbCategoryOne.SelectedIndex = 0; 
                } 
                int num2 = length * 20; 
                if (num2 >= base.Width) 
                { 
                    this.xcmbCategoryOne.Width = (base.Width / 2) - 5; 
                } 
                else 
                { 
                    this.xcmbCategoryOne.Width = num2; 
                } 
                this.xcmbCategoryTwo.Width = (base.Width - this.xcmbCategoryOne.Width) - 5; 
                this.xcmbCategoryTwo.Left = this.xcmbCategoryOne.Right + 5; 
            } 
        } 
 
        public bool Unselected 
        { 
            set 
            { 
                this._unselected = value; 
                if (this._unselected) 
                { 
                    this.xcmbCategoryOne.SelectedItem = null; 
                    this.xcmbCategoryTwo.SelectedItem = null; 
                    this.xcmbCategoryOne.Text = StringTable.GroupCategory.PleaseSelect; 
                    this.xcmbCategoryTwo.Text = StringTable.GroupCategory.PleaseSelect; 
                } 
            } 
        } 
 
        public string Value 
        { 
            get 
            { 
                PersonalGroupCategory.Category selectedItem = this.xcmbCategoryTwo.SelectedItem as PersonalGroupCategory.Category; 
                if ((selectedItem != null) && (selectedItem.Id != "-1")) 
                { 
                    return selectedItem.Id; 
                } 
                selectedItem = this.xcmbCategoryOne.SelectedItem as PersonalGroupCategory.Category; 
                if (selectedItem != null) 
                { 
                    return selectedItem.Id; 
                } 
                return "-1"; 
            } 
            set 
            { 
                if (value != "-1") 
                { 
                    foreach (PersonalGroupCategory.Category category in this._categorys.Keys) 
                    { 
                        if (category.Id == value) 
                        { 
                            this.xcmbCategoryOne.SelectedItem = category; 
                            break; 
                        } 
                        foreach (PersonalGroupCategory.Category category2 in this._categorys[category]) 
                        { 
                            if (category2.Id == value) 
                            { 
                                this.xcmbCategoryOne.SelectedItem = category; 
                                this.xcmbCategoryTwo.SelectedItem = category2; 
                                break; 
                            } 
                        } 
                    } 
                } 
            } 
        } 
    } 
}