CPDFStampUI.xaml.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. using ComPDFKit.PDFAnnotation;
  2. using Compdfkit_Tools.Data;
  3. using Compdfkit_Tools.Properties;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Collections.ObjectModel;
  7. using System.ComponentModel;
  8. using System.IO;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Input;
  13. namespace Compdfkit_Tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
  14. {
  15. public partial class CPDFStampUI : UserControl
  16. {
  17. #region StandardStamp
  18. List<string> Path = new List<string>
  19. {
  20. "pack://application:,,,/Compdfkit_Tools;component/Asset/Resource/Annotation/StampIcons/Approved.png",
  21. "pack://application:,,,/Compdfkit_Tools;component/Asset/Resource/Annotation/StampIcons/NotApproved.png",
  22. "pack://application:,,,/Compdfkit_Tools;component/Asset/Resource/Annotation/StampIcons/Completed.png",
  23. "pack://application:,,,/Compdfkit_Tools;component/Asset/Resource/Annotation/StampIcons/Final.png",
  24. "pack://application:,,,/Compdfkit_Tools;component/Asset/Resource/Annotation/StampIcons/Draft.png",
  25. "pack://application:,,,/Compdfkit_Tools;component/Asset/Resource/Annotation/StampIcons/Confidential.png",
  26. "pack://application:,,,/Compdfkit_Tools;component/Asset/Resource/Annotation/StampIcons/ForPublicRelease.png",
  27. "pack://application:,,,/Compdfkit_Tools;component/Asset/Resource/Annotation/StampIcons/NotForPublicRelease.png",
  28. "pack://application:,,,/Compdfkit_Tools;component/Asset/Resource/Annotation/StampIcons/ForComment.png",
  29. "pack://application:,,,/Compdfkit_Tools;component/Asset/Resource/Annotation/StampIcons/Void.png",
  30. "pack://application:,,,/Compdfkit_Tools;component/Asset/Resource/Annotation/StampIcons/PreliminaryResults.png",
  31. "pack://application:,,,/Compdfkit_Tools;component/Asset/Resource/Annotation/StampIcons/InformationOnly.png",
  32. "pack://application:,,,/Compdfkit_Tools;component/Asset/Resource/Annotation/StampIcons/Accepted.png",
  33. "pack://application:,,,/Compdfkit_Tools;component/Asset/Resource/Annotation/StampIcons/Rejected.png",
  34. "pack://application:,,,/Compdfkit_Tools;component/Asset/Resource/Annotation/StampIcons/Witness.png",
  35. "pack://application:,,,/Compdfkit_Tools;component/Asset/Resource/Annotation/StampIcons/InitialHere.png",
  36. "pack://application:,,,/Compdfkit_Tools;component/Asset/Resource/Annotation/StampIcons/SignHere.png",
  37. "pack://application:,,,/Compdfkit_Tools;component/Asset/Resource/Annotation/StampIcons/revised.png",
  38. "pack://application:,,,/Compdfkit_Tools;component/Asset/Resource/Annotation/StampIcons/PrivateMark1.png",
  39. "pack://application:,,,/Compdfkit_Tools;component/Asset/Resource/Annotation/StampIcons/PrivateMark2.png",
  40. "pack://application:,,,/Compdfkit_Tools;component/Asset/Resource/Annotation/StampIcons/PrivateMark3.png",
  41. };
  42. List<string> StampText = new List<string>
  43. {
  44. "Approved","NotApproved","Completed","Final","Draft","Confidential","ForPublicRelease","NotForPublicRelease",
  45. "ForComment","Void","PreliminaryResults","InformationOnly","Accepted","Rejected","Witness","InitialHere","SignHere",
  46. "revised","PrivateMark#1","PrivateMark#2","PrivateMark#3"
  47. };
  48. List<int> MaxWidth = new List<int>
  49. {
  50. 218,292,234,130,150,280,386,461,282,121,405,366,30,30,133,133,133,173,30,30,30
  51. };
  52. List<int> MaxHeight = new List<int>
  53. {
  54. 66,66,66,66,66,66,66,66,66,66,66,66,30,30,39,39,39,66,30,30,30
  55. };
  56. #endregion
  57. public ObservableCollection<CPDFStampData> StandardStampList { get; set; }
  58. public ObservableCollection<CPDFStampData> CustomStampList { get; set; }
  59. public event EventHandler<CPDFAnnotationData> PropertyChanged;
  60. public CPDFStampUI()
  61. {
  62. InitializeComponent();
  63. }
  64. private void Button_Click(object sender, RoutedEventArgs e)
  65. {
  66. }
  67. private void CPDFOpacityControl_OpacityChanged(object sender, EventArgs e)
  68. {
  69. PropertyChanged?.Invoke(this, new CPDFStampData());
  70. }
  71. private void Text_Click(object sender, RoutedEventArgs e)
  72. {
  73. CPDFCreateStampDialog createStampDialog = new CPDFCreateStampDialog();
  74. createStampDialog.SetCreateHeaderIndex(0);
  75. createStampDialog.Owner = Window.GetWindow(this);
  76. createStampDialog.WindowStartupLocation = WindowStartupLocation.CenterOwner;
  77. createStampDialog.ShowDialog();
  78. UpDataCustomStamp(createStampDialog.cPDFStampData);
  79. }
  80. private void Image_Click(object sender, RoutedEventArgs e)
  81. {
  82. CPDFCreateStampDialog createStampDialog = new CPDFCreateStampDialog();
  83. createStampDialog.SetCreateHeaderIndex(1);
  84. createStampDialog.Owner = Window.GetWindow(this);
  85. createStampDialog.WindowStartupLocation = WindowStartupLocation.CenterOwner;
  86. createStampDialog.ShowDialog();
  87. UpDataCustomStamp(createStampDialog.cPDFStampData);
  88. }
  89. private void Standard_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  90. {
  91. PropertyChanged?.Invoke(this, (sender as ListBoxItem).DataContext as CPDFStampData);
  92. }
  93. private void Customize_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  94. {
  95. PropertyChanged?.Invoke(this, (sender as ListViewItem).DataContext as CPDFStampData);
  96. }
  97. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  98. {
  99. StandardStampList = new ObservableCollection<CPDFStampData>();
  100. CustomStampList = new ObservableCollection<CPDFStampData>();
  101. InitStandardStamp();
  102. LoadSettings();
  103. Binding Standardbinding = new Binding();
  104. Standardbinding.Source = this;
  105. Standardbinding.Path = new PropertyPath("StandardStampList");
  106. StandardListBox.SetBinding(ItemsControl.ItemsSourceProperty, Standardbinding);
  107. Binding Custombinding = new Binding();
  108. Custombinding.Source = this;
  109. Custombinding.Path = new PropertyPath("CustomStampList");
  110. CustomListBox.SetBinding(ItemsControl.ItemsSourceProperty, Custombinding);
  111. ICollectionView groupView = CollectionViewSource.GetDefaultView(CustomStampList);
  112. groupView.GroupDescriptions.Add(new PropertyGroupDescription(nameof(CPDFStampData.TypeText)));
  113. }
  114. public void InitStandardStamp()
  115. {
  116. for (int i = 0; i < Path.Count; i++)
  117. {
  118. CPDFStampData standardStamp = new CPDFStampData();
  119. standardStamp.Author = "";
  120. standardStamp.Opacity = 1;
  121. standardStamp.SourcePath = Path[i];
  122. standardStamp.StampText = StampText[i];
  123. standardStamp.MaxWidth = MaxWidth[i];
  124. standardStamp.MaxHeight = MaxHeight[i];
  125. standardStamp.Type = C_STAMP_TYPE.STANDARD_STAMP;
  126. standardStamp.AnnotationType = CPDFAnnotationType.Stamp;
  127. StandardStampList.Add(standardStamp);
  128. }
  129. }
  130. /// <summary>
  131. /// Loading CacheStamp
  132. /// </summary>
  133. public void LoadSettings()
  134. {
  135. CustomStampList stamps = Settings.Default.CustomStampList;
  136. CustomStampList.Clear();
  137. if (stamps != null)
  138. {
  139. for (int i = 0; i < stamps.Count; i++)
  140. {
  141. CPDFStampData customStamp = new CPDFStampData();
  142. customStamp.Opacity = 1;
  143. customStamp.Author = stamps[i].Author;
  144. customStamp.StampText = stamps[i].StampText;
  145. customStamp.StampTextDate = stamps[i].StampTextDate;
  146. customStamp.MaxWidth = stamps[i].MaxWidth;
  147. customStamp.MaxHeight = stamps[i].MaxHeight;
  148. customStamp.SourcePath = stamps[i].SourcePath;
  149. customStamp.Type = stamps[i].Type;
  150. customStamp.TextSharp = stamps[i].TextSharp;
  151. customStamp.TextColor = stamps[i].TextColor;
  152. customStamp.IsCheckedTime = stamps[i].IsCheckedTime;
  153. customStamp.IsCheckedDate = stamps[i].IsCheckedDate;
  154. customStamp.AnnotationType = CPDFAnnotationType.Stamp;
  155. CustomStampList.Add(customStamp);
  156. }
  157. }
  158. }
  159. public void UpDataCustomStamp(CPDFStampData oldstamp)
  160. {
  161. if (oldstamp != null)
  162. {
  163. CustomStampList.Add(oldstamp);
  164. CustomStampList stamps = Settings.Default.CustomStampList;
  165. if (stamps == null)
  166. {
  167. stamps = Settings.Default.CustomStampList = new CustomStampList();
  168. }
  169. stamps.Add(oldstamp);
  170. Settings.Default.Save();
  171. }
  172. }
  173. private void Delete_Click(object sender, RoutedEventArgs e)
  174. {
  175. Button ThisButton = sender as Button;
  176. if (ThisButton != null)
  177. {
  178. CPDFStampData stampData = ThisButton.DataContext as CPDFStampData;
  179. if (stampData != null)
  180. {
  181. int index = CustomStampList.IndexOf(stampData);
  182. if (index != -1)
  183. {
  184. CPDFDeleteDialog cPDFDeleteDialog = new CPDFDeleteDialog("Warning", "Are you sure to delete?");
  185. cPDFDeleteDialog.Owner = Window.GetWindow(this);
  186. cPDFDeleteDialog.WindowStartupLocation = WindowStartupLocation.CenterOwner;
  187. cPDFDeleteDialog.ShowDialog();
  188. if (!cPDFDeleteDialog.IsDelete)
  189. {
  190. PropertyChanged?.Invoke(this, null);
  191. return;
  192. }
  193. if (stampData.SourcePath != null)
  194. {
  195. try
  196. {
  197. if (File.Exists(stampData.SourcePath))
  198. {
  199. File.Delete(stampData.SourcePath);
  200. }
  201. }
  202. catch (Exception)
  203. {
  204. }
  205. }
  206. CustomStampList.RemoveAt(index);
  207. CustomStampList stamps = Settings.Default.CustomStampList;
  208. if (stamps != null)
  209. {
  210. stamps.RemoveAt(index);
  211. Settings.Default.Save();
  212. }
  213. PropertyChanged?.Invoke(this, null);
  214. }
  215. }
  216. }
  217. }
  218. }
  219. }