Пример #1
0
        private void btnCarica_Click(object sender, EventArgs e)
        {
            Workbook.ScreenUpdating = false;
            Sheet.Protected         = false;

            btnCarica.Enabled  = false;
            btnAnnulla.Enabled = false;

            //object siglaEntita = comboUP.SelectedValue;

            string   nomeCombo = "combo" + groupDati.Controls.OfType <RadioButton>().FirstOrDefault(btn => btn.Checked).Name;
            ComboBox cmb       = groupDati.Controls.OfType <ComboBox>().FirstOrDefault(c => c.Name == nomeCombo);

            string dataEmissione = ((DateTime)cmb.SelectedItem).ToString("yyyyMMdd");

            bool gone = _carica.AzioneInformazione(comboUP.SelectedValue, "METEO", "CARICA", _dataRif, null, dataEmissione);

            _riepilogo.AggiornaRiepilogo(comboUP.SelectedValue, "METEO", gone, _dataRif);

            Workbook.InsertLog(Core.DataBase.TipologiaLOG.LogCarica, "Carica: Previsioni meteo");

            btnCarica.Enabled  = true;
            btnAnnulla.Enabled = true;

            Workbook.ScreenUpdating = true;
            Sheet.Protected         = true;
        }
Пример #2
0
        private void btnApplica_Click(object sender, EventArgs e)
        {
            Workbook.ScreenUpdating = false;
            Sheet.Protected         = false;

            btnApplica.Enabled = false;
            btnAnnulla.Enabled = false;
            btnMeteo.Enabled   = false;

            if (_toProcessDates.Count == 0)
            {
                MessageBox.Show("Non è stata selezionata alcuna data...", Simboli.NomeApplicazione, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (treeViewUP.Nodes.OfType <TreeNode>().Where(n => n.Checked).ToArray().Length == 0)
            {
                MessageBox.Show("Non è stata selezionata alcuna unità...", Simboli.NomeApplicazione, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                SplashScreen.Show();
                Workbook.Application.EnableEvents = false;
                Workbook.ScreenUpdating           = false;
                Workbook.Application.Calculation  = Excel.XlCalculation.xlCalculationManual;

                bool caricaOrGenera = false;
                bool loaded         = false;

                bool g_mp_mgp = false;

                DataView entitaProprieta = Workbook.Repository[DataBase.TAB.ENTITA_PROPRIETA].DefaultView;

                ThroughAllNodes(treeViewAzioni.Nodes, nodoAzione =>
                {
                    if (loaded && Regex.Match(nodoAzione.Name, @"\w[^\d]+").Value == "GENERA")
                    {
                        Workbook.Application.CalculateFull();
                        Workbook.ScreenUpdating = false;
                        loaded = false;
                    }

                    if (nodoAzione.Checked && nodoAzione.Nodes.Count == 0)
                    {
                        TreeNode[] nodiEntita = treeViewUP.Nodes.OfType <TreeNode>().Where(node => node.Checked).ToArray();
                        _azioni.RowFilter     = "SiglaAzione = '" + nodoAzione.Name + "' AND IdApplicazione = " + Workbook.IdApplicazione;
                        if (!g_mp_mgp)
                        {
                            g_mp_mgp = nodoAzione.Name == "G_MP_MGP";
                        }

                        ThroughAllNodes(treeViewUP.Nodes, nodoEntita =>
                        {
                            foreach (DateTime date in _toProcessDates)
                            {
                                string suffissoData = Date.GetSuffissoData(date);

                                if (nodoEntita.Checked && nodoEntita.Nodes.Count == 0)
                                {
                                    entitaProprieta.RowFilter = "SiglaEntita = '" + nodoEntita.Name + "' AND SiglaProprieta LIKE '%GIORNI_STRUTTURA' AND IdApplicazione = " + Workbook.IdApplicazione;
                                    int intervalloGiorni      = Struct.intervalloGiorni;
                                    if (entitaProprieta.Count > 0)
                                    {
                                        intervalloGiorni = int.Parse("" + entitaProprieta[0]["Valore"]);
                                    }

                                    if (date <= Workbook.DataAttiva.AddDays(intervalloGiorni))
                                    {
                                        string nomeFoglio = DefinedNames.GetSheetName(nodoEntita.Name);
                                        bool presente;

                                        DataView entitaAzione  = new DataView(Workbook.Repository[DataBase.TAB.ENTITA_AZIONE]);
                                        entitaAzione.RowFilter = "SiglaEntita = '" + nodoEntita.Name + "' AND SiglaAzione = '" + nodoAzione.Name + "' AND IdApplicazione = " + Workbook.IdApplicazione;

                                        if (entitaAzione.Count > 0 && (entitaAzione[0]["Giorno"] is DBNull || entitaAzione[0]["Giorno"].ToString().Contains(Date.GetSuffissoData(date))))
                                        {
                                            SplashScreen.UpdateStatus("[" + date.ToShortDateString() + "] " + nodoAzione.Parent.Text + " " + nodoAzione.Text + ": " + nodoEntita.Text);

                                            //string[] mercati = null;
                                            string[] mercati = null;
                                            if (Workbook.Repository.Applicazione["ModificaDinamica"].Equals("1"))
                                            {
                                                mercati = groupMercati.Controls
                                                          .OfType <CheckBox>()
                                                          .Where(c => c.Checked)
                                                          .Select(c => Regex.Match(c.Text, @"\d+").Value)
                                                          .OrderBy(s => s)
                                                          .ToArray();
                                            }
                                            else if (Workbook.IdApplicazione == 18)
                                            {
                                                mercati = new string[] { Regex.Match(Workbook.Mercato, @"\d+").Value };
                                            }

                                            switch (Regex.Match(nodoAzione.Parent.Name, @"\w[^\d]+").Value)
                                            {
                                            case "CARICA":
                                                presente = _carica.AzioneInformazione(nodoEntita.Name, nodoAzione.Name, nodoAzione.Parent.Name, date, mercati);
                                                _r.AggiornaRiepilogo(nodoEntita.Name, nodoAzione.Name, presente, date);
                                                caricaOrGenera = true;
                                                loaded         = true;
                                                break;

                                            case "GENERA":
                                                presente = _carica.AzioneInformazione(nodoEntita.Name, nodoAzione.Name, nodoAzione.Parent.Name, date, mercati);
                                                _r.AggiornaRiepilogo(nodoEntita.Name, nodoAzione.Name, presente, date);
                                                caricaOrGenera = true;
                                                break;

                                            case "ESPORTA":
                                                presente = _esporta.RunExport(nodoEntita.Name, nodoAzione.Name, nodoEntita.Text, nodoAzione.Text, date, mercati);
                                                if (presente)
                                                {
                                                    _r.AggiornaRiepilogo(nodoEntita.Name, nodoAzione.Name, presente, date);
                                                }
                                                break;
                                            }

                                            if (_azioni[0]["Relazione"] != DBNull.Value && Struct.visualizzaRiepilogo)
                                            {
                                                string[] azioneRelazione = _azioni[0]["Relazione"].ToString().Split(';');

                                                DefinedNames definedNames = new DefinedNames("Main");

                                                foreach (string relazione in azioneRelazione)
                                                {
                                                    _azioni.RowFilter = "SiglaAzione = '" + relazione + "' AND IdApplicazione = " + Workbook.IdApplicazione;

                                                    Range rng = new Range(definedNames.GetRowByName(nodoEntita.Name), definedNames.GetColFromName(relazione, suffissoData));
                                                    if (Workbook.Main.Range[rng.ToString()].Interior.ColorIndex != 2)
                                                    {
                                                        Workbook.Main.Range[rng.ToString()].Value = "RI" + _azioni[0]["Gerarchia"];
                                                        Style.RangeStyle(Workbook.Main.Range[rng.ToString()], fontSize: 8, bold: true, foreColor: 3, backColor: 6, align: Excel.XlHAlign.xlHAlignCenter);
                                                    }
                                                }
                                                _azioni.RowFilter = "SiglaAzione = '" + nodoAzione.Name + "' AND IdApplicazione = " + Workbook.IdApplicazione;
                                            }
                                        }
                                    }
                                }
                            }
                        });
                        switch (Regex.Match(nodoAzione.Parent.Name, @"\w[^\d]+").Value)
                        {
                        case "CARICA":
                            Workbook.InsertLog(Core.DataBase.TipologiaLOG.LogCarica, "Carica: " + nodoAzione.Text);
                            break;

                        case "GENERA":
                            Workbook.InsertLog(Core.DataBase.TipologiaLOG.LogGenera, "Genera: " + nodoAzione.Text);
                            break;

                        case "ESPORTA":
                            Workbook.InsertLog(Core.DataBase.TipologiaLOG.LogEsporta, "Esporta: " + nodoAzione.Text);
                            break;
                        }
                    }
                });

                Workbook.Application.Calculation = Excel.XlCalculation.xlCalculationAutomatic;

                if (caricaOrGenera)
                {
                    SplashScreen.UpdateStatus("Salvo su DB");
                    Sheet.SalvaModifiche();
                    DataBase.SalvaModificheDB();
                    if (Workbook.IdApplicazione == 5 && g_mp_mgp)
                    {
                        SplashScreen.UpdateStatus("Aggiorno rendimenti");
                        Workbook.Application.Calculation = Excel.XlCalculation.xlCalculationManual;

                        ThroughAllNodes(treeViewUP.Nodes, nodoEntita =>
                        {
                            if (nodoEntita.Checked && nodoEntita.Nodes.Count == 0)
                            {
                                _categoriaEntita.RowFilter = "SiglaEntita = '" + nodoEntita.Name + "' AND IdApplicazione = " + Workbook.IdApplicazione;

                                if (_categoriaEntita[0]["SiglaCategoria"].Equals("IREN_60T"))
                                {
                                    foreach (DateTime date in _toProcessDates)
                                    {
                                        _carica.AzioneInformazione(nodoEntita.Name, "RENDIMENTO", "CARICA", date, null);
                                    }
                                }
                            }
                        });
                        Workbook.Application.Calculation = Excel.XlCalculation.xlCalculationAutomatic;
                        SplashScreen.UpdateStatus("Salvo su DB");
                        Sheet.SalvaModifiche();
                        DataBase.SalvaModificheDB();
                    }
                }

                Workbook.Application.EnableEvents = true;
                Workbook.ScreenUpdating           = true;
                SplashScreen.Close();
            }

            btnApplica.Enabled = true;
            btnAnnulla.Enabled = true;
            btnMeteo.Enabled   = true;

            Sheet.Protected         = true;
            Workbook.ScreenUpdating = true;
        }