PageRenderTime 30ms CodeModel.GetById 23ms app.highlight 5ms RepoModel.GetById 0ms app.codeStats 0ms

/Las/Las.WinUI/FrmDGSelector.cs

http://sgsoft-las.googlecode.com/
C# | 203 lines | 144 code | 26 blank | 33 comment | 9 complexity | 5f6d724a04b763a04a29fe7e58c6a7ac MD5 | raw file
Possible License(s): LGPL-2.1
  1/*
  2 * ????????????????
  3 * ?????????????????????????
  4 * 
  5 * 
  6 * */
  7
  8
  9using System;
 10using System.Collections.Generic;
 11using System.ComponentModel;
 12using System.Data;
 13using System.Drawing;
 14using System.Text;
 15using System.Windows.Forms;
 16
 17using Las.Model;
 18using Las.Dal;
 19using Las.Biz;
 20using Aga.Controls.Tree;
 21using Aga.Controls.Tree.NodeControls;
 22
 23namespace Las.WinUI
 24{
 25    public partial class FrmDGSelector : Form
 26    {
 27        //???????ID
 28        System.Collections.Specialized.StringCollection checkedId = new System.Collections.Specialized.StringCollection();
 29        public FrmDGSelector()
 30        {
 31            InitializeComponent();
 32            SetSelectMode(rbRequired.Checked);            
 33            dgTree.LoadOnDemand = true;//?????????
 34            SetupDGTree(dgTree);
 35            contextMenuStrip1.Enabled = false;
 36        }
 37
 38        public FrmDGSelector(ITreeModel tm):this()
 39        {            
 40            dgTree.Model = tm;
 41            if (dgTree.Root != null)
 42            {
 43                foreach (TreeNodeAdv n in dgTree.Root.Children)
 44                {
 45                    n.Expand();
 46                }
 47            }
 48        }
 49
 50        /// <summary>
 51        /// ??????
 52        /// </summary>
 53        /// <param name="requiredMode">???true???????</param>
 54        private void SetSelectMode(bool requiredMode)
 55        {
 56            labelCnt.Enabled = !requiredMode;
 57            nudCnt.Enabled =!requiredMode;
 58            btnSelect.Text =requiredMode?"??":"??";
 59        }
 60
 61
 62        #region ??????????
 63        private void SetupDGTree(Aga.Controls.Tree.TreeViewAdv tva)
 64        {           
 65          
 66            tva.SelectionMode = TreeSelectionMode.Single;
 67            //????????contextMenu??
 68            tva.SelectionChanged += new EventHandler(tva_SelectionChanged);
 69
 70            
 71            NodeCheckBox cb = new NodeCheckBox("IsChecked");
 72            cb.EditEnabled = true;
 73            cb.ThreeState = false;
 74            cb.CheckStateChanged += new EventHandler<TreePathEventArgs>(cb_CheckStateChanged);
 75            tva.NodeControls.Add(cb);
 76
 77            NodeStateIcon ni = new NodeStateIcon();
 78            ni.DataPropertyName = "Icon";
 79            tva.NodeControls.Add(ni);
 80
 81            NodeTextBox tb = new NodeTextBox();
 82            tb.DataPropertyName = "Text";
 83            tva.NodeControls.Add(tb);
 84        }
 85        #endregion
 86
 87        void cb_CheckStateChanged(object sender, TreePathEventArgs e)
 88        {
 89            IModelNode cn = (IModelNode)e.Path.LastNode;
 90            MoXldg mo = cn.Tag as MoXldg;
 91            bool status = (bool)cn.IsChecked;
 92            if (status)
 93            {
 94                if (!checkedId.Contains(mo.DgId))
 95                {
 96                    checkedId.Add(mo.DgId);
 97                }
 98            }
 99            else
100            {
101                checkedId.Remove(mo.DgId);
102            }
103
104        }
105
106        void tva_SelectionChanged(object sender, EventArgs e)
107        {
108            Aga.Controls.Tree.TreeViewAdv tva = (Aga.Controls.Tree.TreeViewAdv)sender;
109            if (tva.SelectedNodes.Count == 0)
110            {
111                contextMenuStrip1.Enabled = false;
112            }
113            else
114            {
115                contextMenuStrip1.Enabled = true;
116            }
117        }
118
119        /// <summary>
120        /// ???????????UI
121        /// </summary>
122        /// <param name="sender"></param>
123        /// <param name="e"></param>
124        private void btnSelect_Click(object sender, EventArgs e)
125        {
126
127        }
128
129        private void rbRequired_CheckedChanged(object sender, EventArgs e)
130        {
131            SetSelectMode(rbRequired.Checked);
132        }
133
134        #region ????
135        /// <summary>
136        /// ???????/???? ?????
137        /// </summary>
138        /// <param name="tva"></param>
139        /// <param name="tna"></param>
140        /// <param name="status"></param>
141        internal void SetCheckStatus(TreeViewAdv tva, TreeNodeAdv tna, bool status)
142        {
143            IModelNode drn = (IModelNode)tva.GetPath(tna).LastNode;
144            MoXldg mo = drn.Tag as MoXldg;
145            drn.IsChecked = status;
146            if (status)
147            {
148                if (!checkedId.Contains(mo.DgId))
149                {
150                    checkedId.Add(mo.DgId);
151                }
152            }
153            else
154            {
155                if (checkedId.Contains(mo.DgId))
156                {
157                    checkedId.Remove(mo.DgId);
158                }
159            }
160
161            foreach (TreeNodeAdv n in tna.Children)
162            {
163                SetCheckStatus(tva, n, status);
164            }
165        }
166
167        /// <summary>
168        /// ???????????????
169        /// </summary>
170        /// <param name="sender"></param>
171        /// <param name="e"></param>
172        private void tsmiSelectAllSubNode_Click(object sender, EventArgs e)
173        {
174            ToolStripMenuItem tsmi = (ToolStripMenuItem)sender;
175            ContextMenuStrip cmms = (ContextMenuStrip)tsmi.Owner;
176            Aga.Controls.Tree.TreeViewAdv tva = (Aga.Controls.Tree.TreeViewAdv)cmms.SourceControl;
177            tva.SuspendLayout();
178            SetCheckStatus(tva, tva.SelectedNode, true);
179            tva.ResumeLayout(true);
180            tva.Refresh();
181
182
183        }
184
185        /// <summary>
186        /// ??????????????
187        /// </summary>
188        /// <param name="sender"></param>
189        /// <param name="e"></param>
190        private void tsmiUnSelectAllSub_Click(object sender, EventArgs e)
191        {
192            ToolStripMenuItem tsmi = (ToolStripMenuItem)sender;
193            ContextMenuStrip cmms = (ContextMenuStrip)tsmi.Owner;
194            Aga.Controls.Tree.TreeViewAdv tva = (Aga.Controls.Tree.TreeViewAdv)cmms.SourceControl;
195            tva.SuspendLayout();
196            SetCheckStatus(tva, tva.SelectedNode, false);
197            tva.ResumeLayout(true);
198            tva.Refresh();
199        }
200        #endregion
201
202    }
203}