예제 #1
0
        private void ColorCell(Smell smell)
        {
            if (!smell.IsCellBased())
            {
                return;
            }

            try
            {
                var cell = (smell.SourceType == RiskSourceType.SiblingClass) ? ((SiblingClass)smell.Source).Cells[0] : (Cell)smell.Source;

                var excelCell = addIn.Application.Sheets[cell.Worksheet.Name].Cells[cell.Location.Row + 1, cell.Location.Column + 1];

                var smellyCell = new HighlightedCell(excelCell, excelCell.Interior.Pattern, excelCell.Interior.Color, excelCell.Comment);
                smellyCell.Apply(smell);
                if (!smellyCells.Any(x => x.Equals(smellyCell)))
                {
                    smellyCells.Add(smellyCell);
                }
            }
            catch (Exception)
            {
                // ignored
            }
        }
예제 #2
0
 private void applyInRange(FSharpTransformationRule T, ExcelRaw.Range Range, bool previewOnly = false)
 {
     foreach (ExcelRaw.Range cell in Range.Cells)
     {
         if ((bool)cell.HasFormula)
         {
             var Formula = RemoveFirstSymbol((string)cell.Formula);
             if (T.CanBeAppliedonBool(Formula))
             {
                 if (previewOnly)
                 {
                     var transformationCell = new HighlightedCell(cell, cell.Interior.Pattern, cell.Interior.Color, cell.Comment);
                     cell.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow);
                     if (!transformationCells.Any(x => x.Equals(transformationCell)))
                     {
                         transformationCells.Add(transformationCell);
                     }
                 }
                 else
                 {
                     var transformedFormula = T.ApplyOn(Formula);
                     if (valueChanges(cell, transformedFormula))
                     {
                         if (MessageBox.Show("The transformation causes the value of cell " +
                                             cell.Worksheet.Name + ":" + cell.get_Address(false, false, Microsoft.Office.Interop.Excel.XlReferenceStyle.xlA1) +
                                             " to change from " + cell.Value + " to " + getValue(cell, transformedFormula) +
                                             ". Do you want to continue?",
                                             "Alert: Cell value change",
                                             MessageBoxButtons.YesNo,
                                             MessageBoxIcon.Warning)
                             == DialogResult.No)
                         {
                             return;
                         }
                     }
                     cell.Formula        = "=" + transformedFormula;
                     cell.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Green);
                 }
             }
         }
     }
 }