HomePageSetPasswordDialog.xaml.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. using PDF_Office.Helper;
  2. using PDF_Office.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
  3. using PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs;
  4. using PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
  5. using System;
  6. using System.Collections;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Interop;
  10. namespace PDF_Office.Views.Dialog.HomePageToolsDialogs.HomePageBatchProcessing
  11. {
  12. /// <summary>
  13. /// Interaction logic for HomePageSetPasswordDialog
  14. /// </summary>
  15. public partial class HomePageSetPasswordDialog : UserControl
  16. {
  17. private HomePageSetPasswordDialogViewModel viewModel;
  18. private IDropTargetHelper dropHelper;
  19. private Boolean canOpenPasswordBoxHasFocus = false;
  20. private Boolean canOpenTextBoxHasFocus = false;
  21. private Boolean canEditPasswordBoxHasFocus = false;
  22. private Boolean canEditTextBoxHasFocus = false;
  23. private string canOpenPasswordBoxName = "CanOpenPasswordBox";
  24. private string canEditPasswordBoxName = "CanEditPasswordBox";
  25. private string canOpenTextBoxName = "CanOpenTextBox";
  26. private string canEditTextBoxName = "CanEditTextBox";
  27. private string showOpenPasswordBoxEyeLabelName = "ShowOpenPasswordBoxEyeLabel";
  28. private string showEditPasswordBoxEyeLabelName = "ShowEditPasswordBoxEyeLabel";
  29. private string showOpenTextBoxEyeLabelName = "ShowOpenTextBoxEyeLabel";
  30. private string showEditTextBoxEyeLabelName = "ShowEditTextBoxEyeLabel";
  31. public HomePageSetPasswordDialog()
  32. {
  33. InitializeComponent();
  34. viewModel= this.DataContext as HomePageSetPasswordDialogViewModel;
  35. }
  36. private void Menu_Click(object sender, System.Windows.RoutedEventArgs e)
  37. {
  38. menuPop1.IsOpen = true;
  39. }
  40. private void listView_SelectionChanged(object sender, SelectionChangedEventArgs e)
  41. {
  42. IList list = listView.SelectedItems;
  43. var lists = listView.Items;
  44. System.Data.DataRowView a;
  45. viewModel.fileNamesView.Clear();
  46. foreach (var item in list)
  47. {
  48. a = (System.Data.DataRowView)item;
  49. viewModel.fileNamesView.Add(lists.IndexOf(a));
  50. }
  51. if (viewModel.fileNamesView.Count > 0)
  52. {
  53. viewModel.RemoveIsEnable = "True";
  54. }
  55. else
  56. {
  57. viewModel.RemoveIsEnable = "False";
  58. }
  59. }
  60. private void RemoveFileMenuItem_Click(object sender, System.Windows.RoutedEventArgs e)
  61. {
  62. viewModel.removepdffile();
  63. }
  64. private void OpenFileMenuItem_Click(object sender, System.Windows.RoutedEventArgs e)
  65. {
  66. viewModel.openfiledialog();
  67. }
  68. private void PasswordBox_GotFocus(object sender, RoutedEventArgs e)
  69. {
  70. var passwordBox = sender as PasswordBox;
  71. if (passwordBox.Name == canOpenPasswordBoxName)
  72. {
  73. canOpenPasswordBoxHasFocus = true;
  74. canOpenTextBoxHasFocus = false;
  75. }
  76. else if (passwordBox.Name == canEditPasswordBoxName)
  77. {
  78. canEditPasswordBoxHasFocus = true;
  79. canEditTextBoxHasFocus = false;
  80. }
  81. }
  82. private void TextBox_GotFocus(object sender, RoutedEventArgs e)
  83. {
  84. var textBox = sender as TextBox;
  85. if (textBox.Name == canOpenTextBoxName)
  86. {
  87. canOpenPasswordBoxHasFocus = false;
  88. canOpenTextBoxHasFocus = true;
  89. }
  90. else if (textBox.Name == canEditTextBoxName)
  91. {
  92. canEditPasswordBoxHasFocus = false;
  93. canEditTextBoxHasFocus = true;
  94. }
  95. }
  96. private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
  97. {
  98. var passwordBox = sender as PasswordBox;
  99. if (passwordBox.Name == canOpenPasswordBoxName)
  100. {
  101. if (canOpenTextBoxHasFocus)
  102. {
  103. return;
  104. }
  105. CanOpenTextBox.Text = CanOpenPasswordBox.Password;
  106. HomePageSetPasswordDialogModel.PasswordForOpen = CanOpenTextBox.Text;
  107. viewModel.DelegateCanOpenTextChangedCommand.Execute();
  108. }
  109. else if (passwordBox.Name == canEditPasswordBoxName)
  110. {
  111. if (canEditTextBoxHasFocus)
  112. {
  113. return;
  114. }
  115. CanEditTextBox.Text = CanEditPasswordBox.Password;
  116. HomePageSetPasswordDialogModel.PasswordForEdit = CanEditTextBox.Text;
  117. viewModel.DelegateCanOpenTextChangedCommand.Execute();
  118. }
  119. }
  120. private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
  121. {
  122. var textBox = sender as TextBox;
  123. if (textBox.Name == canOpenTextBoxName)
  124. {
  125. if (canOpenPasswordBoxHasFocus)
  126. {
  127. return;
  128. }
  129. CanOpenPasswordBox.Password = CanOpenTextBox.Text;
  130. HomePageSetPasswordDialogModel.PasswordForOpen = CanOpenPasswordBox.Password;
  131. viewModel.DelegateCanOpenTextChangedCommand.Execute();
  132. }
  133. else if (textBox.Name == canEditTextBoxName)
  134. {
  135. if (canEditPasswordBoxHasFocus)
  136. { return; }
  137. CanEditPasswordBox.Password = CanEditTextBox.Text;
  138. HomePageSetPasswordDialogModel.PasswordForEdit = CanEditPasswordBox.Password;
  139. viewModel.DelegateCanOpenTextChangedCommand.Execute();
  140. }
  141. }
  142. private void ShowPasswordBoxEyeLabel_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
  143. {
  144. var label = sender as Label;
  145. if (label.Name == showOpenPasswordBoxEyeLabelName)
  146. {
  147. CanOpenPasswordBox.Visibility = Visibility.Hidden;
  148. ShowOpenPasswordBoxEyeLabel.Visibility = Visibility.Hidden;
  149. CanOpenTextBox.Visibility = Visibility.Visible;
  150. ShowOpenTextBoxEyeLabel.Visibility = Visibility.Visible;
  151. }
  152. else if (label.Name == showEditPasswordBoxEyeLabelName)
  153. {
  154. CanEditPasswordBox.Visibility = Visibility.Hidden;
  155. ShowEditPasswordBoxEyeLabel.Visibility = Visibility.Hidden;
  156. CanEditTextBox.Visibility = Visibility.Visible;
  157. ShowEditTextBoxEyeLabel.Visibility = Visibility.Visible;
  158. }
  159. }
  160. private void ShowTextBoxEyeLabel_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
  161. {
  162. var label = sender as Label;
  163. if (label.Name == showOpenTextBoxEyeLabelName)
  164. {
  165. CanOpenPasswordBox.Visibility = Visibility.Visible;
  166. ShowOpenPasswordBoxEyeLabel.Visibility = Visibility.Visible;
  167. CanOpenTextBox.Visibility = Visibility.Hidden;
  168. ShowOpenTextBoxEyeLabel.Visibility = Visibility.Hidden;
  169. }
  170. else if (label.Name == showEditTextBoxEyeLabelName)
  171. {
  172. CanEditPasswordBox.Visibility = Visibility.Visible;
  173. ShowEditPasswordBoxEyeLabel.Visibility = Visibility.Visible;
  174. CanEditTextBox.Visibility = Visibility.Hidden;
  175. ShowEditTextBoxEyeLabel.Visibility = Visibility.Hidden;
  176. }
  177. }
  178. private void Grid_Drop(object sender, DragEventArgs e)
  179. {
  180. try
  181. {
  182. Point iconPoint = e.GetPosition(this);
  183. dropHelper?.Drop((System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref iconPoint, e.Effects);
  184. }
  185. catch (Exception ex)
  186. {
  187. }
  188. string dropFile = "Drop";
  189. if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop))
  190. {
  191. DropGrid.Visibility = Visibility.Collapsed;
  192. int count = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).Length;
  193. for (int i = 0; i < count; i++)
  194. {
  195. dropFile = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).GetValue(i).ToString(); ;
  196. //MessageBox.Show(dropFile);
  197. if (dropFile.ToLower().EndsWith("pdf"))
  198. { viewModel.addPDFFiles(dropFile); }
  199. }
  200. }
  201. }
  202. private void MainPage_DragEnter(object sender, DragEventArgs e)
  203. {
  204. DropGrid.Visibility = Visibility.Visible;
  205. //页面编辑和缩略图
  206. if ((e.OriginalSource as Image) != null)
  207. return;
  208. try
  209. {
  210. if (dropHelper == null)
  211. {
  212. dropHelper = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("4657278A-411B-11D2-839A-00C04FD918D0"))) as IDropTargetHelper;
  213. }
  214. Point iconPoint = e.GetPosition(this);
  215. dropHelper?.DragEnter(new WindowInteropHelper(Window.GetWindow(this)).Handle, (System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref iconPoint, e.Effects);
  216. }
  217. catch (Exception ex)
  218. {
  219. }
  220. }
  221. private void MainPage_DragOver(object sender, DragEventArgs e)
  222. {
  223. if ((e.OriginalSource as Image) != null)
  224. return;
  225. try
  226. {
  227. Point iconPoint = e.GetPosition(this);
  228. dropHelper?.DragOver(ref iconPoint, e.Effects);
  229. }
  230. catch (Exception ex)
  231. {
  232. }
  233. }
  234. private void MainPage_DragLeave(object sender, DragEventArgs e)
  235. {
  236. DropGrid.Visibility = Visibility.Collapsed;
  237. if ((e.OriginalSource as Image) != null)
  238. return;
  239. try
  240. {
  241. dropHelper?.DragLeave();
  242. }
  243. catch (Exception ex)
  244. {
  245. }
  246. }
  247. }
  248. }