示例#1
0
        /// <summary>
        /// 加载数节点数据
        /// </summary>
        public void LoadTreeView(int selectedNodeCode = 1)
        {
            DataTable tvData = _provider.GetReadXml(_provider.filePath("treePath"));

            if (tvData != null)
            {
                this.tvNodes.Nodes.Clear();
                DataRow[] parent_arr = tvData.Select("parentNode='0'");
                foreach (DataRow dr in parent_arr)
                {
                    //作为一级层次  (根节点)
                    myTreeNode root = new myTreeNode();
                    root.Text               = dr["nodeTitle"].ToString();
                    root.NodeCode           = Convert.ToInt32(dr["nodeCode"].ToString());
                    root.ParentNode         = Convert.ToInt32(dr["parentNode"].ToString());
                    root.ContextMenuStrip   = tvNodeAddParent;
                    root.SelectedImageIndex = 4;
                    root.ImageIndex         = 4;
                    this.tvNodes.Nodes.Add(root);
                    selectedNode = root.NodeCode == selectedNodeCode ? root : selectedNode;
                    DataRow[] dr_arr = tvData.Select("parentNode='" + root.NodeCode + "'");
                    LoadChildTreeData(tvData, dr_arr, root, selectedNodeCode);
                }
            }
            this.tvNodes.ExpandAll();
            selectedNode.Checked      = true;
            this.tvNodes.SelectedNode = selectedNode;
            TreeNodeSelected(selectedNode);
        }
示例#2
0
        /// <summary>
        /// 递归无限级菜单
        /// </summary>
        /// <param name="tvData"></param>
        /// <param name="dr_arr"></param>
        /// <param name="tn_origine"></param>
        private void addNode(DataTable tvData, DataRow[] dr_arr, myTreeNode tn_origine)
        {
            if (dr_arr.Length > 0)
            {
                //下一级层次
                foreach (DataRow dr_sub in dr_arr)
                {
                    myTreeNode tn_sub = new myTreeNode();
                    tn_sub.Text               = dr_sub["nodeTitle"].ToString();
                    tn_sub.NodeCode           = Convert.ToInt32(dr_sub["nodeCode"].ToString());
                    tn_sub.ParentNode         = Convert.ToInt32(dr_sub["parentNode"].ToString());
                    tn_sub.SelectedImageIndex = 1;
                    tn_sub.ImageIndex         = 1;
                    DataRow[] child_arr = tvData.Select("parentNode='" + dr_sub["nodeCode"].ToString() + "'");
                    if (child_arr != null && child_arr.Length > 0)
                    {
                        tn_sub.SelectedImageIndex = 0;
                        tn_sub.ImageIndex         = 0;
                    }

                    tn_origine.Nodes.Add(tn_sub);
                    if (accountModel != null)
                    {
                        if (accountModel.AccountGroupCode == tn_sub.NodeCode)
                        {
                            dfTree = tn_sub;
                        }
                    }
                    addNode(tvData, child_arr, tn_sub);
                }
            }
        }
示例#3
0
 private void TreeNodeSelected(myTreeNode tn)
 {
     if (!string.IsNullOrEmpty(tn.Text))
     {
         if (tn.ParentNode != 0)
         {
             string    path   = _provider.filePath("treePath");
             DataTable dtTree = _provider.GetReadXml(path);
             //当前节点下的所有子节点ID
             List <string> listCode = new List <string>();
             if (dtTree != null)
             {
                 listCode.Add(tn.NodeCode.ToString());
                 DataRow[] dr_arr = dtTree.Select("parentNode='" + tn.NodeCode + "'");
                 //获取当前选中节点下的所有节点ID
                 _provider.SelectedTreeChild(dtTree, dr_arr, listCode);
             }
             LoadGridView(listCode);
         }
         else
         {
             LoadGridView();
         }
     }
     else
     {
         LoadGridView();
     }
 }
示例#4
0
        /// <summary>
        /// 鼠标单击节点时触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tvNodes_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            myTreeNode tn = e.Node as myTreeNode;

            TreeNodeSelected(tn);
            this.tvNodes.SelectedNode = tn;
        }
示例#5
0
 /// <summary>
 /// 递归无限级菜单
 /// </summary>
 /// <param name="tvData"></param>
 /// <param name="dr_arr"></param>
 /// <param name="tn_origine"></param>
 private void LoadChildTreeData(DataTable tvData, DataRow[] dr_arr, myTreeNode tn_origine, int selectedNodeCode)
 {
     if (dr_arr.Length > 0)
     {
         //下一级层次
         foreach (DataRow dr_sub in dr_arr)
         {
             myTreeNode tn_sub = new myTreeNode();
             tn_sub.Text               = dr_sub["nodeTitle"].ToString();
             tn_sub.NodeCode           = Convert.ToInt32(dr_sub["nodeCode"].ToString());
             tn_sub.ParentNode         = Convert.ToInt32(dr_sub["parentNode"].ToString());
             tn_sub.ContextMenuStrip   = tvNodeAdd;
             tn_sub.SelectedImageIndex = 5;
             tn_sub.ImageIndex         = 5;
             DataRow[] child_arr = tvData.Select("parentNode='" + tn_sub.NodeCode + "'");
             if (child_arr != null && child_arr.Length > 0)
             {
                 tn_sub.SelectedImageIndex = 4;
                 tn_sub.ImageIndex         = 4;
             }
             tn_origine.Nodes.Add(tn_sub);
             selectedNode = tn_sub.NodeCode == selectedNodeCode ? tn_sub : selectedNode;
             LoadChildTreeData(tvData, child_arr, tn_sub, selectedNodeCode);
         }
     }
 }
示例#6
0
        private void ShowAccountForm()
        {
            myTreeNode tn = tvNodes.SelectedNode as myTreeNode;

            if (tn == null)
            {
                return;
            }
            EditAccount account = new EditAccount(this, tn);

            account.ShowDialog();
        }
示例#7
0
        /// <summary>
        /// 修改节点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tvNodeUpdateNode_Click(object sender, EventArgs e)
        {
            myTreeNode tn = tvNodes.SelectedNode as myTreeNode;

            if (tn == null)
            {
                return;
            }
            EditNode editnode = new EditNode(this, tn.ParentNode, tn.NodeCode, tn.Text);

            editnode.currentSelectedNode = tn.NodeCode;
            editnode.ShowDialog(this);
        }
示例#8
0
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void gridDelete_Click(object sender, EventArgs e)
        {
            if (dgvData.DataSource != null)
            {
                DataGridViewCellCollection row = dgvData.CurrentRow.Cells;
                if (MessageBox.Show("您确认要删除标题为【" + row[1].Value + "】的数据吗?", "删除提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    string       path         = _provider.filePath("gridPath");
                    DataTable    dtGrid       = _provider.GetReadXml(path);
                    DataColumn[] myPrimaryKey = new DataColumn[1];
                    myPrimaryKey[0]   = dtGrid.Columns["AccountCode"];
                    dtGrid.PrimaryKey = myPrimaryKey;
                    DataRow myEditDataRow = dtGrid.Rows.Find(row[0].Value);
                    myEditDataRow.Delete();
                    dtGrid.AcceptChanges();
                    string gridXml  = _provider.CDataToXml(dtGrid);
                    string filePath = System.IO.Path.Combine(Application.StartupPath, path);
                    if (System.IO.File.Exists(filePath))
                    {
                        System.IO.StreamWriter sw = new System.IO.StreamWriter(filePath, false);
                        sw.WriteLine(gridXml);
                        sw.Close();//写入
                    }


                    myTreeNode tn     = tvNodes.SelectedNode as myTreeNode;
                    string     _path  = _provider.filePath("treePath");
                    DataTable  dtTree = _provider.GetReadXml(_path);
                    //当前节点下的所有子节点ID
                    List <string> listCode = new List <string>();
                    if (dtTree != null)
                    {
                        listCode.Add(tn.NodeCode.ToString());
                        DataRow[] dr_arr = dtTree.Select("parentNode='" + tn.NodeCode + "'");
                        //获取当前选中节点下的所有节点ID
                        _provider.SelectedTreeChild(dtTree, dr_arr, listCode);
                    }

                    LoadGridView(listCode);
                }
            }
        }
示例#9
0
        public EditAccount(Main m, myTreeNode myNode, AccoutnModel model = null)
        {
            InitializeComponent();
            dfTree   = myNode;
            nodeCode = myNode.NodeCode;
            main     = m;
            if (model == null)
            {
                accountModel = new AccoutnModel();
            }
            else
            {
                accountModel = model;

                txtAccountTitle.Text   = accountModel.AccountTitle;
                txtAccoutnName.Text    = accountModel.AccountName;
                txtAccountPwd.Text     = accountModel.AccountPwd;
                txtAccountWebsite.Text = accountModel.AccountWebsite;
                txtAccountRemark.Text  = accountModel.AccountRemark;
            }
            InitMcdTypeTree();
        }
示例#10
0
        /// <summary>
        /// 修改数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void gridUpdate_Click(object sender, EventArgs e)
        {
            if (dgvData.DataSource != null)
            {
                DataGridViewCellCollection row = dgvData.CurrentRow.Cells;
                if (row.Count > 5)
                {
                    AccoutnModel model = new AccoutnModel();
                    model.AccountCode      = Convert.ToInt32(row[0].Value);
                    model.AccountTitle     = row[1].Value.ToString();
                    model.AccountName      = row[2].Value.ToString();
                    model.AccountPwd       = row[3].Value.ToString();
                    model.AccountWebsite   = row[4].Value.ToString();
                    model.AccountRemark    = row[5].Value.ToString();
                    model.AccountGroupCode = Convert.ToInt32(row[6].Value);
                    myTreeNode tn = tvNodes.SelectedNode as myTreeNode;

                    EditAccount account = new EditAccount(this, tn, model);
                    account.ShowDialog();
                }
            }
        }
示例#11
0
        /// <summary>
        /// 删除分组
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tvNodeDelete_Click(object sender, EventArgs e)
        {
            myTreeNode tn = tvNodes.SelectedNode as myTreeNode;

            if (tn == null || tn.NodeCode == 1)
            {
                return;
            }
            if (MessageBox.Show("您确认要删除分组【" + tn.Text + "】以及下面的所有分组吗?", "删除提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                string    path   = _provider.filePath("treePath");
                DataTable dtTree = _provider.GetReadXml(path);
                if (dtTree != null)
                {
                    DataColumn[] myPrimaryKey = new DataColumn[1];
                    myPrimaryKey[0]   = dtTree.Columns["nodeCode"];
                    dtTree.PrimaryKey = myPrimaryKey;
                    DataRow myEditDataRow = dtTree.Select("nodeCode=" + tn.NodeCode)[0];// dtTree.Rows.Find(tn.NodeCode);
                    //int _nodeCode = Convert.ToInt32(myEditDataRow["nodeCode"]);
                    myEditDataRow.Delete();

                    //删除当前节点下的所有子节点
                    DataRow[] dr_arr = dtTree.Select("parentNode=" + tn.NodeCode);
                    deleteNode(dtTree, dr_arr);

                    dtTree.AcceptChanges();
                    string treeXml  = _provider.CDataToXml(dtTree);
                    string filePath = System.IO.Path.Combine(Application.StartupPath, path);
                    if (System.IO.File.Exists(filePath))
                    {
                        System.IO.StreamWriter sw = new System.IO.StreamWriter(filePath, false);
                        sw.WriteLine(treeXml);
                        sw.Close();//写入
                    }
                }
                LoadTreeView();
            }
        }
示例#12
0
        /// <summary>
        /// 窗口加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Main_Load(object sender, EventArgs e)
        {
            selectedNode = new myTreeNode();
            string str = _provider.GetFileText(_provider.filePath("configPath"));

            if (!string.IsNullOrEmpty(str))
            {
                string pwd = _provider.MD5("0|-1");
                if (str == pwd)
                {
                    LoadTreeView();
                }
                else
                {
                    SetPwd sp = new SetPwd(this);
                    sp.ShowDialog(this);
                }
            }
            else
            {
                Application.Exit();
            }
        }
示例#13
0
        /// <summary>
        /// 加载数节点数据
        /// </summary>
        public void InitMcdTypeTree()
        {
            Common    comm   = new Common();
            DataTable tvData = comm.GetReadXml(comm.filePath("treePath"));

            if (tvData != null)
            {
                TreeView treeView = this.cbxTree.TreeView;
                treeView.ImageList = imgList;
                treeView.Nodes.Clear();
                DataRow[] parent_arr = tvData.Select("parentNode='0'");
                foreach (DataRow dr in parent_arr)
                {
                    //作为一级层次  (根节点)
                    myTreeNode rootNode = new myTreeNode();
                    rootNode.Text               = "默认";//dr["nodeTitle"].ToString();
                    rootNode.NodeCode           = Convert.ToInt32(dr["nodeCode"].ToString());
                    rootNode.ParentNode         = Convert.ToInt32(dr["parentNode"].ToString());
                    rootNode.SelectedImageIndex = 0;
                    rootNode.ImageIndex         = 0;
                    treeView.Nodes.Add(rootNode);

                    if (accountModel != null)
                    {
                        if (accountModel.AccountGroupCode == rootNode.NodeCode)
                        {
                            dfTree = rootNode;
                        }
                    }
                    DataRow[] dr_arr = tvData.Select("parentNode='" + dr["nodeCode"].ToString() + "'");
                    addNode(tvData, dr_arr, rootNode);
                }
                treeView.ExpandAll();
                this.cbxTree.setTreeView(dfTree);
            }
        }
示例#14
0
        /// <summary>
        /// 保存帐号信息
        /// </summary>
        /// <returns></returns>
        public bool Save()
        {
            try
            {
                #region 文本框验证
                if (string.IsNullOrEmpty(txtAccountTitle.Text))
                {
                    txtAccountTitle.Focus();
                    return(false);
                }
                if (string.IsNullOrEmpty(txtAccoutnName.Text))
                {
                    txtAccoutnName.Focus();
                    return(false);
                }
                if (string.IsNullOrEmpty(txtAccountPwd.Text))
                {
                    txtAccountPwd.Focus();
                    return(false);
                }
                #endregion

                Common    comm   = new Common();
                string    path   = comm.filePath("gridPath");
                DataTable dtGrid = comm.GetReadXml(path);
                if (accountModel.AccountCode <= 0)
                {
                    #region 添加数据
                    if (dtGrid == null)
                    {
                        dtGrid           = new DataTable();
                        dtGrid.TableName = "AccountData";
                        dtGrid.Columns.Add("AccountCode", typeof(int));
                        dtGrid.Columns.Add("AccountTitle", typeof(string));
                        dtGrid.Columns.Add("AccountName", typeof(string));
                        dtGrid.Columns.Add("AccountPwd", typeof(string));
                        dtGrid.Columns.Add("AccountWebsite", typeof(string));
                        dtGrid.Columns.Add("AccountRemark", typeof(string));
                        dtGrid.Columns.Add("AccountAddTime", typeof(string));
                        dtGrid.Columns.Add("AccountGroupCode", typeof(int));
                    }
                    DataRow row         = dtGrid.NewRow();
                    int     accountCode = -1;
                    foreach (DataRow item in dtGrid.Rows)
                    {
                        int result = 0;
                        int.TryParse(item["AccountCode"].ToString(), out result);

                        if (result > accountCode)
                        {
                            accountCode = result;
                        }
                    }
                    row["AccountCode"]    = accountCode > 0 ? accountCode + 1 : dtGrid.Rows.Count + 1;
                    row["AccountTitle"]   = txtAccountTitle.Text;
                    row["AccountName"]    = txtAccoutnName.Text;
                    row["AccountPwd"]     = txtAccountPwd.Text;
                    row["AccountWebsite"] = txtAccountWebsite.Text;
                    row["AccountRemark"]  = txtAccountRemark.Text;
                    row["AccountAddTime"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    myTreeNode myTree = this.cbxTree.TreeView.SelectedNode as myTreeNode;
                    row["AccountGroupCode"] = myTree != null ? myTree.NodeCode : dfTree.NodeCode;
                    dtGrid.Rows.Add(row);
                    #endregion
                }
                else //修改数据
                {
                    DataColumn[] myPrimaryKey = new DataColumn[1];
                    myPrimaryKey[0]   = dtGrid.Columns["AccountCode"];
                    dtGrid.PrimaryKey = myPrimaryKey;
                    DataRow myEditDataRow = dtGrid.Rows.Find(accountModel.AccountCode);
                    myEditDataRow["AccountTitle"]   = txtAccountTitle.Text;
                    myEditDataRow["AccountName"]    = txtAccoutnName.Text;
                    myEditDataRow["AccountPwd"]     = txtAccountPwd.Text;
                    myEditDataRow["AccountWebsite"] = txtAccountWebsite.Text;
                    myEditDataRow["AccountRemark"]  = txtAccountRemark.Text;
                    myTreeNode myTree = this.cbxTree.TreeView.SelectedNode as myTreeNode;
                    myEditDataRow["AccountGroupCode"] = myTree != null ? myTree.NodeCode : dfTree.NodeCode;
                    dtGrid.AcceptChanges();
                }

                string gridXml  = comm.CDataToXml(dtGrid);
                string filePath = System.IO.Path.Combine(Application.StartupPath, path);
                if (System.IO.File.Exists(filePath))
                {
                    System.IO.StreamWriter sw = new System.IO.StreamWriter(filePath, false);
                    sw.WriteLine(gridXml);
                    sw.Close();//写入
                }


                #region 加载gridview数据
                string    _path  = comm.filePath("treePath");
                DataTable dtTree = comm.GetReadXml(_path);
                //当前节点下的所有子节点ID
                List <string> listCode = new List <string>();
                if (dtTree != null)
                {
                    listCode.Add(nodeCode.ToString());
                    DataRow[] dr_arr = dtTree.Select("parentNode='" + nodeCode + "'");
                    //获取当前选中节点下的所有节点ID
                    comm.SelectedTreeChild(dtTree, dr_arr, listCode);
                }

                main.LoadGridView(listCode);
                #endregion

                MessageBox.Show("保存成功!");
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("保存失败!" + ex.Message);
                return(false);
            }
        }