Example #1
0
        private void TreeTaskForm_Load()
        {
            treeView1.LabelEdit = true;
            DataTable dataTable  = sql.SelectDb("select * from METR_Task_Class", "METR_Task_Class");
            DataTable dataClient = sql.SelectDb("select * from METR_Task_Client", "METR_Task_Client");

            treeView1.LabelEdit = true;
            DataTable table = sql.SelectDb("select * from METR_ERP_TaskLog ", "METR_ERP_TaskLog");
            Dictionary <string, Dictionary <string, HashSet <string> > > dict = new Dictionary <string, Dictionary <string, HashSet <string> > >();

            foreach (DataRow row in table.Rows)
            {
                if (dict.ContainsKey(row[0].ToString()))
                {
                    Dictionary <string, HashSet <string> > client = dict[row[0].ToString()];
                    if (client.ContainsKey(row[1].ToString()))
                    {
                        HashSet <string> str = client[row[1].ToString()];
                        str.Add(row[3].ToString());
                    }
                    else
                    {
                        HashSet <string> str = new HashSet <string>();
                        str.Add(row[3].ToString());
                        client.Add(row[1].ToString(), str);
                    }
                }
                else
                {
                    Dictionary <string, HashSet <string> > client = new Dictionary <string, HashSet <string> >();
                    HashSet <string> str = new HashSet <string>();
                    str.Add(row[3].ToString());
                    client.Add(row[1].ToString(), str);
                    dict.Add(row[0].ToString(), client);
                }
            }
            if (dict.Keys.Count > 0)
            {
                status = true;
                foreach (var key in dict.Keys)
                {
                    TreeNode node = new TreeNode();
                    node.Text = "账套 " + key;
                    node.Name = key;
                    foreach (DataRow row in dataTable.Rows)
                    {
                        TreeNode nodeclass = new TreeNode();
                        nodeclass.Name = row[1].ToString();
                        int count = 0;
                        if (dict[key].ContainsKey(row[1].ToString()))
                        {
                            count = dict[key][row[1].ToString()].Count;
                        }
                        nodeclass.Text = row[1].ToString() + string.Format(" [{0}/{1}]", count, row[2]);
                        node.Nodes.Add(nodeclass);
                        DataRow[] datas = dataClient.Select(string.Format("classID = {0}", row[0]));
                        Console.WriteLine(datas.Length);
                        foreach (DataRow dr in datas)
                        {
                            TreeNode nodeclient = new TreeNode();
                            nodeclient.Name = dr[1].ToString();
                            int       countclient = 0;
                            DataRow[] rows        = table.Select(string.Format("账套 like '{0}' and 模块 like '{1}'", key, dr[1].ToString()));
                            if (rows != null)
                            {
                                countclient = rows.Length;
                            }
                            nodeclient.Text = dr[1].ToString() + string.Format(" [{0}]", countclient);
                            nodeclass.Nodes.Add(nodeclient);
                        }
                    }
                    treeView1.Nodes.Add(node);
                }
            }
            else
            {
                status = false;
                TreeNode node = new TreeNode();
                node.Text = "暂无人使用站点";
                treeView1.Nodes.Add(node);
            }
            treeView1.ExpandAll();
        }