FormBaseVM.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. using ComPDFKitViewer;
  2. using PDF_Office.Model.From;
  3. using Prism.Mvvm;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Media;
  10. using System.Windows;
  11. using PDF_Office.CustomControl.CompositeControl;
  12. using ComPDFKit.PDFAnnotation;
  13. using PDF_Office.Helper;
  14. namespace PDF_Office.ViewModels.Form
  15. {
  16. public class FormBaseVM : BindableBase
  17. {
  18. #region 变量
  19. public UpdateAttributeHelper AttribEvent;
  20. public bool IsCurrentWidget = false;
  21. public bool isCreateWidget = false;
  22. #endregion
  23. #region 一般
  24. //名称
  25. private string _fieldName;
  26. public string FieldName
  27. {
  28. get { return _fieldName; }
  29. set { SetProperty(ref _fieldName, value); ChangeValue(AnnotAttrib.FieldName, value); }
  30. }
  31. //提示
  32. private string _toolTipStr;
  33. public string ToolTipStr
  34. {
  35. get { return _toolTipStr; }
  36. set { SetProperty(ref _toolTipStr, value); ChangeValue(AnnotAttrib.Tooltip, value); }
  37. }
  38. //表单域
  39. private FormFieldType _formField;
  40. public FormFieldType FormField
  41. {
  42. get { return _formField; }
  43. set { SetProperty(ref _formField, value); ChangeValue(AnnotAttrib.FormField, value); }
  44. }
  45. //只读
  46. public bool _isReadOnly = false;
  47. public bool IsReadOnly
  48. {
  49. get { return _isReadOnly; }
  50. set { SetProperty(ref _isReadOnly, value); ChangeValue(AnnotAttrib.ReadOnly, value); }
  51. }
  52. //必填
  53. public bool _isRequiredField = false;
  54. public bool IsRequiredField
  55. {
  56. get { return _isRequiredField; }
  57. set { SetProperty(ref _isRequiredField, value); ChangeValue(AnnotAttrib.IsRequired, value); }
  58. }
  59. //锁定
  60. public bool _isLocked = false;
  61. public bool IsLocked
  62. {
  63. get { return _isLocked; }
  64. set { SetProperty(ref _isLocked, value); ChangeValue(AnnotAttrib.Locked, value); }
  65. }
  66. #endregion
  67. #region 外观
  68. #region 四个选项:颜色样式
  69. private ResetColor _resetColorOne = new ResetColor();
  70. public ResetColor ResetColorOne
  71. {
  72. get { return _resetColorOne; }
  73. set { SetProperty(ref _resetColorOne, value); }
  74. }
  75. private ResetColor _resetColorTwo = new ResetColor();
  76. public ResetColor ResetColorTwo
  77. {
  78. get { return _resetColorTwo; }
  79. set { SetProperty(ref _resetColorTwo, value); }
  80. }
  81. private ResetColor _resetColorThree = new ResetColor();
  82. public ResetColor ResetColorThree
  83. {
  84. get { return _resetColorThree; }
  85. set { SetProperty(ref _resetColorThree, value); }
  86. }
  87. private ResetColor _resetColorForth = new ResetColor();
  88. public ResetColor ResetColorForth
  89. {
  90. get { return _resetColorForth; }
  91. set { SetProperty(ref _resetColorForth, value); }
  92. }
  93. #endregion
  94. //边框颜色
  95. private Color _borderColor = Colors.Transparent;
  96. public Color BorderColor
  97. {
  98. get { return _borderColor; }
  99. set { SetProperty(ref _borderColor, value); ChangeValue(AnnotAttrib.Color, value); }
  100. }
  101. //内容颜色
  102. private Color _contentColor = Colors.Transparent;
  103. public Color ContentColor
  104. {
  105. get { return _contentColor; }
  106. set { SetProperty(ref _contentColor, value); ChangeValue(AnnotAttrib.FontColor, value); }
  107. }
  108. //填充颜色
  109. private Color _fillColor = Colors.Transparent;
  110. public Color FillColor
  111. {
  112. get { return _fillColor; }
  113. set { SetProperty(ref _fillColor, value); ChangeValue(AnnotAttrib.FillColor, value); }
  114. }
  115. //边框大小
  116. private double _borderThiness = 0;
  117. public double BorderThiness
  118. {
  119. get { return _borderThiness; }
  120. set { SetProperty(ref _borderThiness, value); ChangeValue(AnnotAttrib.Thickness, value); }
  121. }
  122. //是否为实线条
  123. private bool _isSolid = true;
  124. public bool IsSolid
  125. {
  126. get { return _isSolid; }
  127. set { SetProperty(ref _isSolid, value); }
  128. }
  129. //线条样式
  130. private ComPDFKit.PDFAnnotation.C_BORDER_STYLE _borderStyle = ComPDFKit.PDFAnnotation.C_BORDER_STYLE.BS_SOLID;
  131. public ComPDFKit.PDFAnnotation.C_BORDER_STYLE BorderStyle
  132. {
  133. get { return _borderStyle; }
  134. set {
  135. SetProperty(ref _borderStyle, value);
  136. if (value == ComPDFKit.PDFAnnotation.C_BORDER_STYLE.BS_SOLID)
  137. IsSolid = true;
  138. else
  139. IsSolid = false;
  140. ChangeValue(AnnotAttrib.LineStyle, value);
  141. }
  142. }
  143. private ComboDataItem _fontFamilyData;
  144. public ComboDataItem FontFamilyData
  145. {
  146. get { return _fontFamilyData; }
  147. set
  148. {
  149. SetProperty(ref _fontFamilyData, value);
  150. ChangeValue(AnnotAttrib.FontFamily, _fontFamilyData.ValueStr);
  151. }
  152. }
  153. private FontStyle _fontStyle;
  154. public FontStyle FontStyleItem
  155. {
  156. get { return _fontStyle; }
  157. set { SetProperty(ref _fontStyle, value); ChangeValue(AnnotAttrib.FontStyle, value); }
  158. }
  159. private FontWeight _fontWeight;
  160. public FontWeight FontWeightItem
  161. {
  162. get { return _fontWeight; }
  163. set { SetProperty(ref _fontWeight, value); ChangeValue(AnnotAttrib.FontWeight, value); }
  164. }
  165. private ComboDataItem _fontWeightStyleItem;
  166. public ComboDataItem FontWeightStyleItem
  167. {
  168. get { return _fontWeightStyleItem; }
  169. set { SetProperty(ref _fontWeightStyleItem, value);
  170. if (_fontWeightStyleItem.ValueStr != null && string.IsNullOrEmpty((string)_fontWeightStyleItem.ValueStr) == false)
  171. {
  172. switch ((string)_fontWeightStyleItem.ValueStr)
  173. {
  174. case "Regular":
  175. FontStyleItem = FontStyles.Normal;
  176. FontWeightItem = FontWeights.Normal;
  177. break;
  178. case "Bold":
  179. FontStyleItem = FontStyles.Normal;
  180. FontWeightItem = FontWeights.Bold;
  181. break;
  182. case "Italic":
  183. FontStyleItem = FontStyles.Italic;
  184. FontWeightItem = FontWeights.Normal;
  185. break;
  186. case "Bold Italic":
  187. FontStyleItem = FontStyles.Italic;
  188. FontWeightItem = FontWeights.Bold;
  189. break;
  190. }
  191. }
  192. }
  193. }
  194. private ComboDataItem _fontSizeData = new ComboDataItem(6);
  195. public ComboDataItem FontSizeData
  196. {
  197. get { return _fontSizeData; }
  198. set { SetProperty(ref _fontSizeData, value);
  199. if(_fontSizeData != null)
  200. ChangeValue(AnnotAttrib.FontSize, (int)_fontSizeData.Value); }
  201. }
  202. //宽大小
  203. private double _widthSize = 150;
  204. public double WidthSize
  205. {
  206. get { return _widthSize; }
  207. set { SetProperty(ref _widthSize, value); ChangeValue(AnnotAttrib.Width, value); }
  208. }
  209. //高大小
  210. private double _heightSize = 22;
  211. public double HeightSize
  212. {
  213. get { return _heightSize; }
  214. set { SetProperty(ref _heightSize, value); ChangeValue(AnnotAttrib.Height, value); }
  215. }
  216. #endregion
  217. #region 选项
  218. private C_TEXT_ALIGNMENT _textAlignment;
  219. public C_TEXT_ALIGNMENT TextAlignmentItem
  220. {
  221. get { return _textAlignment; }
  222. set { SetProperty(ref _textAlignment, value); ChangeValue(AnnotAttrib.TextAlign, value); }
  223. }
  224. private ComboDataItem _fextAlignmentData = new ComboDataItem("Left", "Left");
  225. public ComboDataItem TextAlignmentData
  226. {
  227. get { return _fextAlignmentData; }
  228. set
  229. {
  230. SetProperty(ref _fextAlignmentData, value);
  231. if (_fextAlignmentData != null && string.IsNullOrEmpty(_fextAlignmentData.ValueStr) == false)
  232. {
  233. switch(_fextAlignmentData.ValueStr)
  234. {
  235. case "Left":
  236. TextAlignmentItem = C_TEXT_ALIGNMENT.ALIGNMENT_LEFT;
  237. break;
  238. case "Center":
  239. TextAlignmentItem = C_TEXT_ALIGNMENT.ALIGNMENT_CENTER;
  240. break;
  241. case "Right":
  242. TextAlignmentItem = C_TEXT_ALIGNMENT.ALIGNMENT_RIGHT;
  243. break;
  244. }
  245. }
  246. }
  247. }
  248. //内容
  249. private string _content;
  250. public string FormContent
  251. {
  252. get { return _content; }
  253. set { SetProperty(ref _content, value); ChangeValue(AnnotAttrib.Text, value); }
  254. }
  255. //默认值
  256. private string _defaultValue;
  257. public string DefaultValue
  258. {
  259. get { return _defaultValue; }
  260. set { SetProperty(ref _defaultValue, value); }
  261. }
  262. //多行
  263. private bool _isMultiline = false;
  264. public bool IsMultiLine
  265. {
  266. get { return _isMultiline; }
  267. set { SetProperty(ref _isMultiline, value); ChangeValue(AnnotAttrib.IsMutilLine, value); }
  268. }
  269. //滚动显示长文本
  270. private bool _isScrollText = false;
  271. public bool IsScrollText
  272. {
  273. get { return _isScrollText; }
  274. set { SetProperty(ref _isScrollText, value); ChangeValue(AnnotAttrib.ScrollFlag, value); }
  275. }
  276. //下拉框Form,
  277. private bool _isDefaultCheckBox = false;
  278. public bool IsDefaultCheckBox
  279. {
  280. get { return _isDefaultCheckBox; }
  281. set { SetProperty(ref _isDefaultCheckBox, value); ChangeValue(AnnotAttrib.IsChecked, value); }
  282. }
  283. //复选框的导出值
  284. private string _exportedValues;
  285. public string ExportedValues
  286. {
  287. get { return _exportedValues; }
  288. set { SetProperty(ref _exportedValues, value); ChangeValue(AnnotAttrib.ExportValue, value); }
  289. }
  290. //单选框Form,
  291. private bool _isDefaultRadioBox = false;
  292. public bool IsDefaultRadioBox
  293. {
  294. get { return _isDefaultRadioBox; }
  295. set { SetProperty(ref _isDefaultRadioBox, value); ChangeValue(AnnotAttrib.IsChecked, value); }
  296. }
  297. //复选框的导出值
  298. private string _radioMemberName;
  299. public string RadioMemberName
  300. {
  301. get { return _radioMemberName; }
  302. set { SetProperty(ref _radioMemberName, value); ChangeValue(AnnotAttrib.RadioMemberName, value); }
  303. }
  304. //Option
  305. //是否可以输入内容
  306. private bool _isInputOption = false;
  307. public bool IsInputOption
  308. {
  309. get { return _isInputOption; }
  310. set { SetProperty(ref _isInputOption, value); }
  311. }
  312. private bool _isUpOption = false;
  313. public bool IsUpOption
  314. {
  315. get { return _isUpOption; }
  316. set{ SetProperty(ref _isUpOption, value); }
  317. }
  318. private bool _isDownOption = false;
  319. public bool IsDownOption
  320. {
  321. get { return _isDownOption; }
  322. set { SetProperty(ref _isDownOption, value); }
  323. }
  324. private bool _isRemoveOption = false;
  325. public bool IsRemoveOption
  326. {
  327. get { return _isRemoveOption; }
  328. set { SetProperty(ref _isRemoveOption, value); }
  329. }
  330. public int OptionSelectedIndex = -1;
  331. private string _optionKey;
  332. public string OptionKey
  333. {
  334. get { return _optionKey; }
  335. set { SetProperty(ref _optionKey, value); }
  336. }
  337. private string _optionKeyValue;
  338. public string OptionKeyValue
  339. {
  340. get { return _optionKeyValue; }
  341. set { SetProperty(ref _optionKeyValue, value); }
  342. }
  343. private Dictionary<string, string> _optionsList;
  344. public Dictionary<string, string> OptionsList
  345. {
  346. get { return _optionsList; }
  347. set { SetProperty(ref _optionsList, value); }
  348. }
  349. #endregion
  350. public void ChangeValue(AnnotAttrib annotAttrib,object obj)
  351. {
  352. if(AttribEvent != null && IsCurrentWidget && AttribEvent.IsCreateForm() == false)
  353. {
  354. AttribEvent.UpdateAttrib(annotAttrib, obj);
  355. AttribEvent.UpdateAnnot();
  356. }
  357. }
  358. #region
  359. public ResetColor InitResetColor(Color border, Color font, Color fill)
  360. {
  361. return new ResetColor()
  362. {
  363. BorderColor = new SolidColorBrush(border),
  364. FontColor = new SolidColorBrush(font),
  365. FillColor = new SolidColorBrush(fill)
  366. };
  367. }
  368. //退出或切换属性面板,清除数据
  369. public void ClearVMData()
  370. {
  371. isCreateWidget = false;
  372. IsCurrentWidget = false;
  373. OptionsList = null;
  374. IsRemoveOption = false;
  375. IsInputOption = false;
  376. IsUpOption = false;
  377. IsDownOption = false;
  378. OptionSelectedIndex = -1;
  379. OptionKey = "";
  380. OptionKeyValue = "";
  381. }
  382. #endregion
  383. }
  384. public class ResetColor : BindableBase
  385. {
  386. private SolidColorBrush _borderColor;
  387. public SolidColorBrush BorderColor
  388. {
  389. get { return _borderColor; }
  390. set { SetProperty(ref _borderColor, value); }
  391. }
  392. private SolidColorBrush _fontColor;
  393. public SolidColorBrush FontColor
  394. {
  395. get { return _fontColor; }
  396. set { SetProperty(ref _fontColor, value); }
  397. }
  398. private SolidColorBrush _fillColor;
  399. public SolidColorBrush FillColor
  400. {
  401. get { return _fillColor; }
  402. set { SetProperty(ref _fillColor, value); }
  403. }
  404. }
  405. }