FormBaseVM.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. using ComPDFKitViewer;
  2. using PDF_Master.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_Master.CustomControl.CompositeControl;
  12. using ComPDFKit.PDFAnnotation;
  13. using PDF_Master.Helper;
  14. namespace PDF_Master.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.FontName, _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.IsItalic, value==FontStyles.Italic); }
  158. }
  159. private FontWeight _fontWeight;
  160. public FontWeight FontWeightItem
  161. {
  162. get { return _fontWeight; }
  163. set { SetProperty(ref _fontWeight, value); ChangeValue(AnnotAttrib.IsBold, value==FontWeights.Bold); }
  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); if (isNoUpdateValue == false) 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);if (isNoUpdateValue == false) ChangeValue(AnnotAttrib.Height, value); }
  215. }
  216. private bool isNoUpdateValue = false;
  217. public void SetSizeNoUpdateValue(double width, double height)
  218. {
  219. isNoUpdateValue = true;
  220. WidthSize = width;
  221. HeightSize = height;
  222. isNoUpdateValue = false;
  223. }
  224. #endregion
  225. #region 选项
  226. private C_TEXT_ALIGNMENT _textAlignment;
  227. public C_TEXT_ALIGNMENT TextAlignmentItem
  228. {
  229. get { return _textAlignment; }
  230. set { SetProperty(ref _textAlignment, value); ChangeValue(AnnotAttrib.TextAlign, value); }
  231. }
  232. private ComboDataItem _fextAlignmentData = new ComboDataItem("Left", "Left");
  233. public ComboDataItem TextAlignmentData
  234. {
  235. get { return _fextAlignmentData; }
  236. set
  237. {
  238. SetProperty(ref _fextAlignmentData, value);
  239. if (_fextAlignmentData != null && string.IsNullOrEmpty(_fextAlignmentData.ValueStr) == false)
  240. {
  241. switch(_fextAlignmentData.ValueStr)
  242. {
  243. case "Left":
  244. TextAlignmentItem = C_TEXT_ALIGNMENT.ALIGNMENT_LEFT;
  245. break;
  246. case "Center":
  247. TextAlignmentItem = C_TEXT_ALIGNMENT.ALIGNMENT_CENTER;
  248. break;
  249. case "Right":
  250. TextAlignmentItem = C_TEXT_ALIGNMENT.ALIGNMENT_RIGHT;
  251. break;
  252. }
  253. }
  254. }
  255. }
  256. //内容
  257. private string _content;
  258. public string FormContent
  259. {
  260. get { return _content; }
  261. set { SetProperty(ref _content, value); ChangeValue(AnnotAttrib.Text, value); }
  262. }
  263. //默认值
  264. private string _defaultValue;
  265. public string DefaultValue
  266. {
  267. get { return _defaultValue; }
  268. set { SetProperty(ref _defaultValue, value); }
  269. }
  270. //多行
  271. private bool _isMultiline = false;
  272. public bool IsMultiLine
  273. {
  274. get { return _isMultiline; }
  275. set { SetProperty(ref _isMultiline, value); ChangeValue(AnnotAttrib.IsMutilLine, value); }
  276. }
  277. //滚动显示长文本
  278. private bool _isScrollText = false;
  279. public bool IsScrollText
  280. {
  281. get { return _isScrollText; }
  282. set { SetProperty(ref _isScrollText, value); ChangeValue(AnnotAttrib.ScrollFlag, value); }
  283. }
  284. //下拉框Form,
  285. private bool _isDefaultCheckBox = false;
  286. public bool IsDefaultCheckBox
  287. {
  288. get { return _isDefaultCheckBox; }
  289. set { SetProperty(ref _isDefaultCheckBox, value); ChangeValue(AnnotAttrib.IsChecked, value); }
  290. }
  291. //复选框的导出值
  292. private string _exportedValues;
  293. public string ExportedValues
  294. {
  295. get { return _exportedValues; }
  296. set { SetProperty(ref _exportedValues, value); ChangeValue(AnnotAttrib.ExportValue, value); }
  297. }
  298. //单选框Form,
  299. private bool _isDefaultRadioBox = false;
  300. public bool IsDefaultRadioBox
  301. {
  302. get { return _isDefaultRadioBox; }
  303. set { SetProperty(ref _isDefaultRadioBox, value); ChangeValue(AnnotAttrib.IsChecked, value); }
  304. }
  305. //复选框的导出值
  306. private string _radioMemberName;
  307. public string RadioMemberName
  308. {
  309. get { return _radioMemberName; }
  310. set { SetProperty(ref _radioMemberName, value); ChangeValue(AnnotAttrib.RadioMemberName, value); }
  311. }
  312. //Option
  313. //是否可以输入内容
  314. private bool _isInputOption = false;
  315. public bool IsInputOption
  316. {
  317. get { return _isInputOption; }
  318. set { SetProperty(ref _isInputOption, value); }
  319. }
  320. private bool _isUpOption = false;
  321. public bool IsUpOption
  322. {
  323. get { return _isUpOption; }
  324. set{ SetProperty(ref _isUpOption, value); }
  325. }
  326. private bool _isDownOption = false;
  327. public bool IsDownOption
  328. {
  329. get { return _isDownOption; }
  330. set { SetProperty(ref _isDownOption, value); }
  331. }
  332. private bool _isRemoveOption = false;
  333. public bool IsRemoveOption
  334. {
  335. get { return _isRemoveOption; }
  336. set { SetProperty(ref _isRemoveOption, value); }
  337. }
  338. public int OptionSelectedIndex = -1;
  339. private string _optionKey;
  340. public string OptionKey
  341. {
  342. get { return _optionKey; }
  343. set { SetProperty(ref _optionKey, value); }
  344. }
  345. private string _optionKeyValue;
  346. public string OptionKeyValue
  347. {
  348. get { return _optionKeyValue; }
  349. set { SetProperty(ref _optionKeyValue, value); }
  350. }
  351. private Dictionary<string, string> _optionsList;
  352. public Dictionary<string, string> OptionsList
  353. {
  354. get { return _optionsList; }
  355. set { SetProperty(ref _optionsList, value); }
  356. }
  357. #endregion
  358. public void ChangeValue(AnnotAttrib annotAttrib,object obj)
  359. {
  360. if(AttribEvent != null && IsCurrentWidget && AttribEvent.IsCreateForm() == false)
  361. {
  362. AttribEvent.UpdateAttrib(annotAttrib, obj);
  363. AttribEvent.UpdateAnnot();
  364. }
  365. }
  366. #region
  367. public ResetColor InitResetColor(Color border, Color font, Color fill)
  368. {
  369. return new ResetColor()
  370. {
  371. BorderColor = new SolidColorBrush(border),
  372. FontColor = new SolidColorBrush(font),
  373. FillColor = new SolidColorBrush(fill)
  374. };
  375. }
  376. //退出或切换属性面板,清除数据
  377. public void ClearVMData()
  378. {
  379. isCreateWidget = false;
  380. IsCurrentWidget = false;
  381. OptionsList = null;
  382. IsRemoveOption = false;
  383. IsInputOption = false;
  384. IsUpOption = false;
  385. IsDownOption = false;
  386. OptionSelectedIndex = -1;
  387. OptionKey = "";
  388. OptionKeyValue = "";
  389. }
  390. #endregion
  391. }
  392. public class ResetColor : BindableBase
  393. {
  394. private SolidColorBrush _borderColor;
  395. public SolidColorBrush BorderColor
  396. {
  397. get { return _borderColor; }
  398. set { SetProperty(ref _borderColor, value); }
  399. }
  400. private SolidColorBrush _fontColor;
  401. public SolidColorBrush FontColor
  402. {
  403. get { return _fontColor; }
  404. set { SetProperty(ref _fontColor, value); }
  405. }
  406. private SolidColorBrush _fillColor;
  407. public SolidColorBrush FillColor
  408. {
  409. get { return _fillColor; }
  410. set { SetProperty(ref _fillColor, value); }
  411. }
  412. }
  413. }