Beispiel #1
0
        private void InsertAttribute(object sender, EventArgs e)
        {
#if f
            var o = AttributeListBox.SelectedValue as DataRowView;
            SelectedAttribute = new Attribute
            {
                Table    = o[0].ToString(),
                Name     = o[2].ToString(),
                Property = o[3].ToString().GetHashString()
                           //FPath = o[3].ToString().GetHashString()
            };
            Word.Range currentRange = Globals.ThisAddIn.Application.Selection.Range;

            var attribute = SelectedAttribute;

            try
            {
                var placeholder = extendedDocument.Controls.AddPlainTextContentControl(currentRange, attribute.Name);

                placeholder.PlaceholderText = attribute.Name;
                placeholder.Tag             = /*attribute.Table + @"\" + */ attribute.Property;
                placeholder.LockContents    = true;
            }
            catch (COMException ex)
            {
                MessageBox.Show(ex.Message);
            }
#else
            var        attribute    = (AddInAttribute)AttributeListBox.SelectedItem;
            Word.Range currentRange = Globals.ThisAddIn.Application.Selection.Range;

            try
            {
                var placeholder = extendedDocument.Controls.AddPlainTextContentControl(currentRange, (i++).ToString());

                placeholder.PlaceholderText = attribute.Alias;

                var entity = addInSchema.Entities.First(o => o.ID == EntityBox.SelectedValue);
                var attr   = entity.Attributes.First(o => o.ID == AttributeListBox.SelectedValue);
                var type   = addInSchema.Types.First(x => x.Name == attr.Type.Name);
                var format = type.GetAdmissableFormats().First(o => o.ID == FormatListBox.SelectedValue);
                //var format = Schema.GetType(attr.Type.Name).GetAdmissableFormats().First(o => o.ID == FormatListBox.SelectedValue);

                var idCreator = new UniqueIDCreator();
                placeholder.Tag = idCreator.Aggregate(entity, attr, format).ToString();

                placeholder.LockContents = true;
            }
            catch (COMException)
            {
                //MessageBox.Show("Не удаётся добавить выбранный аттрибут.", "Уведомление", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning);
                MessageBox.Show(this, "Выберите позицию для вставки аттрибута.", "Предупреждение",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
#endif
        }
Beispiel #2
0
        /// <summary>
        /// Доабвление атрибута сущности в документ.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void InsertAttribute(object sender, EventArgs e)
        {
            if (!CheckTemplateSheet())
            {
                MessageBox.Show("Нет сислиста!");
            }



            var r                        = ExcelApplication.ActiveCell;
            var addressCoords            = r.Address.Split('$').Where(x => x != "").ToArray();
            var insertCellAddress        = addressCoords[0].Trim(new char[] { ':', ' ' }) + "1";
            var templateAliasCellAddress = addressCoords[0].Trim(new char[] { ':', ' ' }) + "2";


            //var attribute = (Teleform.Reporting.Attribute)AttributeListBox.SelectedItem;
            //var entity = Schema.Entities.First(o => o.ID == EntityBox.SelectedValue);
            //var attr = entity.Attributes.First(o => o.ID == AttributeListBox.SelectedValue);
            //var format = Schema.GetType(attr.Type.Name).GetAdmissableFormats().First(o => o.ID == FormatListBox.SelectedValue);

            var attribute = (AddInAttribute)AttributeListBox.SelectedItem;

            var uidCreator = new UniqueIDCreator();

            var entity = AddInSchema.Entities.First(o => o.ID == EntityBox.SelectedValue);

            var attr = entity.Attributes.First(o => o.ID == AttributeListBox.SelectedValue);

            var format = AddInSchema.Types.First(o => o.Name == attr.Type.Name).GetAdmissableFormats().First(o => o.ID == FormatListBox.SelectedValue);

            var uid = uidCreator.Aggregate(entity, attr, format);

            ExcelApplication.ActiveSheet.Range(insertCellAddress).Value = attribute.Alias;
            this.TemplateSheet.Range(templateAliasCellAddress).Value    = attribute.Alias;
            this.TemplateSheet.Range(insertCellAddress).Value           = uid.ToString();
        }