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

            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);
            }

            signatureComboBox.Items.Clear();

            Signature signature = new Signature();

            signature.findAll();

            foreach (Signature signatureList in signature.signatures)
            {
                signatureComboBox.Items.Add(signatureList.signaturename);
            }

            officeComboBox.Items.Clear();

            Office office = new Office();

            office.findAll();

            foreach (Office officeList in office.offices)
            {
                officeComboBox.Items.Add(officeList.officedescription);
            }

            this.Cursor = System.Windows.Forms.Cursors.Default;
        }
        public Signatures()
        {
            InitializeComponent();

            Signature signature = new Signature();

            signature.findAll();

            foreach (Signature signatureList in signature.signatures)
            {
                signatureComboBox.Items.Add(signatureList.signaturename);
            }

            Person person = new Person();

            person.findAll();

            foreach (Person personList in person.persons)
            {
                if (personList.personstate == true)
                {
                    if (personList.personemail == null)
                    {
                        personCheckedListBox.Items.Add(personList.personname);
                    }
                    else
                    {
                        personCheckedListBox.Items.Add(personList.personname + " - " + personList.personemail);
                    }
                }
            }

            if (windowsUsername.Contains(@"\"))
            {
                windowsUsernameSplit = windowsUsername.Split('\\');
                windowsUsername = windowsUsernameSplit[1];
            }

            textBox1.Text= @"C:\Users\" + windowsUsername + @"\Documents";
        }
        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");
        }
        private void button4_Click(object sender, EventArgs e)
        {
            if (verificationTextBox())
            {
                foreach (object itemChecked in personCheckedListBox.CheckedItems)
                {
                    Person person = new Person();
                    Person_User person_user = new Person_User();
                    User user = new User();
                    Person_User_Computer person_user_computer = new Person_User_Computer();

                    person.personname = itemChecked.ToString();

                    person.findByPersonname();

                    Console.WriteLine("IDperson: " + person.idperson);
                    Console.WriteLine("personname: " + person.personname);
                    Console.WriteLine("personemail: " + person.personemail);

                    person_user.idperson = person.idperson;

                    person_user.findByIdPerson();

                    Console.WriteLine("IDperson_user: "******"IDperson: " + person_user.idperson);
                    Console.WriteLine("IDuser: "******"IDperson_user: "******"IDcomputer: " + person_user_computer.idcomputer);
                    Console.WriteLine("computername: " + person_user_computer.computername);

                    user.iduser = person_user.iduser;

                    user.findByIdUser();

                    Console.WriteLine("IDuser: "******"username: "******"useremail: " + user.useremail);
                    Console.WriteLine("IDDepartmant: " + user.iddepartment);

                    destinationUserPath = @"\\"+person_user_computer.computername+@"\c$\Users\"+user.username+@"\AppData\Roaming\Microsoft\Signatures\";

                    Console.WriteLine(destinationUserPath);

                    sourcePath = System.IO.Path.Combine(textBox2.Text);

                    sourcePathsParts = sourcePath.Split('\\');

                    destinationBackupPath = System.IO.Path.Combine(textBox1.Text);

                    destinationBackupPath = destinationBackupPath + @"\" + person.personname + @"\" + sourcePathsParts.Last();

                    Console.WriteLine(destinationBackupPath);

                    if (!System.IO.Directory.Exists(destinationBackupPath))
                    {
                        System.IO.Directory.CreateDirectory(destinationBackupPath);
                    }

                    /*if (Directory.Exists(textBox2.Text))
                    {
                        filesSignatures = Directory.GetFiles(textBox2.Text);

                        foreach (string file in filesSignatures)
                        {
                            fileName = Path.GetFileName(file);
                            destinationFileBackupPath = Path.Combine(destinationBackupPath, fileName);
                            File.Copy(file, destinationFileBackupPath, true);
                            destinationFileUserPath = Path.Combine(destinationUserPath, fileName);
                            File.Copy(file, destinationFileUserPath, true);
                        }
                    }
                    else
                    {
                        MessageBox.Show("O caminho " + textBox2.Text + " não existe.", "Erro");
                    }*/
                }
            }
            else
            {
                MessageBox.Show("Tem que selecionar algo!!");
            }
        }
        public void findAll()
        {
            db = new Database();

            person_user_computerQuery = new MySqlCommand();

            person_user_computerQuery.Connection = db.Connection();

            person_user_computerQuery.CommandText = "SELECT * FROM person_user_computer";

            person_user_computerResult = person_user_computerQuery.ExecuteReader();

            while (person_user_computerResult.Read())
            {
                if (!person_user_computerResult.IsDBNull(0))
                {
                    idperson_user = person_user_computerResult.GetInt32(0);
                }

                if (!person_user_computerResult.IsDBNull(1))
                {
                    person = new Person();

                    person.idperson = person_user_computerResult.GetInt32(1);

                    person.findByIdperson();
                }

                if (!person_user_computerResult.IsDBNull(2))
                {
                    user = new User();

                    user.iduser = person_user_computerResult.GetInt32(2);

                    user.findByIdUser();
                }

                //if (!person_user_computerResult.IsDBNull(3))
                //{
                //    person_userstart = person_user_computerResult.GetDateTime(3);
                //}
                //else
                //{
                //    person_userstart = null;
                //}

                //if (!person_user_computerResult.IsDBNull(4))
                //{
                //    person_userfinish = person_user_computerResult.GetDateTime(4);
                //}
                //else
                //{
                //    person_userfinish = null;
                //}

                persons_users_computers.Add(new Person_User_Computer { idperson_user = this.idperson_user, person = this.person, user = this.user });
            }

            db.Close();
        }