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);
        }
        public bool Load(string ID, string FileConclusione, Hashtable _Sessioni, Hashtable _SessioniTitoli, Hashtable _SessioniID, int _SessioneNow, string _IDTree, string _IDCliente, string _IDSessione)
        {
            id = int.Parse(ID.ToString());
            cBusinessObjects.idcliente  = int.Parse(_IDCliente.ToString());
            cBusinessObjects.idsessione = int.Parse(_IDSessione.ToString());

            Sessioni       = _Sessioni;
            SessioniTitoli = _SessioniTitoli;
            SessioniID     = _SessioniID;
            SessioneNow    = _SessioneNow;
            IDTree         = _IDTree;
            IDCliente      = _IDCliente;
            IDSessione     = _IDSessione;


            _ID = ID;

            #region DA MATERIALITA'

            MasterFile mf = MasterFile.Create();
            string     FileDataRevisione = mf.GetRevisioneAssociataFromConclusioneFile(FileConclusione);

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


            DataTable tmpNode_true = null;

            string idsessionedatimaterialita = cBusinessObjects.CercaSessione("Conclusione", "Revisione", IDSessione, cBusinessObjects.idcliente);

            DataTable datimaterialita = cBusinessObjects.GetData(int.Parse(ID_Materialità_1), typeof(Excel_LimiteMaterialitaSPCE), cBusinessObjects.idcliente, int.Parse(idsessionedatimaterialita), 1);


            if (datimaterialita.Rows.Count > 0)
            {
                string    statomat = "";
                DataTable statom   = cBusinessObjects.GetData(int.Parse(ID_Materialità_1), typeof(StatoNodi), cBusinessObjects.idcliente, int.Parse(idsessionedatimaterialita), 1);

                foreach (DataRow dd in statom.Rows)
                {
                    statomat = dd["Stato"].ToString().Trim();
                }
                if (datimaterialita.Rows.Count > 0 && statomat != "" && ((App.TipoTreeNodeStato)(Convert.ToInt32(statomat))) == App.TipoTreeNodeStato.Completato)
                {
                    Materialità_1 = true;

                    ucExcel_LimiteMaterialitaSPCE uce_lm = new ucExcel_LimiteMaterialitaSPCE(IDTree);
                    uce_lm.Load(ID_Materialità_1, FileDataRevisione, IpotesiMaterialita.Prima, IDCliente, IDSessione);
                    uce_lm.Save();

                    brdPrima.Visibility   = System.Windows.Visibility.Visible;
                    brdSeconda.Visibility = System.Windows.Visibility.Collapsed;
                    brdTerza.Visibility   = System.Windows.Visibility.Collapsed;
                    tmpNode_true          = datimaterialita;
                }

                //if (tmpNode_true == null)
                {
                    datimaterialita = cBusinessObjects.GetData(int.Parse(ID_Materialità_2), typeof(Excel_LimiteMaterialitaSPCE), cBusinessObjects.idcliente, int.Parse(idsessionedatimaterialita), 1);

                    statom = cBusinessObjects.GetData(int.Parse(ID_Materialità_2), typeof(StatoNodi), cBusinessObjects.idcliente, int.Parse(idsessionedatimaterialita), 1);
                    foreach (DataRow dd in statom.Rows)
                    {
                        statomat = dd["Stato"].ToString().Trim();
                    }
                    if (datimaterialita.Rows.Count > 0 && statomat != "" && ((App.TipoTreeNodeStato)(Convert.ToInt32(statomat))) == App.TipoTreeNodeStato.Completato)
                    {
                        Materialità_2 = true;

                        ucExcel_LimiteMaterialitaSPCE uce_lm = new ucExcel_LimiteMaterialitaSPCE(IDTree);
                        uce_lm.Load(ID_Materialità_2, FileDataRevisione, IpotesiMaterialita.Seconda, IDCliente, IDSessione);
                        uce_lm.Save();

                        brdPrima.Visibility   = System.Windows.Visibility.Collapsed;
                        brdSeconda.Visibility = System.Windows.Visibility.Visible;
                        brdTerza.Visibility   = System.Windows.Visibility.Collapsed;
                        tmpNode_true          = datimaterialita;
                    }

                    //if (tmpNode_true == null)
                    {
                        datimaterialita = cBusinessObjects.GetData(int.Parse(ID_Materialità_3), typeof(Excel_LimiteMaterialitaSPCE), cBusinessObjects.idcliente, int.Parse(idsessionedatimaterialita), 1);
                        statom          = cBusinessObjects.GetData(int.Parse(ID_Materialità_3), typeof(StatoNodi), cBusinessObjects.idcliente, int.Parse(idsessionedatimaterialita), 1);
                        foreach (DataRow dd in statom.Rows)
                        {
                            statomat = dd["Stato"].ToString().Trim();
                        }
                        if (datimaterialita.Rows.Count > 0 && statomat != "" && ((App.TipoTreeNodeStato)(Convert.ToInt32(statomat))) == App.TipoTreeNodeStato.Completato)
                        {
                            Materialità_3 = true;

                            ucExcel_LimiteMaterialitaSPCE uce_lm = new ucExcel_LimiteMaterialitaSPCE(IDTree);
                            uce_lm.Load(ID_Materialità_3, FileDataRevisione, IpotesiMaterialita.Terza, IDCliente, IDSessione);
                            uce_lm.Save();

                            brdPrima.Visibility   = System.Windows.Visibility.Collapsed;
                            brdSeconda.Visibility = System.Windows.Visibility.Collapsed;
                            brdTerza.Visibility   = System.Windows.Visibility.Visible;
                            tmpNode_true          = datimaterialita;
                        }
                    }
                }
            }

            if (tmpNode_true != null)
            {
                foreach (DataRow dtrow in tmpNode_true.Rows)
                {
                    if (dtrow["ID"].ToString() == "txt7")
                    {
                        txt7.Text = dtrow["value"].ToString();
                    }
                    if (dtrow["ID"].ToString() == "txt7_2sp")
                    {
                        txt7_2sp.Text = dtrow["value"].ToString();
                    }
                    if (dtrow["ID"].ToString() == "txt7_2ce")
                    {
                        txt7_2ce.Text = dtrow["value"].ToString();
                    }
                    if (dtrow["ID"].ToString() == "txt7_3sp")
                    {
                        txt7_3sp.Text = dtrow["value"].ToString();
                    }
                    if (dtrow["ID"].ToString() == "txt7_3ec")
                    {
                        txt7_3ec.Text = dtrow["value"].ToString();
                    }
                    if (dtrow["ID"].ToString() == "txt9")
                    {
                        txt9.Text = dtrow["value"].ToString();
                    }
                    if (dtrow["ID"].ToString() == "txt9_2sp")
                    {
                        txt9_2sp.Text = dtrow["value"].ToString();
                    }
                    if (dtrow["ID"].ToString() == "txt9_2ce")
                    {
                        txt9_2ce.Text = dtrow["value"].ToString();
                    }
                    if (dtrow["ID"].ToString() == "txt9_3ec")
                    {
                        txt9_3ec.Text = dtrow["value"].ToString();
                    }
                    if (dtrow["ID"].ToString() == "txt7BILANCIO")
                    {
                        txt7BILANCIO.Text = dtrow["value"].ToString();
                    }
                    if (dtrow["ID"].ToString() == "txt7_2spBILANCIO")
                    {
                        txt7_2spBILANCIO.Text = dtrow["value"].ToString();
                    }

                    if (dtrow["ID"].ToString() == "txt7_2ceBILANCIO")
                    {
                        txt7_2ceBILANCIO.Text = dtrow["value"].ToString();
                    }

                    if (dtrow["ID"].ToString() == "txt7_3spBILANCIO")
                    {
                        txt7_3spBILANCIO.Text = dtrow["value"].ToString();
                    }

                    if (dtrow["ID"].ToString() == "txt7_3ecBILANCIO")
                    {
                        txt7_3ecBILANCIO.Text = dtrow["value"].ToString();
                    }

                    if (dtrow["ID"].ToString() == "txt9BILANCIO")
                    {
                        txt9BILANCIO.Text = dtrow["value"].ToString();
                    }

                    if (dtrow["ID"].ToString() == "txt9_2spBILANCIO")
                    {
                        txt9_2spBILANCIO.Text = dtrow["value"].ToString();
                    }

                    if (dtrow["ID"].ToString() == "txt9_2ceBILANCIO")
                    {
                        txt9_2ceBILANCIO.Text = dtrow["value"].ToString();
                    }


                    if (dtrow["ID"].ToString() == "txt9_3spBILANCIO")
                    {
                        txt9_3spBILANCIO.Text = dtrow["value"].ToString();
                    }

                    if (dtrow["ID"].ToString() == "txt9_3ecBILANCIO")
                    {
                        txt9_3ecBILANCIO.Text = dtrow["value"].ToString();
                    }

                    if (dtrow["ID"].ToString() == "txt12")
                    {
                        txt12.Text = dtrow["value"].ToString();
                    }

                    if (dtrow["ID"].ToString() == "txt12_2sp")
                    {
                        txt12_2sp.Text = dtrow["value"].ToString();
                    }

                    if (dtrow["ID"].ToString() == "txt12_2sp")
                    {
                        txt12_2sp.Text = dtrow["value"].ToString();
                    }

                    if (dtrow["ID"].ToString() == "txt12_2ce")
                    {
                        txt12_2ce.Text = dtrow["value"].ToString();
                    }

                    if (dtrow["ID"].ToString() == "txt12_3sp")
                    {
                        txt12_3sp.Text = dtrow["value"].ToString();
                    }

                    if (dtrow["ID"].ToString() == "txt12_3ec")
                    {
                        txt12_3ec.Text = dtrow["value"].ToString();
                    }

                    if (dtrow["ID"].ToString() == "txt12BILANCIO")
                    {
                        txt12BILANCIO.Text = dtrow["value"].ToString();
                    }

                    if (dtrow["ID"].ToString() == "txt12_2spBILANCIO")
                    {
                        txt12_2spBILANCIO.Text = dtrow["value"].ToString();
                    }

                    if (dtrow["ID"].ToString() == "txt12_2ceBILANCIO")
                    {
                        txt12_2ceBILANCIO.Text = dtrow["value"].ToString();
                    }

                    if (dtrow["ID"].ToString() == "txt12_3spBILANCIO")
                    {
                        txt12_3spBILANCIO.Text = dtrow["value"].ToString();
                    }

                    if (dtrow["ID"].ToString() == "txt12_3ecBILANCIO")
                    {
                        txt12_3ecBILANCIO.Text = dtrow["value"].ToString();
                    }
                }
            }



            if (Materialità_1 == false && Materialità_2 == false && Materialità_3 == false)
            {
                MessageBox.Show("E' necessario completare prima la materialità", "Attenzione");
                return(false);
            }

            if (((Materialità_1) ? 1 : 0) + ((Materialità_2) ? 1 : 0) + ((Materialità_3) ? 1 : 0) >= 2)
            {
                MessageBox.Show("Il confronto materialità può essere considerato valido solo nel caso sia stato utilizzato un solo calcolo della materialità.", "Attenzione");
                return(false);
            }



            #endregion

            #region CONFRONTO MATERIALITA' CALCOLO
            txt7VALORE.Text  = ConvertNumber((Convert.ToDouble((txt7BILANCIO.Text == "") ? "0" : txt7BILANCIO.Text) - Convert.ToDouble((txt7.Text == "") ? "0" : txt7.Text)).ToString());
            txt9VALORE.Text  = ConvertNumber((Convert.ToDouble((txt9BILANCIO.Text == "") ? "0" : txt9BILANCIO.Text) - Convert.ToDouble((txt9.Text == "") ? "0" : txt9.Text)).ToString());
            txt12VALORE.Text = ConvertNumber((Convert.ToDouble((txt12BILANCIO.Text == "") ? "0" : txt12BILANCIO.Text) - Convert.ToDouble((txt12.Text == "") ? "0" : txt12.Text)).ToString());

            txt7_2spVALORE.Text = ConvertNumber((Convert.ToDouble((txt7_2spBILANCIO.Text == "") ? "0" : txt7_2spBILANCIO.Text) - Convert.ToDouble((txt7_2sp.Text == "") ? "0" : txt7_2sp.Text)).ToString());
            txt7_2ceVALORE.Text = ConvertNumber((Convert.ToDouble((txt7_2ceBILANCIO.Text == "") ? "0" : txt7_2ceBILANCIO.Text) - Convert.ToDouble((txt7_2ce.Text == "") ? "0" : txt7_2ce.Text)).ToString());
            txt7_3spVALORE.Text = ConvertNumber((Convert.ToDouble((txt7_3spBILANCIO.Text == "") ? "0" : txt7_3spBILANCIO.Text) - Convert.ToDouble((txt7_3sp.Text == "") ? "0" : txt7_3sp.Text)).ToString());
            txt7_3ecVALORE.Text = ConvertNumber((Convert.ToDouble((txt7_3ecBILANCIO.Text == "") ? "0" : txt7_3ecBILANCIO.Text) - Convert.ToDouble((txt7_3ec.Text == "") ? "0" : txt7_3ec.Text)).ToString());

            txt9_2spVALORE.Text = ConvertNumber((Convert.ToDouble((txt9_2spBILANCIO.Text == "") ? "0" : txt9_2spBILANCIO.Text) - Convert.ToDouble((txt9_2sp.Text == "") ? "0" : txt9_2sp.Text)).ToString());
            txt9_2ceVALORE.Text = ConvertNumber((Convert.ToDouble((txt9_2ceBILANCIO.Text == "") ? "0" : txt9_2ceBILANCIO.Text) - Convert.ToDouble((txt9_2ce.Text == "") ? "0" : txt9_2ce.Text)).ToString());
            txt9_3spVALORE.Text = ConvertNumber((Convert.ToDouble((txt9_3spBILANCIO.Text == "") ? "0" : txt9_3spBILANCIO.Text) - Convert.ToDouble((txt9_3sp.Text == "") ? "0" : txt9_3sp.Text)).ToString());
            txt9_3ecVALORE.Text = ConvertNumber((Convert.ToDouble((txt9_3ecBILANCIO.Text == "") ? "0" : txt9_3ecBILANCIO.Text) - Convert.ToDouble((txt9_3ec.Text == "") ? "0" : txt9_3ec.Text)).ToString());

            txt12_2spVALORE.Text = ConvertNumber((Convert.ToDouble((txt12_2spBILANCIO.Text == "") ? "0" : txt12_2spBILANCIO.Text) - Convert.ToDouble((txt12_2sp.Text == "") ? "0" : txt12_2sp.Text)).ToString());
            txt12_2ceVALORE.Text = ConvertNumber((Convert.ToDouble((txt12_2ceBILANCIO.Text == "") ? "0" : txt12_2ceBILANCIO.Text) - Convert.ToDouble((txt12_2ce.Text == "") ? "0" : txt12_2ce.Text)).ToString());
            txt12_3spVALORE.Text = ConvertNumber((Convert.ToDouble((txt12_3spBILANCIO.Text == "") ? "0" : txt12_3spBILANCIO.Text) - Convert.ToDouble((txt12_3sp.Text == "") ? "0" : txt12_3sp.Text)).ToString());
            txt12_3ecVALORE.Text = ConvertNumber((Convert.ToDouble((txt12_3ecBILANCIO.Text == "") ? "0" : txt12_3ecBILANCIO.Text) - Convert.ToDouble((txt12_3ec.Text == "") ? "0" : txt12_3ec.Text)).ToString());

            txt7PERCENTUALE.Text  = ConvertPercent(((Convert.ToDouble((txt7BILANCIO.Text == "") ? "0" : txt7BILANCIO.Text) - Convert.ToDouble((txt7.Text == "") ? "0" : txt7.Text)) / Convert.ToDouble((txt7.Text == "") ? "0" : txt7.Text)).ToString());
            txt9PERCENTUALE.Text  = ConvertPercent(((Convert.ToDouble((txt9BILANCIO.Text == "") ? "0" : txt9BILANCIO.Text) - Convert.ToDouble((txt9.Text == "") ? "0" : txt9.Text)) / Convert.ToDouble((txt9.Text == "") ? "0" : txt9.Text)).ToString());
            txt12PERCENTUALE.Text = ConvertPercent(((Convert.ToDouble((txt12BILANCIO.Text == "") ? "0" : txt12BILANCIO.Text) - Convert.ToDouble((txt12.Text == "") ? "0" : txt12.Text)) / Convert.ToDouble((txt12.Text == "") ? "0" : txt12.Text)).ToString());

            txt7_2spPERCENTUALE.Text = ConvertPercent(((Convert.ToDouble((txt7_2spBILANCIO.Text == "") ? "0" : txt7_2spBILANCIO.Text) - Convert.ToDouble((txt7_2sp.Text == "") ? "0" : txt7_2sp.Text)) / Convert.ToDouble((txt7_2sp.Text == "") ? "0" : txt7_2sp.Text)).ToString());
            txt7_2cePERCENTUALE.Text = ConvertPercent(((Convert.ToDouble((txt7_2ceBILANCIO.Text == "") ? "0" : txt7_2ceBILANCIO.Text) - Convert.ToDouble((txt7_2ce.Text == "") ? "0" : txt7_2ce.Text)) / Convert.ToDouble((txt7_2ce.Text == "") ? "0" : txt7_2ce.Text)).ToString());
            txt7_3spPERCENTUALE.Text = ConvertPercent(((Convert.ToDouble((txt7_3spBILANCIO.Text == "") ? "0" : txt7_3spBILANCIO.Text) - Convert.ToDouble((txt7_3sp.Text == "") ? "0" : txt7_3sp.Text)) / Convert.ToDouble((txt7_3sp.Text == "") ? "0" : txt7_3sp.Text)).ToString());
            txt7_3ecPERCENTUALE.Text = ConvertPercent(((Convert.ToDouble((txt7_3ecBILANCIO.Text == "") ? "0" : txt7_3ecBILANCIO.Text) - Convert.ToDouble((txt7_3ec.Text == "") ? "0" : txt7_3ec.Text)) / Convert.ToDouble((txt7_3ec.Text == "") ? "0" : txt7_3ec.Text)).ToString());

            txt9_2spPERCENTUALE.Text = ConvertPercent(((Convert.ToDouble((txt9_2spBILANCIO.Text == "") ? "0" : txt9_2spBILANCIO.Text) - Convert.ToDouble((txt9_2sp.Text == "") ? "0" : txt9_2sp.Text)) / Convert.ToDouble((txt9_2sp.Text == "") ? "0" : txt9_2sp.Text)).ToString());
            txt9_2cePERCENTUALE.Text = ConvertPercent(((Convert.ToDouble((txt9_2ceBILANCIO.Text == "") ? "0" : txt9_2ceBILANCIO.Text) - Convert.ToDouble((txt9_2ce.Text == "") ? "0" : txt9_2ce.Text)) / Convert.ToDouble((txt9_2ce.Text == "") ? "0" : txt9_2ce.Text)).ToString());
            txt9_3spPERCENTUALE.Text = ConvertPercent(((Convert.ToDouble((txt9_3spBILANCIO.Text == "") ? "0" : txt9_3spBILANCIO.Text) - Convert.ToDouble((txt9_3sp.Text == "") ? "0" : txt9_3sp.Text)) / Convert.ToDouble((txt9_3sp.Text == "") ? "0" : txt9_3sp.Text)).ToString());
            txt9_3ecPERCENTUALE.Text = ConvertPercent(((Convert.ToDouble((txt9_3ecBILANCIO.Text == "") ? "0" : txt9_3ecBILANCIO.Text) - Convert.ToDouble((txt9_3ec.Text == "") ? "0" : txt9_3ec.Text)) / Convert.ToDouble((txt9_3ec.Text == "") ? "0" : txt9_3ec.Text)).ToString());

            txt12_2spPERCENTUALE.Text = ConvertPercent(((Convert.ToDouble((txt12_2spBILANCIO.Text == "") ? "0" : txt12_2spBILANCIO.Text) - Convert.ToDouble((txt12_2sp.Text == "") ? "0" : txt12_2sp.Text)) / Convert.ToDouble((txt12_2sp.Text == "") ? "0" : txt12_2sp.Text)).ToString());
            txt12_2cePERCENTUALE.Text = ConvertPercent(((Convert.ToDouble((txt12_2ceBILANCIO.Text == "") ? "0" : txt12_2ceBILANCIO.Text) - Convert.ToDouble((txt12_2ce.Text == "") ? "0" : txt12_2ce.Text)) / Convert.ToDouble((txt12_2ce.Text == "") ? "0" : txt12_2ce.Text)).ToString());
            txt12_3spPERCENTUALE.Text = ConvertPercent(((Convert.ToDouble((txt12_3spBILANCIO.Text == "") ? "0" : txt12_3spBILANCIO.Text) - Convert.ToDouble((txt12_3sp.Text == "") ? "0" : txt12_3sp.Text)) / Convert.ToDouble((txt12_3sp.Text == "") ? "0" : txt12_3sp.Text)).ToString());
            txt12_3ecPERCENTUALE.Text = ConvertPercent(((Convert.ToDouble((txt12_3ecBILANCIO.Text == "") ? "0" : txt12_3ecBILANCIO.Text) - Convert.ToDouble((txt12_3ec.Text == "") ? "0" : txt12_3ec.Text)) / Convert.ToDouble((txt12_3ec.Text == "") ? "0" : txt12_3ec.Text)).ToString());

            #endregion


            return(true);
        }