//----------------------------------------------------------------------------+
        //                                   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();
        }
        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;
                }
            }
        }