private void sendFile(GroupInfoModel group, PackageInfoModel package)
        {
            FileController fileController = new FileController();
            string filePath = fileController.getPathFromFile(group.Name, package.Name);

            if (!File.Exists(filePath))
            {
                return;
            }

            byte[] fileName = Encoding.ASCII.GetBytes(package.Name);
            byte[] fileData = File.ReadAllBytes(filePath);
            byte[] fileNameLen = BitConverter.GetBytes(fileName.Length);
            byte[] file = new byte[4 + fileName.Length + fileData.Length];

            fileNameLen.CopyTo(file, 0);
            fileName.CopyTo(file, 4);
            fileData.CopyTo(file, 4 + fileName.Length);

            try
            {
                tcpConnection.Client.Send(file);
                Console.WriteLine("File: {0} has been sent.", fileName);
            }
            catch (Exception ex)
            {
                Diagnostics.WriteToEventLog(ex.Message, EventLogEntryType.Error, 3003);
            }

            stopConnection();
        }
        public bool gbDeletePackage(PackageInfoModel oPackage)
        {
            try
            {
                SqlCeCommand sqlCmd = new SqlCeCommand();
                string sQry;

                if (mbDataExists("Softwarepaket", "Softwarepaket_ID = " + oPackage.ID))
                {
                    // Softwarepaket löschen
                    sQry = "DELETE FROM Softwarepaket WHERE Softwarepaket_ID = " + oPackage.ID;
                    openConnection();
                    sqlCmd = new SqlCeCommand(sQry, Connection);
                    sqlCmd.ExecuteNonQuery();
                    closeConnection();
                }

                if (mbDataExists("Gruppe_Softwarepakete", "Softwarepaket_ID = " + oPackage.ID))
                {
                    // Gruppen-Einträge löschen, die mit dem Softwarepaket verknüpft sind
                    sQry = "DELETE FROM Gruppe_Softwarepakete WHERE Softwarepaket_ID = " + oPackage.ID;
                    openConnection();
                    sqlCmd = new SqlCeCommand(sQry, Connection);
                    sqlCmd.ExecuteNonQuery();
                    closeConnection();
                }

                return true;
            }
            catch (Exception ex)
            {
                Diagnostics.WriteToEventLog(ex.Message, System.Diagnostics.EventLogEntryType.Error, 3108);
                return false;
            }
        }
        public List<PackageInfoModel> CheckSoftwareClient(ClientInfoModel oClient)
        {
            //Prüfen welcher Client, welche Software hat.

            try
            {
                List<PackageInfoModel> oResult = new List<PackageInfoModel>();
                List<PackageInfoModel> groupPackages = new List<PackageInfoModel>();
                List<PackageInfoModel> clientInstalledPackages = new List<PackageInfoModel>();
                string sQry;
                SqlCeCommand sqlCmd = new SqlCeCommand();
                DataTable oData = new DataTable();

                sQry = "SELECT * FROM Client WHERE Client_MacAdresse = '" + oClient.macAddress + "'";

                // DataTable mit Daten füllen
                SqlCeDataAdapter oDataAdapter = new SqlCeDataAdapter(sQry, Connection);
                oDataAdapter.Fill(oData);

                // Alle Informationen über die MacAdresse ermitteln
                oClient = new ClientInfoModel();
                foreach (DataRow oRow in oData.Rows)
                {
                    if (oData.Rows.Count == 1)
                    {
                        oClient.ID = Convert.ToInt32(oRow["Client_ID"]);
                        oClient.macAddress = oRow["Client_MacAdresse"].ToString();
                        oClient.group = Convert.ToInt32(oRow["Client_Gruppe"]);
                        oClient.admin = Convert.ToBoolean(oRow["Client_Administrator"]);
                        oClient.arc = oRow["Client_Arc"].ToString();
                    }
                }

                // Alle Softwarepakete über die Gruppe ermitteln, die der Client haben soll.
                sQry = "    SELECT SP.Softwarepaket_ID, SP.Softwarepaket_Name " +
                       "           , SP.Softwarepaket_Groesse, SP.Softwarepaket_Arc " +
                       "      FROM Gruppe_Softwarepaket GS " +
                       " LEFT JOIN Softwarepaket AS SP ON GS.Softwarepaket_ID = SP.Softwarepaket_ID " +
                       "     WHERE GS.Gruppe_ID = " + oClient.group;
                oData = new DataTable();
                oDataAdapter = new SqlCeDataAdapter(sQry, Connection);
                oDataAdapter.Fill(oData);

                foreach (DataRow oRow in oData.Rows)
                {
                    PackageInfoModel oPackage = new PackageInfoModel();

                    oPackage.ID = Convert.ToInt32(oRow["Softwarepaket_ID"]);
                    oPackage.Name = oRow["Softwarepaket_Name"].ToString();
                    oPackage.size = Convert.ToInt32(oRow["Softwarepaket_Groesse"]);
                    oPackage.arc = oRow["Softwarepaket_Arc"].ToString();

                    groupPackages.Add(oPackage);
                }

                // Alle installierten Softwarepakete des Clients ermitteln
                sQry = "    SELECT SP.Softwarepaket_ID, SP.Softwarepaket_Name " +
                       "           , SP.Softwarepaket_Groesse, SP.Softwarepaket_Arc " +
                       "      FROM Client_Softwarepaket AS CP " +
                       " LEFT JOIN Softwarepaket AS SP ON CP.Softwarepaket_ID = SP.Softwarepaket_ID " +
                       "     WHERE CP.Client_ID = " + oClient.ID.ToString();
                oData = new DataTable();
                oDataAdapter = new SqlCeDataAdapter(sQry, Connection);
                oDataAdapter.Fill(oData);

                foreach (DataRow oRow in oData.Rows)
                {
                    PackageInfoModel oPackage = new PackageInfoModel();

                    oPackage.ID = Convert.ToInt32(oRow["Softwarepaket_ID"]);
                    oPackage.Name = oRow["Softwarepaket_Name"].ToString();
                    oPackage.size = Convert.ToInt32(oRow["Softwarepaket_Groesse"]);
                    oPackage.arc = oRow["Softwarepaket_Arc"].ToString();

                    clientInstalledPackages.Add(oPackage);
                }

                // Listen abgleichen und in oResult speichern.
                for (int i = 0; i < clientInstalledPackages.Count; i++)
                {
                    for (int n = 0; n < groupPackages.Count; n++)
                    {
                        if (clientInstalledPackages[i].ID == groupPackages[n].ID)
                        {
                            continue;
                        }
                        oResult.Add(groupPackages[n]);
                    }
                }

                return oResult;
            }
            catch (Exception ex)
            {
                Diagnostics.WriteToEventLog(ex.Message, System.Diagnostics.EventLogEntryType.Error, 3102);
                return null;
            }
        }
        public PackageInfoModel gbAddPackage(PackageInfoModel oPackage)
        {
            try
            {
                string sQry;
                PackageInfoModel oResult = new PackageInfoModel();
                SqlCeCommand sqlCmd = new SqlCeCommand();

                if (mbPackageVorhanden(oPackage.Name))
                {
                    sQry = " UPDATE Softwarepaket SET " +
                           " Softwarepaket_Name = '" + oPackage.Name + "'" +
                           " , Softwarepaket_Groesse = " + oPackage.size +
                           " , Softwarepaket_Arc = " + oPackage.arc +
                           " , Softwarepaket_ShowName = '" + oPackage.showName + "'";

                    openConnection();
                    sqlCmd = new SqlCeCommand(sQry, Connection);
                    sqlCmd.ExecuteNonQuery();
                }
                else
                {
                    sQry = " INSERT INTO Softwarepaket(Softwarepaket_Name, Softwarepaket_Groesse " +
                           " , Softwarepaket_Arc, Softwarepaket_ShowName) " +
                           " VALUES('" + oPackage.Name + "', " + oPackage.size +
                           " , '" + oPackage.arc + "', '" + oPackage.showName + "')";

                    openConnection();
                    sqlCmd = new SqlCeCommand(sQry, Connection);
                    sqlCmd.ExecuteNonQuery();
                    closeConnection();
                }

                sQry = "SELECT * FROM Softwarepaket WHERE Softwarepaket_Name = '" + oPackage.Name + "'";
                SqlCeDataAdapter oDataAdapter = new SqlCeDataAdapter(sQry, Connection);
                DataTable oData = new DataTable();
                oDataAdapter.Fill(oData);

                foreach (DataRow oRow in oData.Rows)
                {
                    if (oData.Rows.Count == 1)
                    {
                        oPackage.ID = Convert.ToInt32(oRow["Softwarepaket_ID"]);
                        oPackage.Name = oRow["Softwarepaket_Name"].ToString();
                        oPackage.size = Convert.ToInt32(oRow["Softwarepaket_Groesse"]);
                        oPackage.arc = oRow["Softwarepaket_Arc"].ToString();
                        oPackage.showName = oRow["Softwarepaket_ShowName"].ToString();
                    }
                }

                sQry = " INSERT INTO Gruppe_Softwarepakete(Softwarepaket_ID, Gruppe_ID)" +
                           " VALUES(" + oPackage.ID + ", " + oPackage.group + ")";

                sqlCmd = new SqlCeCommand(sQry, Connection);
                openConnection();
                sqlCmd.ExecuteNonQuery();
                closeConnection();

                return oResult;
            }
            catch (Exception ex)
            {
                Diagnostics.WriteToEventLog(ex.Message, System.Diagnostics.EventLogEntryType.Error, 3105);
                return null;
            }
        }
        public bool ClientGetSoftware(ClientInfoModel client, PackageInfoModel installPack)
        {
            try
            {
                if (!mbAlreadyInstalled(client.ID, installPack.ID))
                {
                    string sQry;

                    sQry = "INSERT INTO Client_Softwarepaket(Client_ID, Softwarepaket_ID)" +
                           " VALUES(" + client.ID + ", " + installPack.ID + ")";
                    SqlCeCommand sqlCmd = new SqlCeCommand(sQry, Connection);
                    openConnection();
                    sqlCmd.ExecuteNonQuery();
                    closeConnection();
                }

                return true;
            }
            catch (Exception ex)
            {
                Diagnostics.WriteToEventLog(ex.Message, System.Diagnostics.EventLogEntryType.Error, 3108);
                return false;
            }
        }
        public List<PackageInfoModel> GetClientPackages(ClientInfoModel oClient)
        {
            try
            {
                List<PackageInfoModel> oResult = new List<PackageInfoModel>();
                DataTable oData = new DataTable();
                string sQry;

                sQry = "    SELECT SP.Softwarepaket_ID, SP.Softwarepaket_Name " +
                       "           , SP.Softwarepaket_Groesse, SP.Softwarepaket_Arc " +
                       "           , SP.Softwarepaket_ShowName " +
                       "      FROM Client_Softwarepaket AS CP " +
                       " LEFT JOIN Softwarepaket AS SP ON CP.Softwarepaket_ID = SP.Softwarepaket_ID " +
                       "     WHERE Client_ID = " + oClient.ID;
                SqlCeDataAdapter oDataAdapter = new SqlCeDataAdapter(sQry, Connection);
                oDataAdapter.Fill(oData);

                foreach (DataRow oRow in oData.Rows)
                {
                    PackageInfoModel package = new PackageInfoModel();

                    package.ID = Convert.ToInt32(oRow["Softwarepaket_ID"]);
                    package.Name = oRow["Softwarepaket_Name"].ToString();
                    package.size = Convert.ToInt32(oRow["Softwarepaket_Groesse"]);
                    package.arc = oRow["Softwarepaket_Arc"].ToString();
                    package.showName = oRow["Softwarepaket_ShowName"].ToString();

                    oResult.Add(package);
                }

                return oResult;
            }
            catch (Exception ex)
            {
                Diagnostics.WriteToEventLog(ex.Message, System.Diagnostics.EventLogEntryType.Error, 3016);
                return null;
            }
        }
        public List<PackageInfoModel> GetPackageInfoModels()
        {
            try
            {
                List<PackageInfoModel> oResult = new List<PackageInfoModel>();
                DataTable oData = new DataTable();

                SqlCeDataAdapter oDataAdapter = new SqlCeDataAdapter("SELECT * FROM Softwarepaket", Connection);
                oDataAdapter.Fill(oData);

                if (oData.Rows.Count > 0)
                {
                    foreach (DataRow oRow in oData.Rows)
                    {
                        PackageInfoModel oPackage = new PackageInfoModel();

                        oPackage.ID = Convert.ToInt32(oRow["Softwarepaket_ID"]);
                        oPackage.Name = oRow["Softwarepaket_Name"].ToString();
                        oPackage.size = Convert.ToInt32(oRow["Softwarepaket_Groesse"]);
                        oPackage.arc = oRow["Softwarepaket_Arc"].ToString();
                        oPackage.showName = oRow["Softwarepaket_ShowName"].ToString();

                        oResult.Add(oPackage);
                    }
                }

                return oResult;
            }
            catch (Exception ex)
            {
                Diagnostics.WriteToEventLog(ex.Message, System.Diagnostics.EventLogEntryType.Error, 3013);
                return null;
            }
        }
        public GroupInfoModel GetGroupByPackage(PackageInfoModel oPackage)
        {
            GroupInfoModel oResult = new GroupInfoModel();
            string sQry;
            DataTable oData = new DataTable();

            sQry = "SELECT G.Gruppe_ID, G.Gruppe_Name FROM Gruppe_Softwarepakete AS GS LEFT JOIN Gruppe AS G ON G.Gruppe_ID = GS.Gruppe_ID WHERE GS.Softwarepaket_ID = " + oPackage.ID;
            SqlCeDataAdapter oDataAdapter = new SqlCeDataAdapter(sQry, Connection);
            oDataAdapter.Fill(oData);

            foreach (DataRow oRow in oData.Rows)
            {
                oResult.ID = Convert.ToInt32(oRow["Gruppe_ID"]);
                oResult.Name = oRow["Gruppe_Name"].ToString();
            }

            return oResult;
        }