Saturday, December 19, 2009

How to Fast Start an Embedded QuickTime MOV file

I encountered this problem last week:

After embedding a QuickTime(MOV) file into your web page, it takes an eternity to start. The

reason is because the http request will ask the server to download the whole clip onto the client's

drive, then start the playback.

The solution is simple, and is called FAST START. Fast Start is a QuickTimefeature that enables

users to watch the movie as it's being downloaded (long before the whole movie has been downloaded)

from a standard web server. Fast Start works well for short-form movies where file size is limited.

It ensures high-quality playback regardless of the users' Internet connection speeds, though those

with slower connections will wait longer before media starts to play (
href="http://support.apple.com/kb/HT2438" >Apple QuickTime, 2009
).

Check the instructions on the QuickTime website here. It also explains how to optimize your video for online streaming.

JQuery Lightbox - PrettyPhoto

Stumbled across one of the best, in my humble opinion, JQuery Lightbox that provides a cool lightbox effect while displaying your galleries and movie clips as well.
Worth checking it out:
http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/

Merry Christmas all, and a Happy New Year 2010!

Saturday, November 7, 2009

how to apply the themes

Hi everyone,
I am now following ALAN's project files to catch up everything what I missed and sometimes I am struggling to understand ... I forgot many things. If you have time, can you help me?

< Question >
I can not find out how to apply the themes (including image,css,skin) to web pages because the theme attribute of the @Page directive (eg. <%@ Page Theme="SkinFile" %>) is not set in the all Web Pages of ALAN's project.
Do you remember how & where Alan applied that?

---------------------------------------------

I got the answer from the below page after I posted!
http://www.dotnettreats.com/samplethemes/Default.aspx
He uses "Web.config" to apply the theme for the Web site. :D

Monday, November 2, 2009

C# Unit Testing - Divide function div()



using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MyCal;

namespace CalcTestProject
{
/// <summary>
/// Summary description for UnitTest1
/// </summary>
[TestClass]
public class DivTest
{

#region Additional test attributes
//
// You can use the following additional attributes as you write your tests:
//
// Use ClassInitialize to run code before running the first test in the class
// [ClassInitialize()]
// public static void MyClassInitialize(TestContext testContext) { }
//
// Use ClassCleanup to run code after all tests in a class have run
// [ClassCleanup()]
// public static void MyClassCleanup() { }
//
// Use TestInitialize to run code before running each test
// [TestInitialize()]
// public void MyTestInitialize() { }
//
// Use TestCleanup to run code after each test has run
// [TestCleanup()]
// public void MyTestCleanup() { }
//
#endregion

[TestMethod]
public void Test_ValidPositive()
{
//call method defined in the MyMath class
Assert.AreEqual(MyMath.Div("20","5"),"4.00");
Assert.AreEqual(MyMath.Div("25", "2"), "12.50");
Assert.AreEqual(MyMath.Div("20", "3"), "6.67");
Assert.AreEqual(MyMath.Div("2147483647", "2"), "1073741823.50");
}

[TestMethod]
public void Test_ValidNegative()
{
Assert.AreEqual(MyMath.Div("-40", "2"), "-20.00");
Assert.AreEqual(MyMath.Div("50", "-2"), "-25.00");
Assert.AreEqual(MyMath.Div("-4", "-2"), "2.00");
Assert.AreEqual(MyMath.Div("-2147483648", "-4"), "536870912.00");
}

[TestMethod]
public void Test_ValidZeroes()
{
Assert.AreEqual(MyMath.Div("0", "2"), "0.00");
Assert.AreEqual(MyMath.Div("2", "0"), "ERROR");
Assert.AreEqual(MyMath.Div("0", "0"), "ERROR");
}

[TestMethod]
[ExpectedException (typeof (FormatException))]
public void Test_CharFirstInput()
{
MyMath.Div("2aa", "4");

}

[TestMethod]
[ExpectedException(typeof(FormatException))]
public void Test_NotIntInput()
{
MyMath.Div("5.5", "2");
MyMath.Div("4", "2.2");
}

[TestMethod]
[ExpectedException(typeof(FormatException))]
public void Test_NotValidInput()
{
MyMath.Div("", "2");
MyMath.Div("22", "");
}

[TestMethod]
[ExpectedException(typeof(OverflowException))]
public void Test_RangeError()
{
MyMath.Div("2147483648", "2");
MyMath.Div("22", "-4147483467");
}

}
}

Monday, October 12, 2009

SQL - My Database

I've included the queries to create the tables for an online TShirt Order Management System (My project).
I have also created a couple of views and stored procedures to add, delete and update tables. Feel free to use and modify the code below for your own database :)

TABLE CREATION



--
--*** CREATE TABLES
--*** -------------------------------------------------------------------------------
--*** Customers, Orders, Suppliers, TShirts, OrderDetails
--***
--******************************************************************************
--***** AUTHOR: Denis K DATE: 05/10/2009
--******************************************************************************
CREATE TABLE Customers
(
CustomerID INT IDENTITY(1000,1) PRIMARY KEY,
FirstName VARCHAR(20) NOT NULL,
LastName VARCHAR(20) NOT NULL,
Address VARCHAR(40) NOT NULL,
City VARCHAR(20) NOT NULL,
Country VARCHAR(20) NOT NULL,
DOB DATETIME NOT NULL,
Mobile NCHAR(10),
Status INT DEFAULT 0
)


CREATE TABLE Orders
(
OrderID INT IDENTITY(1,1) PRIMARY KEY,
OrderDate DATETIME,
CustomerID INT NOT NULL,
FOREIGN KEY (CustomerID) REFERENCES Customers (CustomerID)
)

CREATE TABLE Suppliers
(
SupplierID INT IDENTITY(1000,1) PRIMARY KEY,
CompanyName VARCHAR(20) NOT NULL,
ContactName VARCHAR(20) NOT NULL,
Address VARCHAR(40) NOT NULL,
City VARCHAR(20) NOT NULL,
Phone VARCHAR(15) NOT NULL,
Fax VARCHAR(15) NOT NULL,
HomePage VARCHAR(30),
Status INT DEFAULT 0
)

CREATE TABLE TShirts
(
TShirtID INT IDENTITY(50000,1) PRIMARY KEY,
ProductName VARCHAR(20) NOT NULL,
Size VARCHAR(20) NOT NULL,
Color VARCHAR(20) NOT NULL,
UnitPrice MONEY,
UnitsInStock INT,
Discontinued INT DEFAULT 0,
Picture VARCHAR(40),
SupplierID INT NOT NULL,
FOREIGN KEY (SupplierID) REFERENCES Suppliers (SupplierID)
)

CREATE TABLE OrderDetails
(
OrderDetailsID INT IDENTITY(1,1) PRIMARY KEY,
Quantity INT NOT NULL,
Discount MONEY,
OrderID INT NOT NULL,
TShirtID INT NOT NULL,
FOREIGN KEY (OrderID) REFERENCES Orders (OrderID),
FOREIGN KEY (TShirtID) REFERENCES TShirts (TShirtID)
)




VIEWS AND STORED PROCEDURES



********************************************************************************
CUSTOMERS
********************************************************************************

CREATE VIEW view_DisplayAllCustomers AS
SELECT CustomerID, FirstName, LastName, Address, City, Country, DOB, Mobile, Status
FROM Customers


CREATE VIEW view_DisplayActiveCustomers AS
SELECT CustomerID, FirstName, LastName, Address, City, Country, DOB, Mobile, Status
FROM Customers WHERE Status = 0


CREATE VIEW view_DisplayInactiveCustomers AS
SELECT CustomerID, FirstName, LastName, Address, City, Country, DOB, Mobile, Status
FROM Customers WHERE Status = 1




(
@FirstName VARCHAR(20),
@LastName VARCHAR(20),
@Address VARCHAR(40),
@City VARCHAR(20),
@Country VARCHAR(20),
@DOB DATETIME,
@Mobile NCHAR(10),
@Status INT
)

AS
INSERT INTO Customers (FirstName, LastName, Address, City, Country, DOB, Mobile, Status)
VALUES (@FirstName, @LastName, @Address, @City, @Country, @DOB, @Mobile, @Status)
RETURN


CREATE PROCEDURE dbo.spUpdateCustomer
(
@CustomerID INT,
@FirstName VARCHAR(20),
@LastName VARCHAR(20),
@Address VARCHAR(40),
@City VARCHAR(20),
@Country VARCHAR(20),
@DOB DATETIME,
@Mobile NCHAR(10),
@Status INT
)
AS
UPDATE Customers
SET FirstName = @FirstName,
LastName = @LastName,
Address = @Address,
City = @City,
Country = @Country,
DOB = @DOB,
Mobile = @Mobile,
Status = @Status
WHERE CustomerID = @CustomerID
RETURN


CREATE PROCEDURE dbo.spDeleteCustomer
(
@CustomerID INT
)

AS
DELETE FROM Customers WHERE CustomerID = @CustomerID
RETURN


CREATE PROCEDURE dbo.spDeactivateCustomer

(
@CustomerID INT
)

AS
UPDATE Customers SET Status = 1
WHERE CustomerID = @CustomerID
RETURN


CREATE PROCEDURE dbo.spDeactivateCustomer

(
@CustomerID INT
)

AS
UPDATE Customers SET Status = 1
WHERE CustomerID = @CustomerID
RETURN


CREATE PROCEDURE dbo.spActivateCustomer
(
@CustomerID INT
)

AS
UPDATE Customers SET Status = 0
WHERE CustomerID = @CustomerID
RETURN




********************************************************************************
SUPPLIERS
********************************************************************************

CREATE VIEW view_DisplayAllSuppliers AS
SELECT *
FROM Suppliers


CREATE VIEW view_DisplayActiveSuppliers AS
SELECT *
FROM Suppliers
WHERE Status = 0


CREATE VIEW view_DisplayInactiveSuppliers AS
SELECT *
FROM Suppliers
WHERE Status = 1


CREATE PROCEDURE dbo.spAddNewSupplier

(
@CompanyName VARCHAR(20),
@ContactName VARCHAR(20),
@Address VARCHAR(40),
@City VARCHAR(20),
@Phone VARCHAR(15),
@Fax VARCHAR(15),
@HomePage VARCHAR(30),
@Status INT
)

AS
INSERT INTO Suppliers (CompanyName, ContactName, Address, City, Phone,
Fax, HomePage, Status)
VALUES
(@CompanyName, @ContactName, @Address, @City, @Phone,
@Fax, @HomePage, @Status)
RETURN


CREATE PROCEDURE dbo.spUpdateSupplier

(
@SupplierID INT,
@CompanyName VARCHAR(20),
@ContactName VARCHAR(20),
@Address VARCHAR(40),
@City VARCHAR(20),
@Phone VARCHAR(15),
@Fax VARCHAR(15),
@HomePage VARCHAR(30),
@Status INT
)

AS
UPDATE Suppliers SET CompanyName = @CompanyName,
ContactName = @ContactName,
Address = @Address,
City = @City,
Phone = @Phone,
Fax = @Fax,
HomePage = @HomePage,
Status = @Status
WHERE SupplierID = @SupplierID
RETURN



CREATE PROCEDURE dbo.spDeleteSupplier

(
@SupplierID INT
)

AS
DELETE FROM Suppliers WHERE SupplierID = @SupplierID
RETURN


CREATE PROCEDURE dbo.spDeactivateSupplier
(
@SupplierID INT
)

AS
UPDATE Suppliers SET Status = 1
WHERE SupplierID = @SupplierID
RETURN


CREATE PROCEDURE dbo.spActivateSupplier
(
@SupplierID INT
)

AS
UPDATE Suppliers SET Status = 0
WHERE SupplierID = @SupplierID
RETURN


********************************************************************************
T-SHIRTS
********************************************************************************
CREATE VIEW view_DisplayAllTShirts AS
SELECT *
FROM TShirts


CREATE VIEW view_DisplayActiveTShirts AS
SELECT *
FROM TShirts
WHERE Discontinued = 0


CREATE VIEW view_DisplayDiscontinuedTShirts AS
SELECT *
FROM TShirts
WHERE Discontinued = 1


CREATE PROCEDURE dbo.spAddNewTShirt

(
@ProductName VARCHAR(20),
@Size VARCHAR(20),
@Color VARCHAR(20),
@UnitPrice MONEY,
@UnitsInStock INT,
@Discontinued INT,
@Picture VARCHAR(40),
@SupplierID INT
)

AS
INSERT INTO TShirts (ProductName, Size,Color, UnitPrice, UnitsInStock,
Discontinued, Picture, SupplierID)
VALUES
(@ProductName, @Size, @Color, @UnitPrice, @UnitsInStock,
@Discontinued, @Picture, @SupplierID)
RETURN


CREATE PROCEDURE dbo.spUpdateTShirt
(
@TShirtID INT,
@ProductName VARCHAR(20),
@Size VARCHAR(20),
@Color VARCHAR(20),
@UnitPrice MONEY,
@UnitsInStock INT,
@Discontinued INT,
@Picture VARCHAR(40),
@SupplierID INT)
AS
UPDATE TShirt SET ProductName = @ProductName,
Size = @Size, Color = @Color, UnitPrice = @UnitPrice,
UnitsInStock = @UnitsInStock, Discontinued = @Discontinued,
Picture = @Picture, SupplierID = @SupplierID
WHERE TShirtID = @TShirtID
RETURN


CREATE PROCEDURE dbo.spDeleteTShirt

(
@TShirtID INT
)

AS
DELETE FROM TShirts WHERE TShirtID = @TShirtID
RETURN



CREATE PROCEDURE dbo.spDeactivateTShirt
(
@TShirtID INT
)

AS
UPDATE TShirts SET Discontinued = 1
WHERE TShirtID = @TShirtID
RETURN


CREATE PROCEDURE dbo.spActivateTShirt
(
@TShirtID INT
)

AS
UPDATE TShirts SET Discontinued = 0
WHERE TShirtID = @TShirtID
RETURN

Monday, September 14, 2009

ASP.NET - Session time

To record the session time, two variables are initialised in the global application class Global.asax to hold the name of user and time of session.



<%@ Application Language="C#" %>

<script runat="server">

void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup

}

void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown

}

void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs

}

void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
Session.Add("Name", null);
Session.Add("Time", null);

}

void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.

}

</script>


Now, in the first page (Default.aspx) which holds the textbox for the user name and the login button, the following code is written for the Click event of the login button. The variable Time in the Session object will store the date and time of the click.



protected void btnLogin_Click(object sender, EventArgs e)
{
Session["Name"] = txtName.Text;
Session["Time"] = DateTime.Now;
Response.Redirect("~/Default2.aspx");

}


In Default2.aspx, the name is displayed in the Form_Load event.
The button for logout will display the Session time.



protected void Page_Load(object sender, EventArgs e)
{
lblInfo.Text = Session["Name"].ToString();
}
protected void btnLogout_Click(object sender, EventArgs e)
{

lblInfo.Text = (DateTime.Now.Subtract(DateTime.Parse( Session["Time"].ToString()) )).Seconds.ToString();
}


Note: This code was written in class and has limitations. It will only display seconds. That is, 1 minute and 5 seconds will display as 5 seconds. I believe there are many ways to solve this problem. Please feel free to share your code.

Monday, September 7, 2009

SQL Practice In class - My SQL solution

Q1


CREATE TABLE Employee
(
FirstName VARCHAR(30),
LastName VARCHAR(30),
email VARCHAR(30),
DOB DATETIME,
Phone VARCHAR(12)
)




INSERT INTO Employee
VALUES
('John', 'Smith', 'John.Smith@yahoo.com', '2/4/1968','626 222-222')




INSERT INTO Employee
(FirstName, LastName, email, DOB, Phone)
VALUES ('Steven', 'Goldfish', 'goldfish@fishhere.net', '4/4/1974', '323 455-4545')





INSERT INTO Employee
(FirstName, LastName, email, DOB, Phone)
VALUES ('Paula', 'Brown', 'pb@herowndomain.org', '5/24/1978', '416 323-3232')




INSERT INTO Employee
(FirstName, LastName, email, DOB, Phone)
VALUES ('James', 'Smith', 'jim@supergig.co.uk', '10/20/1980', '416 323-8888')


Q2


SELECT FirstName, LastName, email, DOB, Phone
FROM Employee
WHERE (LastName LIKE 'SMITH')


Q3


SELECT COUNT(*) AS Num_of_Emp_Like_SMITH
FROM Employee
WHERE (LastName LIKE 'SMITH')


Q4


SELECT LastName, COUNT(*) AS NumberOfEmp
FROM Employee
GROUP BY LastName
ORDER BY LastName DESC


Q5


SELECT FirstName, LastName, email, DOB, Phone
FROM Employee
WHERE (DOB >= '01/01/1970')


Q6


SELECT FirstName, LastName, email, DOB, Phone
FROM Employee
WHERE (Phone LIKE '416%')


Q7


SELECT FirstName, LastName, email, DOB, Phone
FROM Employee
WHERE (email LIKE '%.%@%.%')


Q8


UPDATE Employee
SET DOB = '05/10/1974'
WHERE (LastName = 'Goldfish') AND (FirstName = 'Steven')


Q9


SELECT FirstName, LastName, email, DOB, Phone
FROM Employee
ORDER BY DOB DESC


Q10


SELECT FirstName, LastName, email, DOB, Phone
FROM Employee
WHERE (FirstName LIKE '_____%')


Q11


ALTER TABLE Employee ADD Id INT IDENTITY
CONSTRAINT pk_ID PRIMARY KEY(Id)


Q12


SELECT FirstName, LastName, email, DOB, Phone, Id
FROM Employee
WHERE (DATEPART(m, DOB) = DATEPART(m, GETDATE()))


Q13


create table EmployeeHours
(
empFName Varchar(30),
empLName Varchar(30),
Date DATETIME,
Hours



insert into employeehours
VALUES
('John', 'Smith', '5/6/2004', 8)

insert into employeehours
VALUES
('John', 'Smith', '5/7/2004', 9)

insert into employeehours
VALUES
('Steven', 'Goldfish', '5/7/2004', 8)

insert into employeehours
VALUES
('James', 'Smith', '5/7/2004', 9)

insert into employeehours
VALUES
('John', 'Smith', '5/8/2004', 8)

insert into employeehours
VALUES
('James', 'Smith', '5/8/2004', 8)


Q13


Alter table EmployeeHours
add EmployeeID INT
CONSTRAINT fk_ID Foreign Key (EmployeeID) References Employee(id)


Q14


CREATE PROCEDURE UpdateEmpId

AS
UPDATE EmployeeHours
SET EmployeeId =
(SELECT Id
FROM Employee
WHERE (EmployeeHours.EmpFName = FirstName) AND (EmployeeHours.EmpLName = LastName))