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.
 
 

157 lines
6.4 KiB

  1. using AduSkin.Controls.Metro;
  2. using IOT.Help.Model;
  3. using IOT.Help.ViewModel;
  4. using System.Collections.Generic;
  5. using System.Collections.ObjectModel;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Input;
  11. using 服务API.Tool.API请求;
  12. using 服务API.Tool.IOT;
  13. namespace IOT.Help
  14. {
  15. /// <summary>
  16. /// Interaction logic for MainWindow.xaml
  17. /// </summary>
  18. public partial class MainWindow :MetroWindow
  19. {
  20. public MainWindow()
  21. {
  22. InitializeComponent();
  23. this.DataContext = MainViewModel.Instance;
  24. this.Closed += delegate { Application.Current.Shutdown(); };
  25. CarouselTest();
  26. }
  27. private void Button_Click(object sender,RoutedEventArgs e)
  28. {
  29. if (sender is Button)
  30. {
  31. bool istrue = false;
  32. Button button = sender as Button;
  33. if (button.Tag!=null)
  34. {
  35. switch (button.Tag.ToString())
  36. {
  37. case "Add":
  38. istrue = MainViewModel.Instance.Add();
  39. if (istrue) MessageBox.Show("增加成功");
  40. else MessageBox.Show("增加失败");
  41. break;
  42. case "Update":
  43. if (string.IsNullOrEmpty(MainViewModel.Instance.device.IdStr)) {
  44. MessageBox.Show("请先“查询”或者“双击右侧表格行”,修改之后在点击“修改”");
  45. return;
  46. }
  47. istrue= MainViewModel.Instance.Update();
  48. if(istrue) MessageBox.Show("修改成功");
  49. else MessageBox.Show("修改失败");
  50. break;
  51. case "Delete":
  52. if (string.IsNullOrEmpty(MainViewModel.Instance.device.IdStr))
  53. {
  54. MessageBox.Show("请先“查询”或者“双击右侧表格行”,修改之后在点击“删除”");
  55. return;
  56. }
  57. istrue = MainViewModel.Instance.Delete();
  58. if (istrue) MessageBox.Show("删除成功");
  59. else MessageBox.Show("删除失败");
  60. break;
  61. case "SetUrl":
  62. MainViewModel.Instance.ApiURL = apiurl.Text;
  63. MainViewModel.Instance.Refresh();
  64. MessageBox.Show("设置成功");
  65. break;
  66. case "Inquire":
  67. MainViewModel.Instance.device= MainViewModel.Instance.Inquire(chen.Text)?.FirstOrDefault();
  68. break;
  69. case "Save":
  70. System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog();
  71. saveFileDialog.Filter = "txt文件(*.txt)|*.txt";
  72. if (saveFileDialog.ShowDialog()== System.Windows.Forms.DialogResult.OK)
  73. {
  74. StreamWriter sw = File.CreateText(saveFileDialog.FileName);
  75. sw.Write(Tools.JsonConvertTools(MainViewModel.Instance.deviceTable)); //写入文件中
  76. sw.Flush();//清理缓冲区
  77. sw.Close();//关闭文件
  78. }
  79. break;
  80. case "Insert":
  81. System.Windows.Forms.OpenFileDialog file = new System.Windows.Forms.OpenFileDialog();//定义新的文件打开位置控件
  82. file.Filter = "txt文件(*.txt)|*.txt";//设置文件后缀的过滤
  83. if (file.ShowDialog() == System.Windows.Forms.DialogResult.OK)//如果有选择打开文件
  84. {
  85. DeviceTable device = null;
  86. FileStream fs = new FileStream(file.FileName,FileMode.Open,FileAccess.Read,FileShare.ReadWrite);
  87. StreamReader sr = new StreamReader(fs,System.Text.Encoding.UTF8); //选择编码方式
  88. string str = sr.ReadToEnd();
  89. if (!string.IsNullOrEmpty(str))
  90. {
  91. Tools.JsonToObjectTools<List<DeviceTable>>(str)?.ForEach(par =>
  92. {
  93. MainViewModel.Instance.Add(par);
  94. });
  95. MainViewModel.Instance.Refresh();
  96. }
  97. }
  98. break;
  99. }
  100. }
  101. }
  102. }
  103. private void DataGrid_MouseDoubleClick(object sender,MouseButtonEventArgs e)
  104. {
  105. MainViewModel.Instance.device = MainViewModel.Instance.deviceTableSelectedItem;
  106. }
  107. #region Test
  108. /// <summary>
  109. /// 测试轮播
  110. /// </summary>
  111. public void CarouselTest()
  112. {
  113. #region 轮播
  114. ObservableCollection<Carouselname> list = new ObservableCollection<Carouselname>();
  115. for (int i = 0; i < 60; i++)
  116. {
  117. list.Add(new Carouselname()
  118. {
  119. imgpath = "../2.png",
  120. name = "AduSkin",
  121. info = "追求极致,永臻完美"
  122. });
  123. }
  124. this.CoverFlowMain.ItemsSource = list;
  125. CoverFlowMain.JumpTo(2);
  126. #endregion
  127. #region 轮播
  128. ObservableCollection<Carouselname> list1 = new ObservableCollection<Carouselname>();
  129. for (int i = 0; i < 5; i++)
  130. {
  131. list1.Add(new Carouselname()
  132. {
  133. imgpath = "../2.png",
  134. name = "黑菠萝科技",
  135. info = "hello word!"
  136. });
  137. }
  138. this.Carousels.ItemsSource = list1;
  139. #endregion
  140. }
  141. #endregion
  142. }
  143. }