private void NewPerson_User_Computer_Activated(object sender, EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;

            computerComboBox.Items.Clear();

            Computer computer = new Computer();

            computer.findAll();

            foreach (Computer computerList in computer.computers)
            {
                computerComboBox.Items.Add(computerList.idcomputer);
            }

            //person_userComboBox.Items.Clear();

            Person_User person_user = new Person_User();

            //User user = new User();

            //Person person = new Person();

            //person_user.findAll();

            //foreach (Person_User person_userList in person_user.persons_users)
            //{
            //    user.iduser = person_userList.iduser;
            //    user.findByIdUser();
            //    person_user.user = user;

            //    person.idperson = person_userList.idperson;
            //    person.findByIdperson();
            //    person_user.person = person;

            //    person_userComboBox.Items.Add(person_user.user.username + " - " + person_user.person.personname);
            //}

            person_userComboBox.Items.Clear();

            person_user.findAll();

            foreach (Person_User person_userList in person_user.persons_users)
            {
                person_userComboBox.Items.Add(person_userList.person.personname + " - " + person_userList.user.username);
            }

            this.Cursor = System.Windows.Forms.Cursors.Default;
        }
        public void Save(string exporttype)
        {
            int i = 0;
            Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();

            if (xlApp == null)
            {
                Console.WriteLine("EXCEL could not be started. Check that your office installation and project references are correct.");
                return;
            }
            xlApp.Visible = true;

            Workbook wb = xlApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
            Worksheet ws = (Worksheet)wb.Worksheets[1];

            if (ws == null)
            {
                Console.WriteLine("Worksheet could not be created. Check that your office installation and project references are correct.");
            }

            /*string sheet_name = DateTime.Now.ToString("MM-dd-yy");

            Excel.Worksheet sheet = FindSheet(workbook, sheet_name);
            if (sheet == null)
            {
                // Add the worksheet at the end.
                sheet = (Excel.Worksheet)workbook.Sheets.Add(
                    Type.Missing, workbook.Sheets[workbook.Sheets.Count],
                    1, Excel.XlSheetType.xlWorksheet);
                sheet.Name = DateTime.Now.ToString("MM-dd-yy");
            }*/
            switch (exporttype)
            {
                case "person":

                    Person person = new Person();

                    person.findAll();

                    ws.Cells[1, 1] = "Nome";
                    ws.Cells[1, 2] = "Email";

                    i = 2;

                    foreach (Person personList in person.persons)
                    {
                        if (personList.personstate == true)
                        {
                            ws.Cells[i, 1] = personList.personname;
                            ws.Cells[i, 2] = personList.personemail;
                            i++;
                        }
                    }
                    break;
                case "user":

                    User user = new User();
                    Department department = new Department();

                    user.findAll();

                    ws.Cells[1, 1] = "Nome Utilizador";
                    ws.Cells[1, 2] = "Email";
                    ws.Cells[1, 3] = "Departamento";

                    i = 2;

                    foreach (User userList in user.users)
                    {
                        //if (computerList.personstate == true)
                        //{
                        ws.Cells[i, 1] = userList.username;
                        ws.Cells[i, 2] = userList.useremail;

                        department.iddepartment = userList.iddepartment;
                        department.findByIdDepartment();

                        ws.Cells[i, 3] = department.departmentname;
                        i++;
                        //}
                    }
                    break;
                case "computer":

                    Computer computer = new Computer();
                    Type type = new Type();
                    Brand brand = new Brand();

                    ws.Cells[1, 1] = "Número Computador";
                    ws.Cells[1, 2] = "Estado";

                    i = 2;

                    foreach (Computer computerList in computer.computers)
                    {
                        //if (computerList.personstate == true)
                        //{
                            ws.Cells[i, 1] = computerList.idcomputer;
                            ws.Cells[i, 2] = computerList.computerstate;
                            i++;
                        //}
                    }
                    break;
                case "vendor":

                    Vendor vendor = new Vendor();

                    vendor.findAll();

                    ws.Cells[1, 1] = "Fornecedor";

                    i = 2;

                    foreach (Vendor vendorList in vendor.vendors)
                    {
                        //if (computerList.personstate == true)
                        //{
                        ws.Cells[i, 1] = vendorList.vendorname;
                        i++;
                        //}
                    }
                    break;
                case "category":

                    Category category = new Category();

                    category.findAll();

                    ws.Cells[1, 1] = "Categoria";

                    i = 2;

                    foreach (Category categoryList in category.categories)
                    {
                        //if (computerList.personstate == true)
                        //{
                        ws.Cells[i, 1] = categoryList.categorydescription;
                        i++;
                        //}
                    }
                    break;
                default:
                    break;
            }

            //int l = person.persons.Count;
            //string a = "B" + l;
            // Select the Excel cells, in the range c1 to c7 in the worksheet.
            //Range aRange = ws.get_Range("A2", a);

            //if (aRange == null)
            //{
              //  Console.WriteLine("Could not get a range. Check to be sure you have the correct versions of the office DLLs.");
            //}

            // Fill the cells in the C1 to C7 range of the worksheet with the number 6.
            //Object[] args = new Object[1];
            //args[0] = 6;
            //aRange.GetType().InvokeMember("Value", BindingFlags.SetProperty, null, aRange, args);

            // Change the cells in the C1 to C7 range of the worksheet to the number 8.
            //aRange.Value2 = values;

            // Save the changes and close the workbook.
            //wb.Close(true, Type.Missing, Type.Missing);

            // Close the Excel server.
            //xlApp.Quit();

            //MessageBox.Show("Done");
        }