public bool Load(ref XmlDataProviderManager x, string ID, string FileConclusione, Hashtable _Sessioni, Hashtable _SessioniTitoli, Hashtable _SessioniID, int _SessioneNow, string _IDTree, string _IDCliente, string _IDSessione)
        {
            Sessioni       = _Sessioni;
            SessioniTitoli = _SessioniTitoli;
            SessioniID     = _SessioniID;
            SessioneNow    = _SessioneNow;
            IDTree         = _IDTree;
            IDCliente      = _IDCliente;
            IDSessione     = _IDSessione;

            _x  = x.Clone();
            _ID = ID;

            RowDefinition rd;
            Border        brd;
            TextBlock     txt;
            int           row = 3;

            RevisoftApplication.XmlManager xt = new XmlManager();
            xt.TipoCodifica = RevisoftApplication.XmlManager.TipologiaCodifica.Normale;
            XmlDataProvider TreeXmlProvider = new XmlDataProvider();

            TreeXmlProvider.Document = xt.LoadEncodedFile(App.AppTemplateTreeBilancio);

            //Controllo degli indici pro salvataggio AP
            int indice = 0;

            MasterFile mf = MasterFile.Create();

            if (IDTree == "4")
            {
                string FileDataRevisione = mf.GetRevisioneAssociataFromBilancioFile(FileConclusione);

                if (FileDataRevisione != "")
                {
                    _lm = new XmlDataProviderManager(FileDataRevisione);
                }
                else
                {
                    _lm = null;
                }

                _lb = x;
            }
            else
            {
                string FileDataRevisione = mf.GetRevisioneAssociataFromConclusioneFile(FileConclusione);
                string FileDataBilancio  = mf.GetBilancioAssociatoFromConclusioneFile(FileConclusione);

                if (FileDataRevisione != "")
                {
                    _lm = new XmlDataProviderManager(FileDataRevisione);
                }
                else
                {
                    _lm = null;
                }

                if (FileDataBilancio != "")
                {
                    _lb = new XmlDataProviderManager(FileDataBilancio);
                }
                else
                {
                    _lb = null;
                }
            }

            double totaleimporto = 0.0;

            if (_lb != null)
            {
                foreach (XmlNode item in _lb.Document.SelectNodes("/Dati/Dato[@ID]/Valore[@tipo='ErroriRilevatiMR']"))
                {
                    int indiceinterno = 0;

                    if (item.Attributes["ID"] != null)
                    {
                        int.TryParse(item.Attributes["ID"].Value, out indiceinterno);
                    }

                    if (indiceinterno > indice)
                    {
                        indice = indiceinterno;
                    }
                }

                Dictionary <int, XmlNode> lista = new Dictionary <int, XmlNode>();

                foreach (XmlNode item in _lb.Document.SelectNodes("/Dati/Dato[@ID]/Valore[@tipo='ErroriRilevatiMR']"))
                {
                    if (item.Attributes["name"].Value == "Totale")
                    {
                        continue;
                    }

                    XmlNode tnode = TreeXmlProvider.Document.SelectSingleNode("/Tree//Node[@ID=" + item.ParentNode.Attributes["ID"].Value + "]");
                    if (tnode == null)
                    {
                        continue;
                    }

                    int chiave = Convert.ToInt32(tnode.Attributes["Codice"].Value.Replace(".", "").Replace("A", "").Replace("B", "").Replace("C", "").Replace("D", ""));

                    while (lista.Keys.Contains(chiave))
                    {
                        chiave = chiave + 1;
                    }


                    lista.Add(chiave, item);
                }

                bool first = true;

                int indiceinternoRow = 0;

                foreach (KeyValuePair <int, XmlNode> itemD in lista.OrderBy(key => key.Key))
                {
                    XmlNode item = itemD.Value;

                    XmlNode tnode = TreeXmlProvider.Document.SelectSingleNode("/Tree//Node[@ID=" + item.ParentNode.Attributes["ID"].Value + "]");

                    if (item.Attributes["ID"] == null)
                    {
                        XmlAttribute attr = _lb.Document.CreateAttribute("ID");
                        attr.Value = (++indice).ToString();
                        item.Attributes.Append(attr);
                    }

                    rd = new RowDefinition();
                    if (first)
                    {
                        first     = false;
                        rd.Height = new GridLength(0.0);
                    }
                    else
                    {
                        rd.Height = new GridLength(20.0);
                    }
                    grdMainMR.RowDefinitions.Add(rd);
                    row++;


                    brd = new Border();
                    brd.BorderThickness = new Thickness(1.0, 0, 0, 1.0);
                    brd.BorderBrush     = Brushes.Black;

                    indiceinternoRow++;
                    indicerow.Add(indiceinternoRow, row.ToString());

                    txt      = new TextBlock();
                    txt.Name = "txtCodice" + row.ToString();
                    this.RegisterName(txt.Name, txt);
                    txt.Text                = tnode.ParentNode.Attributes["Codice"].Value;
                    txt.ToolTip             = tnode.ParentNode.Attributes["Titolo"].Value;
                    txt.TextAlignment       = TextAlignment.Left;
                    txt.TextWrapping        = TextWrapping.Wrap;
                    txt.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    txt.MaxHeight           = Convert.ToInt32(tnode.ParentNode.Attributes["ID"].Value);
                    txt.MouseDown          += new MouseButtonEventHandler(txt_MouseDown);

                    brd.Child = txt;

                    grdMainMR.Children.Add(brd);
                    Grid.SetRow(brd, row);
                    Grid.SetColumn(brd, 0);

                    brd = new Border();
                    brd.BorderThickness = new Thickness(1.0, 0, 0, 1.0);
                    brd.BorderBrush     = Brushes.Black;

                    txt                     = new TextBlock();
                    txt.Text                = (item.Attributes["name"].Value.Length > 30) ? item.Attributes["name"].Value.Substring(0, 30) + "[...]" : item.Attributes["name"].Value;
                    txt.ToolTip             = item.Attributes["name"].Value;
                    txt.Name                = "txtName" + row.ToString();
                    txt.Margin              = new Thickness(0, 0, 0, 0);
                    txt.Padding             = new Thickness(0, 0, 0, 0);
                    txt.TextAlignment       = TextAlignment.Left;
                    txt.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                    this.RegisterName(txt.Name, txt);

                    brd.Child = txt;

                    grdMainMR.Children.Add(brd);
                    Grid.SetRow(brd, row);
                    Grid.SetColumn(brd, 1);

                    brd = new Border();
                    brd.BorderThickness = new Thickness(1.0, 0, 0, 1.0);
                    brd.Background      = Brushes.LightYellow;
                    brd.BorderBrush     = Brushes.Black;

                    txt      = new TextBlock();
                    txt.Text = item.Attributes["contoimputato"].Value;
                    txt.Name = "txtcontoimputato" + row.ToString();
                    this.RegisterName(txt.Name, txt);
                    txt.TextAlignment = TextAlignment.Right;

                    brd.Child = txt;

                    grdMainMR.Children.Add(brd);
                    Grid.SetRow(brd, row);
                    Grid.SetColumn(brd, 2);

                    brd = new Border();
                    brd.BorderThickness = new Thickness(1.0, 0, 0, 1.0);
                    brd.BorderBrush     = Brushes.Black;

                    txt      = new TextBlock();
                    txt.Text = item.Attributes["contoproposto"].Value;
                    txt.Name = "txtcontoproposto" + row.ToString();
                    this.RegisterName(txt.Name, txt);
                    txt.TextAlignment = TextAlignment.Right;

                    brd.Child = txt;

                    grdMainMR.Children.Add(brd);
                    Grid.SetRow(brd, row);
                    Grid.SetColumn(brd, 3);

                    brd = new Border();
                    brd.BorderThickness = new Thickness(1.0, 0, 0, 1.0);
                    brd.BorderBrush     = Brushes.Black;

                    txt      = new TextBlock();
                    txt.Text = ConvertNumber(item.Attributes["importo"].Value);

                    double valueimporto = 0;
                    double.TryParse(txt.Text, out valueimporto);
                    totaleimporto += valueimporto;

                    txt.Name = "txtEA" + row.ToString();
                    this.RegisterName(txt.Name, txt);
                    txt.TextAlignment = TextAlignment.Right;

                    brd.Child = txt;

                    grdMainMR.Children.Add(brd);
                    Grid.SetRow(brd, row);
                    Grid.SetColumn(brd, 4);

                    brd = new Border();
                    brd.BorderThickness = new Thickness(1.0, 0, 1.0, 1.0);
                    brd.BorderBrush     = Brushes.Black;
                    brd.Background      = Brushes.White;

                    CheckBox chk = new CheckBox();
                    chk.Name = "chkCorretto" + row.ToString();
                    this.RegisterName(chk.Name, chk);
                    chk.IsChecked        = Convert.ToBoolean(item.Attributes["corretto"].Value);
                    chk.IsHitTestVisible = false;

                    chk.HorizontalAlignment      = System.Windows.HorizontalAlignment.Center;
                    chk.VerticalAlignment        = System.Windows.VerticalAlignment.Center;
                    chk.VerticalContentAlignment = System.Windows.VerticalAlignment.Center;

                    brd.Child = chk;

                    grdMainMR.Children.Add(brd);
                    Grid.SetRow(brd, row);
                    Grid.SetColumn(brd, 5);
                }


                rowTOT = row;

                rd        = new RowDefinition();
                rd.Height = new GridLength(20.0);
                grdMainMR.RowDefinitions.Add(rd);

                rd        = new RowDefinition();
                rd.Height = new GridLength(30.0);
                grdMainMR.RowDefinitions.Add(rd);
                row++;

                brd = new Border();
                brd.BorderThickness = new Thickness(0.0);
                brd.BorderBrush     = Brushes.Black;
                brd.Background      = Brushes.White;

                txt      = new TextBlock();
                txt.Text = "TOTALE DELLE RETTIFICHE";
                txt.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                txt.Height     = 30;
                txt.Margin     = new Thickness(0, 0, 20, 0);
                txt.FontWeight = FontWeights.Bold;

                txt.Padding = new Thickness(0, 7, 3, 0);
                brd.Child   = txt;

                grdMainMR.Children.Add(brd);
                Grid.SetRow(brd, row);
                Grid.SetColumn(brd, 1);

                brd = new Border();
                brd.BorderThickness = new Thickness(1.0, 0, 1.0, 1.0);
                brd.BorderBrush     = Brushes.Black;
                brd.Background      = Brushes.LightYellow;

                txt      = new TextBlock();
                txt.Name = "txtTotEA";
                this.RegisterName(txt.Name, txt);
                txt.Text          = ConvertNumber(totaleimporto.ToString());
                txt.TextAlignment = TextAlignment.Right;
                txt.FontWeight    = FontWeights.Bold;

                txt.Padding = new Thickness(0, 7, 3, 0);
                txt.Height  = 30;
                brd.Child   = txt;

                grdMainMR.Children.Add(brd);
                Grid.SetRow(brd, row);
                Grid.SetColumn(brd, 4);
            }

            CalculateValues(null);

            indice = 0;
            row    = 3;

            if (_lb != null)
            {
                foreach (XmlNode item in _lb.Document.SelectNodes("/Dati/Dato[@ID]/Valore[@tipo='ErroriRilevatiNN']"))
                {
                    int indiceinterno = 0;

                    if (item.Attributes["ID"] != null)
                    {
                        int.TryParse(item.Attributes["ID"].Value, out indiceinterno);
                    }

                    if (indiceinterno > indice)
                    {
                        indice = indiceinterno;
                    }
                }

                Dictionary <int, XmlNode> lista = new Dictionary <int, XmlNode>();

                foreach (XmlNode item in _lb.Document.SelectNodes("/Dati/Dato[@ID]/Valore[@tipo='ErroriRilevatiNN']"))
                {
                    if (item.Attributes["name"].Value == "Totale")
                    {
                        continue;
                    }

                    XmlNode tnode = TreeXmlProvider.Document.SelectSingleNode("/Tree//Node[@ID=" + item.ParentNode.Attributes["ID"].Value + "]");
                    if (tnode == null)
                    {
                        continue;
                    }

                    int chiave = Convert.ToInt32(tnode.Attributes["Codice"].Value.Replace(".", "").Replace("A", "").Replace("B", "").Replace("C", "").Replace("D", ""));

                    while (lista.Keys.Contains(chiave))
                    {
                        chiave = chiave + 1;
                    }


                    lista.Add(chiave, item);
                }

                bool first = true;

                foreach (KeyValuePair <int, XmlNode> itemD in lista.OrderBy(key => key.Key))
                {
                    XmlNode item = itemD.Value;

                    XmlNode tnode = TreeXmlProvider.Document.SelectSingleNode("/Tree//Node[@ID=" + item.ParentNode.Attributes["ID"].Value + "]");

                    if (item.Attributes["ID"] == null)
                    {
                        XmlAttribute attr = _lb.Document.CreateAttribute("ID");
                        attr.Value = (++indice).ToString();
                        item.Attributes.Append(attr);
                    }

                    rd = new RowDefinition();
                    if (first)
                    {
                        first     = false;
                        rd.Height = new GridLength(0.0);
                    }
                    else
                    {
                        rd.Height = new GridLength(20.0);
                    }
                    grdMainNN.RowDefinitions.Add(rd);
                    row++;

                    brd = new Border();
                    brd.BorderThickness = new Thickness(1.0, 0, 0, 1.0);
                    brd.BorderBrush     = Brushes.Black;

                    txt                     = new TextBlock();
                    txt.Text                = tnode.ParentNode.Attributes["Codice"].Value;
                    txt.ToolTip             = tnode.ParentNode.Attributes["Titolo"].Value;
                    txt.TextAlignment       = TextAlignment.Left;
                    txt.TextWrapping        = TextWrapping.Wrap;
                    txt.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    txt.MaxHeight           = Convert.ToInt32(tnode.ParentNode.Attributes["ID"].Value);
                    txt.MouseDown          += new MouseButtonEventHandler(txt_MouseDown);

                    brd.Child = txt;

                    grdMainNN.Children.Add(brd);
                    Grid.SetRow(brd, row);
                    Grid.SetColumn(brd, 0);

                    brd = new Border();
                    brd.BorderThickness = new Thickness(1.0, 0, 0, 1.0);
                    brd.BorderBrush     = Brushes.Black;

                    txt                     = new TextBlock();
                    txt.Text                = (item.Attributes["name"].Value.Length > 30) ? item.Attributes["name"].Value.Substring(0, 30) + "[...]" : item.Attributes["name"].Value;
                    txt.ToolTip             = item.Attributes["name"].Value;
                    txt.Margin              = new Thickness(0, 0, 0, 0);
                    txt.Padding             = new Thickness(0, 0, 0, 0);
                    txt.TextAlignment       = TextAlignment.Left;
                    txt.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;

                    brd.Child = txt;

                    grdMainNN.Children.Add(brd);
                    Grid.SetRow(brd, row);
                    Grid.SetColumn(brd, 1);

                    brd = new Border();
                    brd.BorderThickness = new Thickness(1.0, 0, 0, 1.0);
                    brd.Background      = Brushes.LightYellow;
                    brd.BorderBrush     = Brushes.Black;

                    txt               = new TextBlock();
                    txt.Text          = item.Attributes["numero"].Value;
                    txt.TextAlignment = TextAlignment.Right;

                    brd.Child = txt;

                    grdMainNN.Children.Add(brd);
                    Grid.SetRow(brd, row);
                    Grid.SetColumn(brd, 2);

                    brd = new Border();
                    brd.BorderThickness = new Thickness(1.0, 0, 1.0, 1.0);
                    brd.BorderBrush     = Brushes.Black;
                    brd.Background      = Brushes.White;

                    CheckBox chk = new CheckBox();
                    chk.IsChecked        = Convert.ToBoolean(item.Attributes["corretto"].Value);
                    chk.IsHitTestVisible = false;

                    chk.HorizontalAlignment      = System.Windows.HorizontalAlignment.Center;
                    chk.VerticalAlignment        = System.Windows.VerticalAlignment.Center;
                    chk.VerticalContentAlignment = System.Windows.VerticalAlignment.Center;

                    brd.Child = chk;

                    grdMainNN.Children.Add(brd);
                    Grid.SetRow(brd, row);
                    Grid.SetColumn(brd, 3);
                }

                rd        = new RowDefinition();
                rd.Height = new GridLength(20.0);
                grdMainNN.RowDefinitions.Add(rd);
            }

            return(true);
        }