コード例 #1
0
        private void ComputerForm_Activated(object sender, EventArgs e)
        {
            using (var context = new PineappleContext())
            {
                computerTable.DataSource = null;
                computerTable.Rows.Clear();
                computerTable.Refresh();

                context.Computers.Load();
                context.Cpus.Load();
                context.Hdds.Load();
                context.Monitors.Load();
                context.Motherboards.Load();
                context.Mouses.Load();
                context.Printers.Load();
                DbSet <Computer> computers = context.Computers;
                int i = 0;
                computerTable.RowCount = computers.Count();

                foreach (Computer computer in computers)
                {
                    computerTable[0, i].Value = computer.Id;
                    computerTable[1, i].Value = computer.Condition;
                    computerTable[2, i].Value = computer.cpu.name;
                    computerTable[3, i].Value = computer.hdd.name;
                    computerTable[4, i].Value = computer.monitor.name;
                    computerTable[5, i].Value = computer.motherboard.name;
                    computerTable[6, i].Value = computer.mouse.name;
                    computerTable[7, i].Value = computer.printer.name;
                    i++;
                }
            }
        }
コード例 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (var context = new PineappleContext())
            {
                var editedEmployee = context.Employees.Find(id);

                editedEmployee.Name        = nameTextBox.Text;
                editedEmployee.Surname     = surnameTextBox.Text;
                editedEmployee.DateOfBirth = birthDayDateTimePicker.Value;
                editedEmployee.Position    = positionComboBox.Text;
                editedEmployee.Department  = departmentComboBox.Text;

                context.SaveChanges();
                Close();
            }
            using (var context = new PineappleContext())
            {
                var editedEmployee = context.Employees.Find(id);
                nameTextBox.Text                = context.Employees.Find(id).Name;
                surnameTextBox.Text             = context.Employees.Find(id).Surname;
                birthDayDateTimePicker.Value    = context.Employees.Find(id).DateOfBirth;
                positionComboBox.SelectedItem   = context.Employees.Find(id).Position;
                departmentComboBox.SelectedItem = context.Employees.Find(id).Department;
            }
        }
コード例 #3
0
        private void EditEmployeeForm_Load(object sender, EventArgs e)
        {
            positionComboBox.DataSource = null;
            positionComboBox.Items.Clear();

            departmentComboBox.DataSource = null;
            departmentComboBox.Items.Clear();

            using (var context = new PineappleContext())
            {
                context.Positions.Load();
                context.Departments.Load();
                DbSet <Position>   positions   = context.Positions;
                DbSet <Department> departments = context.Departments;

                foreach (Position position in positions)
                {
                    positionComboBox.Items.Add(position.Name);
                }
                foreach (Department department in departments)
                {
                    departmentComboBox.Items.Add(department.Name);
                }
            }

            using (var context = new PineappleContext())
            {
                var editedEmployee = context.Employees.Find(id);
                nameTextBox.Text                = context.Employees.Find(id).Name;
                surnameTextBox.Text             = context.Employees.Find(id).Surname;
                birthDayDateTimePicker.Value    = context.Employees.Find(id).DateOfBirth;
                positionComboBox.SelectedItem   = context.Employees.Find(id).Position;
                departmentComboBox.SelectedItem = context.Employees.Find(id).Department;
            }
        }
コード例 #4
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            using (var context = new PineappleContext())
            {
                var newComputer = new Computer()
                {
                    Id        = Convert.ToInt32(idTextBox.Text),
                    Condition = nameTextBox.Text
                };
                foreach (CPU cpu in context.Cpus)
                {
                    if (cpu.name == cpuCombobox.Text)
                    {
                        newComputer.cpu = cpu;
                    }
                }
                foreach (HDD hdd in context.Hdds)
                {
                    if (hdd.name == comboBoxHDD.Text)
                    {
                        newComputer.hdd = hdd;
                    }
                }
                foreach (Monitor monitor in context.Monitors)
                {
                    if (monitor.name == comboBoxMonitor.Text)
                    {
                        newComputer.monitor = monitor;
                    }
                }
                foreach (Motherboard motherboard in context.Motherboards)
                {
                    if (motherboard.name == comboBoxMonitor.Text)
                    {
                        newComputer.motherboard = motherboard;
                    }
                }
                foreach (Mouse mouse in context.Mouses)
                {
                    if (mouse.name == comboBoxMouse.Text)
                    {
                        newComputer.mouse = mouse;
                    }
                }
                foreach (Printer printer in context.Printers)
                {
                    if (printer.name == comboBoxPrinter.Text)
                    {
                        newComputer.printer = printer;
                    }
                }

                context.Computers.Add(newComputer);
                context.SaveChanges();
                Close();
            }
        }
コード例 #5
0
 private void AddButton_Click(object sender, EventArgs e)
 {
     using (var context = new PineappleContext())
     {
         var newPeriphery = new Periphery()
         {
             Id        = Convert.ToInt32(idTextBox.Text),
             Condition = nameTextBox.Text
         };
         context.Peripheries.Add(newPeriphery);
         context.SaveChanges();
         Close();
     }
 }
コード例 #6
0
 private void AddButton_Click(object sender, EventArgs e)
 {
     using (var context = new PineappleContext())
     {
         var newDepartment = new Department()
         {
             Id   = Convert.ToInt32(idTextBox.Text),
             Name = nameTextBox.Text
         };
         context.Departments.Add(newDepartment);
         context.SaveChanges();
         Close();
     }
 }
コード例 #7
0
 private void button1_Click(object sender, EventArgs e)
 {
     using (var context = new PineappleContext())
     {
         var newPosition = new Position()
         {
             Id   = Convert.ToInt32(idTextBox.Text),
             Name = nameTextBox.Text
         };
         context.Positions.Add(newPosition);
         context.SaveChanges();
         Close();
     }
 }
コード例 #8
0
 private void AddButton_Click(object sender, EventArgs e)
 {
     using (var context = new PineappleContext())
     {
         var newCPU = new CPU()
         {
             name         = nameTextBox.Text,
             frequency    = idTextBox.Text,
             manufacturer = textBox1.Text
         };
         context.Cpus.Add(newCPU);
         context.SaveChanges();
         Close();
     }
 }
コード例 #9
0
        private void buttonDelete_Click(object sender, EventArgs e)
        {
            var confirmResult = MessageBox.Show("Удалить этого работника из базы данных?",
                                                "Подтверждение удаления",
                                                MessageBoxButtons.YesNo);

            if (confirmResult == DialogResult.Yes)
            {
                using (var context = new PineappleContext())
                {
                    context.Employees.Load();
                    //add remove from department and computer

                    context.Employees.Remove(context.Employees.Find(id));
                    context.SaveChanges();
                    Close();
                }
            }
        }
コード例 #10
0
        private void PeripheryForm_Load(object sender, EventArgs e)
        {
            using (var context = new PineappleContext())
            {
                dataGridView1.DataSource = null;
                dataGridView1.Rows.Clear();
                dataGridView1.Refresh();

                context.Peripheries.Load();
                DbSet <Periphery> peripheries = context.Peripheries;
                int i = 0;
                dataGridView1.RowCount = peripheries.Count();

                foreach (Periphery periphery in peripheries)
                {
                    dataGridView1[0, i].Value = periphery.Id;
                    dataGridView1[1, i].Value = periphery.Condition;
                    i++;
                }
            }
        }
コード例 #11
0
        private void DepartmentForm_Activated(object sender, EventArgs e)
        {
            using (var context = new PineappleContext())
            {
                dataGridView1.DataSource = null;
                dataGridView1.Rows.Clear();
                dataGridView1.Refresh();

                context.Departments.Load();
                DbSet <Department> departments = context.Departments;
                int i = 0;
                dataGridView1.RowCount = departments.Count();

                foreach (Department department in departments)
                {
                    dataGridView1[0, i].Value = department.Id;
                    dataGridView1[1, i].Value = department.Name;
                    i++;
                }
            }
        }
コード例 #12
0
        private void MonitorForm_Activated(object sender, EventArgs e)
        {
            using (var context = new PineappleContext())
            {
                MonitorTable.DataSource = null;
                MonitorTable.Rows.Clear();
                MonitorTable.Refresh();

                context.Monitors.Load();
                DbSet <Monitor> monitors = context.Monitors;
                int             i        = 0;
                MonitorTable.RowCount = monitors.Count();

                foreach (Monitor monitor in monitors)
                {
                    MonitorTable[0, i].Value = monitor.name;
                    MonitorTable[1, i].Value = monitor.manufacturer;

                    i++;
                }
            }
        }
コード例 #13
0
        private void MouseForm_Load(object sender, EventArgs e)
        {
            using (var context = new PineappleContext())
            {
                MouseTable.DataSource = null;
                MouseTable.Rows.Clear();
                MouseTable.Refresh();

                context.Mouses.Load();
                DbSet <Mouse> mouses = context.Mouses;
                int           i      = 0;
                MouseTable.RowCount = mouses.Count();

                foreach (Mouse mouse in mouses)
                {
                    MouseTable[0, i].Value = mouse.name;
                    MouseTable[1, i].Value = mouse.manufacturer;

                    i++;
                }
            }
        }
コード例 #14
0
        private void PositionForm_Activated(object sender, EventArgs e)
        {
            using (var context = new PineappleContext())
            {
                PositionsTable.DataSource = null;
                PositionsTable.Rows.Clear();
                PositionsTable.Refresh();

                context.Positions.Load();
                DbSet <Position> positions = context.Positions;
                int i = 0;
                PositionsTable.RowCount = positions.Count();

                foreach (Position position in positions)
                {
                    PositionsTable[0, i].Value = position.Id;
                    PositionsTable[1, i].Value = position.Name;

                    i++;
                }
            }
        }
コード例 #15
0
ファイル: TestData.cs プロジェクト: stepandanilov/PineappleV2
        public void ClearData()
        {
            using (var context = new PineappleContext())
            {
                //context.CompSettings.RemoveRange(context.CompSettings);
                context.Computers.RemoveRange(context.Computers);
                context.Departments.RemoveRange(context.Departments);
                context.Employees.RemoveRange(context.Employees);
                context.Peripheries.RemoveRange(context.Peripheries);
                //context.PerSettings.RemoveRange(context.PerSettings);
                context.Positions.RemoveRange(context.Positions);
                //periphery
                context.Cpus.RemoveRange(context.Cpus);
                context.Hdds.RemoveRange(context.Hdds);
                context.Monitors.RemoveRange(context.Monitors);
                context.Motherboards.RemoveRange(context.Motherboards);
                context.Mouses.RemoveRange(context.Mouses);
                context.Printers.RemoveRange(context.Printers);

                context.SaveChanges();
            }
        }
コード例 #16
0
        private void PrinterForm_Activated(object sender, EventArgs e)
        {
            using (var context = new PineappleContext())
            {
                PrinterTable.DataSource = null;
                PrinterTable.Rows.Clear();
                PrinterTable.Refresh();

                context.Printers.Load();
                DbSet <Printer> printers = context.Printers;
                int             i        = 0;
                PrinterTable.RowCount = printers.Count();

                foreach (Printer printer in printers)
                {
                    PrinterTable[0, i].Value = printer.name;
                    PrinterTable[1, i].Value = printer.manufacturer;

                    i++;
                }
            }
        }
コード例 #17
0
        private void HDDForm_Activated(object sender, EventArgs e)
        {
            using (var context = new PineappleContext())
            {
                HDDTable.DataSource = null;
                HDDTable.Rows.Clear();
                HDDTable.Refresh();

                context.Hdds.Load();
                DbSet <HDD> hdds = context.Hdds;
                int         i    = 0;
                HDDTable.RowCount = hdds.Count();

                foreach (HDD hdd in hdds)
                {
                    HDDTable[0, i].Value = hdd.name;
                    HDDTable[1, i].Value = hdd.space;
                    HDDTable[2, i].Value = hdd.manufacturer;

                    i++;
                }
            }
        }
コード例 #18
0
ファイル: CPUForm.cs プロジェクト: stepandanilov/PineappleV2
        private void CPUForm_Activated(object sender, EventArgs e)
        {
            using (var context = new PineappleContext())
            {
                CPUTable.DataSource = null;
                CPUTable.Rows.Clear();
                CPUTable.Refresh();

                context.Cpus.Load();
                DbSet <CPU> cpus = context.Cpus;
                int         i    = 0;
                CPUTable.RowCount = cpus.Count();

                foreach (CPU cpu in cpus)
                {
                    CPUTable[0, i].Value = cpu.Id;
                    CPUTable[1, i].Value = cpu.name;
                    CPUTable[2, i].Value = cpu.frequency;
                    CPUTable[3, i].Value = cpu.manufacturer;

                    i++;
                }
            }
        }
コード例 #19
0
        private void AddComputer_Load(object sender, EventArgs e)
        {
            cpuCombobox.DataSource = null;
            cpuCombobox.Items.Clear();

            comboBoxHDD.DataSource = null;
            comboBoxHDD.Items.Clear();

            comboBoxMonitor.DataSource = null;
            comboBoxMonitor.Items.Clear();

            comboBoxMotherboard.DataSource = null;
            comboBoxMotherboard.Items.Clear();

            comboBoxMouse.DataSource = null;
            comboBoxMouse.Items.Clear();

            comboBoxPrinter.DataSource = null;
            comboBoxPrinter.Items.Clear();

            using (var context = new PineappleContext())
            {
                context.Cpus.Load();
                context.Hdds.Load();
                context.Monitors.Load();
                context.Motherboards.Load();
                context.Mouses.Load();
                context.Printers.Load();


                DbSet <CPU>         cpus         = context.Cpus;
                DbSet <HDD>         hdds         = context.Hdds;
                DbSet <Monitor>     monitors     = context.Monitors;
                DbSet <Motherboard> motherboards = context.Motherboards;
                DbSet <Mouse>       mouses       = context.Mouses;
                DbSet <Printer>     printers     = context.Printers;

                foreach (CPU cpu in cpus)
                {
                    cpuCombobox.Items.Add(cpu.name);
                }
                foreach (HDD hdd in hdds)
                {
                    comboBoxHDD.Items.Add(hdd.name);
                }
                foreach (Monitor monitor in monitors)
                {
                    comboBoxMonitor.Items.Add(monitor.name);
                }
                foreach (Motherboard motherboard in motherboards)
                {
                    comboBoxMotherboard.Items.Add(motherboard.name);
                }
                foreach (Mouse mouse in mouses)
                {
                    comboBoxMouse.Items.Add(mouse.name);
                }
                foreach (Printer printer in printers)
                {
                    comboBoxPrinter.Items.Add(printer.name);
                }
            }
        }
コード例 #20
0
ファイル: TestData.cs プロジェクト: stepandanilov/PineappleV2
        public void FillDb()
        {
            using (var context = new PineappleContext())
            {
                //positions
                var position1 = new Position()
                {
                    Name = "Директор"
                };
                var position2 = new Position()
                {
                    Name = "Бухгалтер"
                };
                var position3 = new Position()
                {
                    Name = "Системный администратор"
                };
                var position4 = new Position()
                {
                    Name = "Программист"
                };
                var position5 = new Position()
                {
                    Name = "Заместитель"
                };
                context.Positions.Add(position1);
                context.Positions.Add(position2);
                context.Positions.Add(position3);
                context.Positions.Add(position4);
                context.Positions.Add(position5);
                //departments
                var department1 = new Department()
                {
                    Id   = 1,
                    Name = "Технический"
                };
                var department2 = new Department()
                {
                    Id   = 2,
                    Name = "Юридический"
                };
                var department3 = new Department()
                {
                    Id   = 3,
                    Name = "Бухгалтерский"
                };
                var department4 = new Department()
                {
                    Id   = 4,
                    Name = "ИТ"
                };
                context.Departments.Add(department1);
                context.Departments.Add(department2);
                context.Departments.Add(department3);
                context.Departments.Add(department4);
                context.SaveChanges();
                //main

                var periphery1 = new Periphery()
                {
                    Id        = 1,
                    Condition = "Работает"
                };
                var periphery2 = new Periphery()
                {
                    Id        = 2,
                    Condition = "На ремонте"
                };
                var periphery3 = new Periphery()
                {
                    Id        = 3,
                    Condition = "Сломан"
                };
                context.Peripheries.Add(periphery1);
                context.Peripheries.Add(periphery2);
                context.Peripheries.Add(periphery3);

                //periphery
                var cpu1 = new CPU()
                {
                    Id           = 1,
                    name         = "R5-3600",
                    frequency    = "3600MHz",
                    manufacturer = "AMD"
                };
                var cpu2 = new CPU()
                {
                    Id           = 2,
                    name         = "i5-9400F",
                    frequency    = "2.9GHz",
                    manufacturer = "Intel"
                };
                var cpu3 = new CPU()
                {
                    Id           = 3,
                    name         = "i7-960",
                    frequency    = "3200Mhz",
                    manufacturer = "Intel"
                };
                var cpu4 = new CPU()
                {
                    Id           = 4,
                    name         = "i5-10400",
                    frequency    = "2.9GHz",
                    manufacturer = "Intel"
                };
                var cpu5 = new CPU()
                {
                    Id           = 5,
                    name         = "R5-3500x",
                    frequency    = "3.6GHz",
                    manufacturer = "AMD"
                };
                context.Cpus.Add(cpu1);
                context.Cpus.Add(cpu2);
                context.Cpus.Add(cpu3);
                context.Cpus.Add(cpu4);
                context.Cpus.Add(cpu5);

                var hdd1 = new HDD()
                {
                    name         = "WD10EZEX",
                    manufacturer = "SATA",
                    space        = "1TB"
                };
                var hdd2 = new HDD()
                {
                    name         = "ST2000DM008",
                    manufacturer = "Seagate Barracuda",
                    space        = "2TB"
                };
                var hdd3 = new HDD()
                {
                    name         = "KOKOKOKOKWEDWQDS",
                    manufacturer = "Toshiba",
                    space        = "1TB"
                };
                var hdd4 = new HDD()
                {
                    name         = "HDWD105UZASDA",
                    manufacturer = "Toshiba",
                    space        = "500GB"
                };
                var hdd5 = new HDD()
                {
                    name         = "ASDASDASDASD",
                    manufacturer = "Toshiba",
                    space        = "1TB"
                };
                context.Hdds.Add(hdd1);
                context.Hdds.Add(hdd2);
                context.Hdds.Add(hdd3);
                context.Hdds.Add(hdd4);
                context.Hdds.Add(hdd5);
                context.SaveChanges();

                var motherboard1 = new Motherboard()
                {
                    name         = "A320M-DVS R4.0",
                    manufacturer = "ASRock"
                };
                var motherboard2 = new Motherboard()
                {
                    name         = "A68HM-K",
                    manufacturer = "ASUS"
                };
                var motherboard3 = new Motherboard()
                {
                    name         = "H310CM-HDV",
                    manufacturer = "ASRock"
                };
                var motherboard4 = new Motherboard()
                {
                    name         = "760GM-HDV",
                    manufacturer = "ASRock"
                };
                var motherboard5 = new Motherboard()
                {
                    name         = "A320M-PRO-E",
                    manufacturer = "MSI"
                };
                context.Motherboards.Add(motherboard1);
                context.Motherboards.Add(motherboard2);
                context.Motherboards.Add(motherboard3);
                context.Motherboards.Add(motherboard4);
                context.Motherboards.Add(motherboard5);
                context.SaveChanges();
                var monitor1 = new Monitor()
                {
                    name         = "T3U81AA",
                    manufacturer = "HP"
                };
                var monitor2 = new Monitor()
                {
                    name         = "193V5LSB2",
                    manufacturer = "Philips"
                };
                var monitor3 = new Monitor()
                {
                    name         = "E970SWN",
                    manufacturer = "AOC"
                };
                var monitor4 = new Monitor()
                {
                    name         = "V206HQLAb",
                    manufacturer = "Acer"
                };
                var monitor5 = new Monitor()
                {
                    name         = "T3U83AA",
                    manufacturer = "HP"
                };

                context.Monitors.Add(monitor1);
                context.Monitors.Add(monitor2);
                context.Monitors.Add(monitor3);
                context.Monitors.Add(monitor4);
                context.Monitors.Add(monitor5);

                var mouse1 = new Mouse()
                {
                    name         = "G102",
                    manufacturer = "Logitech"
                };
                var mouse2 = new Mouse()
                {
                    name         = "M170",
                    manufacturer = "Logitech"
                };
                var mouse3 = new Mouse()
                {
                    name         = "G502-Hero",
                    manufacturer = "Logitech"
                };
                var mouse4 = new Mouse()
                {
                    name         = "DeathAdder",
                    manufacturer = "Razer"
                };
                var mouse5 = new Mouse()
                {
                    name         = "G403-Hero",
                    manufacturer = "Logitech"
                };
                context.Mouses.Add(mouse1);
                context.Mouses.Add(mouse2);
                context.Mouses.Add(mouse3);
                context.Mouses.Add(mouse4);
                context.Mouses.Add(mouse5);

                var printer1 = new Printer()
                {
                    name         = "Phaser 3020",
                    manufacturer = "Xerox"
                };
                var printer2 = new Printer()
                {
                    name         = "HL-L2300DR",
                    manufacturer = "Brother"
                };
                var printer3 = new Printer()
                {
                    name         = "L805",
                    manufacturer = "Epson"
                };
                var printer4 = new Printer()
                {
                    name         = "L120",
                    manufacturer = "Epson"
                };
                var printer5 = new Printer()
                {
                    name         = "L1110",
                    manufacturer = "Epson"
                };
                context.Printers.Add(printer1);
                context.Printers.Add(printer2);
                context.Printers.Add(printer3);
                context.Printers.Add(printer4);
                context.Printers.Add(printer5);
                context.SaveChanges();
                var computer1 = new Computer()
                {
                    Id          = 1,
                    Condition   = "Работает",
                    cpu         = cpu1,
                    hdd         = hdd1,
                    monitor     = monitor1,
                    motherboard = motherboard1,
                    mouse       = mouse1,
                    printer     = printer1
                };

                var computer2 = new Computer()
                {
                    Id          = 2,
                    Condition   = "На ремонте",
                    cpu         = cpu2,
                    hdd         = hdd2,
                    monitor     = monitor2,
                    motherboard = motherboard2,
                    mouse       = mouse2,
                    printer     = printer2
                };
                var computer3 = new Computer()
                {
                    Condition   = "Сломан",
                    cpu         = cpu3,
                    hdd         = hdd3,
                    monitor     = monitor3,
                    motherboard = motherboard3,
                    mouse       = mouse3,
                    printer     = printer3
                };
                var computer4 = new Computer()
                {
                    Condition   = "Сломан",
                    cpu         = cpu4,
                    hdd         = hdd4,
                    monitor     = monitor4,
                    motherboard = motherboard4,
                    mouse       = mouse4,
                    printer     = printer4
                };
                var computer5 = new Computer()
                {
                    Condition   = "Сломан",
                    cpu         = cpu5,
                    hdd         = hdd5,
                    monitor     = monitor5,
                    motherboard = motherboard5,
                    mouse       = mouse5,
                    printer     = printer5
                };
                context.Computers.Add(computer1);
                context.Computers.Add(computer2);
                context.Computers.Add(computer3);
                context.Computers.Add(computer4);
                context.Computers.Add(computer5);
                var employee1 = new Employee()
                {
                    Id          = 1,
                    Name        = "Иван",
                    Surname     = "Иванов",
                    DateOfBirth = DateTime.Now.AddYears(-35),
                    Position    = position1.Name,
                    Department  = department1.Name
                };
                var employee2 = new Employee()
                {
                    Id          = 2,
                    Name        = "Степанов",
                    Surname     = "Степан",
                    DateOfBirth = DateTime.Now.AddYears(-34),
                    Position    = position2.Name,
                    Department  = department2.Name
                };
                var employee3 = new Employee()
                {
                    Id          = 3,
                    Name        = "Петров",
                    Surname     = "Петр",
                    DateOfBirth = DateTime.Now.AddYears(-29),
                    Position    = position3.Name,
                    Department  = department3.Name
                };
                var employee4 = new Employee()
                {
                    Id          = 3,
                    Name        = "Кычкин",
                    Surname     = "Кычик",
                    DateOfBirth = DateTime.Now.AddYears(-30),
                    Position    = position4.Name,
                    Department  = department4.Name
                };
                context.Employees.Add(employee1);
                context.Employees.Add(employee2);
                context.Employees.Add(employee3);
                context.Employees.Add(employee4);
                context.SaveChanges();
            }
        }