Exemplo n.º 1
0
        /// <summary>
        /// Aggiorna la colorazione della barra superiore del riepilogo in base allo schema colori basato sui giorni.
        /// </summary>
        protected void UpdateDayColor()
        {
            DataView azioni = new DataView(Workbook.Repository[DataBase.TAB.AZIONE]);

            azioni.RowFilter = "Visibile = 1 AND Operativa = 1 AND IdApplicazione = " + Workbook.IdApplicazione;

            Range rngTitleBar = new Range(_definedNames.GetFirstRow(), _definedNames.GetFirstCol() + 1, 3, azioni.Count);

            CicloGiorni((oreGiorno, suffissoData, giorno) =>
            {
                ASheet.AssegnaColori(_ws.Range[rngTitleBar.ToString()], giorno);

                rngTitleBar.StartColumn += azioni.Count;
            });
        }
Exemplo n.º 2
0
        public void AggiornaPrevisione(object siglaEntita)
        {
            DateTime dataFine = Workbook.DataAttiva.AddDays(Struct.intervalloGiorni);
            int      mainRow  = _definedNames.GetRowByName(Date.SuffissoDATA1);
            int      mainCol  = 0;

            DataView entitaInformazione = new DataView(Workbook.Repository[DataBase.TAB.ENTITA_INFORMAZIONE]);

            entitaInformazione.RowFilter = "SiglaEntita = '" + siglaEntita + "' AND IdApplicazione = " + Workbook.IdApplicazione;
            string nomeFoglio = DefinedNames.GetSheetName(siglaEntita);

            Excel.Worksheet ws           = Workbook.WB.Sheets[nomeFoglio];
            DefinedNames    definedNames = new DefinedNames(nomeFoglio, DefinedNames.InitType.Naming);

            //copio nel main il valore dei totali
            foreach (DataRowView info in entitaInformazione)
            {
                int col = definedNames.GetFirstCol();
                int row = definedNames.GetRowByNameSuffissoData(siglaEntita, info["SiglaInformazione"], Date.SuffissoDATA1);

                Array rngTotali = ws.Range[Range.GetRange(row, col + 25, Struct.intervalloGiorni)].Value as Array;

                int i = 1;
                for (DateTime giorno = Workbook.DataAttiva; giorno < dataFine; giorno = giorno.AddDays(1))
                {
                    Range[] rngGiornoGas = Sheet.GetRangeGiornoGas(giorno, info, definedNames);

                    Array primoGiorno   = ws.Range[rngGiornoGas[0].ToString()].Value as Array;
                    Array secondoGiorno = ws.Range[rngGiornoGas[1].ToString()].Value as Array;

                    if (!(primoGiorno.OfType <double>().Any() || secondoGiorno.OfType <double>().Any()))
                    {
                        rngTotali.SetValue(null, i, 1);
                    }

                    i++;
                }

                mainCol = _definedNames.GetColFromName(siglaEntita);
                Excel.Range rngMain = Workbook.Main.Range[Range.GetRange(mainRow, mainCol, Struct.intervalloGiorni)];
                rngMain.Value = rngTotali;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Aggiunge la funzione ottimo per l'entità da ottimizzare.
        /// </summary>
        /// <param name="siglaEntita">Entità da ottimizzare.</param>
        protected virtual void AddOpt(object siglaEntita)
        {
            _entitaInformazioni.RowFilter = "SiglaEntita = '" + siglaEntita + "' AND SiglaTipologiaInformazione = 'OTTIMO' AND IdApplicazione = " + Workbook.IdApplicazione;

            if (_entitaInformazioni.Count > 0)
            {
                object siglaEntitaInfo = _entitaInformazioni[0]["SiglaEntitaRif"] is DBNull ? _entitaInformazioni[0]["SiglaEntita"] : _entitaInformazioni[0]["SiglaEntitaRif"];
                Range  rng             = new Range(_definedNames.GetRowByName(siglaEntitaInfo, _entitaInformazioni[0]["SiglaInformazione"]), _definedNames.GetFirstCol());
                try { Workbook.WB.Names.Item("WBMAX").Delete(); }
                catch { }
                double width = Workbook.Sheets[_sheet].Range[rng.ToString()].ColumnWidth;
                Workbook.Application.Run("wbBest", "'" + _sheet + "'!" + rng.ToString(), "Maximize");
                Workbook.Sheets[_sheet].Range[rng.ToString()].ColumnWidth = width;
            }
        }
Exemplo n.º 4
0
        protected bool InviaMail(DefinedNames definedNames, object siglaEntita)
        {
            string fileNameFull = "";
            string fileName     = "";

            try
            {
                fileName     = @"PrevisioneGAS_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
                fileNameFull = Environment.ExpandEnvironmentVariables(@"%TEMP%\" + fileName);

                Excel.Workbook wb = Globals.ThisWorkbook.Application.Workbooks.Add();

                Workbook.Main.Range[Range.GetRange(definedNames.GetFirstRow(), definedNames.GetFirstCol(), definedNames.GetRowOffset(), definedNames.GetColOffsetRiepilogo()).ToString()].Copy();
                wb.Sheets[1].Range["B2"].PasteSpecial();

                wb.Sheets[1].UsedRange.ColumnWidth = 17;
                wb.Sheets[1].Range["A1"].Select();
                wb.SaveAs(fileNameFull, Excel.XlFileFormat.xlExcel8);
                wb.Close();
                Marshal.ReleaseComObject(wb);

                var    config = Workbook.GetUsrConfigElement("destMailTest");
                string mailTo = config.Test;
                string mailCC = "";

                DataView entitaProprieta = new DataView(Workbook.Repository[DataBase.TAB.ENTITA_PROPRIETA]);

                if (Workbook.Ambiente == Simboli.PROD)
                {
                    entitaProprieta.RowFilter = "SiglaEntita = '" + siglaEntita + "' AND SiglaProprieta = 'PREV_CONSUMO_GAS_MAIL_TO' AND IdApplicazione = " + Workbook.IdApplicazione;

                    if (entitaProprieta.Count > 0)
                    {
                        mailTo = entitaProprieta[0]["Valore"].ToString();
                    }

                    entitaProprieta.RowFilter = "SiglaEntita = '" + siglaEntita + "' AND SiglaProprieta = 'PREV_CONSUMO_GAS_MAIL_CC' AND IdApplicazione = " + Workbook.IdApplicazione;

                    if (entitaProprieta.Count > 0)
                    {
                        mailCC = entitaProprieta[0]["Valore"].ToString();
                    }
                }
                if (DataBase.OpenConnection())
                {
                    Outlook.Application outlook = GetOutlookInstance();
                    Outlook._MailItem   mail    = outlook.CreateItem(Outlook.OlItemType.olMailItem);

                    config = Workbook.GetUsrConfigElement("oggettoMail");
                    string oggetto = config.Value.Replace("%DATA%", DateTime.Now.ToString("dd-MM-yyyy")).Replace("%ORA%", DateTime.Now.ToString("HH:mm"));
                    config = Workbook.GetUsrConfigElement("messaggioMail");
                    string messaggio = config.Value.Replace("%NOMEUTENTE%", Workbook.NomeUtente);
                    messaggio = Regex.Replace(messaggio, @"^[^\S\r\n]+", "", RegexOptions.Multiline);


                    ////TODO check se manda sempre con lo stesso account...
                    Outlook.Account senderAccount = outlook.Session.Accounts[1];
                    foreach (Outlook.Account account in outlook.Session.Accounts)
                    {
                        if (account.DisplayName == "Bidding")
                        {
                            senderAccount = account;
                        }
                    }
                    mail.SendUsingAccount = senderAccount;
                    mail.Subject          = oggetto;
                    mail.Body             = messaggio;
                    foreach (string dest in mailTo.Split(';'))
                    {
                        if (dest.Trim() != "")
                        {
                            mail.Recipients.Add(dest.Trim());
                        }
                    }
                    mail.CC = mailCC;
                    mail.Attachments.Add(fileNameFull);

                    mail.Send();

                    File.Delete(fileNameFull);
                }
                else
                {
                    string emailFolder = @"C:\Emergenza\Email\" + Simboli.NomeApplicazione;

                    if (!Directory.Exists(emailFolder))
                    {
                        Directory.CreateDirectory(emailFolder);
                    }

                    File.Move(fileNameFull, Path.Combine(emailFolder, fileName));
                }
            }
            catch (Exception e)
            {
                Workbook.InsertLog(Core.DataBase.TipologiaLOG.LogErrore, "PrevisioneGAS.Esporta.InvioMail: " + e.Message);

                System.Windows.Forms.MessageBox.Show(e.Message, Simboli.NomeApplicazione + " - ERRORE!!", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);

                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }

                return(false);
            }

            return(true);
        }
Exemplo n.º 5
0
        private void ChangeSelectionToIncrement(Excel.Range Target)
        {
            // Descrizione Combo / Riga Calcolo
            //offerta_dictionary = new Dictionary<string, int>();
            // SiglaInformazione riga selezionata / SiglaInformazione riga calcolo
            //calcolo_dictionary = new Dictionary<string, string>();

            _gotoDictionary = new Dictionary <string, int>();

            btnApplica.Enabled = false;

            comboBox_VaiA.DataSource     = null;
            comboBox_applicaA.DataSource = null;

            groupQuantità.Visible = false;
            groupPrezzo.Visible   = false;

            lbErrore.Text       = "";
            lbErrore.ForeColor  = Color.Red;
            btnApplica.Enabled  = false;
            _selectionIsCorrect = false;

            if (Target.Rows.Count > 1)
            {
                foreach (Excel.Range row in Target.Rows)
                {
                    if (row.EntireRow.Hidden)
                    {
                        lbErrore.Text = "ERRORE: Nel range selezionato ci sono righe nascoste.";
                        return;
                    }
                }
                lbErrore.ForeColor = Color.DarkOrange;
                lbErrore.Text      = "ATTENZIONE: Nel range selezionato ci sono più righe.";
            }
            foreach (Excel.Range row in Target.Rows)
            {
                if (!_definedNames.IsEditable(row.Row))
                {
                    lbErrore.Text = "ERRORE: Il range selezionato contiene delle righe non modificabili.";
                    return;
                }
            }

            int firstCol = _definedNames.GetFirstCol();

            if (Target.Column < firstCol + Simboli.GetMarketOffsetMI(Workbook.Mercato, Workbook.DataAttiva))
            {
                lbErrore.Text = "ERRORE: Il range selezionato contiene celle appartenenti a mercati chiusi.";
                return;
            }

            /* Controllo se la riga selezionata è corretta per l'operazione richiesta */
            string name_col_row_selected = _definedNames.GetNameByRow(Target.Row).FirstOrDefault();
            string siglaEntita           = name_col_row_selected.Split('.').First();
            string siglaInformazione     = name_col_row_selected.Split('.').Last();

            is_price    = is_Name_Match_Price(name_col_row_selected);
            is_quantity = is_Name_Match_Quantity(name_col_row_selected);

            //DataView definizioneOfferta = Workbook.Repository[DataBase.TAB.DEFINIZIONE_OFFERTA].DefaultView;

            //definizioneOfferta.RowFilter = "SiglaEntita ='" + siglaEntita + "' AND SiglaInformazione = '" + siglaInformazione + "' AND IdMercato = " + Workbook.Mercato.Substring(2, Workbook.Mercato.Length - 2);

            //if (definizioneOfferta.Count == 0)
            //{
            //    lbErrore.Text = "ERRORE: Non ci sono opzioni attive per questa funzione.";
            //    return;
            //}

            //DataView informazioni = Workbook.Repository[DataBase.TAB.ENTITA_INFORMAZIONE].DefaultView;

            //DataTable entitaInformazione = Workbook.Repository[DataBase.TAB.ENTITA_INFORMAZIONE];

            //foreach (DataRowView offerta in definizioneOfferta)
            //{
            //    string desInformazioneCombo = entitaInformazione.AsEnumerable()
            //        .Where(r => r["SiglaEntita"].Equals(offerta["SiglaEntita"])
            //                 && (r["SiglaEntitaRif"] is DBNull || r["SiglaEntitaRif"].Equals(offerta["SiglaEntitaCombo"]))
            //                 && r["SiglaInformazione"].Equals(offerta["SiglaInformazioneCombo"]))
            //        .Select(r => r["DesInformazione"].ToString())
            //        .FirstOrDefault();

            //    object entitaCalcolo = offerta["SiglaEntitaCalcolo"] is DBNull ? offerta["SiglaEntitaCombo"] : offerta["SiglaEntitaCalcolo"];
            //    object infoCalcolo = offerta["SiglaInformazioneCalcolo"] is DBNull ? offerta["SiglaInformazioneCombo"] : offerta["SiglaInformazioneCalcolo"];

            //    _gotoDictionary.Add(desInformazioneCombo, _definedNames.GetRowByName(entitaCalcolo, infoCalcolo));
            //}

            _gotoDictionary = OfferteMIHelper.GetGOTODictionary(siglaEntita, siglaInformazione, _definedNames);

            if (_gotoDictionary == null)
            {
                lbErrore.Text = "ERRORE: Non ci sono opzioni attive per questa funzione.";
                return;
            }

            if (is_price)
            {
                groupQuantità.Visible = false;
                groupPrezzo.Visible   = true;

                comboBox_applicaA.DataSource    = new BindingSource(_gotoDictionary, null);
                comboBox_applicaA.ValueMember   = "Value";
                comboBox_applicaA.DisplayMember = "Key";
                comboBox_applicaA.SelectedIndex = -1;
            }
            else if (is_quantity)
            {
                groupQuantità.Visible = true;
                groupPrezzo.Visible   = false;

                comboBox_VaiA.DataSource    = new BindingSource(_gotoDictionary, null);
                comboBox_VaiA.ValueMember   = "Value";
                comboBox_VaiA.DisplayMember = "Key";
                comboBox_VaiA.SelectedIndex = -1;
            }
            else
            {
                lbErrore.Text = "ERRORE: Il range selezionato non si riferisce a quantità o prezzi.";
                return;
            }

            _selectionIsCorrect = true;

            if (_valuesAreCorrect)
            {
                btnApplica.Enabled = true;
            }

            btnRipristina.Enabled = false;

            _origRng = Target;

            Handler.SaveOriginValues(Target, tableName: ALL_OLD_VALUE);
            if (is_price)
            {
                Excel.Range rng = _ws.Range[_ws.Cells[Target.Row - 2, Target.Column], _ws.Cells[Target.Row - 2, Target.Column + Target.Columns.Count - 1]];
                Handler.SaveOriginValues(rng, tableName: ALL_OLD_VALUE);
            }
            if (is_quantity)
            {
                Excel.Range rng = _ws.Range[_ws.Cells[Target.Row - 1, Target.Column], _ws.Cells[Target.Row - 1, Target.Column + Target.Columns.Count - 1]];
                Handler.SaveOriginValues(rng, tableName: ALL_OLD_VALUE);
            }
        }
Exemplo n.º 6
0
        protected override bool EsportaAzioneInformazione(object siglaEntita, object siglaAzione, object desEntita, object desAzione, DateTime dataRif, string[] mercati)
        {
            DataView entitaAzione = Workbook.Repository[DataBase.TAB.ENTITA_AZIONE].DefaultView;

            entitaAzione.RowFilter = "SiglaEntita = '" + siglaEntita + "' AND SiglaAzione = '" + siglaAzione + "' AND IdApplicazione = " + Workbook.IdApplicazione;
            if (entitaAzione.Count == 0)
            {
                return(false);
            }

            switch (siglaAzione.ToString())
            {
            case "E_VDT":

                string pathStr = PreparePath(Workbook.GetUsrConfigElement("pathExportSisComTerna"));

                if (Directory.Exists(pathStr))
                {
                    if (!CreaVariazioneDatiTecniciXML(siglaEntita, pathStr))
                    {
                        return(false);
                    }
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("Il percorso '" + pathStr + "' non è raggiungibile.", Simboli.NomeApplicazione + " - ERRORE!!", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);

                    return(false);
                }

                break;

            case "MAIL":
                Workbook.ScreenUpdating = false;
                string       nomeFoglio   = DefinedNames.GetSheetName(siglaEntita);
                DefinedNames definedNames = new DefinedNames(nomeFoglio, DefinedNames.InitType.Naming);

                var oldActiveWindow = Globals.ThisWorkbook.Application.ActiveWindow;
                Globals.ThisWorkbook.Worksheets[nomeFoglio].Activate();

                List <Range> export = new List <Range>();

                //titolo entità
                export.Add(new Range(definedNames.GetRowByNameSuffissoData(siglaEntita, "T", Date.SuffissoDATA1), definedNames.GetFirstCol() - 2).Extend(colOffset: 2 + Date.GetOreGiorno(Workbook.DataAttiva)));

                //data
                export.Add(new Range(Globals.ThisWorkbook.Application.ActiveWindow.SplitRow - 1, definedNames.GetFirstCol() - 2).Extend(colOffset: 2 + Date.GetOreGiorno(Workbook.DataAttiva)));

                //ora
                export.Add(new Range(Globals.ThisWorkbook.Application.ActiveWindow.SplitRow, definedNames.GetFirstCol() - 2).Extend(colOffset: 2 + Date.GetOreGiorno(Workbook.DataAttiva)));


                DataView entitaAzioneInformazione = Workbook.Repository[DataBase.TAB.ENTITA_AZIONE_INFORMAZIONE].DefaultView;
                entitaAzioneInformazione.RowFilter = "SiglaEntita = '" + siglaEntita + "' AND SiglaAzione = '" + siglaAzione + "' AND IdApplicazione = " + Workbook.IdApplicazione;
                foreach (DataRowView info in entitaAzioneInformazione)
                {
                    export.Add(new Range(definedNames.GetRowByNameSuffissoData(siglaEntita, info["SiglaInformazione"], Date.SuffissoDATA1), definedNames.GetFirstCol() - 2).Extend(colOffset: 2 + Date.GetOreGiorno(Workbook.DataAttiva)));
                }

                if (InviaMail(nomeFoglio, siglaEntita, export))
                {
                }

                oldActiveWindow.Activate();

                Workbook.ScreenUpdating = true;
                break;
            }
            return(true);
        }