예제 #1
0
        private void TreeView1_AfterCheck(object sender, TreeViewEventArgs e)
        {
            if (!working)
            {
                for (int i = 0; i < e.Node.Nodes.Count; i++)
                {
                    e.Node.Nodes[i].Checked = e.Node.Checked;
                }
            }

            if (initial)
            {
                if (e.Node.Nodes.Count == 0)
                {
                    string path = e.Node.FullPath;
                    Console.WriteLine("caminho node " + path);
                    paths.Add(path.Replace(@"Pastas :\", ""));
                }
            }
            else
            {
                Pastapref.checkifexist(f1.prefpastas, e.Node.FullPath.Replace(@"Pastas :\", ""), e.Node.Checked);
                if (File.Exists(f1.pastapath))
                {
                    File.Delete(f1.pastapath);
                }
                StreamWriter sw = new StreamWriter(f1.pastapath);
                sw.Write(Newtonsoft.Json.JsonConvert.SerializeObject(f1.prefpastas));
                sw.Close();
            }
            //if (f1.prefpastas!=null)
            // f1.prefpastas.Print();
        }
예제 #2
0
        public pastaspref(string json)
        {
            InitializeComponent();
            initial = true;
            working = false;
            paths   = new List <string>();
            treeView1.CheckBoxes  = true;
            treeView1.AfterCheck += TreeView1_AfterCheck;;

            try
            {
                DisplayTreeView(JToken.Parse(json), @"Pastas :\");
            }
            catch
            {
            }
            try
            {
                treeView1.Nodes[0].Checked = true;
                initial = false;
                if (f1.prefpastas == null)
                {
                    f1.prefpastas = new List <Pastapref>();
                    foreach (string s in paths)
                    {
                        f1.prefpastas.Add(new Pastapref(s, true));
                    }
                }
                else
                {
                    working = true;
                    Console.WriteLine("no add");
                    f1.prefpastas.Print();
                    foreach (string s in paths)
                    {
                        Pastapref.addifNew(f1.prefpastas, s);
                    }

                    Console.WriteLine("AfterAdd");
                    f1.prefpastas.Print();
                    Console.WriteLine("-------");
                    List <TreeNode> nodes = treeView1.GetAllNodes();
                    Console.WriteLine("kkkk");
                    for (int i = 0; i < nodes.Count; i++)
                    {
                        string    a  = nodes[i].FullPath.Replace(@"Pastas :\", "");
                        Pastapref pf = Pastapref.getboolvalue(f1.prefpastas, a);
                        if (pf != null && pf.check != nodes[i].Checked)
                        {
                            nodes[i].Checked = pf.check;
                        }
                    }
                    working = false;
                }
            }
            catch (Exception xp)
            {
                MessageBox.Show("Erro ao gerar pastas, os arquivos ainda não foram carregados \r\n " + xp.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            try
            {/*
              *   List<TreeNode> tr = treeView1.GetAllNodes();
              *    List<TreeNode> checados = new List<TreeNode>();
              *
              *    foreach (TreeNode te in tr)
              *    {
              *        int a = -1;
              *        Console.WriteLine("procurei node2 " + te.Name);
              *
              *        if (!checados.Contains(te))
              *            for (int i = 0; i < te.Nodes.Count; i++)
              *            {
              *                a++;
              *                Console.WriteLine("procurei node " + te.Name);
              *                if (te.Nodes[i].Checked) a++;
              *            }
              *        if (a !=0&& te.Nodes.Count>0) te.Checked = false;
              *        checados.Add(te);
              *    }*/
            }
            catch
            {
            }
        }