using ComPDFKitViewer; using PDF_Office.Model.From; using Prism.Mvvm; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Media; using System.Windows; using PDF_Office.CustomControl.CompositeControl; using ComPDFKit.PDFAnnotation; using PDF_Office.Helper; namespace PDF_Office.ViewModels.Form { public class FormBaseVM : BindableBase { #region 变量 public UpdateAttributeHelper AttribEvent; public bool IsCurrentWidget = false; public bool isCreateWidget = false; #endregion #region 一般 //名称 private string _fieldName; public string FieldName { get { return _fieldName; } set { SetProperty(ref _fieldName, value); ChangeValue(AnnotAttrib.FieldName, value); } } //提示 private string _toolTipStr; public string ToolTipStr { get { return _toolTipStr; } set { SetProperty(ref _toolTipStr, value); ChangeValue(AnnotAttrib.Tooltip, value); } } //表单域 private FormFieldType _formField; public FormFieldType FormField { get { return _formField; } set { SetProperty(ref _formField, value); ChangeValue(AnnotAttrib.FormField, value); } } //只读 public bool _isReadOnly = false; public bool IsReadOnly { get { return _isReadOnly; } set { SetProperty(ref _isReadOnly, value); ChangeValue(AnnotAttrib.ReadOnly, value); } } //必填 public bool _isRequiredField = false; public bool IsRequiredField { get { return _isRequiredField; } set { SetProperty(ref _isRequiredField, value); ChangeValue(AnnotAttrib.IsRequired, value); } } //锁定 public bool _isLocked = false; public bool IsLocked { get { return _isLocked; } set { SetProperty(ref _isLocked, value); ChangeValue(AnnotAttrib.Locked, value); } } #endregion #region 外观 #region 四个选项:颜色样式 private ResetColor _resetColorOne = new ResetColor(); public ResetColor ResetColorOne { get { return _resetColorOne; } set { SetProperty(ref _resetColorOne, value); } } private ResetColor _resetColorTwo = new ResetColor(); public ResetColor ResetColorTwo { get { return _resetColorTwo; } set { SetProperty(ref _resetColorTwo, value); } } private ResetColor _resetColorThree = new ResetColor(); public ResetColor ResetColorThree { get { return _resetColorThree; } set { SetProperty(ref _resetColorThree, value); } } private ResetColor _resetColorForth = new ResetColor(); public ResetColor ResetColorForth { get { return _resetColorForth; } set { SetProperty(ref _resetColorForth, value); } } #endregion //边框颜色 private Color _borderColor = Colors.Transparent; public Color BorderColor { get { return _borderColor; } set { SetProperty(ref _borderColor, value); ChangeValue(AnnotAttrib.Color, value); } } //内容颜色 private Color _contentColor = Colors.Transparent; public Color ContentColor { get { return _contentColor; } set { SetProperty(ref _contentColor, value); ChangeValue(AnnotAttrib.FontColor, value); } } //填充颜色 private Color _fillColor = Colors.Transparent; public Color FillColor { get { return _fillColor; } set { SetProperty(ref _fillColor, value); ChangeValue(AnnotAttrib.FillColor, value); } } //边框大小 private double _borderThiness = 0; public double BorderThiness { get { return _borderThiness; } set { SetProperty(ref _borderThiness, value); ChangeValue(AnnotAttrib.Thickness, value); } } //是否为实线条 private bool _isSolid = true; public bool IsSolid { get { return _isSolid; } set { SetProperty(ref _isSolid, value); } } //线条样式 private ComPDFKit.PDFAnnotation.C_BORDER_STYLE _borderStyle = ComPDFKit.PDFAnnotation.C_BORDER_STYLE.BS_SOLID; public ComPDFKit.PDFAnnotation.C_BORDER_STYLE BorderStyle { get { return _borderStyle; } set { SetProperty(ref _borderStyle, value); if (value == ComPDFKit.PDFAnnotation.C_BORDER_STYLE.BS_SOLID) IsSolid = true; else IsSolid = false; ChangeValue(AnnotAttrib.LineStyle, value); } } private ComboDataItem _fontFamilyData; public ComboDataItem FontFamilyData { get { return _fontFamilyData; } set { SetProperty(ref _fontFamilyData, value); ChangeValue(AnnotAttrib.FontFamily, _fontFamilyData.ValueStr); } } private FontStyle _fontStyle; public FontStyle FontStyleItem { get { return _fontStyle; } set { SetProperty(ref _fontStyle, value); ChangeValue(AnnotAttrib.FontStyle, value); } } private FontWeight _fontWeight; public FontWeight FontWeightItem { get { return _fontWeight; } set { SetProperty(ref _fontWeight, value); ChangeValue(AnnotAttrib.FontWeight, value); } } private ComboDataItem _fontWeightStyleItem; public ComboDataItem FontWeightStyleItem { get { return _fontWeightStyleItem; } set { SetProperty(ref _fontWeightStyleItem, value); if (_fontWeightStyleItem.ValueStr != null && string.IsNullOrEmpty((string)_fontWeightStyleItem.ValueStr) == false) { switch ((string)_fontWeightStyleItem.ValueStr) { case "Regular": FontStyleItem = FontStyles.Normal; FontWeightItem = FontWeights.Normal; break; case "Bold": FontStyleItem = FontStyles.Normal; FontWeightItem = FontWeights.Bold; break; case "Italic": FontStyleItem = FontStyles.Italic; FontWeightItem = FontWeights.Normal; break; case "Bold Italic": FontStyleItem = FontStyles.Italic; FontWeightItem = FontWeights.Bold; break; } } } } private ComboDataItem _fontSizeData = new ComboDataItem(6); public ComboDataItem FontSizeData { get { return _fontSizeData; } set { SetProperty(ref _fontSizeData, value); if(_fontSizeData != null) ChangeValue(AnnotAttrib.FontSize, (int)_fontSizeData.Value); } } //宽大小 private double _widthSize = 150; public double WidthSize { get { return _widthSize; } set { SetProperty(ref _widthSize, value); ChangeValue(AnnotAttrib.Width, value); } } //高大小 private double _heightSize = 22; public double HeightSize { get { return _heightSize; } set { SetProperty(ref _heightSize, value); ChangeValue(AnnotAttrib.Height, value); } } #endregion #region 选项 private C_TEXT_ALIGNMENT _textAlignment; public C_TEXT_ALIGNMENT TextAlignmentItem { get { return _textAlignment; } set { SetProperty(ref _textAlignment, value); ChangeValue(AnnotAttrib.TextAlign, value); } } private ComboDataItem _fextAlignmentData = new ComboDataItem("Left", "Left"); public ComboDataItem TextAlignmentData { get { return _fextAlignmentData; } set { SetProperty(ref _fextAlignmentData, value); if (_fextAlignmentData != null && string.IsNullOrEmpty(_fextAlignmentData.ValueStr) == false) { switch(_fextAlignmentData.ValueStr) { case "Left": TextAlignmentItem = C_TEXT_ALIGNMENT.ALIGNMENT_LEFT; break; case "Center": TextAlignmentItem = C_TEXT_ALIGNMENT.ALIGNMENT_CENTER; break; case "Right": TextAlignmentItem = C_TEXT_ALIGNMENT.ALIGNMENT_RIGHT; break; } } } } //内容 private string _content; public string FormContent { get { return _content; } set { SetProperty(ref _content, value); ChangeValue(AnnotAttrib.Text, value); } } //默认值 private string _defaultValue; public string DefaultValue { get { return _defaultValue; } set { SetProperty(ref _defaultValue, value); } } //多行 private bool _isMultiline = false; public bool IsMultiLine { get { return _isMultiline; } set { SetProperty(ref _isMultiline, value); ChangeValue(AnnotAttrib.IsMutilLine, value); } } //滚动显示长文本 private bool _isScrollText = false; public bool IsScrollText { get { return _isScrollText; } set { SetProperty(ref _isScrollText, value); ChangeValue(AnnotAttrib.ScrollFlag, value); } } //下拉框Form, private bool _isDefaultCheckBox = false; public bool IsDefaultCheckBox { get { return _isDefaultCheckBox; } set { SetProperty(ref _isDefaultCheckBox, value); ChangeValue(AnnotAttrib.IsChecked, value); } } //复选框的导出值 private string _exportedValues; public string ExportedValues { get { return _exportedValues; } set { SetProperty(ref _exportedValues, value); ChangeValue(AnnotAttrib.ExportValue, value); } } //单选框Form, private bool _isDefaultRadioBox = false; public bool IsDefaultRadioBox { get { return _isDefaultRadioBox; } set { SetProperty(ref _isDefaultRadioBox, value); ChangeValue(AnnotAttrib.IsChecked, value); } } //复选框的导出值 private string _radioMemberName; public string RadioMemberName { get { return _radioMemberName; } set { SetProperty(ref _radioMemberName, value); ChangeValue(AnnotAttrib.RadioMemberName, value); } } #endregion private void ChangeValue(AnnotAttrib annotAttrib,object obj) { if(AttribEvent != null && IsCurrentWidget && AttribEvent.IsCreateForm() == false) { AttribEvent.UpdateAttrib(annotAttrib, obj); AttribEvent.UpdateAnnot(); } } #region public ResetColor InitResetColor(Color border, Color font, Color fill) { return new ResetColor() { BorderColor = new SolidColorBrush(border), FontColor = new SolidColorBrush(font), FillColor = new SolidColorBrush(fill) }; } #endregion } public class ResetColor : BindableBase { private SolidColorBrush _borderColor; public SolidColorBrush BorderColor { get { return _borderColor; } set { SetProperty(ref _borderColor, value); } } private SolidColorBrush _fontColor; public SolidColorBrush FontColor { get { return _fontColor; } set { SetProperty(ref _fontColor, value); } } private SolidColorBrush _fillColor; public SolidColorBrush FillColor { get { return _fillColor; } set { SetProperty(ref _fillColor, value); } } } }