CPDFStampUI.xaml.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.Controls.Data;
  3. using ComPDFKit.Controls.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. using ComPDFKit.Controls.Helper;
  14. namespace ComPDFKit.Controls.Annotation.PDFAnnotationPanel.PDFAnnotationUI
  15. {
  16. public partial class CPDFStampUI : UserControl
  17. {
  18. #region StandardStamp
  19. List<string> Path = new List<string>
  20. {
  21. "pack://application:,,,/ComPDFKit.Controls;component/Asset/Resource/Annotation/StampIcons/Approved.png",
  22. "pack://application:,,,/ComPDFKit.Controls;component/Asset/Resource/Annotation/StampIcons/NotApproved.png",
  23. "pack://application:,,,/ComPDFKit.Controls;component/Asset/Resource/Annotation/StampIcons/Completed.png",
  24. "pack://application:,,,/ComPDFKit.Controls;component/Asset/Resource/Annotation/StampIcons/Final.png",
  25. "pack://application:,,,/ComPDFKit.Controls;component/Asset/Resource/Annotation/StampIcons/Draft.png",
  26. "pack://application:,,,/ComPDFKit.Controls;component/Asset/Resource/Annotation/StampIcons/Confidential.png",
  27. "pack://application:,,,/ComPDFKit.Controls;component/Asset/Resource/Annotation/StampIcons/ForPublicRelease.png",
  28. "pack://application:,,,/ComPDFKit.Controls;component/Asset/Resource/Annotation/StampIcons/NotForPublicRelease.png",
  29. "pack://application:,,,/ComPDFKit.Controls;component/Asset/Resource/Annotation/StampIcons/ForComment.png",
  30. "pack://application:,,,/ComPDFKit.Controls;component/Asset/Resource/Annotation/StampIcons/Void.png",
  31. "pack://application:,,,/ComPDFKit.Controls;component/Asset/Resource/Annotation/StampIcons/PreliminaryResults.png",
  32. "pack://application:,,,/ComPDFKit.Controls;component/Asset/Resource/Annotation/StampIcons/InformationOnly.png",
  33. "pack://application:,,,/ComPDFKit.Controls;component/Asset/Resource/Annotation/StampIcons/Accepted.png",
  34. "pack://application:,,,/ComPDFKit.Controls;component/Asset/Resource/Annotation/StampIcons/Rejected.png",
  35. "pack://application:,,,/ComPDFKit.Controls;component/Asset/Resource/Annotation/StampIcons/Witness.png",
  36. "pack://application:,,,/ComPDFKit.Controls;component/Asset/Resource/Annotation/StampIcons/InitialHere.png",
  37. "pack://application:,,,/ComPDFKit.Controls;component/Asset/Resource/Annotation/StampIcons/SignHere.png",
  38. "pack://application:,,,/ComPDFKit.Controls;component/Asset/Resource/Annotation/StampIcons/revised.png",
  39. "pack://application:,,,/ComPDFKit.Controls;component/Asset/Resource/Annotation/StampIcons/PrivateMark1.png",
  40. "pack://application:,,,/ComPDFKit.Controls;component/Asset/Resource/Annotation/StampIcons/PrivateMark2.png",
  41. "pack://application:,,,/ComPDFKit.Controls;component/Asset/Resource/Annotation/StampIcons/PrivateMark3.png",
  42. };
  43. List<string> StampText = new List<string>
  44. {
  45. "Approved","NotApproved","Completed","Final","Draft","Confidential","ForPublicRelease","NotForPublicRelease",
  46. "ForComment","Void","PreliminaryResults","InformationOnly","Accepted","Rejected","Witness","InitialHere","SignHere",
  47. "revised","PrivateMark#1","PrivateMark#2","PrivateMark#3"
  48. };
  49. List<int> MaxWidth = new List<int>
  50. {
  51. 218,292,234,130,150,280,386,461,282,121,405,366,30,30,133,133,133,173,30,30,30
  52. };
  53. List<int> MaxHeight = new List<int>
  54. {
  55. 66,66,66,66,66,66,66,66,66,66,66,66,30,30,39,39,39,66,30,30,30
  56. };
  57. #endregion
  58. public ObservableCollection<CPDFStampData> StandardStampList { get; set; }
  59. public ObservableCollection<CPDFStampData> CustomStampList { get; set; }
  60. public event EventHandler<CPDFAnnotationData> PropertyChanged;
  61. public CPDFStampUI()
  62. {
  63. InitializeComponent();
  64. }
  65. private void Button_Click(object sender, RoutedEventArgs e)
  66. {
  67. }
  68. private void CPDFOpacityControl_OpacityChanged(object sender, EventArgs e)
  69. {
  70. PropertyChanged?.Invoke(this, new CPDFStampData());
  71. }
  72. private void Text_Click(object sender, RoutedEventArgs e)
  73. {
  74. CPDFCreateStampDialog createStampDialog = new CPDFCreateStampDialog();
  75. createStampDialog.SetCreateHeaderIndex(0);
  76. createStampDialog.Owner = Window.GetWindow(this);
  77. createStampDialog.WindowStartupLocation = WindowStartupLocation.CenterOwner;
  78. createStampDialog.ShowDialog();
  79. UpdataCustomStamp(createStampDialog.cPDFStampData);
  80. }
  81. private void Image_Click(object sender, RoutedEventArgs e)
  82. {
  83. CPDFCreateStampDialog createStampDialog = new CPDFCreateStampDialog();
  84. createStampDialog.SetCreateHeaderIndex(1);
  85. createStampDialog.Owner = Window.GetWindow(this);
  86. createStampDialog.WindowStartupLocation = WindowStartupLocation.CenterOwner;
  87. createStampDialog.ShowDialog();
  88. UpdataCustomStamp(createStampDialog.cPDFStampData);
  89. }
  90. private void Standard_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  91. {
  92. PropertyChanged?.Invoke(this, (sender as ListBoxItem).DataContext as CPDFStampData);
  93. }
  94. private void Customize_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  95. {
  96. PropertyChanged?.Invoke(this, (sender as ListViewItem).DataContext as CPDFStampData);
  97. }
  98. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  99. {
  100. StandardStampList = new ObservableCollection<CPDFStampData>();
  101. CustomStampList = new ObservableCollection<CPDFStampData>();
  102. InitStandardStamp();
  103. LoadSettings();
  104. Binding Standardbinding = new Binding();
  105. Standardbinding.Source = this;
  106. Standardbinding.Path = new PropertyPath("StandardStampList");
  107. StandardListBox.SetBinding(ItemsControl.ItemsSourceProperty, Standardbinding);
  108. Binding Custombinding = new Binding();
  109. Custombinding.Source = this;
  110. Custombinding.Path = new PropertyPath("CustomStampList");
  111. CustomListBox.SetBinding(ItemsControl.ItemsSourceProperty, Custombinding);
  112. ICollectionView groupView = CollectionViewSource.GetDefaultView(CustomStampList);
  113. groupView.GroupDescriptions.Add(new PropertyGroupDescription(nameof(CPDFStampData.TypeText)));
  114. }
  115. public void InitStandardStamp()
  116. {
  117. for (int i = 0; i < Path.Count; i++)
  118. {
  119. CPDFStampData standardStamp = new CPDFStampData();
  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.StampText = stamps[i].StampText;
  144. customStamp.StampTextDate = stamps[i].StampTextDate;
  145. customStamp.MaxWidth = stamps[i].MaxWidth;
  146. customStamp.MaxHeight = stamps[i].MaxHeight;
  147. customStamp.SourcePath = stamps[i].SourcePath;
  148. customStamp.Type = stamps[i].Type;
  149. customStamp.TextSharp = stamps[i].TextSharp;
  150. customStamp.TextColor = stamps[i].TextColor;
  151. customStamp.IsCheckedTime = stamps[i].IsCheckedTime;
  152. customStamp.IsCheckedDate = stamps[i].IsCheckedDate;
  153. customStamp.AnnotationType = CPDFAnnotationType.Stamp;
  154. CustomStampList.Add(customStamp);
  155. }
  156. }
  157. }
  158. public void UpdataCustomStamp(CPDFStampData oldstamp)
  159. {
  160. if (oldstamp != null)
  161. {
  162. CustomStampList.Add(oldstamp);
  163. CustomStampList stamps = Settings.Default.CustomStampList;
  164. if (stamps == null)
  165. {
  166. stamps = Settings.Default.CustomStampList = new CustomStampList();
  167. }
  168. stamps.Add(oldstamp);
  169. Settings.Default.Save();
  170. }
  171. }
  172. private void Delete_Click(object sender, RoutedEventArgs e)
  173. {
  174. Button ThisButton = sender as Button;
  175. if (ThisButton != null)
  176. {
  177. CPDFStampData stampData = ThisButton.DataContext as CPDFStampData;
  178. if (stampData != null)
  179. {
  180. int index = CustomStampList.IndexOf(stampData);
  181. if (index != -1)
  182. {
  183. CPDFDeleteDialog cPDFDeleteDialog = new CPDFDeleteDialog(LanguageHelper.CommonManager.GetString("Caption_Warning"),
  184. LanguageHelper.CommonManager.GetString("Warn_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. }