using System; using System.Collections.Generic; using System.Text; using ZigBee.Device; namespace Shared.Phone.UserCenter.DeviceShard { /// /// 编辑分享设备的信息 /// public class ShardDeviceMacInfoEditorForm : UserCenterCommonForm { #region ■ 变量声明___________________________ /// /// 画面正常关闭的回调函数 /// public Action ActionFormClose = null; /// /// 设备对象 /// private List listNewDevice = null; /// /// 获取得到了镜像信息 /// private bool receiveImageInfo = false; #endregion #region ■ 初始化_____________________________ /// /// 画面显示(底层会固定调用此方法,借以完成画面创建) /// /// 设备列表 public void ShowForm(List listdevices) { this.listNewDevice = listdevices; //设置标题信息 base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uDeviceInfo)); //初始化删除设备的界面(右上) //this.InitDeleteDeviceForm(); //初始化中部控件 this.InitMiddleFrame(); } /// /// 初始化中部控件 /// private void InitMiddleFrame() { this.bodyFrameLayout.RemoveAll(); //设备图片 var btnpictrue = new PicViewControl(510, 320); btnpictrue.Gravity = Gravity.CenterHorizontal; btnpictrue.Y = Application.GetRealHeight(100); Common.LocalDevice.Current.SetRealDeviceIconToControl(btnpictrue, listNewDevice); bodyFrameLayout.AddChidren(btnpictrue); var listview = new VerticalScrolViewLayout(); listview.Y = btnpictrue.Bottom + Application.GetRealHeight(100); listview.Height = bodyFrameLayout.Height - btnpictrue.Bottom - Application.GetRealHeight(100); bodyFrameLayout.AddChidren(listview); //生产商名称 var row = new RowLayout(); row.Height = ControlCommonResourse.ListViewRowHeight; listview.AddChidren(row); var btnManuView = new RowTopGrayView(false); btnManuView.TextID = R.MyInternationalizationString.uManufacturerName; row.AddChidren(btnManuView); var btnManu = new RowBottomBlackView(false); btnManu.Text = listNewDevice[0].ManufacturerName; if (string.IsNullOrEmpty(btnManu.Text) == true) { if (listNewDevice[0].DriveCode > 0) { //虚拟设备固定使用HDL btnManu.Text = "HDL"; } } row.AddChidren(btnManu); //设备型号 row = new RowLayout(); row.Height = ControlCommonResourse.ListViewRowHeight; listview.AddChidren(row); var btnModelIdView = new RowTopGrayView(false); btnModelIdView.TextID = R.MyInternationalizationString.uModelIdentifier; row.AddChidren(btnModelIdView); var btnModelId = new RowBottomBlackView(false); btnModelId.Text = listNewDevice[0].ModelIdentifier; row.AddChidren(btnModelId); //序列号 row = new RowLayout(); row.Height = ControlCommonResourse.ListViewRowHeight; listview.AddChidren(row); var btnSerialView = new RowTopGrayView(false); btnSerialView.TextID = R.MyInternationalizationString.uSerialNumber; row.AddChidren(btnSerialView); var btnSerial = new RowBottomBlackView(false); btnSerial.Text = listNewDevice[0].SerialNumber; if (string.IsNullOrEmpty(btnSerial.Text) == true) { btnSerial.Text = listNewDevice[0].DeviceAddr; } row.AddChidren(btnSerial); //产品名称 string caption = Language.StringByID(R.MyInternationalizationString.uProductName); string nameValue = Common.LocalDevice.Current.GetDeviceMacName(listNewDevice[0]); var btnDeviceView = new EditorNameValueRow(caption, nameValue); listview.AddChidren(btnDeviceView); btnDeviceView.InitControl(); //请输入产品名称 btnDeviceView.SetEmptyNameTip(Language.StringByID(R.MyInternationalizationString.uProductNameMastInput)); //编辑产品名称 btnDeviceView.SetDialogTitle(Language.StringByID(R.MyInternationalizationString.uEditorProductName)); btnDeviceView.ActionNameChangedEvent += (deviceName) => { //设备重命名然后打开新的画面 this.DeviceReName(deviceName); }; //只有是河东的设备的时候 if (Common.LocalDevice.Current.IsHdlDevice(listNewDevice[0]) == true) { //添加【固件信息】行 this.AddFirmwareVersionRow(listview); } } #endregion #region ■ 固件信息___________________________ /// /// 添加【固件信息】行 /// /// private void AddFirmwareVersionRow(VerticalScrolViewLayout listview) { //拥有200端口这个东西的时候,才会显示这一行 var oTADevice = Common.LocalDevice.Current.GetOTADevice(listNewDevice[0].DeviceAddr); if (oTADevice == null || oTADevice.ImgVersion == -1) { return; } var statuRow = new StatuRowLayout(listview); //固件信息 var btnUpview = new RowCenterView(false); btnUpview.TextID = R.MyInternationalizationString.uFirmwareInformation; statuRow.AddChidren(btnUpview); statuRow.AddRightIconControl(); statuRow.MouseUpEvent += (sender, e) => { var form = new Device.DeviceFirmwareInfoForm(); this.AddForm(form, listNewDevice); }; //设置设备的版本信息 this.SetDeviceVersionInfo(oTADevice); } /// /// 设置设备的版本信息 /// /// ota设备 private void SetDeviceVersionInfo(OTADevice oTADevice) { //打开进度条 this.ShowProgressBar(); new System.Threading.Thread(async () => { //设置设备全部的镜像信息 Common.LocalDevice.Current.SetAllImageInfoToOtaDevice(oTADevice, this.OtaImageInfoActionBack); int count = 5; while (this.receiveImageInfo == false && count > 0) { //等待设备镜像的反馈 await System.Threading.Tasks.Task.Delay(300); count--; } //变量还原 this.receiveImageInfo = false; //关闭进度条 this.CloseProgressBar(); }) { IsBackground = true }.Start(); } /// /// 获取到了OTA镜像信息回调(100%特定回调) /// /// /// private void OtaImageInfoActionBack(CommonDevice device, CommonDevice.DeviceStatusReportData reportData) { this.receiveImageInfo = true; } #endregion #region ■ 修改名字___________________________ /// /// 设备重命名 /// /// deviceName. private async void DeviceReName(string i_deviceName) { //修改MAC名 string deviceName = i_deviceName.Trim(); var result = await Common.LocalDevice.Current.ReMacName(this.listNewDevice, deviceName); if (result == false) { return; } Application.RunOnMainThread(() => { if (ActionFormClose != null) { this.ActionFormClose(deviceName); } }); } #endregion #region ■ 删除界面___________________________ /// /// 初始化删除设备的界面 /// private void InitDeleteDeviceForm() { var btnIcon = new TopLayoutMostRightView(); btnIcon.UnSelectedImagePath = "Item/More.png"; btnIcon.SelectedImagePath = "Item/MoreSelected.png"; topFrameLayout.AddChidren(btnIcon); btnIcon.MouseUpEventHandler += ((sender, e) => { //显示删除设备的弹窗界面 this.ShowDeleteDeviceDialogForm(); }); } /// /// 显示删除设备的弹窗界面 /// private void ShowDeleteDeviceDialogForm() { var frame = new TopRightMenuControl(this, 1); //删除设备 string deviceMenu = Language.StringByID(R.MyInternationalizationString.uDeleteDevice); frame.AddRowMenu(deviceMenu, (obj) => { //确认要删除该设备?{0}(删除设备后,绑定目标将消失) string msg = Language.StringByID(R.MyInternationalizationString.uDeleteDeviceMsg); if (msg.Contains("{0}") == true) { msg = string.Format(msg, "\r\n"); } this.ShowConfirmMsg(msg, "DoDeleteDevice"); }); } /// /// 删除指定设备 /// public async void DoDeleteDevice() { //开启进度条 this.ShowProgressBar(); //删除设备 bool result = await Common.LocalDevice.Current.DeleteDevice(listNewDevice); this.CloseProgressBar(); if (result == false) { return; } Application.RunOnMainThread(() => { //关闭界面 this.CloseForm(); //移除设备列表界面指定的设备 //this.LoadFormMethodByName("DeviceManagementMainForm", "RemoveDeviceFromMemory", listNewDevice); }); } #endregion } }