Archive Page 3

Using Hexadecimal Color Values in WPF 3.5

I am currently preparing for my WPF content for the Philippine Launch Wave of Visual Studio 2008, Windows Server 2008, and SQL Server 2008. As a seasoned web developer, I am quite accustomed to the colors that I frequently use in hexadecimal and I intend to use these colors in my demo. I have a basic XAML file that has a Window with a ListBox, TextBlock and Slider in it. I am trying to show how LINQ works in a WPF 3.5 application.


<window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="500" Width="500">
    <grid>
        <listBox Name="listBox1" SelectionChanged="listBox1_SelectionChanged" Margin="0,0,0,120" />
        <textBlock Height="105" Name="textBlock1"  FontSize="{Binding ElementName=slider1, Path=Value}" VerticalAlignment="Bottom">Label</textBlock>
        <slider Height="21" Margin="203,0,-5,0" SizeChanged="slider1_SizeChanged" ValueChanged="slider1_ValueChanged" Minimum="10" Maximum="50" Name="slider1" VerticalAlignment="Bottom" Value="10" />
    </grid>
</window>

While working on a certain functionality that I want to display, I became curious if I can use the colors in my sample application. The color, which I don’t exactly know the name but I refer to it as maroonish red (the UP blood in me), has an hexadecimal value of “#cd0001”. I tried appending that value in the Foreground property of the TextBlock (textBlock1 mentioned above) but it doesn’t work.


// This code won't work

textBlock1.Foreground = "#cd0001";

// Even this

textBlock1.Foreground = (Brush)"#cd0001";

To have a workaround on this, you need to use the BrushConverter class in able to use your hexadecimal based colors as a brush.


BrushConverter bc = new BrushConverter();
Brush brush;
brush = (Brush)bc.ConvertFrom("#cd0001");
textBlock1.Foreground = brush;

And it works! If you are more familiar with the colors that you want in hexadecimal, you can replace the hex value in the text above and most likely that would work.

Enjoy!

Advertisements

Why I Hate Firefox

firefox.png

And it is running only with 4 tabs open: Gmail, Outlook Web Access, MS Forums, and Manila Tonight WordPress (blogging this).

Even if I have a generous amount of RAM in my office workstation, this browser still consumes a large memory. If not for its organized Bookmarks and better web developer toolbar (against IE’s), I would have leave this for IE.

Launch Wave 2008!

launch.png

Join us in the launch of Microsoft’s upcoming products on 10 April 2008 in SMX, SM Mall of Asia, Pasay City, Metro Manila, Philippines!

Philippine .NET Users Group (PHINUG), together with other user groups will be there for the breakout sessions for each product (Visual Studio 2008, Windows Server 2008, and SQL Server 2008). We’re still fixing our surprises but I do hope you’ll enjoy them on the event day.

Click on the link to register! See you all there!

A Humble Recognition

communityheroes.png

Microsoft has included me in the list of Community Heroes in their page.

Thanks Microsoft and I labia! Inspires me to do more for the community.  🙂

Searching Approved Users in Roles in ASP.NET Membership

Still more ASP.NET membership tweaks!

The role manager in ASP.NET Membership provides a mechanism to list all the users in the ASP.NET Membership Database for a specific role.


Roles.GetUsersInRoles("rolename");

This method returns a string array of usernames that’s a member of that role. Unfortunately, this list returns all the users even if they are approved or not, locked out or not. If you are working on an application that requires to filter out users in the role that’s locked out or isn’t approved yet, there’s no other mechanism on the built-in methods. There’s no overload to the method provided out of the box.roles.png

Luckily, as mentioned in the previous blog about ASP.NET membership, the database is filled with various stored procedures that you can use (or even pattern after) for various usage. I tweaked one of the stored procedures and came up with a stored procedure that gets all the approved users in the ASP.NET membership database.


CREATE PROCEDURE dbo.Membership_GetActiveUsersInRoles

    @RoleName nvarchar(256)

AS

    BEGIN

        DECLARE @RoleId uniqueidentifier

        SELECT @RoleId = RoleId
        FROM dbo.aspnet_Roles
        WHERE LOWER(@RoleName) = LoweredRoleName

        SELECT u.UserName, u.UserId
        FROM dbo.aspnet_Users u, dbo.aspnet_UsersInRoles ur, dbo.aspnet_Membership m
        WHERE
        u.UserId = m.UserId AND
        u.UserId = ur.UserId AND
        @RoleId = ur.RoleId and
        m.IsApproved = 'true'
         -- You can also specify m.IsLockedOut = 'false' for other purposes

END

Just copy the said code above and create it in your ASP.NET Membership database (either that ASPNETDB.MDF or an ASP.NET membership configured database) and run it.Happy Coding!

PHINUG February Technical Sharing

PHINUG is back for its first event for 2008!

Presenting new features for Visual Studio 2008 and ASP.NET 3.5 are our topics for the February Technical Sharing. Our speaker is Edwin Sarmiento, a senior systems engineer/DBA for Fujitsu Asia Pte Ltd in Singapore and a Microsoft MVP for Windows Small Business Server. He is responsible for maintaining 200+ servers and databases for a global client in 10 countries.

The event is free and the link to the sign-up page is located here.

Searching Users with ASP.NET Membership Database

In my previous post, we have successfully bind the Membership.GetAllUsers() method to a databound control such as the GridView to enable paging and sorting. This time, I am building a mechanism that will allow me to search for users in the ASP.NET Membership database. By default, ASP.NET Membership supports searching by specific matches: email (Membership.FindUsersByEmail()), user id (aka provider user key), and by username (Membership.FindUsersByName()). There’s no built-in mechanism wherein you can query for users that contain specific characters — say you want to get users that starts with a specific letter or contains certain characters.

Examining closely the ASP.NET Membership database (either created by the WSAT or configured using the aspnet_regsql.exe), it has stored procedures that performs various queries to the ASP.NET membership. I tweaked one query to get the result that I wanted and stored into a new stored procedure and named it “Membership_QueryUsersByLetter”. This stored procedure should reside on the same database of your ASP.NET Membership.

CREATE PROCEDURE [dbo].[Membership_QueryUsersByLetter]
    @SearchKey nvarchar(256)
AS
BEGIN
    SELECT u.UserName, m.Email, m.PasswordQuestion,
	m.Comment, m.IsApproved,
	m.CreateDate,
	m.LastLoginDate,
	u.LastActivityDate,
	m.LastPasswordChangedDate,
	u.UserId, m.IsLockedOut,
        m.LastLockoutDate
    FROM
	dbo.aspnet_Membership m, dbo.aspnet_Users u
    WHERE
	u.UserId = m.UserId AND u.UserName LIKE '%' + @SearchKey + '%'
    ORDER BY
	u.UserName
END

This query assumes that the ASP.NET membership database is configured for one application only. A sample application that you can use for this one can be downloaded here. Rename the file (searchusers.odt) to a zip extension file to extract files. Note however that you need to modify the connection string to match your current machine configuration to point to an ASP.NET membership database (or ASP.NET Membership configured database).


Blog Stats

  • 4,042 hits
October 2018
S M T W T F S
« Nov    
 123456
78910111213
14151617181920
21222324252627
28293031  
Advertisements