Esempio n. 1
0
        private void OK_OnClick(object sender, RoutedEventArgs e)
        {
            switch (CurrType.ToString())
            {
            case "UchetVT.Board":
            {
                Board board = (Board)this.DataContext;

                if (board.HasError)
                {
                    MessageBox.Show("");
                    break;
                }

                if (board.Id == 0)
                {
                    DB.Boards.Set(board);
                }
                else
                {
                    DB.Boards.Update(board);
                }

                break;
            }

            case "UchetVT.CPU":
            {
                CPU cpu = (CPU)this.DataContext;

                if (cpu.Id == 0)
                {
                    DB.CPUs.Set(cpu);
                }
                else
                {
                    DB.CPUs.Update(cpu);
                }

                break;
            }

            case "UchetVT.HDD":
            {
                HDD hdd = (HDD)this.DataContext;

                if (hdd.Id == 0)
                {
                    DB.HDDs.Set(hdd);
                }
                else
                {
                    DB.HDDs.Update(hdd);
                }

                break;
            }

            case "UchetVT.License":
            {
                License license = (License)this.DataContext;

                if (license.Id == 0)
                {
                    DB.Licenses.Set(license);
                }
                else
                {
                    DB.Licenses.Update(license);
                }

                break;
            }

            case "UchetVT.NetworkDevice":
            {
                NetworkDevice networkDevice = (NetworkDevice)this.DataContext;

                if (networkDevice.Id == 0)
                {
                    DB.NetworkDevices.Set(networkDevice);
                }
                else
                {
                    DB.NetworkDevices.Update(networkDevice);
                }

                break;
            }

            case "UchetVT.OS":
            {
                OS os = (OS)this.DataContext;

                if (os.Id == 0)
                {
                    DB.OSes.Set(os);
                }
                else
                {
                    DB.OSes.Update(os);
                }

                break;
            }

            case "UchetVT.Printer":
            {
                Printer printer = (Printer)this.DataContext;

                if (printer.Id == 0)
                {
                    DB.Printers.Set(printer);
                }
                else
                {
                    DB.Printers.Update(printer);
                }

                break;
            }

            case "UchetVT.Region":
            {
                Region region = (Region)this.DataContext;

                if (region.Id == 0)
                {
                    DB.Regions.Set(region);
                }
                else
                {
                    DB.Regions.Update(region);
                }

                break;
            }

            case "UchetVT.UPS":
            {
                UPS ups = (UPS)this.DataContext;

                if (ups.Id == 0)
                {
                    DB.UPSes.Set(ups);
                }
                else
                {
                    DB.UPSes.Update(ups);
                }

                break;
            }

            case "UchetVT.User":
            {
                User user = (User)this.DataContext;

                if (user.Id == 0)
                {
                    DB.Users.Set(user);
                }
                else
                {
                    DB.Users.Update(user);
                }

                break;
            }

            case "UchetVT.VTComputer":
            {
                VTComputer vtComputer = (VTComputer)this.DataContext;

                // TODO: нати решение получше!
                //Готовим подстановку Id по выбранным вариантам из комбо-боксов
                vtComputer.BoardId = vtComputer.Board.Id = (DB.Boards.GetAll()
                                                            .FirstOrDefault(b => b.Motherboard == vtComputer.Board.Motherboard)).Id;

                vtComputer.CpuId = vtComputer.Cpu.Id = (DB.CPUs.GetAll()
                                                        .FirstOrDefault(b => b.NameCPU == vtComputer.Cpu.NameCPU)).Id;

                vtComputer.HddId = vtComputer.Hdd.Id = (DB.HDDs.GetAll()
                                                        .FirstOrDefault(b => b.NameHDD == vtComputer.Hdd.NameHDD)).Id;

                vtComputer.LicenseId = vtComputer.License.Id = (DB.Licenses.GetAll()
                                                                .FirstOrDefault(b => b.LicenseState == vtComputer.License.LicenseState)).Id;

                vtComputer.OsId = vtComputer.OS.Id = (DB.OSes.GetAll()
                                                      .FirstOrDefault(b => b.NameOS == vtComputer.OS.NameOS)).Id;

                //Добавляем ид района
                vtComputer.OwnerRegion = ((Region)((MainWindow)this.Owner).SideListView.SelectedItem).Id;
                // MessageBox.Show(vtComputer.OwnerRegion.ToString());  //TODO Убрать!

                if (vtComputer.Id == 0)
                {
                    DB.VTComputers.Set(vtComputer);
                }
                else
                {
                    DB.VTComputers.Update(vtComputer);
                }



                break;
            }

            case "UchetVT.VTPrinter":
            {
                VTPrinter vtPrinter = (VTPrinter)this.DataContext;

                // TODO: нати решение получше!
                //Готовим подстановку Id по выбранным вариантам из комбо-боксов
                vtPrinter.PrinterId = vtPrinter.Printer.Id = (DB.Printers.GetAll()
                                                              .FirstOrDefault(b => b.NamePrinter == vtPrinter.Printer.NamePrinter)).Id;

                //Добавляем ид района
                vtPrinter.OwnerRegion = ((Region)((MainWindow)this.Owner).SideListView.SelectedItem).Id;

                if (vtPrinter.Id == 0)
                {
                    DB.VTPrinters.Set(vtPrinter);
                }
                else
                {
                    DB.VTPrinters.Update(vtPrinter);
                }

                break;
            }

            case "UchetVT.VTNetworkDevice":
            {
                VTNetworkDevice vtNetworkDevice = (VTNetworkDevice)this.DataContext;

                // TODO: нати решение получше!
                //Готовим подстановку Id по выбранным вариантам из комбо-боксов
                vtNetworkDevice.DeviceId = vtNetworkDevice.NetworkDevice.Id = (DB.NetworkDevices.GetAll()
                                                                               .FirstOrDefault(b => b.NameNetworkDevice == vtNetworkDevice.NetworkDevice.NameNetworkDevice)).Id;

                //Добавляем ид района
                vtNetworkDevice.OwnerRegion = ((Region)((MainWindow)this.Owner).SideListView.SelectedItem).Id;

                if (vtNetworkDevice.Id == 0)
                {
                    DB.VTNetworkDevices.Set(vtNetworkDevice);
                }
                else
                {
                    DB.VTNetworkDevices.Update(vtNetworkDevice);
                }

                break;
            }

            case "UchetVT.VTUPS":
            {
                VTUPS vtUPS = (VTUPS)this.DataContext;

                // TODO: нати решение получше!
                //Готовим подстановку Id по выбранным вариантам из комбо-боксов
                vtUPS.UPSId = vtUPS.UPS.Id = (DB.UPSes.GetAll()
                                              .FirstOrDefault(b => b.NameUPS == vtUPS.UPS.NameUPS)).Id;

                //Добавляем ид района
                vtUPS.OwnerRegion = ((Region)((MainWindow)this.Owner).SideListView.SelectedItem).Id;

                if (vtUPS.Id == 0)
                {
                    DB.VTUPSes.Set(vtUPS);
                }
                else
                {
                    DB.VTUPSes.Update(vtUPS);
                }

                break;
            }
            }

            this.DialogResult = true;
            Close();
        }
Esempio n. 2
0
        private void EditButton_OnClick(object sender, RoutedEventArgs e)
        {
            if (SideListView.SelectedItem == null)
            {
                MessageBox.Show("Не выбран район или справочник");
                return;
            }
            RecordWindow recordWindow = new RecordWindow {
                Owner = this
            };

            //addRecordWindow.ShowDialog()
            //if (addRecordWindow.ShowDialog() == true) MessageBox.Show("OK!");

            switch (CurrentSideView)
            {
            case SideView.BookList:
            {
                Book b = (Book)SideListView.SelectedItem;
                if (b is Book)
                {
                    switch (b.Id)
                    {
                    case 1:
                    {
                        if (MainListView.SelectedItem is Board)
                        {
                            recordWindow.DataContext = MainListView.SelectedItem;
                        }
                        else
                        {
                            Board board = new Board()
                            {
                                Motherboard = "", YearOut = null
                            };
                            recordWindow.DataContext = board;
                        }
                        recordWindow.CurrType         = typeof(Board);
                        recordWindow.GroupBox.Content = TryFindResource("BoardFieldSet");


                        if (recordWindow.ShowDialog() == true)
                        {
                            MainListView.ItemsSource   = DB.Boards.GetAll();
                            MainListView.SelectedIndex = MainListView.Items.Count - 1;
                        }
                        break;
                    }

                    case 2:
                    {
                        if (MainListView.SelectedItem is CPU)
                        {
                            recordWindow.DataContext = MainListView.SelectedItem;
                        }
                        else
                        {
                            CPU cpu = new CPU()
                            {
                                NameCPU = ""
                            };
                            recordWindow.DataContext = cpu;
                        }
                        recordWindow.CurrType         = typeof(CPU);
                        recordWindow.GroupBox.Content = TryFindResource("CPUFieldSet");

                        if (recordWindow.ShowDialog() == true)
                        {
                            MainListView.ItemsSource   = DB.CPUs.GetAll();
                            MainListView.SelectedIndex = MainListView.Items.Count - 1;
                        }
                        break;
                    }

                    case 3:
                    {
                        if (MainListView.SelectedItem is HDD)
                        {
                            recordWindow.DataContext = MainListView.SelectedItem;
                        }
                        else
                        {
                            HDD hdd = new HDD()
                            {
                                NameHDD = ""
                            };
                            recordWindow.DataContext = hdd;
                        }
                        recordWindow.CurrType         = typeof(HDD);
                        recordWindow.GroupBox.Content = TryFindResource("HDDFieldSet");

                        if (recordWindow.ShowDialog() == true)
                        {
                            MainListView.ItemsSource   = DB.HDDs.GetAll();
                            MainListView.SelectedIndex = MainListView.Items.Count - 1;
                        }
                        break;
                    }

                    case 4:
                    {
                        if (MainListView.SelectedItem is License)
                        {
                            recordWindow.DataContext = MainListView.SelectedItem;
                        }
                        else
                        {
                            License license = new License()
                            {
                                LicenseState = ""
                            };
                            recordWindow.DataContext = license;
                        }
                        recordWindow.CurrType         = typeof(License);
                        recordWindow.GroupBox.Content = TryFindResource("LicenseFieldSet");

                        if (recordWindow.ShowDialog() == true)
                        {
                            MainListView.ItemsSource   = DB.Licenses.GetAll();
                            MainListView.SelectedIndex = MainListView.Items.Count - 1;
                        }
                        break;
                    }

                    case 5:
                    {
                        if (MainListView.SelectedItem is NetworkDevice)
                        {
                            recordWindow.DataContext = MainListView.SelectedItem;
                        }
                        else
                        {
                            NetworkDevice networkDevice = new NetworkDevice()
                            {
                                NameNetworkDevice = ""
                            };
                            recordWindow.DataContext = networkDevice;
                        }
                        recordWindow.CurrType         = typeof(NetworkDevice);
                        recordWindow.GroupBox.Content = TryFindResource("NetworkDeviceFieldSet");

                        if (recordWindow.ShowDialog() == true)
                        {
                            MainListView.ItemsSource   = DB.NetworkDevices.GetAll();
                            MainListView.SelectedIndex = MainListView.Items.Count - 1;
                        }
                        break;
                    }

                    case 6:
                    {
                        if (MainListView.SelectedItem is OS)
                        {
                            recordWindow.DataContext = MainListView.SelectedItem;
                        }
                        else
                        {
                            OS os = new OS()
                            {
                                NameOS = ""
                            };
                            recordWindow.DataContext = os;
                        }
                        recordWindow.CurrType         = typeof(OS);
                        recordWindow.GroupBox.Content = TryFindResource("OSFieldSet");


                        if (recordWindow.ShowDialog() == true)
                        {
                            MainListView.ItemsSource   = DB.OSes.GetAll();
                            MainListView.SelectedIndex = MainListView.Items.Count - 1;
                        }
                        break;
                    }

                    case 7:
                    {
                        if (MainListView.SelectedItem is Printer)
                        {
                            recordWindow.DataContext = MainListView.SelectedItem;
                        }
                        else
                        {
                            Printer printer = new Printer()
                            {
                                NamePrinter = "", LaserJet = false, MFU = false, MonoColor = false
                            };
                            recordWindow.DataContext = printer;
                        }
                        recordWindow.CurrType         = typeof(Printer);
                        recordWindow.GroupBox.Content = TryFindResource("PrinterFieldSet");

                        if (recordWindow.ShowDialog() == true)
                        {
                            MainListView.ItemsSource   = DB.Printers.GetAll();
                            MainListView.SelectedIndex = MainListView.Items.Count - 1;
                        }
                        break;
                    }

                    case 8:
                    {
                        //регионы
                        break;
                    }

                    case 9:
                    {
                        if (MainListView.SelectedItem is UPS)
                        {
                            recordWindow.DataContext = MainListView.SelectedItem;
                        }
                        else
                        {
                            UPS ups = new UPS()
                            {
                                NameUPS = ""
                            };
                            recordWindow.DataContext = ups;
                        }
                        recordWindow.CurrType         = typeof(UPS);
                        recordWindow.GroupBox.Content = TryFindResource("UPSFieldSet");

                        if (recordWindow.ShowDialog() == true)
                        {
                            MainListView.ItemsSource   = DB.UPSes.GetAll();
                            MainListView.SelectedIndex = MainListView.Items.Count - 1;
                        }
                        break;
                    }

                    case 10:
                    {
                        if (MainListView.SelectedItem is User)
                        {
                            recordWindow.DataContext = MainListView.SelectedItem;
                        }
                        else
                        {
                            User user = new User()
                            {
                                Name = "", Position = "", UserName = "", AccessToRegion = "", AccessToBook = ""
                            };
                            recordWindow.DataContext = user;
                        }
                        recordWindow.CurrType         = typeof(User);
                        recordWindow.GroupBox.Content = TryFindResource("UserFieldSet");

                        if (recordWindow.ShowDialog() == true)
                        {
                            MainListView.ItemsSource   = DB.Users.GetAll();
                            MainListView.SelectedIndex = MainListView.Items.Count - 1;
                        }
                        break;
                    }
                    }
                }
                break;
            }

            case SideView.RegionList:
            {
                switch (CurrentMainView)
                {
                case MainView.Computer:
                {
                    if (MainListView.SelectedItem is VTComputer)
                    {
                        recordWindow.DataContext = MainListView.SelectedItem;
                    }
                    else
                    {
                        VTComputer vtComputer = new VTComputer()
                        {
                            Board   = new Board(),
                            Cpu     = new CPU(),
                            Hdd     = new HDD(),
                            License = new License(),
                            OS      = new OS()
                        };
                        recordWindow.DataContext = vtComputer;
                    }
                    recordWindow.CurrType         = typeof(VTComputer);
                    recordWindow.GroupBox.Content = TryFindResource("VTComputerFieldSet");


                    if (recordWindow.ShowDialog() == true)
                    {
                        Region r = (Region)SideListView.SelectedItem;
                        MainListView.ItemsSource   = DB.VTComputers.GetAll(r.Id);
                        MainListView.SelectedIndex = MainListView.Items.Count - 1;
                    }
                    break;
                }

                case MainView.Printer:
                {
                    if (MainListView.SelectedItem is VTPrinter)
                    {
                        recordWindow.DataContext = MainListView.SelectedItem;
                    }
                    else
                    {
                        VTPrinter vtPrinter = new VTPrinter()
                        {
                            Printer = new Printer()
                        };
                        recordWindow.DataContext = vtPrinter;
                    }
                    recordWindow.CurrType         = typeof(VTPrinter);
                    recordWindow.GroupBox.Content = TryFindResource("VTPrinterFieldSet");


                    if (recordWindow.ShowDialog() == true)
                    {
                        Region r = (Region)SideListView.SelectedItem;
                        MainListView.ItemsSource   = DB.VTPrinters.GetAll(r.Id);
                        MainListView.SelectedIndex = MainListView.Items.Count - 1;
                    }
                    break;
                }

                case MainView.Network:
                {
                    if (MainListView.SelectedItem is VTNetworkDevice)
                    {
                        recordWindow.DataContext = MainListView.SelectedItem;
                    }
                    else
                    {
                        VTNetworkDevice vtNetworkDevice = new VTNetworkDevice()
                        {
                            NetworkDevice = new NetworkDevice()
                        };
                        recordWindow.DataContext = vtNetworkDevice;
                    }
                    recordWindow.CurrType         = typeof(VTNetworkDevice);
                    recordWindow.GroupBox.Content = TryFindResource("VTNetworkDeviceFieldSet");


                    if (recordWindow.ShowDialog() == true)
                    {
                        Region r = (Region)SideListView.SelectedItem;
                        MainListView.ItemsSource   = DB.VTNetworkDevices.GetAll(r.Id);
                        MainListView.SelectedIndex = MainListView.Items.Count - 1;
                    }
                    break;
                }

                case MainView.UPS:
                {
                    if (MainListView.SelectedItem is VTUPS)
                    {
                        recordWindow.DataContext = MainListView.SelectedItem;
                    }
                    else
                    {
                        VTUPS vtNetworkDevice = new VTUPS()
                        {
                            UPS = new UPS()
                        };
                        recordWindow.DataContext = vtNetworkDevice;
                    }
                    recordWindow.CurrType         = typeof(VTUPS);
                    recordWindow.GroupBox.Content = TryFindResource("VTUPSFieldSet");


                    if (recordWindow.ShowDialog() == true)
                    {
                        Region r = (Region)SideListView.SelectedItem;
                        MainListView.ItemsSource   = DB.VTUPSes.GetAll(r.Id);
                        MainListView.SelectedIndex = MainListView.Items.Count - 1;
                    }
                    break;
                }
                }
                break;
            }
            }
        }