Exemple #1
0
 /// <summary>
 /// Launcher per la compilazione del riepilogo in seguito allo svolgimento di un'azione.
 /// </summary>
 /// <param name="siglaEntita">Entità per individuare la riga in cui scrivere.</param>
 /// <param name="siglaAzione">Azione per individuare la colonna in cui scrivere.</param>
 /// <param name="presente">Se l'azione ha portato a risultati oppure no.</param>
 /// <param name="dataRif">La data in cui andare a scrivere. Assieme all'azione indica la colonna.</param>
 ///
 public override void AggiornaRiepilogo(object siglaEntita, object siglaAzione, bool presente, DateTime dataRif)
 {
     if (dataRif - Workbook.DataAttiva <= new TimeSpan(Struct.intervalloGiorni, 0, 0, 0))
     {
         if (Struct.visualizzaRiepilogo && !Simboli.EmergenzaForzata)
         {
             Range       cell = _definedNames.Get(siglaEntita, siglaAzione, Date.GetSuffissoData(dataRif));
             Excel.Range rng  = _ws.Range[cell.ToString()];
             if (presente)
             {
                 string commento = "Utente: " + Workbook.NomeUtente + "\nData: " + DateTime.Now.ToString("dd MMM yyyy") + "\nOra: " + DateTime.Now.ToString("HH:mm");
                 rng.ClearComments();
                 rng.AddComment(commento).Visible = false;
                 rng.Value = "OK";
                 Style.RangeStyle(rng, foreColor: 1, bold: true, fontSize: 9, backColor: 4, align: Excel.XlHAlign.xlHAlignCenter);
             }
             else
             {
                 rng.ClearComments();
                 rng.Value = "Non presente";
                 Style.RangeStyle(rng, foreColor: 3, bold: false, fontSize: 7, backColor: 2, align: Excel.XlHAlign.xlHAlignCenter);
             }
         }
     }
 }
Exemple #2
0
 private void ExcelApplication_WorkbookBeforeClose(Excel.Workbook Wb, ref bool Cancel)
 {
     Excel.Sheets    excelSheets    = Wb.Worksheets;
     Excel.Worksheet excelWorksheet = HelperUtil.GetSheetNameFromGroupOfSheets(GlobalMembers.InstanceGlobalMembers.MetaDataSheetName, excelSheets);
     Excel.Range     excelRange     = excelWorksheet.UsedRange;
     excelRange.ClearContents();
     excelRange.ClearFormats();
     excelRange.ClearComments();
 }
Exemple #3
0
        /// <summary>
        /// Carico i dati e i commenti che devono essere scritti nelle celle.
        /// </summary>
        protected void CaricaDatiRiepilogo()
        {
            try
            {
                CicloGiorni((oreGiorno, suffissoData, giorno) =>
                {
                    if (DataBase.OpenConnection())
                    {
                        DataView datiRiepilogo = GetDataView_CaricaDatiRiepilogo(giorno);

                        foreach (DataRowView valore in datiRiepilogo)
                        {
                            Range cellaAzione = new Range(_definedNames.GetRowByName(valore["SiglaEntita"]), _definedNames.GetColFromName(valore["SiglaAzione"], suffissoData));

                            Excel.Range rng = _ws.Range[cellaAzione.ToString()];

                            if (valore["Presente"].Equals("1"))
                            {
                                rng.ClearComments();
                                DateTime data = DateTime.ParseExact(valore["Data"].ToString(), "yyyyMMddHHmm", CultureInfo.InvariantCulture);
                                rng.AddComment("Utente: " + valore["Utente"] + "\nData: " + data.ToString("dd MMM yyyy") + "\nOra: " + data.ToString("HH:mm"));
                                rng.Value = "OK";
                                Style.RangeStyle(rng, foreColor: 1, bold: true, fontSize: 9, backColor: 4, align: Excel.XlHAlign.xlHAlignCenter);
                            }
                            else
                            {
                                rng.ClearComments();
                                rng.Value = "Non presente";
                                Style.RangeStyle(rng, foreColor: 3, bold: false, fontSize: 7, backColor: 2, align: Excel.XlHAlign.xlHAlignCenter);
                            }
                        }
                    }
                });
            }
            catch (Exception e)
            {
                Workbook.InsertLog(PSO.Core.DataBase.TipologiaLOG.LogErrore, "CaricaDatiRiepilogo: " + e.Message);

                System.Windows.Forms.MessageBox.Show(e.Message, Simboli.NomeApplicazione + " - ERRORE!!", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
        }
Exemple #4
0
        public static void ClearCell(CellUpdate uc, Excel.Worksheet ws)
        {
            Excel.Range thisRange = null;

            try
            {
                WaitForApplicationReady();

                thisRange = createRange(ws, uc.Row, uc.Col);
                if (thisRange != null)
                {
                    WaitForApplicationReady();
                    thisRange.ClearComments();


                    //dynamic oldFC = null;
                    //dynamic oldAppliesTo = null;
                    //if (thisRange.FormatConditions.Count > 0)
                    //{
                    //    foreach (dynamic fc in thisRange.FormatConditions)
                    //    {
                    //        if (fc.Type != 4)
                    //        {
                    //            oldFC = fc;
                    //            oldAppliesTo = fc.AppliesTo;
                    //        }
                    //    }


                    //    thisRange.FormatConditions.Delete();
                    //    oldFC.ModifyAppliesToRange(oldAppliesTo);
                    //}
                }
            }
            catch (Exception ex)
            {
                ErrorLog(ex, uc);
                throw;
            }
            finally
            {
                if (thisRange != null)
                {
                    Marshal.ReleaseComObject(thisRange);
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Funzione che scrive le informazioni nella cella indicata dai parametri in input.
        /// </summary>
        /// <param name="ws">Foglio a cui appartengono le celle da scrivere.</param>
        /// <param name="definedNames">Oggetto che contiene l'indirizzamento delle celle per il foglio su cui si sta lavorando.</param>
        /// <param name="siglaEntita">Sigla dell'entità su cui scrivere i dati.</param>
        /// <param name="info">DataRow contenente le informazioni da scrivere nella cella</param>
        /// <param name="suffissoData">Suffisso della data di riferimento necessario per l'indirizzamento.</param>
        /// <param name="suffissoOra">Suffisso dell'ora di riferimento necessario per l'indirizzamento.</param>
        /// <param name="risultato">Risultato del calcolo da scrivere nella cella.</param>
        /// <param name="saveToDB">Flag che indica se l'informazione deve essere salvata o no sul DB in modo da attivare la routine di salvataggio della modifica.</param>
        protected virtual void ScriviCella(Excel.Worksheet ws, DefinedNames definedNames, object siglaEntita, DataRowView info, string suffissoData, string suffissoOra, object risultato, bool saveToDB, bool fromCarica)
        {
            object siglaEntitaRif = siglaEntita;

            if (info.DataView.Table.Columns.Contains("SiglaEntitaRif") && info["SiglaEntitaRif"] != DBNull.Value)
            {
                siglaEntitaRif = info["SiglaEntitaRif"];
            }

            Range rng = definedNames.Get(siglaEntitaRif, info["SiglaInformazione"], suffissoData, suffissoOra);

            Excel.Range xlRng = ws.Range[rng.ToString()];

            xlRng.Value = risultato;

            if (info["BackColor"] != DBNull.Value)
            {
                xlRng.Interior.ColorIndex = info["BackColor"];
            }
            if (info["ForeColor"] != DBNull.Value)
            {
                xlRng.Font.ColorIndex = info["ForeColor"];
            }

            xlRng.ClearComments();

            if (info["Commento"] != DBNull.Value)
            {
                xlRng.AddComment(info["Commento"]).Visible = false;
            }

            if (saveToDB && !fromCarica)
            {
                Handler.StoreEdit(xlRng, 0, true);
            }
        }
Exemple #6
0
        private Boolean RefreshSheet(CellUpdate uc)
        {
            Excel.Worksheet ws        = null;
            Excel.Range     thisRange = null;
            Excel.Comment   comment   = null;

            try
            {
                ws = GlobalFunctions.findWorksheetByName(uc.Worksheet);
                if (ws == null)
                {
                    throw new Exception("Worksheet not found: " + uc.Worksheet);
                }

                GlobalFunctions.WaitForApplicationReady();
                thisRange = GlobalFunctions.createRange(ws, uc.Row, uc.Col);
                if (thisRange != null)
                {
                    CellUpdate oldCell = new CellUpdate(thisRange, uc.TypeEnum);
                    if (!uc.Equals(oldCell))
                    {
                        switch (uc.TypeEnum)
                        {
                        case Enums.CellChangeType.Value:
                            thisRange.Formula = uc.val;
                            break;

                        case Enums.CellChangeType.Comment:
                            comment = thisRange.Comment;
                            if (comment == null)
                            {
                                thisRange.AddComment(uc.val);
                            }
                            else
                            {
                                if (String.IsNullOrEmpty(uc.val))
                                {
                                    thisRange.ClearComments();
                                }
                                else
                                {
                                    comment.Text(uc.val);
                                }
                            }
                            break;
                        }
                    }
                    GlobalFunctions.InfoLog("Received", uc);
                    //RefreshedCell rc = new RefreshedCell(thisRange, uc, oldCell.val);
                    //RefreshedCell rc = new RefreshedCell(thisRange, uc, "");
                    Vars.LatestUpdateTime = GlobalFunctions.MaxDate(Vars.LatestUpdateTime, uc.changeTime.AddSeconds(-1));
                }
                else
                {
                    Marshal.ReleaseComObject(thisRange);
                }

                return(true);
            }
            catch (Exception ex)
            {
                GlobalFunctions.ErrorLog(ex, uc);
                throw ex;
            }
            finally
            {
                if (thisRange != null)
                {
                    Marshal.ReleaseComObject(thisRange);
                }
                if (ws != null)
                {
                    Marshal.ReleaseComObject(ws);
                }
            }
        }
 public void AddComment(Excel.Range c)
 {
     c.ClearComments();
     c.AddComment(NameInfo + "\n" + DisplayInfo);
 }