Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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