private void GestoreEvento_ChiusuraFinestra(object sender, CancelEventArgs e)
        {
            if (IDClienteImport != "-1")
            {
                ;// MessageBox.Show( "La Sessione viene adesso generata\r\nDovrà essere selezionata nella tendina Destinazione della finestra di Import\r\nScegliere le CdL da Importare e premere Importa\r\nPer accedere alla sessione appena importata bisognerà chiudere la Sessione in corso e aprire quella nuova.", "Attenzione" );
                return;
            }

            //Configuro stato
            if (TipologiaAttivita != App.TipoAttivitaScheda.View && cmbClienti.SelectedIndex != -1)
            {
                string     IDCliente = htClienti[cmbClienti.SelectedIndex].ToString();
                MasterFile mf        = MasterFile.Create();
                mf.SetAnafraficaStato(Convert.ToInt32(IDCliente), App.TipoAnagraficaStato.Disponibile);
            }
            //dati non modificati
            if (!_DatiCambiati)
            {
                return;
            }


            //dati modificati
            Utilities u = new Utilities();

            if (MessageBoxResult.No == u.AvvisoPerditaDati())
            {
                e.Cancel = true;
            }
        }
Exemple #2
0
        public void TestCreateNewMaster()
        {
            var pm      = new FilePersistenceManager();
            var dirName = "TestCreateNewMaster1";

            pm.CreateDirectory(dirName);
            var storeConfig = new StoreConfiguration {
                PersistenceType = PersistenceType.AppendOnly
            };
            var storeSetId = Guid.NewGuid();
            var mf         = MasterFile.Create(pm, dirName, storeConfig, storeSetId);
            var storeId    = mf.StoreId;

            mf = MasterFile.Open(pm, dirName);
            Assert.AreEqual(storeId, mf.StoreId);
            Assert.AreEqual(storeSetId, mf.StoreSetId);
            Assert.AreEqual(StoreType.Standard, mf.StoreType);
            Assert.AreEqual(PersistenceType.AppendOnly, mf.PersistenceType);

            dirName = "TestCreateNewMaster2";
            pm.CreateDirectory(dirName);
            storeConfig.PersistenceType = PersistenceType.Rewrite;
            storeSetId = Guid.NewGuid();
            mf         = MasterFile.Create(pm, dirName, storeConfig, storeSetId);
            storeId    = mf.StoreId;
            mf         = MasterFile.Open(pm, dirName);
            Assert.AreEqual(storeId, mf.StoreId);
            Assert.AreEqual(storeSetId, mf.StoreSetId);
            Assert.AreEqual(StoreType.Standard, mf.StoreType);
            Assert.AreEqual(PersistenceType.Rewrite, mf.PersistenceType);

            // Enumerating commit points of a new master file should not throw an error
            Assert.AreEqual(0, mf.GetCommitPoints().Count());
        }
        private void functionCmbDataChanged(ComboBox cmb)
        {
            if (cmb.SelectedIndex != -1)
            {
                try
                {
                    _InCaricamento = true;

                    string IDPianificazioniVigilanza = htDate[cmb.SelectedIndex].ToString();

                    MasterFile mf          = MasterFile.Create();
                    Hashtable  htVigilanza = new Hashtable();

                    htVigilanza             = mf.GetPianificazioniVigilanza(IDPianificazioniVigilanza);
                    dtpDataInizio.IsEnabled = true;
                    dtpDataFine.IsEnabled   = true;

                    dtpDataInizio.Text = htVigilanza["DataInizio"].ToString();
                    dtpDataFine.Text   = (htVigilanza["DataFine"] != null) ? htVigilanza["DataFine"].ToString() : htVigilanza["DataInizio"].ToString();

                    _InCaricamento = false;
                }
                catch (Exception ex)
                {
                    cBusinessObjects.logger.Error(ex, "wSchedaPianificazioneVigilanza.functionCmbDataChanged exception");
                    string log = ex.Message;
                }
            }
        }
Exemple #4
0
        private void buttonSbloccaUtenti_Click(object sender, RoutedEventArgs e)
        {
            //richiesta conferma
            Utilities u = new Utilities();

            if (MessageBoxResult.Yes == u.ConfermaSbloccoUtenti())
            {
                MasterFile mf = MasterFile.Create();
                bool       esportatipresenti = false;

                foreach (Hashtable item in mf.GetAnagrafiche())
                {
                    if (mf.GetAnafraficaStato(Convert.ToInt32(item["ID"].ToString())) != App.TipoAnagraficaStato.Esportato)
                    {
                        mf.SetAnafraficaStato(Convert.ToInt32(item["ID"].ToString()), App.TipoAnagraficaStato.Disponibile);
                    }
                    else
                    {
                        esportatipresenti = true;
                    }
                }

                ((RevisoftApplication.MainWindow)(this.Owner)).CaricaClienti();

                if (esportatipresenti == true)
                {
                    MessageBox.Show("Sblocco Utenti Esportati disponibile solo da HelpDesk");
                }
                else
                {
                    MessageBox.Show("Sblocco Utenti Avvenuto con successo");
                }
            }
        }
        private void ButtonApri_Click(object sender, RoutedEventArgs e)
        {
            //controllo selezione clienti
            if (cmbClienti.SelectedIndex == -1)
            {
                MessageBox.Show("selezionare un cliente");
                return;
            }

            //dati modificati
            if (_DatiCambiati)
            {
                //Utilities u = new Utilities();
                //if (MessageBoxResult.No == u.AvvisoPerditaDati("Alcuni dati sono stati modificati, confermi apertura?"))
                //    return;

                //Salvataggio automatico come richiesto da 2.3
                App.TipoAttivitaScheda OLDTipologiaAttivita = TipologiaAttivita;
                TipologiaAttivita = App.TipoAttivitaScheda.Edit;
                buttonComando_Click(sender, e);
                TipologiaAttivita = OLDTipologiaAttivita;
            }

            //disponibile: blocco cliente
            int        IDCliente = Convert.ToInt32(htClienti[cmbClienti.SelectedIndex].ToString());
            MasterFile mf        = MasterFile.Create();

            App.TipoAnagraficaStato anaStato = mf.GetAnafraficaStato(IDCliente);

            if (anaStato == App.TipoAnagraficaStato.Disponibile && TipologiaAttivita != App.TipoAttivitaScheda.View)
            {
                mf.SetAnafraficaStato(Convert.ToInt32(IDCliente), App.TipoAnagraficaStato.InUso);
            }

            //apre treee
            int IDPianificazioniVerifica = App.MasterFile_NewID;

            try
            {
                IDPianificazioniVerifica = Convert.ToInt32(htDate[cmbData.SelectedIndex].ToString());
            }
            catch (Exception ex)
            {
                cBusinessObjects.logger.Error(ex, "wSchedaPianificazioneVerifica.ButtonApri_Click exception");
                string log = ex.Message;
            }

            if (IDPianificazioniVerifica == -1)
            {
                MessageBox.Show("selezionare una sessione");
            }
            else
            {
                bool isSchedaReadOnly = TipologiaAttivita == App.TipoAttivitaScheda.View || anaStato == App.TipoAnagraficaStato.InUso;
                cBusinessObjects.VerificaSessione("PianificazioniVerifica", cmbData.SelectedValue.ToString(), IDPianificazioniVerifica, IDCliente);

                Accedi_Click(IDPianificazioniVerifica.ToString(), isSchedaReadOnly);
            }
        }
Exemple #6
0
        public void TestCorruptCommitPoint()
        {
            var pm      = new FilePersistenceManager();
            var dirName = "TestCorruptCommitPoint";

            pm.CreateDirectory(dirName);
            var storeConfig = new StoreConfiguration {
                PersistenceType = PersistenceType.AppendOnly
            };
            var      storeSetId   = Guid.NewGuid();
            var      mf           = MasterFile.Create(pm, dirName, storeConfig, storeSetId);
            DateTime commit1Time  = DateTime.UtcNow;
            Guid     commit1JobId = Guid.NewGuid();

            mf = MasterFile.Open(pm, dirName);
            mf.AppendCommitPoint(new CommitPoint(1ul, 1ul, commit1Time, commit1JobId));
            DateTime commit2Time  = DateTime.UtcNow;
            Guid     commit2JobId = Guid.NewGuid();

            mf = MasterFile.Open(pm, dirName);
            mf.AppendCommitPoint(new CommitPoint(2ul, 2ul, commit2Time, commit2JobId));

            mf = MasterFile.Open(pm, dirName);
            var allCommits = mf.GetCommitPoints().ToList();

            Assert.AreEqual(2, allCommits.Count);

            using (var fs = pm.GetOutputStream(Path.Combine(dirName, MasterFile.MasterFileName), FileMode.Open))
            {
                fs.Seek(-250, SeekOrigin.End);
                fs.WriteByte(255);
            }
            // Error in one half of commit point should not cause a problem
            mf = MasterFile.Open(pm, dirName);
            var lastCommit = mf.GetLatestCommitPoint();

            allCommits = mf.GetCommitPoints().ToList();
            Assert.AreEqual(2, allCommits.Count);
            Assert.AreEqual(2ul, lastCommit.CommitNumber);
            Assert.AreEqual(2ul, lastCommit.LocationOffset);
            Assert.AreEqual(commit2JobId, lastCommit.JobId);
            Assert.AreEqual(commit2Time.Ticks, lastCommit.CommitTime.Ticks);

            using (var fs = pm.GetOutputStream(Path.Combine(dirName, MasterFile.MasterFileName), FileMode.Open))
            {
                fs.Seek(-120, SeekOrigin.End);
                fs.WriteByte(255);
            }
            // Error in both halves of commit point should force a rewind to previous commit point
            mf         = MasterFile.Open(pm, dirName);
            lastCommit = mf.GetLatestCommitPoint();
            allCommits = mf.GetCommitPoints().ToList();
            Assert.AreEqual(1, allCommits.Count);

            Assert.AreEqual(1ul, lastCommit.CommitNumber);
            Assert.AreEqual(1ul, lastCommit.LocationOffset);
            Assert.AreEqual(commit1JobId, lastCommit.JobId);
            Assert.AreEqual(commit1Time.Ticks, lastCommit.CommitTime.Ticks);
        }
        public void CreateSnapshot(string srcStoreLocation, string destStoreLocation,
                                   PersistenceType storePersistenceType, ulong commitPointId = StoreConstants.NullUlong)
        {
            Logging.LogInfo("Snapshot store {0} to new store {1} with persistence type {2}", srcStoreLocation,
                            destStoreLocation, storePersistenceType);
            if (_persistenceManager.DirectoryExists(destStoreLocation))
            {
                throw new StoreManagerException(destStoreLocation, "Store already exists");
            }

            // Open the source store for reading
            using (IStore srcStore = commitPointId == StoreConstants.NullUlong
                                         ? OpenStore(srcStoreLocation, true)
                                         : OpenStore(srcStoreLocation, commitPointId))
            {
                // Create the directory for the destination store
                _persistenceManager.CreateDirectory(destStoreLocation);

                // Create empty data file
                var dataFilePath = Path.Combine(destStoreLocation, DataFileName);
                _persistenceManager.CreateFile(dataFilePath);

                // Create initial master file
                var destStoreConfiguration = _storeConfiguration.Clone() as StoreConfiguration;
                destStoreConfiguration.PersistenceType = storePersistenceType;
                var destMasterFile = MasterFile.Create(_persistenceManager, destStoreLocation, destStoreConfiguration,
                                                       Guid.NewGuid());

                // Copy resource files from source store
                var resourceFilePath = Path.Combine(destStoreLocation, ResourceFileName);
                _persistenceManager.CopyFile(Path.Combine(srcStoreLocation, ResourceFileName), resourceFilePath, true);

                // Initialize data page store
                IPageStore destPageStore = null;
                switch (storePersistenceType)
                {
                case PersistenceType.AppendOnly:
                    destPageStore = new AppendOnlyFilePageStore(_persistenceManager, dataFilePath, PageSize, false,
                                                                _storeConfiguration.DisableBackgroundWrites);
                    break;

                case PersistenceType.Rewrite:
                    destPageStore = new BinaryFilePageStore(_persistenceManager, dataFilePath, PageSize, false, 0, 1, _storeConfiguration.DisableBackgroundWrites);
                    break;

                default:
                    throw new BrightstarInternalException("Unrecognized target store type: " + storePersistenceType);
                }

                // Copy Data
                ulong destStorePageId = srcStore.CopyTo(destPageStore, 1ul);

                destPageStore.Close();

                destMasterFile.AppendCommitPoint(
                    new CommitPoint(destStorePageId, 1ul, DateTime.UtcNow, Guid.Empty), true);
            }
        }
        public wWorkAreaTreeLimited()
        {
            InitializeComponent();
            txtTitoloAttivita.Foreground       = App._arrBrushes[0];
            txtTitoloRagioneSociale.Foreground = App._arrBrushes[9];
            ButtonBar.Background = App._arrBrushes[12];
            SolidColorBrush tmpBrush = (SolidColorBrush)Resources["buttonHover"];

            tmpBrush.Color = ((SolidColorBrush)App._arrBrushes[13]).Color;

            MasterFile mf = MasterFile.Create();

            //string date = mf.GetData();

            //try
            //{
            //    if (Convert.ToDateTime(date) < DateTime.Now)
            //    {
            //        MessageBox.Show("Licenza scaduta");
            //        this.Close();
            //        return;
            //    }
            //}
            //catch (Exception ex)
            //{
            //    string log = ex.Message;
            //    this.Close();
            //    return;
            //}


            TreeXmlProvider = this.FindResource("xdpTree") as XmlDataProvider;

            //Colonna selezionata
            YearColor.Add(-1, "82BDE4");
            //Colori colonne di sezione
            YearColor.Add(2000, "F1F1F1");
            YearColor.Add(2001, "D3D3D3");
            YearColor.Add(2002, "F1F1F1");
            YearColor.Add(2003, "D3D3D3");
            YearColor.Add(2004, "F1F1F1");
            YearColor.Add(2005, "D3D3D3");
            YearColor.Add(2006, "F1F1F1");
            YearColor.Add(2007, "D3D3D3");
            YearColor.Add(2008, "F1F1F1");
            YearColor.Add(2009, "D3D3D3");
            YearColor.Add(2010, "F1F1F1");
            YearColor.Add(2011, "D3D3D3");
            YearColor.Add(2012, "F1F1F1");
            YearColor.Add(2013, "D3D3D3");
            YearColor.Add(2014, "F1F1F1");
            YearColor.Add(2015, "D3D3D3");
            YearColor.Add(2016, "F1F1F1");
            YearColor.Add(2017, "D3D3D3");
            YearColor.Add(2018, "F1F1F1");
            YearColor.Add(2019, "D3D3D3");
            YearColor.Add(2020, "F1F1F1");
        }
Exemple #9
0
        public void ConfiguraMaschera()
        {
            MasterFile mf = MasterFile.Create();

            int index = 0;

            int selectedIndex = -1;

            if (cmbClienti.Items.Count != 0)
            {
                selectedIndex = cmbClienti.SelectedIndex;
                cmbClienti.Items.Clear();
                htClienti.Clear();
            }

            List <KeyValuePair <string, string> > myList = new List <KeyValuePair <string, string> >();

            foreach (Hashtable item in mf.GetAnagrafiche())
            {
                if (mf.GetBilanci(item["ID"].ToString()).Count == 0 && mf.GetRevisioni(item["ID"].ToString()).Count == 0 && mf.GetISQCs(item["ID"].ToString()).Count == 0 && mf.GetIncarichi(item["ID"].ToString()).Count == 0 && mf.GetConclusioni(item["ID"].ToString()).Count == 0 && mf.GetVerifiche(item["ID"].ToString()).Count == 0)
                {
                    continue;
                }

                string cliente = item["RagioneSociale"].ToString();

                myList.Add(new KeyValuePair <string, string>(item["ID"].ToString(), cliente));
            }

            myList.Sort
            (
                delegate(KeyValuePair <string, string> firstPair, KeyValuePair <string, string> nextPair)
            {
                return(firstPair.Value.CompareTo(nextPair.Value));
            }
            );

            foreach (KeyValuePair <string, string> item in myList)
            {
                cmbClienti.Items.Add(item.Value);
                htClienti.Add(index, item.Key);
                index++;
            }

            cmbClienti.SelectedIndex = selectedIndex;

            string IDCliente = mf.GetClienteFissato();

            foreach (DictionaryEntry item in htClienti)
            {
                if (item.Value.ToString() == IDCliente)
                {
                    cmbClienti.SelectedIndex = Convert.ToInt32(item.Key.ToString());
                    return;
                }
            }
        }
        public IStore CreateStore(string storeLocation, PersistenceType storePersistenceType, bool readOnly, bool withTransactionLogging)
        {
            Logging.LogInfo("Create Store {0} with persistence type {1}", storeLocation, storePersistenceType);
            if (_persistenceManager.DirectoryExists(storeLocation))
            {
                throw new StoreManagerException(storeLocation, "Store already exists");
            }

            _persistenceManager.CreateDirectory(storeLocation);

            var dataFilePath = Path.Combine(storeLocation, DataFileName);

            _persistenceManager.CreateFile(dataFilePath);

            var resourceFilePath = Path.Combine(storeLocation, ResourceFileName);

            _persistenceManager.CreateFile(resourceFilePath);

            var targetStoreConfiguration = _storeConfiguration.Clone() as StoreConfiguration;

            targetStoreConfiguration.PersistenceType = storePersistenceType;
            MasterFile.Create(_persistenceManager, storeLocation, targetStoreConfiguration, Guid.NewGuid());
            IPageStore dataPageStore = null;

            switch (storePersistenceType)
            {
            case PersistenceType.AppendOnly:
                dataPageStore = new AppendOnlyFilePageStore(_persistenceManager, dataFilePath, PageSize, false, _storeConfiguration.DisableBackgroundWrites);
                break;

            case PersistenceType.Rewrite:
                dataPageStore = new BinaryFilePageStore(_persistenceManager, dataFilePath, PageSize, false, 0, 1, _storeConfiguration.DisableBackgroundWrites);
                break;
            }

            IPageStore resourcePageStore = new AppendOnlyFilePageStore(_persistenceManager, resourceFilePath, PageSize, false, _storeConfiguration.DisableBackgroundWrites);
            var        resourceTable     = new ResourceTable(resourcePageStore);

            using (var store = new Store(storeLocation, dataPageStore, resourceTable))
            {
                store.Commit(Guid.Empty);
                store.Close();
            }

            if (withTransactionLogging)
            {
                _persistenceManager.CreateFile(Path.Combine(storeLocation, "transactionheaders.bs"));
                _persistenceManager.CreateFile(Path.Combine(storeLocation, "transactions.bs"));
            }

            Logging.LogInfo("Store created at {0}", storeLocation);
            return(OpenStore(storeLocation, readOnly));
        }
Exemple #11
0
        private void buttonResetMasterFile_Click(object sender, RoutedEventArgs e)
        {
            //richiesta conferma
            Utilities u = new Utilities();

            if (MessageBoxResult.Yes == u.ConfermaResetArchivio())
            {
                MasterFile mf = MasterFile.Create();
                mf.ResetMasterFile();
                ((MainWindow)(this.Owner)).ReloadMainWindow();
                MessageBox.Show("Reset Avvenuto con successo");
            }
        }
        private void cmbDataDaVigilanza_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (cmbDataDaVigilanza.Items.Count <= 0)
            {
                return;
            }

            MasterFile mf = MasterFile.Create();
            string     IDPianificazioniVigilanza = htDateVigilanze[cmbDataDaVigilanza.SelectedIndex].ToString();

            Hashtable htSelected = mf.GetPianificazioniVerifica(IDPianificazioniVigilanza.ToString());

            dtpDataInizio.Text = (htSelected["DataInizio"] != null) ? htSelected["DataInizio"].ToString() : "";
            dtpDataFine.Text   = (htSelected["DataFine"] != null) ? htSelected["DataFine"].ToString() : "";
        }
        public void ConfiguraMaschera(string IDCliente)
        {
            stpSessioni1.Children.Clear();

            MasterFile mf = MasterFile.Create();

            alIncarichi = mf.GetIncarichi(IDCliente);

            foreach (Hashtable hthere in alIncarichi)
            {
                RadioButton chkSessione = new RadioButton();
                chkSessione.Tag     = hthere["ID"].ToString();
                chkSessione.Content = hthere["DataNomina"].ToString();
                stpSessioni1.Children.Add(chkSessione);
            }
        }
Exemple #14
0
        //------------------------------------------------------------------------+
        //                           ConfiguraMaschera                            |
        //------------------------------------------------------------------------+
        public void ConfiguraMaschera()
        {
            int index, selectedIndex;
            List <KeyValuePair <string, string> > myList;
            MasterFile mf;
            string     cliente, idClienteFissato;

            mf    = MasterFile.Create();
            index = 0; selectedIndex = -1;
            if (cmbClienti.Items.Count != 0)
            {
                selectedIndex = cmbClienti.SelectedIndex;
                cmbClienti.Items.Clear();
                htClienti.Clear();
            }
            myList = new List <KeyValuePair <string, string> >();
            foreach (Hashtable item in mf.GetAnagrafiche())
            {
                cliente = item["RagioneSociale"].ToString();
                myList.Add(new KeyValuePair <string, string>(item["ID"].ToString(), cliente));
            }
            myList.Sort
            (
                delegate(KeyValuePair <string, string> firstPair, KeyValuePair <string, string> nextPair)
            {
                return(firstPair.Value.CompareTo(nextPair.Value));
            }
            );
            foreach (KeyValuePair <string, string> item in myList)
            {
                cmbClienti.Items.Add(item.Value);
                htClienti.Add(index, item.Key);
                index++;
            }
            cmbClienti.SelectedIndex = selectedIndex;
            idClienteFissato         = mf.GetClienteFissato();
            foreach (DictionaryEntry item in htClienti)
            {
                if (item.Value.ToString() == idClienteFissato)
                {
                    cmbClienti.SelectedIndex = Convert.ToInt32(item.Key.ToString());
                    return;
                }
            }
        }
Exemple #15
0
        public void TestAppendCommitPoint()
        {
            var          pm      = new FilePersistenceManager();
            const string dirName = "TestAppendCommitPoint";

            EnsureEmptyDirectory(pm, dirName);

            var storeConfig = new StoreConfiguration {
                PersistenceType = PersistenceType.AppendOnly
            };
            var      storeSetId   = Guid.NewGuid();
            var      mf           = MasterFile.Create(pm, dirName, storeConfig, storeSetId);
            DateTime commit1Time  = DateTime.UtcNow;
            Guid     commit1JobId = Guid.NewGuid();

            mf = MasterFile.Open(pm, dirName);
            mf.AppendCommitPoint(new CommitPoint(1ul, 1ul, commit1Time, commit1JobId));
            DateTime commit2Time  = DateTime.UtcNow;
            Guid     commit2JobId = Guid.NewGuid();

            mf = MasterFile.Open(pm, dirName);
            mf.AppendCommitPoint(new CommitPoint(2ul, 2ul, commit2Time, commit2JobId));

            mf = MasterFile.Open(pm, dirName);
            var allCommits = mf.GetCommitPoints().ToList();

            Assert.AreEqual(2, allCommits.Count);
            Assert.AreEqual(2ul, allCommits[0].CommitNumber);
            Assert.AreEqual(2ul, allCommits[0].LocationOffset);
            Assert.AreEqual(commit2JobId, allCommits[0].JobId);
            Assert.AreEqual(commit2Time.Ticks, allCommits[0].CommitTime.Ticks);

            Assert.AreEqual(1ul, allCommits[1].CommitNumber);
            Assert.AreEqual(1ul, allCommits[1].LocationOffset);
            Assert.AreEqual(commit1JobId, allCommits[1].JobId);
            Assert.AreEqual(commit1Time.Ticks, allCommits[1].CommitTime.Ticks);

            var lastCommit = mf.GetLatestCommitPoint();

            Assert.AreEqual(2ul, lastCommit.CommitNumber);
            Assert.AreEqual(2ul, lastCommit.LocationOffset);
            Assert.AreEqual(commit2JobId, lastCommit.JobId);
            Assert.AreEqual(commit2Time.Ticks, lastCommit.CommitTime.Ticks);
        }
 //----------------------------------------------------------------------------+
 //                           ConvertDataToEsercizio                           |
 //----------------------------------------------------------------------------+
 private string ConvertDataToEsercizio(string data)
 {
   string returnvalue = "";
   MasterFile mf = MasterFile.Create();
   Hashtable clientetmp = mf.GetAnagrafica(Convert.ToInt32(IDCliente));
   switch (
     (App.TipoAnagraficaEsercizio)
       (Convert.ToInt32(clientetmp["Esercizio"].ToString())))
   {
     case App.TipoAnagraficaEsercizio.ACavallo:
       returnvalue = Convert.ToDateTime(data).Year.ToString() + " - " +
         (Convert.ToDateTime(data).Year + 1).ToString();
       break;
     case App.TipoAnagraficaEsercizio.AnnoSolare:
     case App.TipoAnagraficaEsercizio.Sconosciuto:
     default:
       returnvalue = Convert.ToDateTime(data).Year.ToString();
       break;
   }
   return returnvalue;
 }
        public void Load(string __ID, string FileData, string IDCliente, string IDTree, string IDSessione)
        {
            id = int.Parse(__ID);
            cBusinessObjects.idcliente  = int.Parse(IDCliente.ToString());
            cBusinessObjects.idsessione = int.Parse(IDSessione.ToString());
            _ID = __ID;

            dati = cBusinessObjects.GetData(id, typeof(LuogoDataFirma));
            MasterFile mf = MasterFile.Create();

            if ((mf.GetAnagrafica(Convert.ToInt32(IDCliente)))["OrganoDiControllo"] != null && (mf.GetAnagrafica(Convert.ToInt32(IDCliente)))["OrganoDiControllo"].ToString() == "1" && IDTree != "21")
            {
                brdFirma.Visibility = System.Windows.Visibility.Visible;
            }
            else
            {
                brdFirma.Visibility = System.Windows.Visibility.Collapsed;

                if ((mf.GetAnagrafica(Convert.ToInt32(IDCliente)))["OrganoDiControllo"] == null)
                {
                    MessageBox.Show("Aggiornare i dati dell'Organo di Controllo nella scheda del CLIENTE (Modifica Cliente)");
                }
            }

            foreach (DataRow dtrow in dati.Rows)
            {
                if (dtrow["cmbFirma"] != null)
                {
                    cmbFirma.Text = dtrow["cmbFirma"].ToString();
                }
                if (dtrow["txtData"] != null)
                {
                    txtData.Text = dtrow["txtData"].ToString();
                }
                if (dtrow["txtLuogo"] != null)
                {
                    txtLuogo.Text = dtrow["txtLuogo"].ToString();
                }
            }
        }
Exemple #18
0
        public wSceltaISCQ(string IDCliente, string IDTree)
        {
            _IDCliente = IDCliente;
            _IDTree    = IDTree;

            InitializeComponent();
            labelTitolo.Foreground = App._arrBrushes[0];

            MasterFile mf = MasterFile.Create();

            alISQCs = mf.GetISQCs(IDCliente);

            //ISQC
            foreach (Hashtable hthere in alISQCs)
            {
                RadioButton chkSessione = new RadioButton();
                chkSessione.Tag       = hthere["ID"].ToString();
                chkSessione.Content   = hthere["DataNomina"].ToString() + " - " + ((hthere["DataFine"] == null) ? "" : hthere["DataFine"].ToString());
                chkSessione.GroupName = "ISQC";
                stpSessioniISQC.Children.Add(chkSessione);
            }
        }
        private string ConvertDataToEsercizio(string anno)
        {
            string returnvalue = "";

            MasterFile mf         = MasterFile.Create();
            Hashtable  clientetmp = mf.GetAnagrafica(Convert.ToInt32(IDCliente));

            switch ((App.TipoAnagraficaEsercizio)(Convert.ToInt32(clientetmp["Esercizio"].ToString())))
            {
            case App.TipoAnagraficaEsercizio.ACavallo:
                returnvalue = anno + "/" + ((Convert.ToInt32(anno) % 100) + 1).ToString();
                break;

            case App.TipoAnagraficaEsercizio.AnnoSolare:
            case App.TipoAnagraficaEsercizio.Sconosciuto:
            default:
                returnvalue = anno;
                break;
            }

            return(returnvalue);
        }
        private void functionCmbDataChanged(ComboBox cmb)
        {
            if (cmb.SelectedIndex != -1)
            {
                try
                {
                    _InCaricamento = true;

                    IDRelazioneBV = htDate[cmb.SelectedIndex].ToString();

                    MasterFile mf            = MasterFile.Create();
                    Hashtable  htRelazioneBV = new Hashtable();

                    htRelazioneBV           = mf.GetRelazioneBV(IDRelazioneBV);
                    dtpDataNomina.IsEnabled = true;
                    txtNota.IsEnabled       = true;

                    foreach (DictionaryEntry item in htSelectedDate)
                    {
                        if (item.Value.ToString() == ConvertDataToEsercizio(htRelazioneBV["Data"].ToString(), htRelazioneBV))
                        {
                            dtpDataNomina.SelectedIndex = Convert.ToInt32(item.Key.ToString());
                        }
                    }

                    txtNota.Text = htRelazioneBV["Note"].ToString();

                    _InCaricamento = false;
                }
                catch (Exception ex)
                {
                    cBusinessObjects.logger.Error(ex, "wSchedaRelazioneBV.functionCmbDataChanged exception");
                    string log = ex.Message;
                }
            }
        }
Exemple #21
0
        private void buttonSOSPESI_Click(object sender, RoutedEventArgs e)
        {
            MasterFile mf = MasterFile.Create();

            wSchedaAnafrafica shere = ((wSchedaAnafrafica)(this.Owner));

            int idCliente = shere.idRecord;

            if (IntermedioDa.Text == "")
            {
                MessageBox.Show("Inserire Valore Periodo Intermedio");
                return;
            }

            try
            {
                DateTime da = Convert.ToDateTime(IntermedioDa.Text.Trim());
            }
            catch (Exception ex)
            {
                cBusinessObjects.logger.Error(ex, "wSchedaCambioEsercizio.buttonSOSPESI_Click1 exception");
                string log = ex.Message;
                MessageBox.Show("Inserire Valore Periodo Intermedio Valido");
                return;
            }

            if (IntermedioA.Text == "")
            {
                MessageBox.Show("Inserire Valore Periodo Intermedio");
                return;
            }

            try
            {
                DateTime da = Convert.ToDateTime(IntermedioA.Text.Trim());
            }
            catch (Exception ex)
            {
                cBusinessObjects.logger.Error(ex, "wSchedaCambioEsercizio.buttonSOSPESI_Click2 exception");
                string log = ex.Message;
                MessageBox.Show("Inserire Valore Periodo Intermedio Valido");
                return;
            }

            if (txtEsercizioDal.Text == "")
            {
                MessageBox.Show("Inizio Esercizio mancante.");
                return;
            }

            if (txtEsercizioAl.Text == "")
            {
                MessageBox.Show("Fine Esercizio mancante");
                return;
            }

            if (rdbEsercizioAcavallo.IsChecked == true)
            {
                try
                {
                    //calcola la durata ipotetica del periodo in esame
                    TimeSpan ts = Convert.ToDateTime(txtEsercizioAl.Text.Trim() + "/2013").Subtract(Convert.ToDateTime(txtEsercizioDal.Text.Trim() + "/2012"));
                    if (ts.Days != 364)
                    {
                        MessageBox.Show("Attenzione, periodo a cavallo inferiore ai 365 giorni");
                        return;
                    }
                }
                catch (Exception ex)
                {
                    cBusinessObjects.logger.Error(ex, "wSchedaCambioEsercizio.buttonSOSPESI_Click3 exception");
                    string log = ex.Message;
                    MessageBox.Show("Attenzione, periodo a cavallo inferiore ai 365 giorni");
                    return;
                }
            }

            shere.txtEsercizioAl.Text  = txtEsercizioAl.Text;
            shere.txtEsercizioDal.Text = txtEsercizioDal.Text;

            shere.rdbEsercizioAcavallo.IsChecked = rdbEsercizioAcavallo.IsChecked;
            shere.rdbEsercizioSolare.IsChecked   = rdbEsercizioSolare.IsChecked;

            Hashtable ht = new Hashtable();

            ht.Add("Cliente", idCliente);
            ht.Add("Data", IntermedioDa.Text);
            ht.Add("Note", "Periodo intermedio per cambio esercizio dal " + IntermedioDa.Text + " al " + IntermedioA.Text);

            mf.SetRevisioneIntermedio(ht, idCliente, IntermedioDa.Text, IntermedioA.Text);

            ht.Clear();
            ht.Add("Cliente", idCliente);
            ht.Add("Data", IntermedioDa.Text);
            ht.Add("Note", "Periodo intermedio per cambio esercizio dal " + IntermedioDa.Text + " al " + IntermedioA.Text);

            mf.SetBilancioIntermedio(ht, idCliente, IntermedioDa.Text, IntermedioA.Text);

            ht.Clear();
            ht.Add("Cliente", idCliente);
            ht.Add("Data", IntermedioDa.Text);
            ht.Add("Note", "Periodo intermedio per cambio esercizio dal " + IntermedioDa.Text + " al " + IntermedioA.Text);

            mf.SetConclusioneIntermedio(ht, idCliente, IntermedioDa.Text, IntermedioA.Text);


            ht.Clear();
            ht.Add("Cliente", idCliente);
            ht.Add("Data", IntermedioDa.Text);
            ht.Add("Note", "Periodo intermedio per cambio esercizio dal " + IntermedioDa.Text + " al " + IntermedioA.Text);

            mf.SetRelazioneBIntermedio(ht, idCliente, IntermedioDa.Text, IntermedioA.Text);

            ht.Clear();
            ht.Add("Cliente", idCliente);
            ht.Add("Data", IntermedioDa.Text);
            ht.Add("Note", "Periodo intermedio per cambio esercizio dal " + IntermedioDa.Text + " al " + IntermedioA.Text);

            mf.SetRelazioneBCIntermedio(ht, idCliente, IntermedioDa.Text, IntermedioA.Text);

            ht.Clear();
            ht.Add("Cliente", idCliente);
            ht.Add("Data", IntermedioDa.Text);
            ht.Add("Note", "Periodo intermedio per cambio esercizio dal " + IntermedioDa.Text + " al " + IntermedioA.Text);

            mf.SetRelazioneVIntermedio(ht, idCliente, IntermedioDa.Text, IntermedioA.Text);

            ht.Clear();
            ht.Add("Cliente", idCliente);
            ht.Add("Data", IntermedioDa.Text);
            ht.Add("Note", "Periodo intermedio per cambio esercizio dal " + IntermedioDa.Text + " al " + IntermedioA.Text);

            mf.SetRelazioneVCIntermedio(ht, idCliente, IntermedioDa.Text, IntermedioA.Text);

            ht.Clear();
            ht.Add("Cliente", idCliente);
            ht.Add("Data", IntermedioDa.Text);
            ht.Add("Note", "Periodo intermedio per cambio esercizio dal " + IntermedioDa.Text + " al " + IntermedioA.Text);

            mf.SetRelazioneBVIntermedio(ht, idCliente, IntermedioDa.Text, IntermedioA.Text);

            base.Close();
        }
        public void accedi(string ID, bool ReadOnly, bool tobeclosed)
        {
            if (checkdatecorreto == false)
            {
                return;
            }

            MasterFile mf         = MasterFile.Create();
            Hashtable  htSelected = mf.GetPianificazioniVigilanza(ID);

            if (htSelected.Count == 0)
            {
                return;
            }

            try
            {
                WindowWorkAreaTree wWorkArea = new WindowWorkAreaTree();
                //Prisc
                try
                {
                    wWorkArea.Owner = this;
                }
                catch (Exception ex)
                {
                    cBusinessObjects.logger.Error(ex, "wSchedaPianificazioneVigilanza.accedi1 exception");
                }
                wWorkArea.SelectedTreeSource = App.AppDataDataFolder + "\\" + htSelected["File"].ToString();
                wWorkArea.SelectedDataSource = App.AppDataDataFolder + "\\" + htSelected["FileData"].ToString();
                wWorkArea.ReadOnly           = ReadOnly;
                wWorkArea.TipoAttivita       = App.TipoAttivita.PianificazioniVigilanza;
                wWorkArea.Cliente            = (((Hashtable)(mf.GetAnagrafica(Convert.ToInt32(htSelected["Cliente"].ToString()))))["RagioneSociale"].ToString()) + " (C.F. " + (((Hashtable)(mf.GetAnagrafica(Convert.ToInt32(htSelected["Cliente"].ToString()))))["CodiceFiscale"].ToString()) + ")";
                wWorkArea.SessioneAlias      = "";
                wWorkArea.SessioneFile       = "";

                wWorkArea.IDTree     = (Convert.ToInt32(App.TipoFile.PianificazioniVigilanza)).ToString();
                wWorkArea.IDCliente  = htSelected["Cliente"].ToString();
                wWorkArea.IDSessione = ID;

                foreach (Hashtable item in ((ArrayList)(mf.GetPianificazioniVigilanze(htSelected["Cliente"].ToString()))))
                {
                    wWorkArea.SessioneAliasAdditivo += ((wWorkArea.SessioneAliasAdditivo == "") ? "" : "|") + item["DataFine"].ToString();
                    wWorkArea.SessioneFile          += ((wWorkArea.SessioneFile == "") ? "" : "|") + App.AppDataDataFolder + "\\" + item["FileData"].ToString();
                    wWorkArea.SessioneAlias         += ((wWorkArea.SessioneAlias == "") ? "" : "|") + item["DataInizio"].ToString();
                    wWorkArea.SessioneID            += ((wWorkArea.SessioneID == "") ? "" : "|") + item["ID"].ToString();
                }


                //aperto in sola lettura
                wWorkArea.ApertoInSolaLettura = TipologiaAttivita == App.TipoAttivitaScheda.View;

                wWorkArea.LoadTreeSource();
                Hide();
                wWorkArea.ShowDialog();

                //setto dati
                Hashtable ht = new Hashtable();
                ht.Add("Cliente", Convert.ToInt32(htSelected["Cliente"].ToString()));


                ht.Add("DataInizio", dtpDataInizio.SelectedDate.Value.ToShortDateString());
                ht.Add("DataFine", dtpDataFine.SelectedDate.Value.ToShortDateString());

                mf.SetPianificazioniVigilanza(ht, Convert.ToInt32(ID), Convert.ToInt32(htSelected["Cliente"].ToString()), false);

                if (TipologiaAttivita != App.TipoAttivitaScheda.View)
                {
                    int IDCliente = Convert.ToInt32(htClienti[cmbClienti.SelectedIndex].ToString());
                    mf.SetAnafraficaStato(Convert.ToInt32(IDCliente), App.TipoAnagraficaStato.Disponibile);
                }

                functionCmbDataChanged(cmbData);

                //if ( tobeclosed == true )
                //{
                //  Close();
                //}
            }
            catch (Exception ex)
            {
                cBusinessObjects.logger.Error(ex, "wSchedaPianificazioneVigilanza.accedi2 exception");
            }
            Close();
        }
        private void buttonComando_Click(object sender, RoutedEventArgs e)
        {
            checkdatecorreto = false;

            //controllo selezione clienti
            if (cmbClienti.SelectedIndex == -1)
            {
                MessageBox.Show("selezionare un cliente");
                return;
            }

            MasterFile mf = MasterFile.Create();
            Utilities  u  = new Utilities();

            int IDCliente = Convert.ToInt32(htClienti[cmbClienti.SelectedIndex].ToString());

            IDPianificazioniVigilanza = App.MasterFile_NewID;

            try
            {
                IDPianificazioniVigilanza = Convert.ToInt32(htDate[cmbData.SelectedIndex].ToString());
            }
            catch (Exception ex)
            {
                cBusinessObjects.logger.Error(ex, "wSchedaPianificazioneVigilanza.buttonComando_Click1 exception");
                string log = ex.Message;
            }

            if (TipologiaAttivita == App.TipoAttivitaScheda.Delete && IDPianificazioniVigilanza == -1)
            {
                MessageBox.Show("selezionare una sessione");
                return;
            }

            App.TipoAttivitaScheda oldTipo = TipologiaAttivita;
            if (TipologiaAttivita == App.TipoAttivitaScheda.New)
            {
                stackPanel1.IsEnabled = false;
                //tabControl1.IsEnabled = false;
                //   gridButtons.IsEnabled = false;
                loading.Visibility = Visibility;
                Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate { }));
                //cBusinessObjects.show_workinprogress("Prima creazione dell'albero in corso...");
            }

            switch (TipologiaAttivita)
            {
            //Nuovo e salva
            case App.TipoAttivitaScheda.New:
            case App.TipoAttivitaScheda.Edit:
                //convalida dati
                //Campi Obbligatorio
                if (!u.ConvalidaDatiInterfaccia(dtpDataInizio, "Data Inizio periodo mancante."))
                {
                    cBusinessObjects.hide_workinprogress();
                    return;
                }


                if (!u.ConvalidaDatiInterfaccia(dtpDataFine, "Data Fine periodo mancante."))
                {
                    cBusinessObjects.hide_workinprogress();
                    return;
                }


                DateTime dtinizio = new DateTime();
                DateTime dtfine   = new DateTime();

                try
                {
                    dtinizio = Convert.ToDateTime(dtpDataInizio.SelectedDate.Value.ToShortDateString());
                }
                catch (Exception ex)
                {
                    cBusinessObjects.logger.Error(ex, "wSchedaPianificazioneVigilanza.buttonComando_Click2 exception");
                    string log = ex.Message;
                    cBusinessObjects.hide_workinprogress();
                    MessageBox.Show("Attenzione data inizio inserita non valida");
                    return;
                }

                try
                {
                    dtfine = Convert.ToDateTime(dtpDataFine.SelectedDate.Value.ToShortDateString());
                }
                catch (Exception ex)
                {
                    cBusinessObjects.logger.Error(ex, "wSchedaPianificazioneVigilanza.buttonComando_Click3 exception");
                    string log = ex.Message;
                    cBusinessObjects.hide_workinprogress();
                    MessageBox.Show("Attenzione data fine inserita non valida");
                    return;
                }

                if (dtinizio.CompareTo(dtfine) > 0)

                {
                    cBusinessObjects.hide_workinprogress();
                    MessageBox.Show("Attenzione data fine precedente a data inizio");
                    return;
                }

                //Controllo che questa data non sia già stata presa
                if (!mf.CheckDoppio_PianificazioniVigilanza(IDPianificazioniVigilanza, IDCliente, dtpDataInizio.SelectedDate.Value.ToShortDateString(), dtpDataFine.SelectedDate.Value.ToShortDateString()))
                {
                    cBusinessObjects.hide_workinprogress();
                    MessageBox.Show("Data già pianificata");
                    return;
                }

                Hashtable htSelected = mf.GetPianificazioniVigilanza(IDPianificazioniVigilanza.ToString());

                if (htSelected.Count != 0)
                {
                    XmlDataProviderManager x = new XmlDataProviderManager(App.AppDataDataFolder + "\\" + htSelected["FileData"].ToString());

                    string    firstdata   = "";
                    string    lastData    = "";
                    DataTable datiTestata = cBusinessObjects.GetData(100003, typeof(PianificazioneVerificheTestata), IDCliente, IDPianificazioniVigilanza, 27);
                    foreach (DataRow item in datiTestata.Rows)
                    {
                        DateTime datehere = new DateTime();

                        try
                        {
                            datehere = Convert.ToDateTime(item["Data"].ToString());
                        }
                        catch (Exception ex)
                        {
                            cBusinessObjects.logger.Error(ex, "wSchedaPianificazioneVerifica.buttonComando_Click4 exception");
                            string log = ex.Message;
                            continue;
                        }

                        if (firstdata == "")
                        {
                            firstdata = item["Data"].ToString();
                        }

                        if (lastData == "")
                        {
                            lastData = item["Data"].ToString();
                        }

                        if (datehere.CompareTo(Convert.ToDateTime(firstdata)) < 0)
                        {
                            firstdata = item["Data"].ToString();
                        }

                        if (datehere.CompareTo(Convert.ToDateTime(lastData)) > 0)
                        {
                            lastData = item["Data"].ToString();
                        }
                    }

                    if (firstdata != "")
                    {
                        if (dtinizio.CompareTo(Convert.ToDateTime(firstdata)) > 0)
                        {
                            cBusinessObjects.hide_workinprogress();
                            MessageBox.Show("Attenzione data inizio successiva alla prima data pianificata.");
                            return;
                        }

                        if (dtfine.CompareTo(Convert.ToDateTime(lastData)) < 0)
                        {
                            cBusinessObjects.hide_workinprogress();
                            MessageBox.Show("Attenzione data fine precedente all ultima data pianificata");
                            return;
                        }
                    }
                }

                checkdatecorreto = true;

                //setto dati
                Hashtable ht = new Hashtable();
                ht.Add("Cliente", IDCliente);
                ht.Add("DataInizio", dtpDataInizio.SelectedDate.Value.ToShortDateString());
                ht.Add("DataFine", ((dtpDataFine.SelectedDate != null) ? dtpDataFine.SelectedDate.Value.ToShortDateString() : dtpDataInizio.SelectedDate.Value.ToShortDateString()));

                IDPianificazioniVigilanza = mf.SetPianificazioniVigilanza(ht, IDPianificazioniVigilanza, IDCliente);

                RegistrazioneEffettuata = true;

                if (TipologiaAttivita == App.TipoAttivitaScheda.New)
                {
                    if (IDClienteImport != "-1")
                    {
                        cBusinessObjects.hide_workinprogress();
                        this.Close();
                    }

                    //Process wait - START
                    //ProgressWindow pw = new ProgressWindow();
                    cBusinessObjects.SessioneIsNew = true;
                    TipologiaAttivita = App.TipoAttivitaScheda.Edit;
                    mf.SetAnafraficaStato(Convert.ToInt32(IDCliente), App.TipoAnagraficaStato.Disponibile);

                    ConfiguraMaschera();

                    foreach (DictionaryEntry item in htClienti)
                    {
                        if (Convert.ToInt32(item.Value.ToString()) == IDCliente)
                        {
                            cmbClienti.SelectedIndex = Convert.ToInt32(item.Key.ToString());
                        }
                    }

                    functionCmbClientiChanged(cmbClienti);

                    cmbData.IsEnabled = true;

                    foreach (DictionaryEntry item in htDate)
                    {
                        if (Convert.ToInt32(item.Value.ToString()) == IDPianificazioniVigilanza)
                        {
                            cmbData.SelectedIndex = Convert.ToInt32(item.Key.ToString());
                        }
                    }

                    functionCmbDataChanged(cmbData);
                    cBusinessObjects.AddSessione("PianificazioniVigilanza", cmbData.SelectedValue.ToString(), IDPianificazioniVigilanza, IDCliente);

                    //Process wait - STOP
                    //pw.Close();
                }
                _DatiCambiati = false;
                break;

            case App.TipoAttivitaScheda.Delete:
                //richiesta conferma
                if (MessageBoxResult.No == u.ConfermaCancellazione())
                {
                    return;
                }
                //cancellazione
                mf.DeletePianificazioniVigilanza(IDPianificazioniVigilanza, IDCliente.ToString());
                RegistrazioneEffettuata = true;
                base.Close();
                break;

            case App.TipoAttivitaScheda.Export:
                break;
            }

            //apro tree appena creato
            if (oldTipo == App.TipoAttivitaScheda.New)
            {
                //MessageBox.Show("apro tree appena creato");
                AccediVigilanza_Click(IDPianificazioniVigilanza.ToString(), false);
            }

            //chiudo maschera
            if (TipologiaAttivita != App.TipoAttivitaScheda.Edit)
            {
                base.Close();
            }
        }
        private void functionCmbClientiChanged(ComboBox cmb)
        {
            if (_cmbInCaricamento)
            {
                return;
            }

            if (oldTipologiaAttivita != App.TipoAttivitaScheda.View)
            {
                TipologiaAttivita = oldTipologiaAttivita;
            }

            _InCaricamento              = true;
            cmbData.SelectedIndex       = -1;
            dtpDataNomina.SelectedIndex = -1;
            txtNota.Text          = "";
            imageStato.Visibility = System.Windows.Visibility.Hidden;

            if (cmb.SelectedIndex != -1)
            {
                try
                {
                    string IDCliente = htClienti[cmb.SelectedIndex].ToString();

                    OldSelectedCmbClienti = Convert.ToInt32(IDCliente);

                    MasterFile mf = MasterFile.Create();

                    int index = 0;
                    htDate.Clear();
                    cmbData.Items.Clear();

                    List <KeyValuePair <string, string> > myList = new List <KeyValuePair <string, string> >();

                    foreach (Hashtable item in mf.GetRelazioniBV(IDCliente))
                    {
                        myList.Add(new KeyValuePair <string, string>(item["ID"].ToString(), ConvertDataToEsercizio(item["Data"].ToString(), item)));
                    }

                    myList.Sort
                    (
                        delegate(KeyValuePair <string, string> firstPair, KeyValuePair <string, string> nextPair)
                    {
                        try
                        {
                            return(Convert.ToInt32(nextPair.Value).CompareTo(Convert.ToInt32(firstPair.Value)));
                        }
                        catch (Exception ex)
                        {
                            cBusinessObjects.logger.Error(ex, "wSchedaRelazioneBV.functionCmbClientiChanged1 exception");
                            string log = ex.Message;
                            return(1);
                        }
                    }
                    );

                    foreach (KeyValuePair <string, string> item in myList)
                    {
                        cmbData.Items.Add(item.Value);
                        htDate.Add(index, item.Key);
                        index++;
                    }

                    index = 0;
                    htSelectedDate.Clear();
                    dtpDataNomina.Items.Clear();

                    for (int i = 2009; i <= (DateTime.Now.Year + 1); i++)
                    {
                        Hashtable clientetmp = mf.GetAnagrafica(Convert.ToInt32(IDCliente));

                        string datatmp = "";

                        switch ((App.TipoAnagraficaEsercizio)(Convert.ToInt32(clientetmp["Esercizio"].ToString())))
                        {
                        case App.TipoAnagraficaEsercizio.ACavallo:
                            datatmp = "31/12/" + i.ToString();
                            break;

                        case App.TipoAnagraficaEsercizio.AnnoSolare:
                        case App.TipoAnagraficaEsercizio.Sconosciuto:
                        default:
                            datatmp = "01/01/" + i.ToString();
                            break;
                        }

                        if (!cmbData.Items.Contains(ConvertDataToEsercizio(datatmp)))
                        {
                            dtpDataNomina.Items.Add(ConvertDataToEsercizio(datatmp));
                            htSelectedDate.Add(index, datatmp);
                            index++;
                        }
                    }

                    //stato
                    if (IDClienteImport == "-1")
                    {
                        App.TipoAnagraficaStato anaStato = mf.GetAnafraficaStato(Convert.ToInt32(IDCliente));

                        //non disponibile: configuro interfaccia
                        if (anaStato != App.TipoAnagraficaStato.Disponibile)
                        {
                            oldTipologiaAttivita = TipologiaAttivita;
                            TipologiaAttivita    = App.TipoAttivitaScheda.View;
                        }
                    }


                    if (TipologiaAttivita != App.TipoAttivitaScheda.New)
                    {
                        cmbData.IsEnabled        = true;
                        dtpDataNomina.IsEnabled  = false;
                        label2.Visibility        = System.Windows.Visibility.Collapsed;
                        dtpDataNomina.Visibility = System.Windows.Visibility.Collapsed;
                        label3.Visibility        = System.Windows.Visibility.Visible;
                        cmbData.Visibility       = System.Windows.Visibility.Visible;
                        txtNota.IsEnabled        = false;
                    }
                    else
                    {
                        cmbData.IsEnabled        = false;
                        dtpDataNomina.IsEnabled  = true;
                        label2.Visibility        = System.Windows.Visibility.Visible;
                        dtpDataNomina.Visibility = System.Windows.Visibility.Visible;
                        label3.Visibility        = System.Windows.Visibility.Collapsed;
                        cmbData.Visibility       = System.Windows.Visibility.Collapsed;
                        txtNota.IsEnabled        = true;
                    }
                }
                catch (Exception ex)
                {
                    cBusinessObjects.logger.Error(ex, "wSchedaRelazioneBV.functionCmbClientiChanged2 exception");
                    string log = ex.Message;

                    cmbData.IsEnabled       = false;
                    dtpDataNomina.IsEnabled = false;
                    txtNota.IsEnabled       = false;
                }
            }
        }
        public void ConfiguraMaschera()
        {
            //inibisco tutto i controlli
            dtpDataNomina.IsEnabled = false;
            txtNota.IsReadOnly      = true;

            //nascondo testo help - non + usato
            textBlockDescrizione.Text       = "";
            textBlockDescrizione.Visibility = System.Windows.Visibility.Collapsed;

            switch (TipologiaAttivita)
            {
            case App.TipoAttivitaScheda.New:
                labelTitolo.Content      = "Nuova Sessione";
                buttonComando.Content    = "Crea";
                GridComboData.Visibility = System.Windows.Visibility.Collapsed;
                buttonComando.Visibility = System.Windows.Visibility.Visible;
                buttonApri.Visibility    = System.Windows.Visibility.Hidden;
                //abilito controlli
                dtpDataNomina.IsEnabled = true;
                txtNota.IsReadOnly      = false;
                break;

            case App.TipoAttivitaScheda.Edit:
                labelTitolo.Content      = "Modifica Sessione";
                buttonComando.Content    = "Salva";
                buttonComando.Visibility = System.Windows.Visibility.Collapsed;
                //abilito controlli
                dtpDataNomina.IsEnabled = true;
                txtNota.IsReadOnly      = false;
                break;

            case App.TipoAttivitaScheda.Delete:
                labelTitolo.Content      = "Elimina Sessione";
                buttonComando.Content    = "Elimina";
                buttonComando.Visibility = System.Windows.Visibility.Visible;
                buttonApri.Visibility    = System.Windows.Visibility.Collapsed;
                break;

            case App.TipoAttivitaScheda.Export:
                labelTitolo.Content      = "Esporta Sessione";
                buttonComando.Content    = "Esporta";
                buttonComando.Visibility = System.Windows.Visibility.Visible;
                break;

            case App.TipoAttivitaScheda.View:
            default:
                labelTitolo.Content   = "Apri Sessione in sola lettura";
                cmbData.Visibility    = System.Windows.Visibility.Visible;
                buttonApri.Visibility = System.Windows.Visibility.Visible;
                buttonApri.Margin     = buttonComando.Margin;
                break;
            }

            MasterFile mf        = MasterFile.Create();
            string     IDCliente = mf.GetClienteFissato();

            foreach (DictionaryEntry item in htClienti)
            {
                if (item.Value.ToString() == IDCliente)
                {
                    cmbClienti.SelectedIndex = Convert.ToInt32(item.Key.ToString());
                    return;
                }
            }
        }
        private void cmbArea_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            MasterFile mf = MasterFile.Create();

            string IDCliente = htClienti[cmbClienti.SelectedIndex].ToString();

            cmbPianificate.SelectedIndex = -1;
            cmbPianificate.Items.Clear();

            if (cmbData.SelectedIndex == 0)
            {
                ArrayList       al  = mf.GetPianificazioniVerifiche(IDCliente);
                List <DateTime> alX = new List <DateTime>();

                foreach (Hashtable itemHT in al)
                {
                    DataTable pianificazione = cBusinessObjects.GetData(100013, typeof(PianificazioneVerificheTestata), int.Parse(IDCliente), int.Parse(itemHT["ID"].ToString()), 26);

                    foreach (DataRow itemXPP in pianificazione.Rows)
                    {
                        DateTime dt = Convert.ToDateTime(itemXPP["Data"].ToString());

                        if (!alX.Contains(dt))
                        {
                            alX.Add(dt);
                        }
                    }
                }

                if (alX.Count > 0)
                {
                    alX.Sort();

                    foreach (DateTime item in alX)
                    {
                        cmbPianificate.Items.Add(item.ToShortDateString());
                    }

                    grdPianificazione.Visibility = System.Windows.Visibility.Visible;
                }
                else
                {
                    grdPianificazione.Visibility = System.Windows.Visibility.Collapsed;
                }
            }
            else if (cmbData.SelectedIndex == 1)
            {
                ArrayList       al  = mf.GetPianificazioniVigilanze(IDCliente);
                List <DateTime> alX = new List <DateTime>();

                foreach (Hashtable itemHT in al)
                {
                    DataTable pianificazione = cBusinessObjects.GetData(100003, typeof(PianificazioneVerificheTestata), int.Parse(IDCliente), int.Parse(itemHT["ID"].ToString()), 27);

                    foreach (DataRow itemXPP in pianificazione.Rows)
                    {
                        DateTime dt = Convert.ToDateTime(itemXPP["Data"].ToString());

                        if (!alX.Contains(dt))
                        {
                            alX.Add(dt);
                        }
                    }
                }

                if (alX.Count > 0)
                {
                    alX.Sort();

                    foreach (DateTime item in alX)
                    {
                        cmbPianificate.Items.Add(item.ToShortDateString());
                    }

                    grdPianificazione.Visibility = System.Windows.Visibility.Visible;
                }
                else
                {
                    grdPianificazione.Visibility = System.Windows.Visibility.Collapsed;
                }
            }
        }
        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);
        }
        void txt_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ClickCount == 2)
            {
                //Se vecchio nodo presente nello stesso bilancio
                if (IDTree == "4")
                {
                    WindowWorkArea wa = new WindowWorkArea(ref _x);

                    //Nodi
                    int index = -1;
                    wa.NodeHome = -1;

                    RevisoftApplication.XmlManager xt = new XmlManager();
                    xt.TipoCodifica = RevisoftApplication.XmlManager.TipologiaCodifica.Normale;
                    XmlDataProvider TreeXmlProvider = new XmlDataProvider();
                    TreeXmlProvider.Document = xt.LoadEncodedFile(App.AppTemplateTreeBilancio);

                    if (TreeXmlProvider.Document != null && TreeXmlProvider.Document.SelectSingleNode("/Tree") != null)
                    {
                        foreach (XmlNode item in TreeXmlProvider.Document.SelectNodes("/Tree//Node"))
                        {
                            if (item.Attributes["Tipologia"].Value == "Nodo Multiplo" || item.ChildNodes.Count == 1)
                            {
                                index++;

                                if (item.Attributes["ID"].Value == ((TextBlock)(sender)).MaxHeight.ToString())
                                {
                                    wa.NodeHome = index;
                                }

                                wa.Nodes.Add(index, item);
                            }
                        }
                    }

                    if (wa.NodeHome == -1)
                    {
                        e.Handled = true;
                        return;
                    }

                    wa.NodeNow = wa.NodeHome;

                    wa.Owner = Window.GetWindow(this);

                    //posizione e dimensioni finestra
                    wa.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
                    wa.Height    = System.Windows.SystemParameters.PrimaryScreenHeight * 90.0 / 100.0;
                    wa.Width     = System.Windows.SystemParameters.PrimaryScreenWidth * 90.0 / 100.0;
                    wa.MaxHeight = System.Windows.SystemParameters.PrimaryScreenHeight * 90.0 / 100.0;
                    wa.MaxWidth  = System.Windows.SystemParameters.PrimaryScreenWidth * 90.0 / 100.0;
                    wa.MinHeight = System.Windows.SystemParameters.PrimaryScreenHeight * 90.0 / 100.0;
                    wa.MinWidth  = System.Windows.SystemParameters.PrimaryScreenWidth * 90.0 / 100.0;

                    //Sessioni
                    wa.Sessioni       = Sessioni;
                    wa.SessioniTitoli = SessioniTitoli;
                    wa.SessioniID     = SessioniID;

                    foreach (DictionaryEntry item in Sessioni)
                    {
                        if (item.Value.ToString() == _x.File)
                        {
                            wa.SessioneHome = Convert.ToInt32(item.Key.ToString());
                            wa.SessioneNow  = wa.SessioneHome;
                            break;
                        }
                    }

                    //Variabili
                    wa.ReadOnly            = true;
                    wa.ReadOnlyOLD         = true;
                    wa.ApertoInSolaLettura = true;

                    //XmlNode nodeSessione = node.SelectSingleNode( "Sessioni/Sessione[@Alias=\"" + selectedAliasCodificato + "\"]" );
                    //if ( nodeSessione != null )
                    //{
                    //    wa.Stato = ((App.TipoTreeNodeStato)(Convert.ToInt32( nodeSessione.Attributes["Stato"].Value )));
                    //    wa.OldStatoNodo = wa.Stato;
                    //}

                    //passaggio dati
                    wa.IDTree     = IDTree;
                    wa.IDSessione = IDSessione;
                    wa.IDCliente  = IDCliente;

                    //apertura
                    wa.Load();

                    App.MessaggioSolaScrittura      = "Carta in sola lettura, premere tasto ESCI";
                    App.MessaggioSolaScritturaStato = "Carta in sola lettura, premere tasto ESCI";

                    wa.ShowDialog();

                    App.MessaggioSolaScrittura      = "Occorre selezionare Sblocca Stato per modificare il contenuto.";
                    App.MessaggioSolaScritturaStato = "Sessione in sola lettura, impossibile modificare lo stato.";
                }
                else
                {
                    MasterFile mf = MasterFile.Create();
                    string     bilancioAssociato     = mf.GetBilancioAssociatoFromConclusioneFile(Sessioni[SessioneNow].ToString());
                    string     bilancioTreeAssociato = mf.GetBilancioTreeAssociatoFromConclusioneFile(Sessioni[SessioneNow].ToString());
                    string     bilancioIDAssociato   = mf.GetBilancioIDAssociatoFromConclusioneFile(Sessioni[SessioneNow].ToString());


                    if (bilancioAssociato == "")
                    {
                        e.Handled = true;
                        return;
                    }

                    XmlDataProviderManager _xNew = new XmlDataProviderManager(bilancioAssociato);

                    WindowWorkArea wa = new WindowWorkArea(ref _xNew);

                    //Nodi
                    wa.NodeHome = 0;

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

                    if (TreeXmlProvider.Document != null && TreeXmlProvider.Document.SelectSingleNode("/Tree") != null)
                    {
                        foreach (XmlNode item in TreeXmlProvider.Document.SelectNodes("/Tree//Node"))
                        {
                            if (item.Attributes["Codice"].Value == ((TextBlock)(sender)).Text)
                            {
                                wa.Nodes.Add(0, item);
                            }
                        }
                    }

                    if (wa.Nodes.Count == 0)
                    {
                        e.Handled = true;
                        return;
                    }

                    wa.NodeNow = wa.NodeHome;

                    wa.Owner = Window.GetWindow(this);

                    //posizione e dimensioni finestra
                    wa.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
                    wa.Height    = System.Windows.SystemParameters.PrimaryScreenHeight * 90.0 / 100.0;
                    wa.Width     = System.Windows.SystemParameters.PrimaryScreenWidth * 90.0 / 100.0;
                    wa.MaxHeight = System.Windows.SystemParameters.PrimaryScreenHeight * 90.0 / 100.0;
                    wa.MaxWidth  = System.Windows.SystemParameters.PrimaryScreenWidth * 90.0 / 100.0;
                    wa.MinHeight = System.Windows.SystemParameters.PrimaryScreenHeight * 90.0 / 100.0;
                    wa.MinWidth  = System.Windows.SystemParameters.PrimaryScreenWidth * 90.0 / 100.0;

                    //Sessioni
                    wa.Sessioni.Clear();
                    wa.Sessioni.Add(0, bilancioAssociato);

                    wa.SessioniTitoli.Clear();
                    wa.SessioniTitoli.Add(0, SessioniTitoli[SessioneNow].ToString());

                    wa.SessioniID.Clear();
                    wa.SessioniID.Add(0, bilancioIDAssociato);

                    wa.SessioneHome = 0;
                    wa.SessioneNow  = 0;

                    //Variabili
                    wa.ReadOnly            = true;
                    wa.ReadOnlyOLD         = true;
                    wa.ApertoInSolaLettura = true;

                    //passaggio dati
                    wa.IDTree     = "4";
                    wa.IDSessione = bilancioIDAssociato;
                    wa.IDCliente  = IDCliente;

                    wa.Stato        = App.TipoTreeNodeStato.Sconosciuto;
                    wa.OldStatoNodo = wa.Stato;

                    //apertura
                    wa.Load();

                    App.MessaggioSolaScrittura      = "Carta in sola lettura, premere tasto ESCI";
                    App.MessaggioSolaScritturaStato = "Carta in sola lettura, premere tasto ESCI";

                    wa.ShowDialog();

                    App.MessaggioSolaScrittura      = "Occorre selezionare Sblocca Stato per modificare il contenuto.";
                    App.MessaggioSolaScritturaStato = "Sessione in sola lettura, impossibile modificare lo stato.";
                }
            }
        }
        private void buttonComando_Click(object sender, RoutedEventArgs e)
        {
            //controllo selezione clienti
            if (cmbClienti.SelectedIndex == -1)
            {
                MessageBox.Show("selezionare un cliente");
                return;
            }

            MasterFile mf = MasterFile.Create();
            Utilities  u  = new Utilities();

            int IDCliente     = Convert.ToInt32(htClienti[cmbClienti.SelectedIndex].ToString());
            int IDRelazioneBV = App.MasterFile_NewID;

            try
            {
                IDRelazioneBV = Convert.ToInt32(htDate[cmbData.SelectedIndex].ToString());
            }
            catch (Exception ex)
            {
                cBusinessObjects.logger.Error(ex, "wSchedaRelazioneBV.buttonComando_Click exception");
                string log = ex.Message;
            }

            if (TipologiaAttivita == App.TipoAttivitaScheda.Delete && IDRelazioneBV == -1)
            {
                MessageBox.Show("selezionare una sessione");
                return;
            }

            App.TipoAttivitaScheda oldTipo = TipologiaAttivita;
            if (TipologiaAttivita == App.TipoAttivitaScheda.New)
            {
                tabControl1.IsEnabled = false;
                gridButtons.IsEnabled = false;
                loading.Visibility    = Visibility;
                Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate { }));
            }

            switch (TipologiaAttivita)
            {
            //Nuovo e salva
            case App.TipoAttivitaScheda.New:
            case App.TipoAttivitaScheda.Edit:
                //Campi Obbligatorio
                if (dtpDataNomina.SelectedIndex == -1)// !u.ConvalidaDatiInterfaccia(dtpDataNomina, "Data mancante."))
                {
                    cBusinessObjects.hide_workinprogress();
                    MessageBox.Show("Selezionare un Esercizio.");
                    return;
                }

                //Controllo che questa data non sia già stata presa
                if (!mf.CheckDoppio_RelazioneBV(IDRelazioneBV, IDCliente, htSelectedDate[dtpDataNomina.SelectedIndex].ToString()))
                {
                    cBusinessObjects.hide_workinprogress();
                    MessageBox.Show("Data già presente per questo cliente");
                    return;
                }

                //setto dati
                Hashtable ht = new Hashtable();

                ht.Add("Cliente", IDCliente);
                ht.Add("Data", htSelectedDate[dtpDataNomina.SelectedIndex].ToString());
                ht.Add("Note", txtNota.Text.Trim());

                IDRelazioneBV = mf.SetRelazioneBV(ht, IDRelazioneBV, IDCliente);

                RegistrazioneEffettuata = true;

                if (TipologiaAttivita == App.TipoAttivitaScheda.New)
                {
                    if (IDClienteImport != "-1")
                    {
                        cBusinessObjects.hide_workinprogress();
                        this.Close();
                    }

                    cBusinessObjects.SessioneIsNew = true;
                    TipologiaAttivita = App.TipoAttivitaScheda.Edit;
                    mf.SetAnafraficaStato(Convert.ToInt32(IDCliente), App.TipoAnagraficaStato.Disponibile);

                    ConfiguraMaschera();

                    foreach (DictionaryEntry item in htClienti)
                    {
                        if (Convert.ToInt32(item.Value.ToString()) == IDCliente)
                        {
                            cmbClienti.SelectedIndex = Convert.ToInt32(item.Key.ToString());
                        }
                    }

                    functionCmbClientiChanged(cmbClienti);

                    cmbData.IsEnabled = true;

                    foreach (DictionaryEntry item in htDate)
                    {
                        if (Convert.ToInt32(item.Value.ToString()) == IDRelazioneBV)
                        {
                            cmbData.SelectedIndex = Convert.ToInt32(item.Key.ToString());
                        }
                    }

                    functionCmbDataChanged(cmbData);
                    cBusinessObjects.AddSessione("RelazioneBV", cmbData.SelectedValue.ToString(), IDRelazioneBV, IDCliente);
                }

                _DatiCambiati = false;
                break;

            case App.TipoAttivitaScheda.Delete:
                //richiesta conferma
                if (MessageBoxResult.No == u.ConfermaCancellazione())
                {
                    return;
                }
                //cancellazione
                mf.DeleteRelazioneBV(IDRelazioneBV, IDCliente.ToString());
                RegistrazioneEffettuata = true;
                base.Close();
                break;

            case App.TipoAttivitaScheda.Export:
                break;
            }

            //apro tree appena creato
            if (oldTipo == App.TipoAttivitaScheda.New)
            {
                //MessageBox.Show("apro tree appena creato");
                Accedi_Click(IDRelazioneBV.ToString(), false);
            }

            //chiudo maschera
            if (TipologiaAttivita != App.TipoAttivitaScheda.Edit)
            {
                base.Close();
            }
        }
        //----------------------------------------------------------------------------+
        //                                   accedi                                   |
        //----------------------------------------------------------------------------+
        public void accedi(string ID, bool ReadOnly)
        {
            MasterFile mf         = MasterFile.Create();
            Hashtable  htSelected = mf.GetRelazioneBV(ID);

            if (htSelected.Count == 0)
            {
                return;
            }
            WindowWorkAreaTree wWorkArea = new WindowWorkAreaTree();

            //Prisc
            try
            {
                wWorkArea.Owner = this;
            }
            catch (Exception ex)
            {
                cBusinessObjects.logger.Error(ex, "wSchedaRelazioneBV.accedi exception");
                string log = ex.Message;
            }
            wWorkArea.SelectedTreeSource = App.AppDataDataFolder + "\\" + htSelected["File"].ToString();
            wWorkArea.SelectedDataSource = App.AppDataDataFolder + "\\" + htSelected["FileData"].ToString();
            if (htSelected["Sigillo"] != null && htSelected["Sigillo"].ToString() != "")
            {
                wWorkArea.ReadOnly = true;
            }
            else
            {
                wWorkArea.ReadOnly = ReadOnly;
            }
            wWorkArea.TipoAttivita            = App.TipoAttivita.RelazioneBV;
            wWorkArea.Cliente                 = (((Hashtable)(mf.GetAnagrafica(Convert.ToInt32(htSelected["Cliente"].ToString()))))["RagioneSociale"].ToString()) + " (C.F. " + (((Hashtable)(mf.GetAnagrafica(Convert.ToInt32(htSelected["Cliente"].ToString()))))["CodiceFiscale"].ToString()) + ")";
            wWorkArea.SessioneAlias           = "";
            wWorkArea.SessioneFile            = "";
            wWorkArea.SessioneSigillo         = null;
            wWorkArea.SessioneSigilloData     = null;
            wWorkArea.SessioneSigilloPassword = null;
            wWorkArea.IDTree     = (Convert.ToInt32(App.TipoFile.RelazioneBV)).ToString();
            wWorkArea.IDCliente  = htSelected["Cliente"].ToString();
            wWorkArea.IDSessione = ID;
            foreach (Hashtable item in ((ArrayList)(mf.GetRelazioniBV(htSelected["Cliente"].ToString()))))
            {
                wWorkArea.SessioneFile            += ((wWorkArea.SessioneFile == "") ? "" : "|") + App.AppDataDataFolder + "\\" + item["FileData"].ToString();
                wWorkArea.SessioneAlias           += ((wWorkArea.SessioneAlias == "") ? "" : "|") + item["Data"].ToString();// ConvertDataToEsercizio(item["Data"].ToString());
                wWorkArea.SessioneID              += ((wWorkArea.SessioneID == "") ? "" : "|") + item["ID"].ToString();
                wWorkArea.SessioneSigillo         += ((wWorkArea.SessioneSigillo == null) ? "" : "|") + ((item["Sigillo"] != null) ? item["Sigillo"].ToString() : "");
                wWorkArea.SessioneSigilloData     += ((wWorkArea.SessioneSigilloData == null) ? "" : "|") + ((item["Sigillo_Data"] != null) ? item["Sigillo_Data"].ToString() : "");
                wWorkArea.SessioneSigilloPassword += ((wWorkArea.SessioneSigilloPassword == null) ? "" : "|") + ((item["Sigillo_Password"] != null) ? item["Sigillo_Password"].ToString() : "");
            }
            //aperto in sola lettura
            wWorkArea.ApertoInSolaLettura = TipologiaAttivita == App.TipoAttivitaScheda.View;
            wWorkArea.LoadTreeSource();
            Hide();
            wWorkArea.ShowDialog();
            if (TipologiaAttivita != App.TipoAttivitaScheda.View)
            {
                int IDCliente = Convert.ToInt32(htClienti[cmbClienti.SelectedIndex].ToString());
                mf.SetAnafraficaStato(Convert.ToInt32(IDCliente), App.TipoAnagraficaStato.Disponibile);
            }
            Close();
        }