public static ViewDevModel DataToView(DeviceModel item) { string ImageUrl; switch (item.Type) { case "温度": ImageUrl = "/Source/Temp.png"; break; case "湿度": ImageUrl = "/Source/humidity.png"; break; case "Lumia 930": ImageUrl = "/Source/phone.png"; break; case "AirConditioner": ImageUrl = "/Source/airconditioner.png"; break; case "照明系统": ImageUrl = "/Source/Lightpng.png"; break; default: ImageUrl = null; break; } ViewDevModel Obj = new ViewDevModel() { NetPort = item.NetPort, Type = item.Type, IPAddress = item.IPAddress, ImageUrl = ImageUrl }; return(Obj); }
public static DeviceModel ViewToData(ViewDevModel ViewInfo) { DeviceModel Info = new DeviceModel() { NetPort = ViewInfo.NetPort, IPAddress = ViewInfo.IPAddress, Type = ViewInfo.Type }; return(Info); }
}//向云上传数据 #endregion #region 设备模型相关 private async void BtnAdd_Click(object sender, RoutedEventArgs e) { string[] data = cmbIp.SelectedItem.ToString().Trim().Split(Convert.ToChar("/")); DeviceModel Device = new DeviceModel { NetPort = await DevicesMethod.GetPortNum() + 1, Type = data[1], IPAddress = data[0] }; ViewDevModel DevObj = ModelConverter.DataToView(Device); Obj.Add(Device); DevicesMethod.UpdateDevices(Obj); gridView.Items.Add(DevObj); CreateLine(Device.NetPort); //绑定新通道 SendAllow(Device.NetPort); //发送端口允许 }