| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- using DeviceCenter.model;
- using DeviceCenter.utils;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- namespace DeviceCenter
- {
- /// <summary>
- /// AddDevice.xaml 的交互逻辑
- /// </summary>
- public partial class AddDevice : Window
- {
- private Config config = Config.getInstance();
- private ObservableCollection<Area> areas = new ObservableCollection<Area>();
- private ObservableCollection<Building> buildings = new ObservableCollection<Building>();
- private ObservableCollection<Floor> floors = new ObservableCollection<Floor>();
- public Device device { get; set; }
- public AddDevice()
- {
- InitializeComponent();
- cb_area.ItemsSource = areas;
- cb_building.ItemsSource = buildings;
- cb_floor.ItemsSource = floors;
- http.get<GetAreasResponse>("/area/all", new Dictionary<string, string> { ["size"] = "1000" }).Then(res =>
- {
- Console.WriteLine(res);
- res.content.ToList().ForEach(areas.Add);
- });
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- if (string.IsNullOrWhiteSpace(tb_name.Text))
- {
- MessageBox.Show("请输入名称");
- return;
- }
- if (string.IsNullOrWhiteSpace(tb_ip.Text))
- {
- MessageBox.Show("请输入ip");
- return;
- }
- if (cb_type.SelectedValue == null)
- {
- MessageBox.Show("请选择设备类型");
- return;
- }
- if ((DeviceType)cb_type.SelectedValue == DeviceType.ACS && string.IsNullOrWhiteSpace(tb_port.Text))
- {
- MessageBox.Show("请输入端口");
- return;
- }
- Device device;
- if ((DeviceType)cb_type.SelectedValue == DeviceType.ACS)
- {
- device = new AcsDevice();
- }
- else
- {
- device = new CarCamDevice();
- }
- device.ip = tb_ip.Text;
- if (!string.IsNullOrEmpty(tb_port.Text))
- {
- device.port = int.Parse(tb_port.Text);
- }
- device.name = tb_name.Text;
- device.username = tb_username.Text;
- device.password = tb_password.Text;
- device.status = DeviceStatus.IDLE;
- device.areaId = (long?)cb_area.SelectedValue;
- device.buildingId = (long?)cb_building.SelectedValue;
- device.floorId = (long?)cb_floor.SelectedValue;
- if (cb_dir.SelectedValue != null)
- {
- device.direction = (Direction)cb_dir.SelectedValue;
- }
- this.DialogResult = true;
- this.device = device;
- Close();
- }
- private void cb_area_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- http.get<GetBuildingResponse>("/building/all", new Dictionary<string, string>
- {
- ["size"] = "1000",
- ["query"] = "%7B%22areaId%22:" + cb_area.SelectedValue + "%7d"
- }).Then(res =>
- {
- buildings.Clear();
- res.content.ToList().ForEach(buildings.Add);
- }).Catch(err =>
- {
- Console.WriteLine(err);
- });
- }
- private void cb_building_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- http.get<GetFloorResponse>("/floor/all", new Dictionary<string, string>
- {
- ["size"] = "1000",
- ["query"] = "%7B%22buildingId%22:" + cb_building.SelectedValue + "%7d"
- }).Then(res =>
- {
- floors.Clear();
- res.content.ToList().ForEach(floors.Add);
- }).Catch(err =>
- {
- Console.WriteLine(err);
- });
- }
- }
- }
|