コード例 #1
0
 public RemoteFileComment(int id, string text, User user, DateTime created)
 {
     Id = id;
     Text = text;
     User = user;
     Created = created;
 }
コード例 #2
0
        public FormUser(User user)
        {
            InitializeComponent();

            User = user;

            labelUsernameValue.Text = User.Username;
            labelRatingValue.Text = User.GetTotalRating().ToString();
            labelFilesizeValue.Text = Filesize.ConvertByteToMegaByte(User.GetFilesizeCurrentlyUploaded()).ToString();

            comboBoxUploadLimit.Items.Add(Filesize.ConvertByteToMegaByte(User.UploadLimit).ToString());
            comboBoxUploadLimit.SelectedIndex = 0;
            // Add the preset values to the ComboBox.
            for (int i = 2000; i <= 20000; i += 1000)
            {
                comboBoxUploadLimit.Items.Add(i);
            }

            labelAmountOfFilesValue.Text = User.GetAmountOfFiles().ToString();
            labelAmountReportsValue.Text = User.GetAmountOfReports().ToString();
        }
コード例 #3
0
        public FormRemoteFile(RemoteFile file, User user)
        {
            InitializeComponent();

            RemoteFile = file;
            User = user;

            labelTitleValue.Text = RemoteFile.Title;
            labelSizeValue.Text = Filesize.ConvertByteToMegaByte(RemoteFile.Size).ToString();
            labelCategoryValue.Text = RemoteFile.Category != null ? RemoteFile.Category.Title : "";
            labelRatingValue.Text = RemoteFile.Rating.ToString();
            try
            {
                labelUserValue.Text = RemoteFile.User.Username;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            textBoxDescriptionValue.Text = RemoteFile.Description;

            ReloadComments();
        }
コード例 #4
0
        public FormMain(User user)
        {
            InitializeComponent();

            this.user = user;

            // If the user is not an employee remove the moderator tab.
            if (!user.IsEmployee)
            {
                tabControl.Controls.Remove(tabPageModerator);
            }

            // Bind the events to the background workers.
            FtpUpload.BackgroundWorker.ProgressChanged += ftpUpload_ProgressChanged;
            FtpUpload.BackgroundWorker.RunWorkerCompleted += ftpUpload_RunWorkerCompleted;

            FtpDownload.BackgroundWorker.ProgressChanged += ftpDownload_ProgressChanged;
            FtpDownload.BackgroundWorker.RunWorkerCompleted += ftpDownload_RunWorkerCompleted;

            // Bind the events to the listviews.
            listViewUpload.SelectedIndexChanged += control_RefreshInterfaceUpload;
            listViewUpload.ItemChecked += control_RefreshInterfaceUpload;

            listViewDownload.SelectedIndexChanged += control_RefreshInterfaceDownload;
            listViewDownload.SelectedIndexChanged += listViewDownload_SelectedIndexChanged;
            listViewDownload.ItemChecked += control_RefreshInterfaceDownload;

            // Add the default setting for the filesize filter.
            {
                comboBoxDownloadFilterFilesize.Items.Add(new ComboBoxItem("<Niet filteren>", null));
                comboBoxDownloadFilterFilesize.SelectedIndex = 0;
            }

            // Add filesize filter ComboBox items.
            for (int i = 1; i <= 20; i++)
            {
                int limit = i*100 - 100;
                int lowerLimit = limit;
                int upperLimit = 0;

                if (comboBoxDownloadFilterFilesize.Items.Count == 1)
                {
                    comboBoxDownloadFilterFilesize.Items.Add(new ComboBoxItem("", new FilterFilesize(lowerLimit, upperLimit)));
                }
                else
                {
                    // Get the previous ComboBox and set the correct upper limit.
                    ComboBoxItem item = comboBoxDownloadFilterFilesize.Items[i - 1] as ComboBoxItem;
                    if (item != null)
                    {
                        FilterFilesize filter = item.Value as FilterFilesize;
                        if (filter != null)
                        {
                            filter.UpperLimit = limit;

                            if (i - 1 == 0)
                            {
                                item.Text = filter.UpperLimit.ToString() + " < ";
                            }
                            else
                            {
                                item.Text = filter.LowerLimit.ToString() + " - " + filter.UpperLimit.ToString();
                            }

                            comboBoxDownloadFilterFilesize.Items.Add(new ComboBoxItem(" > " + lowerLimit.ToString(),
                                new FilterFilesize(lowerLimit, upperLimit)));
                        }
                    }
                }

            }

            // Add the default value for the category ComboBox.
            {
                comboBoxCategories.Items.Add(new ComboBoxItem("<Alle categorieën>", null));
                comboBoxCategories.SelectedIndex = 0;
            }

            try
            {
                // Add all categories nested correctly in the ComboBox.
                foreach (Category category in Category.GetAll())
                {
                    if (category.ParentId < 1)
                    {
                        AddCategoryToComboboxRecursive(category, 0);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            this.BringToFront();
        }
コード例 #5
0
 /// <summary>
 /// Uploads the file to the FTP server, with the owner(user).
 /// </summary>
 /// <param name="localFile"></param>
 /// <param name="user"></param>
 public static void Upload(LocalFile localFile, User user)
 {
     FtpUpload.localFile = localFile;
     FtpUpload.user = user;
     backgroundWorker.RunWorkerAsync();
 }
コード例 #6
0
        /// <summary>
        /// Gets the user based on the given id.
        /// Returns null when the user is not found.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static User GetById(int id)
        {
            User user = null;

            Database db = new Database();

            try
            {
                db.CreateCommand("SELECT * FROM users WHERE id = :id");
                db.AddParameter("id", id);

                db.OpenConnection();
                db.ExecuteCommand();

                OracleDataReader dr = db.DataReader;

                if (dr.HasRows)
                {
                    dr.Read();
                    int userId = dr.GetValueByColumn<int>("id");
                    string username = dr.GetValueByColumn<string>("Username");
                    long uploadLimit = dr.GetValueByColumn<long>("uploadlimit");
                    bool isEmployee = dr.GetValueByColumn<int>("isemployee") == 1 ? true : false;

                    user = new User(id, username, uploadLimit, isEmployee);
                }

            }
            finally
            {
                db.CloseConnection();
            }

            return user;
        }
コード例 #7
0
        /// <summary>
        /// Loads the current rating of the file.
        /// </summary>
        private void LoadRating()
        {
            Database db = new Database();

            try
            {
                db.CreateCommand(
                    "SELECT files_likes.positive, users.* FROM files_likes LEFT JOIN users ON users.id = files_likes.users_id WHERE files_likes.files_id = :files_id");
                db.AddParameter("files_id", Id);

                db.OpenConnection();
                db.ExecuteCommand();

                OracleDataReader dr = db.DataReader;
                while (dr.Read())
                {
                    User user = new User(dr.GetInt32(1), dr.GetString(2));

                    // If the rating is positive it is a like else it is a dislike.
                    if (dr.GetValueByColumn<int>("positive") == 1)
                    {
                        likes.Add(user);
                    }
                    else
                    {
                        dislikes.Add(user);
                    }
                }
            }
            finally
            {
                db.CloseConnection();
            }
            ratingsLoaded = true;
        }
コード例 #8
0
        /// <summary>
        /// Reports the file. If the file has 3 or more reports the file will be deactivated and hidden to all users.
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool Report(User user)
        {
            Database db = new Database();
            int count = 0;
            try
            {
                db.CreateCommand("SELECT * FROM files_reports WHERE files_id = :id");
                db.AddParameter("files_id", Id);
                db.OpenConnection();
                db.ExecuteCommand();

                OracleDataReader dr = db.DataReader;

                while (dr.Read())
                {
                    count++;
                    int userId = dr.GetValueByColumn<int>("users_id");

                    if (userId == user.Id)
                    {
                        throw new Exception("U heeft dit bestand al gerapporteerd.");
                    }
                }
            }
            finally
            {
                db.CloseConnection();
            }

            try
            {
                db.CreateCommand("INSERT INTO files_reports(files_id, users_id) VALUES(:filesId, :usersId)");
                db.AddParameter("filesId", Id);
                db.AddParameter("usersId", user.Id);
                db.OpenConnection();
                db.ExecuteCommand();
            }
            finally
            {
                db.CloseConnection();
            }

            if (count >= 2)
            {
                try
                {
                    db.CreateCommand("UPDATE files SET active = 0 WHERE id = :filesId");
                    db.AddParameter("filesId", Id);
                    db.OpenConnection();
                    db.ExecuteCommand();
                }
                finally
                {
                    db.CloseConnection();
                }
            }
            return true;
        }
コード例 #9
0
        /// <summary>
        /// Rates the file for the given user. Positive(true) for a like, Positive(false) for a dislike.
        /// </summary>
        /// <param name="user"></param>
        /// <param name="positive"></param>
        public void Rate(User user, bool positive)
        {
            Database db = new Database();

            int currentRating = CurrentRating(user);

            try
            {
                if (currentRating == 0)
                {
                    db.CreateCommand(
                        "INSERT INTO files_likes(positive, files_id, users_id) VALUES(:positive, :filesId, :usersId)");
                }
                else
                {

                    if (currentRating == 1 && !positive)
                    {
                        int index = likes.FindIndex(x => x.Id == user.Id);
                        if (index >= 0)
                        {
                            likes.RemoveAt(index);
                        }
                    }
                    else if (currentRating == -1 && positive)
                    {
                        int index = dislikes.FindIndex(x => x.Id == user.Id);
                        if (index >= 0)
                        {
                            dislikes.RemoveAt(index);
                        }
                    }

                    db.CreateCommand(
                        "UPDATE files_likes SET positive = :positive WHERE files_id = :filesId  AND users_id = :usersId");
                }

                db.AddParameter("positive", positive ? "1" : "-1");
                db.AddParameter("filesId", Id);
                db.AddParameter("usersId", user.Id);

                db.OpenConnection();

                db.ExecuteCommand();
            }
            finally
            {
                db.CloseConnection();
            }

            if (positive)
            {
                likes.Add(user);
            }
            else
            {
                dislikes.Add(user);
            }
        }
コード例 #10
0
        /// <summary>
        /// Checks if the user has liked or disliked the file or not rated. Returns 1 for like, -1 for dislike, 0 for no rating.
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public int CurrentRating(User user)
        {
            if (!ratingsLoaded)
            {
                LoadRating();
            }

            if (likes.Find(x => x.Id == user.Id) != null)
            {
                return 1;
            }

            if (dislikes.Find(x => x.Id == user.Id) != null)
            {
                return -1;
            }
            return 0;
        }
コード例 #11
0
        public void Comment(User user, String comment)
        {
            Database db = new Database();

            try
            {
                db.CreateCommand(
                    "INSERT INTO files_comments(files_id, users_id, text) VALUES(:filesId, :usersId, :text)");
                db.AddParameter("filesId", Id);
                db.AddParameter("usersId", user.Id);
                db.AddParameter("text", comment);
                db.OpenConnection();
                db.ExecuteCommand();
            }
            finally
            {
                db.CloseConnection();
            }

            LoadRating();
        }
コード例 #12
0
        /// <summary>
        /// Correctly inserts the file into the database.
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="title"></param>
        /// <param name="size"></param>
        /// <param name="description"></param>
        /// <param name="user"></param>
        /// <param name="category"></param>
        /// <param name="privacy"></param>
        /// <returns></returns>
        public static bool Insert(string filename, string title, long size, string description, User user, Category category, Privacy privacy)
        {
            Database db = new Database();
            try
            {
                db.CreateCommand(
                    "INSERT INTO files(filename, title, filesize, description, users_id, files_categories_id, private, active) VALUES(:filename, :title, :filesize, :description, :users_id, :files_categories_id, :private, 1)");
                db.AddParameter("filename", filename);
                db.AddParameter("title", title);
                db.AddParameter("filesize", size);
                db.AddParameter("description", description);
                db.AddParameter("users_id", user.Id);

                if (category != null)
                {
                    db.AddParameter("files_categories_id", category.Id);
                }
                else
                {
                    db.AddParameter("files_categories_id", DBNull.Value);
                }

                if (privacy == Privacy.@private)
                {
                    db.AddParameter("private", 1);
                }
                else
                {
                    db.AddParameter("private", DBNull.Value);
                }
                db.OpenConnection();
                db.ExecuteCommand();
            }
            finally
            {
                db.CloseConnection();
            }

            return true;
        }
コード例 #13
0
        public ListViewItemModerator(User user)
        {
            User = user;

            Refresh();
        }