RobotView.xaml.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel.Composition;
  5. using System.IO;
  6. using System.Windows;
  7. using Infrastructure;
  8. using NPOI.HSSF.UserModel;
  9. using NPOI.SS.UserModel;
  10. namespace Robot
  11. {
  12. /// <summary>
  13. /// RobotView.xaml 的交互逻辑
  14. /// </summary>
  15. [ViewExport(RegionName = "RobotRegion"), PartCreationPolicy(CreationPolicy.NonShared)]
  16. public partial class RobotView
  17. {
  18. public RobotView()
  19. {
  20. this.InitializeComponent();
  21. }
  22. [Import]
  23. private RobotViewModel ViewModel
  24. {
  25. get
  26. {
  27. return this.DataContext as RobotViewModel;
  28. }
  29. set
  30. {
  31. this.DataContext = value;
  32. }
  33. }
  34. private void menuReload_Click(object sender, RoutedEventArgs e)
  35. {
  36. this.ViewModel.Reload();
  37. }
  38. private async void btnFindPlayer_Click(object sender, RoutedEventArgs e)
  39. {
  40. await this.ViewModel.GetCharacterInfo();
  41. this.tcCharacterInfo.IsEnabled = true;
  42. this.btnForbidCharacter.IsEnabled = true;
  43. this.btnAllowCharacter.IsEnabled = true;
  44. this.tbLog.AppendText(Environment.NewLine + this.ViewModel.ErrorInfo);
  45. this.tbLog.ScrollToEnd();
  46. }
  47. private void menuLogin_Click(object sender, RoutedEventArgs e)
  48. {
  49. this.ViewModel.ReLogin();
  50. }
  51. private async void menuServers_Click(object sender, RoutedEventArgs e)
  52. {
  53. await this.ViewModel.Servers();
  54. this.tcAll.SelectedIndex = 0;
  55. this.tbLog.AppendText(Environment.NewLine + this.ViewModel.ErrorInfo);
  56. this.tbLog.ScrollToEnd();
  57. }
  58. private async void btnForbidCharacter_Click(object sender, RoutedEventArgs e)
  59. {
  60. await
  61. this.ViewModel.ForbidCharacter(this.cbForbiddenType.SelectedValue.ToString(),
  62. this.tbForbiddenTime.Text);
  63. this.tbLog.AppendText(Environment.NewLine + this.ViewModel.ErrorInfo);
  64. this.tbLog.ScrollToEnd();
  65. }
  66. private async void btnAllowCharacter_Click(object sender, RoutedEventArgs e)
  67. {
  68. await
  69. this.ViewModel.ForbidCharacter(this.cbForbiddenType.SelectedValue.ToString(),
  70. "-1");
  71. this.tbLog.AppendText(Environment.NewLine + this.ViewModel.ErrorInfo);
  72. this.tbLog.ScrollToEnd();
  73. }
  74. private async void btnSendCommand_Click(object sender, RoutedEventArgs e)
  75. {
  76. await this.ViewModel.SendCommand();
  77. this.tbLog.AppendText(Environment.NewLine + this.ViewModel.ErrorInfo);
  78. this.tbLog.ScrollToEnd();
  79. }
  80. private async void btnForbiddenLogin_Click(object sender, RoutedEventArgs e)
  81. {
  82. await
  83. this.ViewModel.ForbiddenLogin(this.cbForbiddenLogin.SelectedValue.ToString(),
  84. this.tbForbiddenLoginContent.Text, this.tbForbiddenLoginTime.Text);
  85. this.tbLog.AppendText(Environment.NewLine + this.ViewModel.ErrorInfo);
  86. this.tbLog.ScrollToEnd();
  87. }
  88. private async void btnAllowLogin_Click(object sender, RoutedEventArgs e)
  89. {
  90. await
  91. this.ViewModel.ForbiddenLogin(this.cbForbiddenLogin.SelectedValue.ToString(),
  92. this.tbForbiddenLoginContent.Text, "-1");
  93. this.tbLog.AppendText(Environment.NewLine + this.ViewModel.ErrorInfo);
  94. this.tbLog.ScrollToEnd();
  95. }
  96. private async void btnSendMail_Click(object sender, RoutedEventArgs e)
  97. {
  98. await this.ViewModel.SendMail();
  99. this.tbLog.AppendText(Environment.NewLine + this.ViewModel.ErrorInfo);
  100. this.tbLog.ScrollToEnd();
  101. }
  102. private void btnExcel_Click(object sender, RoutedEventArgs e)
  103. {
  104. var dict = new Dictionary<string, int>
  105. {
  106. { "英雄令", 1 },
  107. { "英雄令材料", 2 },
  108. { "双倍", 3 },
  109. { "会员", 4 },
  110. { "聊天", 5 },
  111. { "材料", 6 },
  112. { "印记页", 7 },
  113. { "血统页", 8 },
  114. { "坐骑", 9 },
  115. { "染色", 10 },
  116. { "星之魂玉", 11 },
  117. { "月之魂玉", 12 },
  118. { "日之魂玉", 13 },
  119. { "技能书", 14 },
  120. { "混沌之玉", 15 },
  121. { "战绩", 16 },
  122. { "坐骑翅膀", 17 },
  123. { "变身", 18 },
  124. { "将星", 19 },
  125. { "平台装备", 20 },
  126. { "将星装备", 21 },
  127. { "血魄", 22 },
  128. { "装饰", 23 },
  129. { "烟花", 24 },
  130. { "英雄礼包", 25 },
  131. { "套装", 26 },
  132. };
  133. HSSFWorkbook hssfWorkbook;
  134. const string path = @"F:\MallItemProto.xls";
  135. using (var file = new FileStream(path, FileMode.Open, FileAccess.Read))
  136. {
  137. hssfWorkbook = new HSSFWorkbook(file);
  138. }
  139. var sheet = hssfWorkbook.GetSheetAt(0);
  140. IEnumerator rows = sheet.GetRowEnumerator();
  141. const int nameIndex = 'Z' - 'A';
  142. rows.MoveNext();
  143. rows.MoveNext();
  144. rows.MoveNext();
  145. rows.MoveNext();
  146. while (rows.MoveNext())
  147. {
  148. var row = (HSSFRow) rows.Current;
  149. if (row.GetCell(nameIndex) == null)
  150. {
  151. continue;
  152. }
  153. var name = row.GetCell(nameIndex).ToString();
  154. if (!dict.ContainsKey(name))
  155. {
  156. continue;
  157. }
  158. ICell cell = row.GetCell(nameIndex - 1) ?? row.CreateCell(nameIndex - 1);
  159. cell.SetCellValue(dict[name].ToString());
  160. }
  161. using (var file = new FileStream(path, FileMode.Open, FileAccess.Write))
  162. {
  163. hssfWorkbook.Write(file);
  164. }
  165. this.lblShowResult.Content = "OK";
  166. }
  167. }
  168. }