Exemplo n.º 1
0
        private async void Change_Click(object sender, RoutedEventArgs e)
        {
            List <DeviceModel> changeDeviceModels = new List <DeviceModel>();
            ModelManager       modelManager       = ModelManager.GetInstance();
            var index             = DeviceGroupBox.SelectedIndex;
            var targetDeviceGroup = DeviceGroupModels[index];
            var req = "\"" + targetDeviceGroup.Context.Id + "\"";

            bool changed = false;

            Cursor = System.Windows.Input.Cursors.Wait;
            this.ChangeButton.IsEnabled = false;
            this.LoadButton.IsEnabled   = false;
            this.CloseButton.IsEnabled  = false;
            foreach (DeviceModelEx model in this.DeviceModelIces)
            {
                if (model.IsChecked)
                {
                    changeDeviceModels.Add(model.DeviceModel);
                }
            }

            if (changeDeviceModels.Count >= 1)
            {
                if (await modelManager.ChangeDeviceGroup(CurrentTenantModel, targetDeviceGroup, changeDeviceModels, req))
                {
                    changed = true;
                }
            }
            else
            {
                Cursor = null;
                this.ChangeButton.IsEnabled = true;
                this.LoadButton.IsEnabled   = true;
                this.CloseButton.IsEnabled  = true;
                return;
            }

            if (changed)
            {
                this.DeviceModels = await modelManager.GetDeviceModels(CurrentTenantModel, false);

                foreach (DeviceModel model in this.DeviceModels)
                {
                    DeviceModelEx newObj = GetDeviceModelEx(model.Id);
                    if (newObj != null)
                    {
                        DeviceModelIces.Remove(newObj);
                        newObj.Product     = model.Product;
                        newObj.DeviceGroup = model.DeviceGroup;
                        newObj.DeviceModel = model;
                        DeviceModelIces.Add(newObj);
                    }
                }
                gridDeviceGroups.ItemsSource = this.DeviceModelIces;
                this.gridDeviceGroups.Items.Refresh();
            }
            Cursor = null;
            this.ChangeButton.IsEnabled = true;
            this.LoadButton.IsEnabled   = true;
            this.CloseButton.IsEnabled  = true;
        }