private void BackClick(object sender, RoutedEventArgs e)
        {
            UserFiles newWindow = new UserFiles(loggedUser);

            newWindow.Show();
            Close();
        }
Example #2
0
        private void UploadClick(object sender, RoutedEventArgs e)
        {
            OpenFileDialog op = new OpenFileDialog();

            op.Title = "Select a file";
            op.ShowDialog();

            string destinationFile = @"C:\test\" + op.SafeFileName;

            File.Copy(op.FileName, destinationFile, true);
            FileInfo newFileInfo = new FileInfo(op.FileName);

            DbCommand command = ConnectionHelper.Connection.CreateCommand();

            DbParameter userIdParameter = command.CreateParameter();

            userIdParameter.DbType        = System.Data.DbType.Int32;
            userIdParameter.IsNullable    = false;
            userIdParameter.ParameterName = "@UserId";
            userIdParameter.Value         = loggedUser.Id;


            DbParameter FilePath = command.CreateParameter();

            FilePath.DbType        = System.Data.DbType.String;
            FilePath.IsNullable    = false;
            FilePath.ParameterName = "@FilePath";
            FilePath.Value         = destinationFile;


            DbParameter Filesize = command.CreateParameter();

            Filesize.DbType        = System.Data.DbType.Decimal;
            Filesize.IsNullable    = false;
            Filesize.ParameterName = "@Filesize";
            Filesize.Value         = newFileInfo.Length;

            DbParameter FileExtension = command.CreateParameter();

            FileExtension.DbType        = System.Data.DbType.String;
            FileExtension.IsNullable    = false;
            FileExtension.ParameterName = "@FileExtension";
            FileExtension.Value         = newFileInfo.Extension;

            command.Parameters.AddRange(new DbParameter[] { userIdParameter, FilePath, Filesize, FileExtension });
            command.CommandText = "insert into UserFiles (UserId,FilePath,Filesize,FileExtension) values (@UserId,@FilePath,@Filesize,@FileExtension);";

            ConnectionHelper.ExecuteCommands(command);

            UserFiles newWindow = new UserFiles(loggedUser);

            newWindow.Show();
            Close();
        }
Example #3
0
        private void SignIn(object sender, RoutedEventArgs e)
        {
            //return context.Product_comments.Where(comment => comment.product_id == product.products_id).ToList();
            User loginUser;


            DbConnection connection = ConnectionHelper.Connection;

            connection.Open();

            DbCommand command = ConnectionHelper.Connection.CreateCommand();

            command.Connection = connection;

            List <User> users = new List <User>();

            command.CommandText = "select * from Users";

            DbDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                users.Add(
                    new User
                {
                    Id             = (int)reader["Id"],
                    Name           = reader["Name"].ToString(),
                    PasswordHash   = reader["PasswordHash"].ToString(),
                    DateRegistered = (DateTime)reader["DateRegistered"]
                });
            }

            loginUser = users.SingleOrDefault(c => c.Name == loginBox.Text.ToString());


            if ((loginUser != null) && (loginUser.PasswordHash == passwordBox.Text.GetHashCode().ToString()))
            {
                UserFiles newWindow = new UserFiles(loginUser);
                this.Close();
                newWindow.Show();
            }
        }
        private void DeleteUserFile(object sender, RoutedEventArgs e)
        {
            DbCommand command = ConnectionHelper.Connection.CreateCommand();

            DbParameter fileIdParameter = command.CreateParameter();

            fileIdParameter.DbType        = System.Data.DbType.Int32;
            fileIdParameter.IsNullable    = false;
            fileIdParameter.ParameterName = "@Id";
            fileIdParameter.Value         = userFilesBox.SelectedValue;

            command.Parameters.AddRange(new DbParameter[] { fileIdParameter });
            command.CommandText = "DELETE FROM UserFiles WHERE Id = @Id";

            ConnectionHelper.ExecuteCommands(command);
            UserFiles newWindow = new UserFiles(loggedUser);

            newWindow.Show();
            Close();
        }