Exemplo n.º 1
0
        /// <summary>
        /// Sets the Value Cell of a Shapesheet's Data Section at the given row
        /// name to the specified value. Also sets the Label Cell to given rowName.
        /// </summary>
        /// <param name="Shape">Shape to change.</param>
        /// <param name="rowIndex">Name of row within the Data Section.</param>
        /// <param name="value">Value to change the Value Cell to.</param>
        public static void setDataSectionValueCell(Visio.Shape Shape, string rowName, string value)
        {
            // Row Names can only contain a-z, A-Z, 0-9, or _
            rowName = spaceToUnderscore(rowName);

            // Name of the Value Cell in the Shapesheet
            string cellName = "Prop." + rowName + ".Value";

            short rowIndex;
            // Return value of == 0 means cell (and thus, the row) doesn't exist.
            short cellExists = Shape.get_CellExists(cellName, 0);

            if (cellExists == 0)
            {
                rowIndex = Shape.AddNamedRow(CaseTypes.SHAPE_DATA_SECTION, rowName,
                                             (short)Visio.VisRowTags.visTagDefault);
            }
            else
            {
                rowIndex = Shape.get_CellsRowIndex(cellName);
            }

            Visio.Cell valueCell = Shape.get_CellsSRC(CaseTypes.SHAPE_DATA_SECTION,
                                                      rowIndex, CaseTypes.DS_VALUE_CELL);

            valueCell.Formula = '"' + value + '"';

            Visio.Cell labelCell = Shape.get_CellsSRC(CaseTypes.SHAPE_DATA_SECTION,
                                                      rowIndex, CaseTypes.DS_LABEL_CELL);

            labelCell.Formula = '"' + rowName + '"';
        }
        public static void Set(IVisio.Shape shape, string name, UserDefinedCellCells cells)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException(nameof(shape));
            }

            if (cells == null)
            {
                throw new System.ArgumentNullException(nameof(cells));
            }

            UserDefinedCellHelper.CheckValidName(name);

            if (UserDefinedCellHelper.Contains(shape, name))
            {
                // The user-defined cell already exists
                string full_udcell_name = UserDefinedCellHelper.__GetRowName(name);

                if (cells.Value.HasValue)
                {
                    string value_cell_name = full_udcell_name;
                    var    cell            = shape.CellsU[value_cell_name];
                    cell.FormulaU = cells.Value.Value;
                }

                if (cells.Prompt.HasValue)
                {
                    string prompt_cell_name = full_udcell_name + ".Prompt";
                    var    cell             = shape.CellsU[prompt_cell_name];
                    cell.FormulaU = cells.Prompt.Value;
                }
            }
            else
            {
                // The user-defined cell doesn't already exist
                short row        = shape.AddNamedRow(_udcell_section, name, (short)IVisio.VisRowIndices.visRowUser);
                var   src_value  = new ShapeSheet.Src(_udcell_section, row, (short)IVisio.VisCellIndices.visUserValue);
                var   src_prompt = new ShapeSheet.Src(_udcell_section, row, (short)IVisio.VisCellIndices.visUserPrompt);

                var writer = new VisioAutomation.ShapeSheet.Writers.SrcWriter();

                if (cells.Value.HasValue)
                {
                    writer.SetValue(src_value, cells.Value.Value);
                }

                if (cells.Prompt.HasValue)
                {
                    writer.SetValue(src_prompt, cells.Prompt.Value);
                }

                writer.CommitFormulas(shape);
            }
        }
Exemplo n.º 3
0
        public static void Set(IVisio.Shape shape, string name, string value, string prompt)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException("shape");
            }

            CheckValidName(name);

            if (Contains(shape, name))
            {
                string full_prop_name = GetRowName(name);

                if (value != null)
                {
                    string value_cell_name = full_prop_name;
                    var    cell            = shape.CellsU[value_cell_name];
                    string value_formula   = Convert.StringToFormulaString(value);
                    cell.FormulaU = value_formula;
                }

                if (prompt != null)
                {
                    string prompt_cell_name = full_prop_name + ".Prompt";
                    var    cell             = shape.CellsU[prompt_cell_name];
                    var    prompt_formula   = Convert.StringToFormulaString(prompt);
                    cell.FormulaU = prompt_formula;
                }
                return;
            }

            short row = shape.AddNamedRow(
                _userdefinedcell_section,
                name,
                (short)IVisio.VisRowIndices.visRowUser);

            var update = new VA.ShapeSheet.Update();

            if (value != null)
            {
                string value_formula = Convert.StringToFormulaString(value);
                var    src           = new VA.ShapeSheet.SRC(_userdefinedcell_section, row, (short)IVisio.VisCellIndices.visUserValue);
                update.SetFormula(src, value_formula);
            }

            if (prompt != null)
            {
                string prompt_formula = Convert.StringToFormulaString(prompt);
                var    src            = new VA.ShapeSheet.SRC(_userdefinedcell_section, row, (short)IVisio.VisCellIndices.visUserPrompt);
                update.SetFormula(src, prompt_formula);
            }

            update.Execute(shape);
        }
Exemplo n.º 4
0
        public static void Set(IVisio.Shape shape, string name, ShapeSheet.CellValueLiteral udfcell_value, ShapeSheet.CellValueLiteral udfcell_prompt)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException(nameof(shape));
            }

            UserDefinedCellHelper.CheckValidName(name);

            if (UserDefinedCellHelper.Contains(shape, name))
            {
                string full_prop_name = UserDefinedCellHelper.GetRowName(name);

                if (udfcell_value.HasValue)
                {
                    string value_cell_name = full_prop_name;
                    var    cell            = shape.CellsU[value_cell_name];
                    cell.FormulaU = VisioAutomation.Utilities.Convert.StringToFormulaString(udfcell_value.Value);
                }

                if (udfcell_prompt.HasValue)
                {
                    string prompt_cell_name = full_prop_name + ".Prompt";
                    var    cell             = shape.CellsU[prompt_cell_name];
                    cell.FormulaU = VisioAutomation.Utilities.Convert.StringToFormulaString(udfcell_prompt.Value);
                }
                return;
            }

            short row = shape.AddNamedRow(
                UserDefinedCellHelper._userdefinedcell_section,
                name,
                (short)IVisio.VisRowIndices.visRowUser);

            var writer = new VisioAutomation.ShapeSheet.Writers.SrcWriter();

            if (udfcell_value.HasValue)
            {
                var src     = new ShapeSheet.Src(UserDefinedCellHelper._userdefinedcell_section, row, (short)IVisio.VisCellIndices.visUserValue);
                var formula = VisioAutomation.Utilities.Convert.StringToFormulaString(udfcell_value.Value);
                writer.SetFormula(src, formula);
            }

            if (udfcell_prompt.HasValue)
            {
                var src     = new ShapeSheet.Src(UserDefinedCellHelper._userdefinedcell_section, row, (short)IVisio.VisCellIndices.visUserPrompt);
                var formula = VisioAutomation.Utilities.Convert.StringToFormulaString(udfcell_prompt.Value);
                writer.SetFormula(src, formula);
            }

            writer.Commit(shape);
        }
        public static void Set(IVisio.Shape shape, string name, ShapeSheet.FormulaLiteral value, ShapeSheet.FormulaLiteral prompt)
        {
            if (shape == null)
            {
                throw new System.ArgumentNullException(nameof(shape));
            }

            UserDefinedCellHelper.CheckValidName(name);

            if (UserDefinedCellHelper.Contains(shape, name))
            {
                string full_prop_name = UserDefinedCellHelper.GetRowName(name);

                if (value.HasValue)
                {
                    string value_cell_name = full_prop_name;
                    var    cell            = shape.CellsU[value_cell_name];
                    cell.FormulaU = value.Encode();
                }

                if (prompt.HasValue)
                {
                    string prompt_cell_name = full_prop_name + ".Prompt";
                    var    cell             = shape.CellsU[prompt_cell_name];
                    cell.FormulaU = prompt.Encode();
                }
                return;
            }

            short row = shape.AddNamedRow(
                UserDefinedCellHelper._userdefinedcell_section,
                name,
                (short)IVisio.VisRowIndices.visRowUser);

            var writer = new FormulaWriterSRC();

            if (value.HasValue)
            {
                var src = new ShapeSheet.SRC(UserDefinedCellHelper._userdefinedcell_section, row, (short)IVisio.VisCellIndices.visUserValue);
                writer.SetFormula(src, value.Encode());
            }

            if (prompt.HasValue)
            {
                var src = new ShapeSheet.SRC(UserDefinedCellHelper._userdefinedcell_section, row, (short)IVisio.VisCellIndices.visUserPrompt);
                writer.SetFormula(src, prompt.Encode());
            }

            writer.Commit(shape);
        }
        public static void Set(
            IVisio.Shape shape,
            string name,
            CustomPropertyCells cp)
        {
            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            CustomPropertyHelper.__CheckValidCustomPropertyName(name);

            if (CustomPropertyHelper.Contains(shape, name))
            {
                string full_prop_name = CustomPropertyHelper.__GetRowName(name);
                var    cell_propname  = shape.CellsU[full_prop_name];

                if (cell_propname == null)
                {
                    string msg = string.Format("Could not retrieve cell for custom property \"{0}\"", full_prop_name);
                    throw new Exceptions.InternalAssertionException(msg);
                }

                var writer = new VisioAutomation.ShapeSheet.Writers.SrcWriter();
                writer.SetValues(cp, cell_propname.Row);

                writer.CommitFormulas(shape);

                return;
            }

            short row = shape.AddNamedRow(
                vis_sec_prop,
                name,
                (short)IVisio.VisRowIndices.visRowProp);

            CustomPropertyHelper.Set(shape, row, cp);
        }
Exemplo n.º 7
0
        public static void Set(
            IVisio.Shape shape,
            string name,
            CustomPropertyCells cp)
        {
            if (shape == null)
            {
                throw new ArgumentNullException("shape");
            }

            CheckValidCustomPropertyName(name);

            if (Contains(shape, name))
            {
                string full_prop_name = GetRowName(name);
                var    cell_propname  = shape.CellsU[full_prop_name];

                if (cell_propname == null)
                {
                    string msg = String.Format("Could not retrieve cell for custom property \"{0}\"", full_prop_name);
                    throw new AutomationException(msg);
                }

                var update = new ShapeSheet.Update();
                update.SetFormulas(cp, cell_propname.Row);
                update.Execute(shape);

                return;
            }

            short row = shape.AddNamedRow(
                (short)IVisio.VisSectionIndices.visSectionProp,
                name,
                (short)IVisio.VisRowIndices.visRowProp);

            Set(shape, row, cp);
        }