Ejemplo n.º 1
0
        /// <summary>
        /// Launcher dell'azione di caricamento/generazione dei dati.
        /// </summary>
        /// <param name="siglaEntita">Sigla dell'entità di cui caricare/generare i dati.</param>
        /// <param name="siglaAzione">Sigla dell'azione per cui è richiesto il caricamento dei dati.</param>
        /// <param name="azionePadre">Sigla dell'azione padre (di solito CARICAx o GENERA).</param>
        /// <param name="giorno">Data di riferimento.</param>
        /// <param name="mercati">Mercati da considerare nell'azione.</param>
        /// <param name="parametro">Parametro da specificare alla storedProcedure CARICA_AZIONE_INFORMAZIONE nel caso sia necessario.</param>
        /// <returns>True se il caricamento va a buon fine.</returns>
        public override bool AzioneInformazione(object siglaEntita, object siglaAzione, object azionePadre, DateTime giorno, string[] mercati, object parametro = null)
        {
            DefinedNames definedNames = new DefinedNames(DefinedNames.GetSheetName(siglaEntita));

            try
            {
                AzzeraInformazione(siglaEntita, siglaAzione, definedNames, giorno, mercati, azionePadre.ToString().StartsWith("CARICA"));
                if (DataBase.OpenConnection())
                {
                    if (azionePadre.Equals("GENERA"))
                    {
                        if (mercati != null)
                        {
                            foreach (string mercato in mercati)
                            {
                                SpecMercato m = Simboli.MercatiMB["MB" + mercato];
                                ElaborazioneInformazione(siglaEntita, siglaAzione, definedNames, giorno, m.Inizio, Math.Min(Date.GetOreGiorno(giorno), m.Fine));
                            }
                        }
                        else
                        {
                            ElaborazioneInformazione(siglaEntita, siglaAzione, definedNames, giorno);
                        }
                        DataBase.InsertApplicazioneRiepilogo(siglaEntita, siglaAzione, giorno);
                    }
                    else
                    {
                        DataTable azioneInformazione = null;
                        if (mercati != null)
                        {
                            azioneInformazione = DataBase.Select(DataBase.SP.CARICA_AZIONE_INFORMAZIONE, "@SiglaEntita=" + siglaEntita + ";@SiglaAzione=" + siglaAzione + ";@Parametro=" + String.Join(",", mercati) + ";@Data=" + giorno.ToString("yyyyMMdd"));
                        }
                        else
                        {
                            azioneInformazione = DataBase.Select(DataBase.SP.CARICA_AZIONE_INFORMAZIONE, "@SiglaEntita=" + siglaEntita + ";@SiglaAzione=" + siglaAzione + ";@Parametro=" + parametro + ";@Data=" + giorno.ToString("yyyyMMdd"));
                        }

                        if (azioneInformazione != null)
                        {
                            if (azioneInformazione.Rows.Count == 0)
                            {
                                DataBase.InsertApplicazioneRiepilogo(siglaEntita, siglaAzione, giorno, false);
                                return(false);
                            }
                            else
                            {
                                ScriviInformazione(siglaEntita, azioneInformazione.DefaultView, definedNames);
                                DataBase.InsertApplicazioneRiepilogo(siglaEntita, siglaAzione, giorno);
                            }
                        }
                    }

                    Sheet s = new Sheet(Workbook.Sheets[definedNames.Sheet]);
                    s.AggiornaGrafici();
                    return(true);
                }
                else
                {
                    if (azionePadre.Equals("GENERA"))
                    {
                        ElaborazioneInformazione(siglaEntita, siglaAzione, definedNames, giorno);

                        Sheet s = new Sheet(Workbook.Sheets[definedNames.Sheet]);
                        s.AggiornaGrafici();

                        return(true);
                    }

                    return(false);
                }
            }
            catch (Exception e)
            {
                Workbook.InsertLog(PSO.Core.DataBase.TipologiaLOG.LogErrore, "CaricaAzioneInformazione [" + siglaEntita + ", " + siglaAzione + "]: " + e.Message);
                System.Windows.Forms.MessageBox.Show(e.Message, Simboli.NomeApplicazione + " - ERRORE!!", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Launcher dell'aggiornamento della struttura.
        /// </summary>
        /// <returns>True se l'aggiornamento è andato a buon fine.</returns>
        public override bool Struttura(bool avoidRepositoryUpdate)
        {
            if (DataBase.OpenConnection() || avoidRepositoryUpdate)
            {
                SetMercatoAttivo();

                //aggiorno i parametri di base dell'applicazione
                Workbook.AggiornaParametriApplicazione(avoidRepositoryUpdate);

                SplashScreen.Show();

                bool wasProtected = Sheet.Protected;
                if (wasProtected)
                    Sheet.Protected = false;

                Workbook.ScreenUpdating = false;

                if (!avoidRepositoryUpdate)
                {
                    SplashScreen.UpdateStatus("Carico struttura dal DB");
                    Workbook.Repository.Aggiorna();
                }
                else
                {
                    //resetto la struttura nomi che verrà ricreata nelle prossime righe
                    Workbook.Repository.InitStrutturaNomi();
                }
                
                SplashScreen.UpdateStatus("Controllo se tutti i fogli sono presenti");

                DataView categorie = Workbook.Repository[DataBase.TAB.CATEGORIA].DefaultView;
                categorie.RowFilter = "Operativa = 1 AND IdApplicazione = " + Workbook.IdApplicazione;

                //cancello i fogli che non ci sono più come categorie
                if (Workbook.CategorySheets != null)
                {
                    foreach (Excel.Worksheet categorySheet in Workbook.CategorySheets)
                    {
                        if ((from DataRowView r in categorie
                             where r["DesCategoria"].Equals(categorySheet.Name)
                             select r).Count() == 0)
                        {
                            bool isactive = Workbook.Application.DisplayAlerts;
                            try
                            {
                                if(isactive)
                                    Workbook.Application.DisplayAlerts = false;
                                
                                Workbook.Sheets[categorySheet.Name].Delete();
                                
                                if(isactive)
                                    Workbook.Application.DisplayAlerts = true;
                            }
                            catch
                            {
                                if (isactive)
                                    Workbook.Application.DisplayAlerts = true;
                            }
                            
                        }
                            
                    }
                }
                
                //creo fogli che si sono aggiunti alle categorie
                foreach (DataRowView categoria in categorie)
                {
                    Excel._Worksheet ws;
                    try
                    {
                        ws = Workbook.Sheets[categoria["DesCategoria"].ToString()];
                        ws.Activate();
                        if(_freezePanes.ContainsKey(ws.Name))
                            _freezePanes[ws.Name] = Tuple.Create<int,int>(Workbook.Application.ActiveWindow.SplitRow + 1, Workbook.Application.ActiveWindow.SplitColumn + 1);
                        else
                            _freezePanes.Add(ws.Name, Tuple.Create<int,int>(Workbook.Application.ActiveWindow.SplitRow + 1, Workbook.Application.ActiveWindow.SplitColumn + 1));
                    }
                    catch
                    {
                        ws = (Excel.Worksheet)Workbook.Sheets.Add(Workbook.Log);
                        ws.Name = categoria["DesCategoria"].ToString();
                        ws.Select();
                        Workbook.Application.Windows[1].DisplayGridlines = false;
#if !DEBUG
                    Workbook.Application.ActiveWindow.DisplayHeadings = false;
#endif
                    }
                }
                Workbook.ScreenUpdating = false;

                try
                {
                    if(DataBase.OpenConnection())
                        CaricaDatiDalDB();

                    Workbook.Application.Calculation = Excel.XlCalculation.xlCalculationManual;
                    SplashScreen.UpdateStatus("Aggiorno struttura Riepilogo");
                    StrutturaRiepilogo();

                    SplashScreen.UpdateStatus("Aggiorno struttura Fogli");
                    StrutturaFogli();

                    SplashScreen.UpdateStatus("Abilito calcolo automatico");
                    Workbook.Application.Calculation = Excel.XlCalculation.xlCalculationAutomatic;

                    SplashScreen.UpdateStatus("Invio modifiche al server");
                    Workbook.ScreenUpdating = false;
                    Sheet.SalvaModifiche();
                    DataBase.SalvaModificheDB();

                    SplashScreen.UpdateStatus("Azzero selezioni");
                    foreach (Excel._Worksheet ws in Workbook.Sheets)
                    {
                        if (ws.Visible == Excel.XlSheetVisibility.xlSheetVisible)
                        {
                            ws.Activate();
                            ws.Range["A1"].Select();
                        }
                    }

                    Workbook.Main.Select();
                    Workbook.Application.WindowState = Excel.XlWindowState.xlMaximized;

                    if (wasProtected)
                        Sheet.Protected = true;

                    SplashScreen.Close();
                    CancellaTabelle();
                    return true;
                }
                catch
                {
                    SplashScreen.Close();
                    CancellaTabelle();
                    return false;
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("Impossibile aggiornare la struttura: ci sono problemi di connessione o la funzione Forza Emergenza è attiva.", Simboli.NomeApplicazione + " - ERRORE!!!", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);

                return false;
            }
        }