LoginWindow.xaml.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. using ivf_tl_Operate.Converts;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Configuration;
  5. using System.Diagnostics;
  6. using System.Globalization;
  7. using System.Linq;
  8. using System.Reflection;
  9. using System.Speech.Synthesis;
  10. using System.Text;
  11. using System.Threading;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. using System.Windows.Controls;
  15. using System.Windows.Data;
  16. using System.Windows.Documents;
  17. using System.Windows.Input;
  18. using System.Windows.Media;
  19. using System.Windows.Media.Imaging;
  20. using System.Windows.Shapes;
  21. namespace ivf_tl_Operate.Windows
  22. {
  23. /// <summary>
  24. /// LoginWindow.xaml 的交互逻辑
  25. /// </summary>
  26. public partial class LoginWindow : Window
  27. {
  28. // M4-04-3:原 KeyProcess 字段用于 Process.Start("osk.exe") 拉起系统软键盘,
  29. // 现已移除(需求 11:屏蔽系统软键盘)。账号/密码框改走内置 SoftKeyboard(见 LoginWindow.xaml 附加属性)。
  30. public LoginWindow(Window w)
  31. {
  32. InitializeComponent();
  33. this.Owner = w;
  34. this._userName.Text = ConfigurationManager.AppSettings["userName"].ToString();
  35. // M5-02-2:passWord 经解密回填(旧明文兼容:CryptoHelper.Decrypt 对明文原样返回,迁移已在 App_Startup 完成)。
  36. this.passwordClose.Password = ivf_tl_Operate.Helpers.CryptoHelper.Decrypt(ConfigurationManager.AppSettings["passWord"].ToString());
  37. this._tlNum.Text = ConfigurationManager.AppSettings["tlNum"].ToString();
  38. }
  39. private void StartDish_Click(object sender, RoutedEventArgs e)
  40. {
  41. try
  42. {
  43. //TestSpeak();
  44. //return;
  45. string account = this._userName.Text.Trim();
  46. string passWord = null;
  47. if (this.eyeClose.Visibility == Visibility.Visible)
  48. {
  49. passWord = this.passwordClose.Password.Trim();
  50. }
  51. else
  52. {
  53. passWord = this.passwordOpen.Text.Trim();
  54. }
  55. if (string.IsNullOrEmpty(passWord) || string.IsNullOrEmpty(account))
  56. {
  57. //this._errorInfo.Text = "账号或密码不能为空";
  58. this._errorInfo.Text = KeyToStringConvert.GetLanguageStringByKey("C0228");
  59. return;
  60. }
  61. string tlNum = this._tlNum.Text.Trim();
  62. if (string.IsNullOrEmpty(tlNum))
  63. {
  64. this._errorInfo.Text = "设备编号不能为空";
  65. return;
  66. }
  67. if (AppData.Instance.CurrentUserInfo.account == account && AppData.Instance.CurrentUserInfo.password == passWord && AppData.Instance.TlNum == tlNum)
  68. {
  69. this.DialogResult = false;
  70. }
  71. else
  72. {
  73. if (AppData.Instance.AppDataInit(account, passWord, tlNum))
  74. {
  75. AppData.Instance.setAppConfig(account, passWord, tlNum);
  76. this.DialogResult = true;
  77. }
  78. else
  79. {
  80. //this._errorInfo.Text = "登录失败";
  81. this._errorInfo.Text = KeyToStringConvert.GetLanguageStringByKey("C0229");
  82. }
  83. }
  84. }
  85. catch (Exception ex)
  86. {
  87. //this._errorInfo.Text = $"登录异常:{ex.Message}";
  88. this._errorInfo.Text = $"{KeyToStringConvert.GetLanguageStringByKey("C0229")}:{ex.Message}";
  89. }
  90. }
  91. public void TestSpeak()
  92. {
  93. try
  94. {
  95. SpeechSynthesizer speech = new SpeechSynthesizer();
  96. speech.Volume = 100;
  97. var currentVoiceInfo = speech.GetInstalledVoices(CultureInfo.CurrentCulture).FirstOrDefault();
  98. if (currentVoiceInfo != null) speech.SelectVoice(currentVoiceInfo.VoiceInfo.Name);
  99. speech.Speak("sdfjksdlj四道口附近上空砥砺奋进圣诞快乐房价上课是独立访客帆帆帆帆帆帆帆帆帆帆帆帆帆帆顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶呱呱呱呱呱呱呱呱呱呱呱呱呱呱呱古古怪怪日日日日日日日日日日日日日日日日日日噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢哦哦哦巅峰时刻记得付款冷热四点零分几位客人你说的,内分泌科看了看速度快角度上考虑附件为可容纳,魔法师。,的父母老师看对方反馈");
  100. }
  101. catch (Exception ex)
  102. {
  103. string ss = ex.Message;
  104. }
  105. }
  106. private void Cancel_Click(object sender, RoutedEventArgs e)
  107. {
  108. this.DialogResult = false;
  109. }
  110. // M4-04-3:原此处 Process.Start("osk.exe") 拉起系统软键盘,现已停用(需求 11:屏蔽系统软键盘)。
  111. // 内置软键盘由 SoftKeyboardHost.Mode 附加属性在获焦/触控时自动弹出(见 LoginWindow.xaml),此处无需处理。
  112. private void TextBox_TouchUp(object sender, TouchEventArgs e)
  113. {
  114. }
  115. // M4-04-3:同上,原 osk.exe 启动逻辑已停用,改走内置软键盘。
  116. private void PasswordBox_TouchUp(object sender, TouchEventArgs e)
  117. {
  118. }
  119. private void Image_eyeClose(object sender, MouseButtonEventArgs e)
  120. {
  121. this.passwordOpen.Text = this.passwordClose.Password;
  122. eyeClose.Visibility = Visibility.Hidden;
  123. passwordClose.Visibility = Visibility.Hidden;
  124. eyeOpen.Visibility = Visibility.Visible;
  125. passwordOpen.Visibility = Visibility.Visible;
  126. passwordOpen.Focus();
  127. passwordOpen.SelectionStart = passwordOpen.Text.Length;
  128. }
  129. private void Image_eyeOpen(object sender, MouseButtonEventArgs e)
  130. {
  131. this.passwordClose.Password = this.passwordOpen.Text;
  132. eyeOpen.Visibility = Visibility.Hidden;
  133. passwordOpen.Visibility = Visibility.Hidden;
  134. eyeClose.Visibility = Visibility.Visible;
  135. passwordClose.Visibility = Visibility.Visible;
  136. passwordClose.Focus();
  137. SetSelection(passwordClose, passwordOpen.Text.Length, 0);
  138. }
  139. /// <summary>
  140. /// 设置光标位置
  141. /// </summary>
  142. /// <param name="passwordBox"></param>
  143. /// <param name="start">光标开始位置</param>
  144. /// <param name="length">选中长度</param>
  145. private void SetSelection(PasswordBox passwordBox, int start, int length)
  146. {
  147. passwordBox.GetType().GetMethod("Select", BindingFlags.Instance | BindingFlags.NonPublic)?.Invoke(passwordBox, new object[] { start, length });
  148. }
  149. }
  150. }