Esempio n. 1
0
        private void OnDeleteDevice(object s, RoutedEventArgs rea)
        {
            try
            {
                HidePopupMessage(mainLayout);

                if (devicesGrid.SelectedItem == null)
                {
                    throw new NullReferenceException("Выберите устройство из списка");
                }
                History.DeleteAllDeviceHistory(
                    devicesGrid.SelectedItem as Device
                    );

                DeviceConfiguration.Delete(
                    DeviceConfiguration.GetDeviceConfiguration(
                        devicesGrid.SelectedItem as Device
                        )
                    );

                Device.Delete(
                    devicesGrid.SelectedItem as Device
                    );

                UpdateDevicesGrid();
            }
            catch (NullReferenceException e)
            {
                ShowPopupMessage(e.Message, mainLayout);
            }
        }
        protected void DisplayDeviceCongifuration()
        {
            DeviceConfiguration currentDeviceConfiguration;
            History             currentHistoryNote;

            // Initializing selected in SuperUserWindow list Device state
            try
            {
                currentDeviceConfiguration =
                    DeviceConfiguration.
                    GetDeviceConfiguration(
                        SelectedDevice
                        );

                // Defining which IP do device have
                for (int i = 0; i < ipAddressBox.Items.Count; i++)
                {
                    if ((ipAddressBox.Items[i] as IPAddress).ID ==
                        currentDeviceConfiguration.IP.ID)
                    {
                        ipAddressBox.SelectedIndex = i;
                    }
                }

                // Displaying device password in passwordTextBox
                passwordBox.Text =
                    currentDeviceConfiguration.
                    AccountPassword;
                // Same for account name
                accoutNameBox.Text = currentDeviceConfiguration.AccountName;
            }
            catch (NoSuchDataException) { }

            try
            {
                currentHistoryNote = History.GetDeviceLastHistoryNote(SelectedDevice);

                // Setting device's Corps
                for (int i = 0; i < corpsBox.Items.Count; i++)
                {
                    if ((corpsBox.Items[i] as Corps).ID == currentHistoryNote.CorpsID)
                    {
                        corpsBox.SelectedIndex = i;
                    }
                }
            }
            catch (NoSuchDataException) { }
        }
        protected override void OnApplyButton(object sender, RoutedEventArgs rea)
        {
            try
            {
                RestoreFieldsBordersColor(mainLayout);
                HidePopupMessage(mainLayout);
                if (IsThereEmptyFields(mainLayout, 3))
                {
                    MakeEmptyFieldsRed(mainLayout, 3);
                    ShowPopupMessage("Не все поля заполнены", mainLayout);
                    return;
                }

                var newDevice = new Device()
                {
                    SerialNumber    = int.Parse(serialNumberBox.Text),
                    InventoryNumber = inventoryNumberBox.Text,
                    Type            = deviceTypeBox.SelectedItem as DeviceType,
                    NetworkName     = networkNameBox.Text
                };

                var newConfiguration = new DeviceConfiguration()
                {
                    DeviceSerialNumber = int.Parse(serialNumberBox.Text),
                    IP              = ipAddressBox.SelectedItem as IPAddress,
                    AccountName     = accoutNameBox.Text,
                    AccountPassword = passwordBox.Text
                };

                var newHistoryNote = new History()
                {
                    DeviceSerialNumber = long.Parse(serialNumberBox.Text),
                    Corps   = corpsBox.SelectedItem as Corps,
                    Cabinet = cabinetBox.SelectedItem as Cabinet,
                    Status  = (bool)statusBox.IsChecked ?
                              Status.GetStatusByName("Убрано на склад") :
                              Status.GetStatusByName("Перемещено"),
                    ChangeTimeDateTime = DateTime.Now
                };

                Device.Edit(
                    SelectedDevice,
                    newDevice
                    );

                DeviceConfiguration.Edit(
                    DeviceConfiguration.GetDeviceConfiguration(SelectedDevice),
                    newConfiguration
                    );

                History.Write(
                    newHistoryNote
                    );
            }
            catch (FormatException)
            {
                MakeRedBorders(serialNumberBox);
                ShowPopupMessage("Серийный номер должен быть числом", mainLayout);
            }
            catch (DataAlreadyExistException)
            {
            }
            catch (ConnectionLostException e) { ShowPopupMessage(e.Message, mainLayout); }
            catch (NoSuchDataException) { }
            finally
            {
                CloseThisWindow();
                parentWindow.UpdateDevicesGrid();
            }
        }