HomePageSetPasswordDialog.xaml.cs 11 KB

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