星火直播PC
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LoginWindow.xaml.cs 37KB

hace 3 años
hace 3 años
hace 3 años
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  1. using Common.system;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Collections.ObjectModel;
  5. using System.Configuration;
  6. using System.Data;
  7. using System.IO;
  8. using System.Security.Principal;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Windows;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using XHZB.Desktop.Utils;
  16. using XHZB.Model;
  17. namespace XHZB.Desktop
  18. {
  19. /// <summary>
  20. /// 登陆
  21. /// </summary>
  22. public partial class LoginWindow : Window/*, ZJDownloadUtil.ZJDownloadCallback*/
  23. {
  24. #region 字段&属性
  25. //属性定义
  26. private Dictionary<int, string> _selGroupList;
  27. /// <summary>
  28. /// 分组下拉列表
  29. /// </summary>
  30. public Dictionary<int, string> selGroupList
  31. {
  32. get => _selGroupList;
  33. set => _selGroupList = value;//NotifyOfPropertyChange("selGroupList");
  34. }
  35. private int _Group;
  36. /// <summary>
  37. ///当前分组
  38. /// </summary>
  39. public int Group
  40. {
  41. get => _Group;
  42. set => _Group = value;
  43. }
  44. /// <summary>
  45. /// 调用接口
  46. /// </summary>
  47. private readonly RegisterController registerController = new RegisterController();
  48. /// <summary>
  49. /// 接口返回 0成功 1失败
  50. /// </summary>
  51. private int serverReturnCode = 0;
  52. public DataTable data = new DataTable();
  53. public DataTable DirectorList = new DataTable();
  54. internal LoginPageData pageData = new LoginPageData();
  55. /// <summary>
  56. /// 记录上次用户的选择的教材
  57. /// </summary>
  58. private int lsbids = 0;
  59. /// <summary>
  60. /// 记录上次用户的选择的章节
  61. /// </summary>
  62. private int directorids = 0;
  63. #endregion 字段&属性
  64. #region 初始化
  65. /// <summary>
  66. /// 初始化
  67. /// </summary>
  68. public LoginWindow()
  69. {
  70. InitializeComponent();
  71. if (!APP.CheckScreenCapturerRecorder())
  72. {
  73. MessageWindow.Show("首次运行需安装环境,请在确定后依次点击“English-OK-Next>-Next>Install”完成安装!");
  74. APP.InstallScreenCapturerRecorder();
  75. }
  76. WindowStartupLocation = WindowStartupLocation.CenterScreen;
  77. string typestr = APP.isDebug ? "测试版" : "正式版";
  78. bool isAdmin = IsAdministrator();
  79. string stradmin = isAdmin ? "管理员" : "普通用户";
  80. version_tb.Text = $"{typestr} v{FileToolsCommon.GetConfigValue("VersionName")}(Build{FileToolsCommon.GetConfigValue("VersionCode")}) [{stradmin}]";
  81. if (File.Exists(APP.dataPath + "interfaceAddress.txt")) //若为空
  82. {
  83. APP.apiUrl = System.IO.File.ReadAllText(APP.dataPath + "interfaceAddress.txt", Encoding.Default);
  84. }
  85. if (File.Exists(APP.dataPath + "imageUploadAddress.txt")) //若为空
  86. {
  87. APP.uploadUrl = System.IO.File.ReadAllText(APP.dataPath + "imageUploadAddress.txt", Encoding.Default);
  88. }
  89. if (File.Exists(APP.dataPath + "pictureShowsAddress.txt")) //若为空
  90. {
  91. APP.showImageUrl = System.IO.File.ReadAllText(APP.dataPath + "pictureShowsAddress.txt", Encoding.Default);
  92. }
  93. if (File.Exists(APP.dataPath + "fileStorageAddress.txt")) //若为空
  94. {
  95. APP.fileStorageAddress = System.IO.File.ReadAllText(APP.dataPath + "fileStorageAddress.txt", Encoding.Default);
  96. }
  97. //APP.AESAccountStr = "9001";
  98. //APP.AESPassWordStr = "123456";
  99. //免登录
  100. if (!string.IsNullOrWhiteSpace(APP.AESAccountStr) && !string.IsNullOrWhiteSpace(APP.AESPassWordStr))
  101. {
  102. Dispatcher.Invoke(new Action(() =>
  103. {
  104. txbAccountNumber.Text = APP.AESAccountStr;
  105. pobPassword.Password = APP.AESPassWordStr;
  106. btnLogin_Click(null, null);
  107. }));
  108. }
  109. }
  110. //#region 登陆页面验证本地激活码 1.验证成功 可登陆。 2.验证失败 弹出激活窗口。 关闭激活窗口,点击登陆时继续 弹出激活窗口
  111. ///// <summary>
  112. ///// 验证激活码
  113. ///// </summary>
  114. //void Verification()
  115. //{
  116. // //如果本地文件为空,弹出弹窗 输密匙
  117. // //本地文件不为空, 解析
  118. // if (!File.Exists(APP.dataPath + "signature.txt"))//上次登陆时间为空 或者签名为空 或者上次登陆时间不是今天 都需要输入密匙验证 ,否则只验证本地的签名
  119. // {
  120. // KeyVerification wins = new KeyVerification
  121. // {
  122. // Topmost = true,
  123. // Owner = this
  124. // };
  125. // wins.ShowDialog();
  126. // }
  127. // else
  128. // {
  129. // UnderVerification();
  130. // }
  131. //}
  132. ///// <summary>
  133. ///// 验证中
  134. ///// </summary>
  135. //void UnderVerification()
  136. //{
  137. // MyApp.myloading.Show();
  138. // Shared.BackgroundWorkerHelper.RunWorkerAsync(InvokeActivationDecryptServering, InvokeActivationDecryptServerCompate);
  139. //}
  140. ///// <summary>
  141. ///// 激活信息--验证签名是否过期-调用
  142. ///// </summary>
  143. ///// <returns></returns>
  144. //private object InvokeActivationDecryptServering()
  145. //{
  146. // return Shared.ServerMsg;
  147. //}
  148. ///// <summary>
  149. ///// 激活信息--验证签名是否过期-返回结果
  150. ///// </summary>
  151. ///// <returns></returns>
  152. //public void InvokeActivationDecryptServerCompate(object obj)
  153. //{
  154. // Dispatcher.Invoke(new Action(() =>
  155. // {
  156. // MyApp.myloading.Hide();
  157. // }));
  158. // //解析
  159. // try
  160. // {
  161. // Shared.Signature = System.IO.File.ReadAllText(ZConfig.dataPath + "signature.txt", Encoding.Default);
  162. // string decrypt = DataProvider.TripleDESDecrypt(Shared.Signature, ZConfig.secretKey);
  163. // decrypt = decrypt.Replace("\u0001", "").Trim();
  164. // Signatures msgBean = ZJsonHelper.JsonToObj<Signatures>(decrypt);
  165. // long currentTimeTimestamp = DataProvider.TimestampTotalSeconds(); //当前时间 时间戳
  166. // if (msgBean.endtime > currentTimeTimestamp)//条件成立 解析成功 code 在有效期内
  167. // {
  168. // if (File.Exists(ZConfig.dataPath + "signatureTime.txt"))
  169. // {
  170. // string signatureTime = System.IO.File.ReadAllText(ZConfig.dataPath + "signatureTime.txt", Encoding.Default);
  171. // string currentTime = DateTime.Now.ToLongDateString().ToString();//当前时间
  172. // if (signatureTime != currentTime)
  173. // {
  174. // Shared.BackgroundWorkerHelper.RunWorkerAsync(InvokeActivationAddHistoryServering, InvokeActivationAddHistoryServerCompate);
  175. // }
  176. // }
  177. // ZConfig.isActivationSuccessful = true;
  178. // //Dispatcher.Invoke(new Action(() =>
  179. // //{
  180. // // //LoginWindow win = new LoginWindow();
  181. // // //win.Show();
  182. // // //Close();
  183. // //}));
  184. // }
  185. // else//时间失效
  186. // {
  187. // Dispatcher.Invoke(new Action(() =>
  188. // {
  189. // KeyVerification wins = new KeyVerification
  190. // {
  191. // Topmost = true,
  192. // Owner = this
  193. // };
  194. // wins.ShowDialog();
  195. // //Close();
  196. // }));
  197. // }
  198. // }
  199. // catch (Exception) //解析失败 输code
  200. // {
  201. // Dispatcher.Invoke(new Action(() =>
  202. // {
  203. // KeyVerification wins = new KeyVerification
  204. // {
  205. // Topmost = true,
  206. // Owner = this
  207. // };
  208. // wins.ShowDialog();
  209. // //Close();
  210. // }));
  211. // }
  212. //}
  213. ///// <summary>
  214. ///// 激活信息--添加激活历史-调用
  215. ///// </summary>
  216. ///// <returns></returns>
  217. //private object InvokeActivationAddHistoryServering()
  218. //{
  219. // serverReturnCode = registerController.ActivationAddHistory(ref Shared.TeachingData);
  220. // return Shared.ServerMsg;
  221. //}
  222. ///// <summary>
  223. ///// 激活信息--添加激活历史-返回结果
  224. ///// </summary>
  225. ///// <returns></returns>
  226. //public void InvokeActivationAddHistoryServerCompate(object obj)
  227. //{
  228. // if (!Directory.Exists(APP.dataPath))
  229. // {
  230. // Directory.CreateDirectory(APP.dataPath);
  231. // }
  232. // string ApplicationData = APP.dataPath + "signatureTime.txt";
  233. // string currentTime = DateTime.Now.ToLongDateString().ToString();//当前时间
  234. // System.IO.File.WriteAllText(ApplicationData, currentTime, Encoding.Default);//存放签名验证日期
  235. //}
  236. //#endregion
  237. public bool IsAdministrator()
  238. {
  239. WindowsIdentity current = WindowsIdentity.GetCurrent();
  240. WindowsPrincipal windowsPrincipal = new WindowsPrincipal(current);
  241. return windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator);
  242. }
  243. /// <summary>
  244. /// 初始化加载
  245. /// </summary>
  246. /// <param name="sender"></param>
  247. /// <param name="e"></param>
  248. private void Window_Loaded(object sender, RoutedEventArgs e)
  249. {
  250. WindowStartupLocation = WindowStartupLocation.CenterScreen;
  251. btnLogin.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#1D8AF4"));
  252. //imgBrush.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/Login/login2_0.png"));
  253. if (GetSettingString("isRemind").Equals("True"))
  254. {
  255. ckSaveName.IsChecked = true;
  256. txbAccountNumber.Text = GetSettingString("userName");
  257. }
  258. //if (GetSettingString("OutputInforLog").Equals("1"))
  259. //{
  260. // ZConfig.outputInforLog = true;
  261. //}
  262. //Verification();
  263. getNewApp();
  264. }
  265. #endregion 初始化
  266. #region 事件
  267. /// <summary>
  268. /// 窗体移动事件
  269. /// </summary>
  270. /// <param name="sender"></param>
  271. /// <param name="e"></param>
  272. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  273. {
  274. DragMove();
  275. }
  276. /// <summary>
  277. /// 窗口弧度
  278. /// </summary>
  279. /// <param name="sender"></param>
  280. /// <param name="e"></param>
  281. private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
  282. {
  283. System.Windows.Rect r = new System.Windows.Rect(e.NewSize);
  284. RectangleGeometry gm = new RectangleGeometry(r, 1, 1);
  285. ((UIElement)sender).Clip = gm;
  286. }
  287. /// <summary>
  288. /// 登陆事件
  289. /// </summary>
  290. /// <param name="sender"></param>
  291. /// <param name="e"></param>
  292. private void btnLogin_Click(object sender, RoutedEventArgs e)
  293. {
  294. //if (!ZConfig.isActivationSuccessful)
  295. //{
  296. // Verification();
  297. // return;
  298. //}
  299. if (string.IsNullOrEmpty(txbAccountNumber.Text))
  300. {
  301. MessageWindow.Show("账号未输入");
  302. return;
  303. }
  304. if (string.IsNullOrEmpty(pobPassword.Password))
  305. {
  306. MessageWindow.Show("密码未输入");
  307. return;
  308. }
  309. APP.myloading.Show();
  310. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeServering, InvokeServerCompate);
  311. }
  312. /// <summary>
  313. /// 开始上课
  314. /// </summary>
  315. /// <param name="sender"></param>
  316. /// <param name="e"></param>
  317. private void btnClassesBegin_Click(object sender, RoutedEventArgs e)
  318. {
  319. if (string.IsNullOrWhiteSpace(cmbClass.Text))
  320. {
  321. MessageWindow.Show("尚未选择班级");
  322. return;
  323. }
  324. if (string.IsNullOrEmpty(cmbTeachingMaterial.Text))
  325. {
  326. MessageWindow.Show("尚未选择章节");
  327. return;
  328. }
  329. APP.myloading.Show();
  330. APP.classid = Convert.ToInt32(cmbClass.SelectedValue.ToString());
  331. for (int i = 0; i < APP.ClassList.Count; i++)
  332. {
  333. if (APP.classid == APP.ClassList[i].classid)
  334. {
  335. APP.REQStartClass.classnum = APP.ClassList[i].classnum;
  336. }
  337. }
  338. APP.REQStartClass.roomname = DateTime.Now.ToString() + cmbClass.Text;
  339. APP.REQStartClass.directorid = Convert.ToInt32(cmbTeachingMaterial.SelectedValue.ToString());
  340. APP.REQStartClass.roomid = TimestampAddRandomNumber();
  341. APP.roomid = APP.REQStartClass.roomid;
  342. try
  343. {
  344. //记录教材 章节 及当前登陆用户id
  345. string ApplicationData = APP.dataPath + "loginUserid.txt";
  346. string temp = APP.LoginUser.userid.ToString();
  347. System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
  348. ApplicationData = APP.dataPath + "loginLsbid.txt";
  349. temp = APP.lsbid.ToString();
  350. System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
  351. ApplicationData = APP.dataPath + "loginDirectorid.txt";
  352. temp = APP.REQStartClass.directorid.ToString();
  353. System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
  354. }
  355. catch (Exception ex)
  356. {
  357. LogHelper.WriteErrLog("【登陆(LoginWindow)" + ex.Message, ex);
  358. }
  359. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeClassStudentListServering, InvokeServerClassStudentListCompate);
  360. }
  361. /// <summary>
  362. /// 返回一个时间戳加3位随机数的long型整数
  363. /// </summary>
  364. /// <returns></returns>
  365. public long TimestampAddRandomNumber()
  366. {
  367. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  368. string timestr = Convert.ToInt64(ts.TotalMilliseconds).ToString();
  369. long tick = DateTime.Now.Ticks;
  370. Random ran = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
  371. int random = ran.Next(100, 999);
  372. return Convert.ToInt64(timestr + random.ToString());
  373. }
  374. /// <summary>
  375. /// 关闭
  376. /// </summary>
  377. /// <param name="sender"></param>
  378. /// <param name="e"></param>
  379. private void btnDown_Click(object sender, RoutedEventArgs e)
  380. {
  381. Close();
  382. Application.Current.Shutdown();
  383. System.Environment.Exit(0);
  384. }
  385. #endregion 事件
  386. #region 方法
  387. /// <summary>
  388. /// 读取客户设置
  389. /// </summary>
  390. /// <param name="settingName"></param>
  391. /// <returns></returns>
  392. public static string GetSettingString(string settingName)
  393. {
  394. try
  395. {
  396. string settingString = FileToolsCommon.GetConfigValue(settingName);
  397. return settingString;
  398. }
  399. catch (Exception)
  400. {
  401. return null;
  402. }
  403. }
  404. /// <summary>
  405. /// 更新设置
  406. /// </summary>
  407. /// <param name="settingName"></param>
  408. /// <param name="valueName"></param>
  409. public static void UpdateSettingString(string settingName, string valueName)
  410. {
  411. //Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  412. //if (ConfigurationManager.AppSettings[settingName] != null)
  413. //{
  414. // config.AppSettings.Settings.Remove(settingName);
  415. //}
  416. //config.AppSettings.Settings.Add(settingName, valueName);
  417. //config.Save(ConfigurationSaveMode.Modified);
  418. //ConfigurationManager.RefreshSection("appSettings");
  419. }
  420. /// <summary>
  421. /// 检测APP更新
  422. /// </summary>
  423. private void getNewApp()
  424. {
  425. //new Thread(o =>
  426. //{
  427. // string url = ZConfig.apiUrl + "/appclient/get_new";
  428. // string result = ZHttpUtil.PostAndRespStr(url, "{}");
  429. // Model.ResultVo<AppModel> resultObj = ZJsonHelper.JsonToObj<Model.ResultVo<AppModel>>(result);
  430. // if (result != null && resultObj.code == 0)
  431. // {
  432. // if (resultObj.obj != null)
  433. // {
  434. // int versionCode = resultObj.obj.versioncode;
  435. // int versionThis = ZConfig.versionCode;
  436. // if (versionThis < versionCode)
  437. // {
  438. // Dispatcher.Invoke(new Action(() =>
  439. // {
  440. // appUpdateShow(resultObj.obj);
  441. // }));
  442. // }
  443. // }
  444. // }
  445. //}).Start();
  446. }
  447. ///// <summary>
  448. ///// 应用更新
  449. ///// </summary>
  450. ///// <param name="app"></param>
  451. //private void appUpdateShow(AppModel app)
  452. //{
  453. // AppUpdateWin win = new AppUpdateWin(app);
  454. // win.Topmost = true;
  455. // win.Owner = this;
  456. // win.ShowDialog();
  457. //}
  458. /// <summary>
  459. /// 登陆服务-调用
  460. /// </summary>
  461. /// <returns></returns>
  462. private object InvokeServering()
  463. {
  464. string accountNumber = string.Empty;
  465. string password = string.Empty;
  466. Dispatcher.Invoke(new Action(() =>
  467. {
  468. accountNumber = txbAccountNumber.Text.Replace(" ", "").Trim();
  469. password = pobPassword.Password.Replace(" ", "").Trim();
  470. }));
  471. serverReturnCode = registerController.Login(accountNumber, password);
  472. return APP.ErrorMessage;
  473. }
  474. /// <summary>
  475. /// 登陆服务-返回结果
  476. /// </summary>
  477. /// <returns></returns>
  478. public void InvokeServerCompate(object obj)
  479. {
  480. APP.myloading.Hide();
  481. if (serverReturnCode == APP.ServerScuessCode)
  482. {
  483. new Thread(o =>
  484. {
  485. InvokeLiveBroadcastServering();
  486. Dispatcher.Invoke(new Action(() =>
  487. {
  488. InvokeServerLiveBroadcastCompate();
  489. }));
  490. }).Start();
  491. //grLogin.Visibility = Visibility.Collapsed;
  492. //grLoginTwo.Visibility = Visibility.Visible;
  493. //imgBrush.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/Login/login2_1.png"));
  494. //txbHeader.Text = APP.LoginUser.username + "老师,您好!";
  495. //version_tb.Visibility = Visibility.Collapsed;
  496. //btnSetUp.Visibility = Visibility.Collapsed;
  497. //UpdateSettingString("userName", txbAccountNumber.Text);
  498. //new Thread(o =>
  499. //{
  500. // InvokeClassListServering();
  501. // Dispatcher.Invoke(new Action(() =>
  502. // {
  503. // InvokeServerClassListCompate();
  504. // }));
  505. //}).Start();
  506. //new Thread(o =>
  507. //{
  508. // InvokeTsubjectbookListServering();
  509. // Dispatcher.Invoke(new Action(() =>
  510. // {
  511. // InvokeServerTsubjectbookListCompate();
  512. // }));
  513. //}).Start();
  514. }
  515. else
  516. {
  517. MessageWindow.Show(APP.ErrorMessage);
  518. }
  519. }
  520. /// <summary>
  521. /// 开始直播服务-调用
  522. /// </summary>
  523. /// <returns></returns>
  524. private object InvokeLiveBroadcastServering()
  525. {
  526. serverReturnCode = registerController.ClassList();
  527. return APP.ErrorMessage;
  528. }
  529. /// <summary>
  530. /// 开始直播服务-返回结果
  531. /// </summary>
  532. /// <returns></returns>
  533. public void InvokeServerLiveBroadcastCompate()
  534. {
  535. if (serverReturnCode == APP.ServerScuessCode)
  536. {
  537. string imagepath = APP.classRoomImagePath();
  538. if (!Directory.Exists(imagepath))
  539. {
  540. Directory.CreateDirectory(imagepath);
  541. }
  542. ToolbarWindow win = new ToolbarWindow();
  543. Close();
  544. win.ShowDialog();
  545. }
  546. else
  547. {
  548. MessageWindow.Show(APP.ErrorMessage);
  549. }
  550. }
  551. /// <summary>
  552. /// 教师任教班级服务-调用
  553. /// </summary>
  554. /// <returns></returns>
  555. private object InvokeClassListServering()
  556. {
  557. serverReturnCode = registerController.ClassList();
  558. return APP.ErrorMessage;
  559. }
  560. /// <summary>
  561. /// 教师任教班级服务-返回结果
  562. /// </summary>
  563. /// <returns></returns>
  564. public void InvokeServerClassListCompate()
  565. {
  566. if (serverReturnCode == APP.ServerScuessCode)
  567. {
  568. data.Columns.Add("Value");
  569. data.Columns.Add("Key");
  570. for (int i = 0; i < APP.ClassList.Count; i++)
  571. {
  572. //创建一行
  573. DataRow row = data.NewRow();
  574. //将此行添加到table中
  575. data.Rows.Add(row);
  576. if (APP.ClassList[i].gradeid != null)
  577. {
  578. switch (APP.ClassList[i].gradeid)
  579. {
  580. case 1:
  581. data.Rows[i]["Value"] = "一年级" + APP.ClassList[i].classname;
  582. break;
  583. case 2:
  584. data.Rows[i]["Value"] = "二年级" + APP.ClassList[i].classname;
  585. break;
  586. case 3:
  587. data.Rows[i]["Value"] = "三年级" + APP.ClassList[i].classname;
  588. break;
  589. case 4:
  590. data.Rows[i]["Value"] = "四年级" + APP.ClassList[i].classname;
  591. break;
  592. case 5:
  593. data.Rows[i]["Value"] = "五年级" + APP.ClassList[i].classname;
  594. break;
  595. case 6:
  596. data.Rows[i]["Value"] = "六年级" + APP.ClassList[i].classname;
  597. break;
  598. case 7:
  599. data.Rows[i]["Value"] = "七年级" + APP.ClassList[i].classname;
  600. break;
  601. case 8:
  602. data.Rows[i]["Value"] = "八年级" + APP.ClassList[i].classname;
  603. break;
  604. case 9:
  605. data.Rows[i]["Value"] = "九年级" + APP.ClassList[i].classname;
  606. break;
  607. case 10:
  608. data.Rows[i]["Value"] = "高一" + APP.ClassList[i].classname;
  609. break;
  610. case 11:
  611. data.Rows[i]["Value"] = "高二" + APP.ClassList[i].classname;
  612. break;
  613. case 12:
  614. data.Rows[i]["Value"] = "高三" + APP.ClassList[i].classname;
  615. break;
  616. default:
  617. data.Rows[i]["Value"] = APP.ClassList[i].classname;
  618. break;
  619. }
  620. }
  621. else
  622. {
  623. data.Rows[i]["Value"] = APP.ClassList[i].classname;
  624. }
  625. data.Rows[i]["Key"] = APP.ClassList[i].classid;
  626. }
  627. dtComponentsUniqueNo = data.DefaultView.ToTable();
  628. cmbClass.ItemsSource = dtComponentsUniqueNo.DefaultView;
  629. cmbClass.SelectedIndex = 0;
  630. //Shared.BackgroundWorkerHelper.RunWorkerAsync(InvokeTsubjectbookListServering, InvokeServerTsubjectbookListCompate);
  631. }
  632. else
  633. {
  634. MessageWindow.Show(APP.ErrorMessage);
  635. }
  636. }
  637. /// <summary>
  638. /// 教师教材列表服务-调用
  639. /// </summary>
  640. /// <returns></returns>
  641. private object InvokeTsubjectbookListServering()
  642. {
  643. serverReturnCode = registerController.TsubjectbookList();
  644. return APP.ErrorMessage;
  645. }
  646. /// <summary>
  647. /// 教师教材列表服务-返回结果
  648. /// </summary>
  649. /// <returns></returns>
  650. public void InvokeServerTsubjectbookListCompate()
  651. {
  652. if (serverReturnCode == APP.ServerScuessCode)
  653. {
  654. try
  655. {
  656. if (File.Exists(APP.dataPath + "loginUserid.txt"))
  657. {
  658. string userid = System.IO.File.ReadAllText(APP.dataPath + "loginUserid.txt", Encoding.Default);
  659. if (userid.Equals(APP.LoginUser.userid.ToString()))
  660. {
  661. if (File.Exists(APP.dataPath + "loginLsbid.txt"))
  662. {
  663. string lsbid = System.IO.File.ReadAllText(APP.dataPath + "loginLsbid.txt", Encoding.Default);
  664. lsbids = Convert.ToInt32(lsbid);
  665. if (File.Exists(APP.dataPath + "loginDirectorid.txt"))
  666. {
  667. string directorid = System.IO.File.ReadAllText(APP.dataPath + "loginDirectorid.txt", Encoding.Default);
  668. directorids = Convert.ToInt32(directorid);
  669. }
  670. }
  671. }
  672. }
  673. }
  674. catch (Exception ex)
  675. {
  676. LogHelper.WriteErrLog("【登陆(LoginWindow)" + ex.Message, ex);
  677. }
  678. int iTemp = 0;
  679. for (int i = 0; i < APP.TsubjectbookList.Count; i++)
  680. {
  681. if (lsbids != 0 && lsbids == APP.TsubjectbookList[i].lsbid)
  682. {
  683. iTemp = i;
  684. }
  685. pageData.bookList.Add(new ComboBoxBeanModel()
  686. {
  687. Key = APP.TsubjectbookList[i].lsbid,
  688. Value = $"{APP.TsubjectbookList[i].subjectname} {APP.TsubjectbookList[i].bookname}"
  689. });
  690. }
  691. book_list.SelectedIndex = iTemp;
  692. DataContext = pageData;
  693. }
  694. else
  695. {
  696. MessageWindow.Show(APP.ErrorMessage);
  697. }
  698. }
  699. /// <summary>
  700. /// 章节列表服务-调用
  701. /// </summary>
  702. /// <returns></returns>
  703. private string InvokeDirectorListServering(int index)
  704. {
  705. int selectIndex = index;
  706. if (selectIndex != -1)
  707. {
  708. APP.lsbid = APP.TsubjectbookList[selectIndex].lsbid;
  709. APP.REQStartClass.subjectid = APP.TsubjectbookList[selectIndex].subjectid;
  710. APP.REQStartClass.subjectname = APP.TsubjectbookList[selectIndex].subjectname;
  711. APP.DirectorList = null;
  712. serverReturnCode = registerController.DirectorList(APP.TsubjectbookList[selectIndex].lsbid,2,APP.LoginUser.userid);
  713. }
  714. return APP.ErrorMessage;
  715. }
  716. /// <summary>
  717. /// 章节列表服务-返回结果
  718. /// </summary>
  719. /// <returns></returns>
  720. public void InvokeServerDirectorListCompate()
  721. {
  722. if (serverReturnCode == APP.ServerScuessCode)
  723. {
  724. pageData.zhangjieList.Clear();
  725. for (int i = 0; i < APP.DirectorList.Count; i++)
  726. {
  727. DirectorListModel item = APP.DirectorList[i];
  728. pageData.zhangjieList.Add(new ComboBoxBeanModel()
  729. {
  730. Key = item.directorid,
  731. Value = item.directorname
  732. });
  733. addChild(item);
  734. }
  735. cmbTeachingMaterial.SelectedIndex = 0;
  736. for (int i = 0; i < pageData.zhangjieList.Count; i++)
  737. {
  738. if (pageData.zhangjieList[i].Key == directorids)
  739. {
  740. cmbTeachingMaterial.SelectedIndex = i;
  741. }
  742. }
  743. }
  744. else
  745. {
  746. MessageWindow.Show(APP.ErrorMessage);
  747. }
  748. }
  749. /// <summary>
  750. /// 子章节递归
  751. /// </summary>
  752. /// <param name="directorList"></param>
  753. private void addChild(DirectorListModel directorList)
  754. {
  755. if (directorList.children != null && directorList.children.Count > 0)
  756. {
  757. foreach (DirectorListModel child in directorList.children)
  758. {
  759. pageData.zhangjieList.Add(new ComboBoxBeanModel()
  760. {
  761. Key = child.directorid,
  762. Value = getSpace(child.directorlevel) + child.directorname
  763. });
  764. if (child.children != null && child.children.Count > 0)
  765. {
  766. addChild(child);
  767. }
  768. }
  769. }
  770. }
  771. /// <summary>
  772. /// 章节是否加空格符
  773. /// </summary>
  774. /// <param name="num"></param>
  775. /// <returns></returns>
  776. private string getSpace(int num)
  777. {
  778. string str = "";
  779. for (int i = 0; i < num; i++)
  780. {
  781. str += " ";
  782. }
  783. return str;
  784. }
  785. /// <summary>
  786. /// 开始课堂服务-调用
  787. /// </summary>
  788. /// <returns></returns>
  789. private object InvokeStartClassServering()
  790. {
  791. //Startclass startclass = new Startclass
  792. //{
  793. // classid = ZCommonData.classid,
  794. // roomname = Shared.TeachingData.REQ_StartClass.roomname,
  795. // subjectid = Shared.TeachingData.REQ_StartClass.subjectid,
  796. // teacherid = ZCommonData.loginUser.userid,
  797. // directorid = Shared.TeachingData.REQ_StartClass.directorid,
  798. // directortype = 1,
  799. // schoolid = ZCommonData.loginUser.schoolid,
  800. // roomid = Shared.TeachingData.REQ_StartClass.roomid,
  801. // lsbid = ZCommonData.lsbid,
  802. // createtime = DataProvider.TimestampTotalSeconds()
  803. //};
  804. //ZSqliteManger.insertClassData(new ClassData()
  805. //{
  806. // unix = DataProvider.TimestampTotalSeconds(),
  807. // roomid = ZCommonData.roomid,
  808. // api = "startclass",
  809. // json = ZJsonHelper.ToJson(startclass),
  810. // askid = DataProvider.TimestampAddRandomNumber()
  811. //});
  812. return APP.ErrorMessage;
  813. }
  814. /// <summary>
  815. /// 开始课堂服务-返回结果
  816. /// </summary>
  817. /// <returns></returns>
  818. public void InvokeStartClassCompate(object obj)
  819. {
  820. try
  821. {
  822. APP.myloading.Hide();
  823. string imagepath = APP.classRoomImagePath();
  824. if (!Directory.Exists(imagepath))
  825. {
  826. Directory.CreateDirectory(imagepath);
  827. }
  828. //Shared.BackgroundWorkerHelper.RunWorkerAsync(InvokeClassStudentListServering, InvokeServerClassStudentListCompate);
  829. ToolbarWindow win = new ToolbarWindow();
  830. Close();
  831. win.ShowDialog();
  832. }
  833. catch (Exception ex)
  834. {
  835. LogHelper.WriteErrLog("【LoginWindow】(InvokeStartClassCompate)" + ex.Message, ex);
  836. }
  837. }
  838. /// <summary>
  839. /// 班级学生--列表服务-调用
  840. /// </summary>
  841. /// <returns></returns>
  842. private object InvokeClassStudentListServering()
  843. {
  844. //serverReturnCode = registerController.ClassStudentList();
  845. return APP.ErrorMessage;
  846. }
  847. /// <summary>
  848. /// 班级学生--列表服务服务-返回结果
  849. /// </summary>
  850. /// <returns></returns>
  851. public void InvokeServerClassStudentListCompate(object obj)
  852. {
  853. //MyApp.myloading.Hide();
  854. if (serverReturnCode == APP.ServerScuessCode)
  855. {
  856. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeStartClassServering, InvokeStartClassCompate);
  857. }
  858. else
  859. {
  860. APP.myloading.Hide();
  861. MessageWindow.Show(APP.ErrorMessage);
  862. }
  863. }
  864. #endregion 方法
  865. private DataTable dtComponentsUniqueNo;
  866. public DataTable DtComponentsUniqueNo
  867. {
  868. get => dtComponentsUniqueNo;
  869. set => dtComponentsUniqueNo = value;
  870. }
  871. private void txbAccountNumber_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  872. {
  873. txbAccountNumber.Text = "";
  874. txbAccountNumber.Tag = "";
  875. }
  876. /// <summary>
  877. /// 单选框事件
  878. /// </summary>
  879. /// <param name="sender"></param>
  880. /// <param name="e"></param>
  881. private void ckSaveName_Click(object sender, RoutedEventArgs e)
  882. {
  883. if (ckSaveName.IsChecked == false)
  884. {
  885. UpdateSettingString("isRemind", ckSaveName.IsChecked.ToString());
  886. }
  887. else
  888. {
  889. UpdateSettingString("isRemind", ckSaveName.IsChecked.ToString());
  890. }
  891. }
  892. public void downloadBegin(int position)
  893. {
  894. }
  895. public void downloadProgress(int position, int progress)
  896. {
  897. }
  898. public void downloadEnd(int position, string filepath)
  899. {
  900. Console.WriteLine("下载完成" + filepath + " position:" + position);
  901. }
  902. /// <summary>
  903. /// 教材选中事件
  904. /// </summary>
  905. /// <param name="sender"></param>
  906. /// <param name="e"></param>
  907. private void toolbar_list_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
  908. {
  909. int SelectedIndex = book_list.SelectedIndex;
  910. new Thread(o =>
  911. {
  912. InvokeDirectorListServering(SelectedIndex);
  913. Dispatcher.Invoke(new Action(() =>
  914. {
  915. InvokeServerDirectorListCompate();
  916. }));
  917. }).Start();
  918. }
  919. /// <summary>
  920. /// 设置
  921. /// </summary>
  922. /// <param name="sender"></param>
  923. /// <param name="e"></param>
  924. private void btnSetUp_Click(object sender, RoutedEventArgs e)
  925. {
  926. //SetWindow win = new SetWindow
  927. //{
  928. // Topmost = true
  929. //};
  930. //win.Show();
  931. }
  932. public void downloadError(int position, string msg)
  933. {
  934. MessageWindow.Show(msg);
  935. }
  936. private void Button_Click(object sender, RoutedEventArgs e)
  937. {
  938. double pwidth = SystemParameters.PrimaryScreenWidth;
  939. if (APP.W_CameraWindow == null)
  940. {
  941. APP.W_CameraWindow = new CameraWindow();
  942. APP.W_CameraWindow.Topmost = true;
  943. APP.W_CameraWindow.Left = pwidth - 320;
  944. APP.W_CameraWindow.Top = 0;
  945. }
  946. APP.W_CameraWindow.Show();
  947. }
  948. }
  949. public class LoginPageData : NotifyModel
  950. {
  951. public ObservableCollection<ComboBoxBeanModel> bookList { get; set; }
  952. public ObservableCollection<ComboBoxBeanModel> zhangjieList { get; set; }
  953. public LoginPageData()
  954. {
  955. bookList = new ObservableCollection<ComboBoxBeanModel>();
  956. zhangjieList = new ObservableCollection<ComboBoxBeanModel>();
  957. }
  958. }
  959. }