using AduSkin.Controls.Metro; using DataVAPI.Model; using DataVAPI.Tool.API请求; using DataVAPI.Tool.IOT; using DataVIOT.Help.Model; using DataVIOT.Help.ViewModel; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Input; namespace IOT.Help { /// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow :MetroWindow { public MainWindow() { InitializeComponent(); this.DataContext = MainViewModel.Instance; this.Closed += delegate { Application.Current.Shutdown(); }; CarouselTest(); } private void Button_Click(object sender,RoutedEventArgs e) { if (sender is Button) { bool istrue = false; Button button = sender as Button; if (button.Tag!=null) { switch (button.Tag.ToString()) { case "Add": istrue = MainViewModel.Instance.Add(); if (istrue) MessageBox.Show("增加成功"); else MessageBox.Show("增加失败"); break; case "Update": if (string.IsNullOrEmpty(MainViewModel.Instance.device.Id)) { MessageBox.Show("请先“查询”或者“双击右侧表格行”,修改之后在点击“修改”"); return; } istrue= MainViewModel.Instance.Update(); if(istrue) MessageBox.Show("修改成功"); else MessageBox.Show("修改失败"); break; case "Delete": if (string.IsNullOrEmpty(MainViewModel.Instance.device.Id)) { MessageBox.Show("请先“查询”或者“双击右侧表格行”,修改之后在点击“删除”"); return; } istrue = MainViewModel.Instance.Delete(); if (istrue) MessageBox.Show("删除成功"); else MessageBox.Show("删除失败"); break; case "SetUrl": MainViewModel.Instance.ApiURL = apiurl.Text; MainViewModel.Instance.Refresh(); MessageBox.Show("设置成功"); break; case "Inquire": MainViewModel.Instance.device= MainViewModel.Instance.Inquire(chen.Text)?.FirstOrDefault(); break; case "Save": System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog(); saveFileDialog.Filter = "txt文件(*.txt)|*.txt"; if (saveFileDialog.ShowDialog()== System.Windows.Forms.DialogResult.OK) { StreamWriter sw = File.CreateText(saveFileDialog.FileName); sw.Write(Tools.JsonConvertTools(MainViewModel.Instance.deviceTable)); //写入文件中 sw.Flush();//清理缓冲区 sw.Close();//关闭文件 } break; case "Insert": System.Windows.Forms.OpenFileDialog file = new System.Windows.Forms.OpenFileDialog();//定义新的文件打开位置控件 file.Filter = "txt文件(*.txt)|*.txt";//设置文件后缀的过滤 if (file.ShowDialog() == System.Windows.Forms.DialogResult.OK)//如果有选择打开文件 { DeviceTable device = null; FileStream fs = new FileStream(file.FileName,FileMode.Open,FileAccess.Read,FileShare.ReadWrite); StreamReader sr = new StreamReader(fs,System.Text.Encoding.UTF8); //选择编码方式 string str = sr.ReadToEnd(); if (!string.IsNullOrEmpty(str)) { Tools.JsonToObjectTools>(str)?.ForEach(par => { MainViewModel.Instance.Add(par); }); MainViewModel.Instance.Refresh(); } } break; } } } } private void DataGrid_MouseDoubleClick(object sender,MouseButtonEventArgs e) { MainViewModel.Instance.device = MainViewModel.Instance.deviceTableSelectedItem; } #region Test /// /// 测试轮播 /// public void CarouselTest() { #region 轮播 ObservableCollection list = new ObservableCollection(); for (int i = 0; i < 60; i++) { list.Add(new Carouselname() { imgpath = "../2.png", name = "AduSkin", info = "追求极致,永臻完美" }); } this.CoverFlowMain.ItemsSource = list; CoverFlowMain.JumpTo(2); #endregion #region 轮播 ObservableCollection list1 = new ObservableCollection(); for (int i = 0; i < 5; i++) { list1.Add(new Carouselname() { imgpath = "../2.png", name = "黑菠萝科技", info = "hello word!" }); } this.Carousels.ItemsSource = list1; #endregion } #endregion } }