Search Results For : sample

Microsoft Powerpoint 2010 – Compress Media

One of the issues which people faced is that the powerpoint slides which they constructed is too big and cannot be sent via email.

I have screencasted a demonstration on how we can use the Compress Media feature to compress the media. Notice that i cut down the amount of disk space i need. From 37.7MB to 9.17MB.

You can download the sample here.
http://cid-29f099c37b76ca59.office.live.com/self.aspx/Blog/Office%20Demo/Compress%20Media%20Demonstration.pptx

For more information, please feel free to email me at guohong@limguohong.com or use the Contact Me form to contact me.

Remove Title Bar from your WPF application

Recently, one of my friends was asking me how can him remove the title bar from his WPF Application. He dont know what the keyword he can use, I thought its interesting so I am posting here so in case if any one needs it in the future.

There are a few ways to do it.
1. Do through coding ( Code Behind ).

this.WindowStyle = WindowStyle.None;

2. Do through XAML. Add in the WindowStyle attribute to the Window Tag
Window WindowStyle="None">

3. Editing through the properties ( Ultimately, this changes the XAML )

Properties

Properties

You can check out the sample application here.
http://cid-29f099c37b76ca59.office.live.com/self.aspx/Blog/Code%20Guide/Windows%20Presentation%20Foundation/RemoveTitleBarWPF.zip

If you have any questions, please feel free to contact me at guohong@limguohong.com

Microsoft Office 2010 – Removing picture background

I have made a screencast to show how do we use the background removal feature in Microsoft Office 2010. This is one of the more common questions which teachers asked me when we were presenting at Yishun Town Secondary School

If you want to give it a try, you can download the sample files from here
http://cid-29f099c37b76ca59.office.live.com/self.aspx/Blog/Office%20Demo/Remove%20Background%20Sample.zip

Should you have any question, please feel free to contact me at guohong@limguohong.com

Detecting theme on Windows Phone 7

This blog post is going to teach you how do we detect if we are on dark or light theme on Windows Phone 7. I realised that this will be useful because I have quite some friends who are asking me about it because they didn’t get the right resources online. If you happened to come across a resource that asks you to get from App.xaml, that doesnt work anymore as its removed after the RC build.

Based on Theme Resources for Windows Phone, under Theme Visibility and Opacity.
By checking Resources, I am able to check if its Visible or Collapsed for the dark or White theme by doing this

Visibility isLight = (Visibility)Resources[“PhoneLightThemeVisibility”]; // for light theme
Visibility isDark = (Visibility)Resources[“PhoneDarkThemeVisibility”]; // for dark theme

Then we use if else to check,

if (isLight == System.Windows.Visibility.Visible)
{
//We are on light theme
}

Light Theme

or

if (isDark == System.Windows.Visibility.Visible)
{
//We are on dark theme
}

Dark Theme

Attached is a sample code to show how do I detect Windows Phone 7 theme, before the Mango buuild ( I am unsure if there is a change after Mango ).
Detect Theme on Windows Phone 7 Sample

Connecting to SQL Azure with PHP

To start, I would like to first say that although many PHP developers usually recommend MySQL as the accompanying database for PHP, it is not difficult to interface PHP with other databases such as SQL Azure, Microsoft’s cloud-based relational database offering.

PHP connects with SQL Azure in a similar manner as how it does with Microsoft SQL Server, ie through an interface known as the Open Database Connectivity (ODBC), which is actually the standard software interface for accessing databases. Each platform and database has its own implementation following the ODBC standard but for this tutorial, I’ll focus on PHP.

There are a few ways to connect your php site to MS SQL but the 2 main approaches are as shown in Figure 1.0.

1. Using the “php_mssql.dll” php extension requiring MS SQL Client Tools installed (Figure 1.0, right column).
2. Using the “sqlsrv” driver (“Microsoft Drivers for PHP for SQL Server”) requiring MS SQL Native Client installed (Figure 1.0, left column)


Figure 1.0

I will be using the 2nd approach for this tutorial because it supports both PHP 5.2 and 5.3, unlike the 1st which is not available for PHP 5.3.

Microsoft Drivers for PHP for SQL Server
As of 1 February 2011, the latest version of the driver is version 2.0.1 (30 November 2010).
You can grab it from http://www.microsoft.com/downloads/en/details.aspx?FamilyID=80e44913-24b4-4113-8807-caae6cf2ca05
Once you have installed the drivers, you should see the following in the installation directory:


Figure 2.0

We will be using the “php_sqlsrv_53_nts_vc9.dll” library for this tutorial.
• “php_sqlsrv” –> Driver name
• “53” –> PHP 5.3
• “nts” –> Non-thread safe (The PHP FastCGI Handler of IIS handles thread-safe operations for PHP, use the non-thread safe version to reduce performance issues)
• “vc9” –> Library compiled using VS 2008, use vc6 (VS 6) if PHP is running on Apache
Configure PHP
1. Copy “php_sqlsrv_53_nts_vc9.dll” into the “ext” folder of your php installation directory.
2. Edit the php.ini to include the library


Figure 3.0


Microsoft SQL Server 2008 R2 Native Client
In order for the PHP for SQL Server Drivers to work, the necessary SQL Server ODBC drivers must be installed on the web server.
The version of the ODBC driver needed for SQL Azure comes with the SQL Server 2008 R2 Native Client.
You can grab it from http://www.microsoft.com/downloads/en/details.aspx?FamilyID=ceb4346f-657f-4d28-83f5-aae0c5c83d52

PHP Syntax
After all the preparation and configuration, here comes the actual thing -> Coding!
This tutorial showcases how to do simple CRUD (Create, Retrieve, Update, Delete) commands.
1. Connect to Database:

$serverName = “servername.database.windows.net”;
$connInfo = array(“UID”=>”username@servername”,
“PWD”=>”password”,
“Database”=>”databasename”);
$conn = sqlsrv_connect($serverName, $connInfo);

2. Insert data to Database (taking data from a html form text field):

$comment = $_POST[“txtComment”];
$comm = “INSERT INTO commentsqlazure (commentContent) VALUES (?)”;
$stmt = sqlsrv_prepare($conn, $comm, array(&$comment));
$result = sqlsrv_execute($stmt);

3. Update data in Database:

$Id = $_POST[“txtUpdateId”];
$comment = $_POST[“txtUpdateComment”];
$comm = “UPDATE commentsqlazure SET commentContent = ? WHERE id = ?”;
$stmt = sqlsrv_prepare($conn, $comm, array(&$comment, &$Id));
$result = sqlsrv_execute($stmt);

4. Remove data from Database:

$Id = $_POST[“txtRemoveId”];
$comm = “DELETE FROM commentsqlazure WHERE id = ?”;
$stmt = sqlsrv_prepare($conn, $comm, array(&$Id));
$result = sqlsrv_execute($stmt);

5. Retrieve data from Database:

$comm = “SELECT id, commentContent FROM commentsqlazure”;
$stmt = sqlsrv_query($conn, $comm);
while($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC))
{
echo $row[“id”].” “.$row[“commentContent”].”
“;
}

6. Close connection and release resources:

sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);

You can download the project file from here.
http://cid-29f099c37b76ca59.office.live.com/browse.aspx/Blog/Code%20Guide/SQL%20Azure?uc=1

Please take note that you have to change the Server Name, Username, Password at the connection string to make this work. You should run the following script to the table first.
http://cid-29f099c37b76ca59.office.live.com/self.aspx/Blog/Code%20Guide/SQL%20Azure/SQLAzureConnection.sql

Credit to Luke Ng.