الأحد، 12 سبتمبر 2010

Simple HOTEL RESERVATION FORM



Simple HOTEL RESERVATION FORM
Steps
1. Create a new Windows application named Hotel Reservation.
2. Drag a label onto the form and set its text to Hotel Reservation Form.
3. Set the font size to 14.
4. Set the font to bold.
5. Set the TextAlign property to MiddleCenter.
6. Drag a check box onto the form and name it chkVIP.
7. Set its background color to Green and its text to VIP Customer.
8. Drag a group box onto the form, and set its text to Room Type.
9. Drag a radio button onto the group form, set its name to rbSingle, and its text to Single.
10. Drag a second radio button onto the group form, set its name to rbDouble and its text to Double.
11. Drag a third radio button onto the group form, set its name to rbSuite, and set its text to Suite.
12. Use the format menu choice to make all three radio buttons the same size, align their left borders, and set their vertical spacing to equal.
13. Resize the group to fit the radio buttons and set the background color ofthe group to Cornflower blue.
14. Drag a checkedListBox onto the form and set its name to clbFeatures.
15. Click on the Items property and add the following features:

Whirlpool
Color TV
VCR
DVD
On-Demand Movies
In-Room Wet Bar
Free Breakfast
Free Lunch
Free Meals
Late checkout
Early check in
16. Set the Sorted property to true and watch the list sort itself.
17. Set the background color to a pleasing pastel.
18. Add a button named btnBook and set its text to Book Reservations.
Stretch the button to fit.
19. Set the button’s background color to red, set its forecolor to yellow, and set its font to bold.
20. Drag a label onto the form. Set its name to lblOutput and its text to blank.
                              Your form should now look more or less like Figure


21. Double-click on the Book Reservations button to open the event handler.
Create a string to hold the output:
string output = "Your reservation...\n";
22. Check if the VIP Customer check box is checked, if so modify the text for
the output string.
if (chkVIP.Checked == true)
output +="VIP Service!\n";
23. Check which radio button is checked and modify the output string.
if (rbSingle.Checked)
output += "Single room\n";
else if (rbDouble.Checked)
output += "Double room\n";
else
output += "Suite";
24. Add output for each feature that is selected and checked in the list.
foreach (string s in clbFeatures.CheckedItems)
output += "Feature: " + s + "\n";
25. Display the output in the label.
lblOutput.Text = output;

ASP.Net : DataList control for beginner


DataList control for beginner

The DataList control is, like the Repeater control, used to display a repeated list of items that are bound to the control. However, the DataList control adds a table around the data items by default. The DataList control may be bound to a database table, an XML file, or another list of items
Example: DataList to display pictures
Steps
1. Create a simple ASP.NET 2.0 Web Form page named StudentDetails.aspx
2. Create a folder in your site’s root and attach a collection from your favorite’s images on it as shown in figure.
1.jpg
3. Drag and Drop to a DataList control from the Data section of the Toolbox to the content area.
4. Open its smart task panel, as shown in Figure, and click Choose Data Source. Click New Data Source for the wizard to create a data source control.
2.jpg
5. Select Database as the source and leave the name as SqlDataSource1.
Use the wildcard (*) to select all fields from Student Table.
6. Run the page in your browser to test it, noticing that you don’t have the pictures yet as shown in figure. Close the browser.
3.jpg
7. Now you need to actually get the pictures displayed. Be sure your browser is closed and then in Design View select the DataList control, open its smart task panel, and click Edit Templates to see a screen similar to Figure. Select and then delete the line that has the text PictureURL and a Label control.
4.jpg
8. From the Toolbox, drag an Image control into the template just below the Picture ID field. Feel free to add a carriage return (by pressing Enter) to get the image control on its own line. On the Image control’s smart task panel, click Edit Data Bindings, and select the property ImageURL to bind to the field PictureURL, as shown in Figure.
5.jpg
9. Click ok
10. To display your data in horizontal state set these properties as shown for DataList control.
6.jpg
11. Run your page and you will see result satisfy you.
Note
In imgurl field in database I am pass the path of image as full path like this:-
images/Chrysanthemum.jpg
if I am pass the name of image only and try to run the sample we will not find image displayed in the control so to solve this case you need to change the following in source code :-
ImageUrl=’’ />

الجمعة، 30 يوليو 2010

Variable

Variables

Variables are, technically, named typed storage locations. What this means is that you can create variables to hold values of a specific type, and you can give these variables names. For example, you can declare:



General format for data type

Type anyName = yourValue;



Example:

int myAge; // declare an integer variable

myAge = 25; // assign a value to the variable



Here you’ve created a variable named myAge and you’ve declared that it will hold an int. An int is an integer variable. You then, subsequently assigned the value 25 to that variable.

Declare, Assign, Initialize

When you allocate space for the variable, you are said to declare the variable. When you give that variable a value, you are said to assign to it. You can combine these two steps into one; this is known as initializing the variable.



int myAge; // declare an integer variable

myAge = 25; // assign a value to the variable

                                          

You can combine these steps into a single initialization:



int myAge = 25; // initialize an integer variable



You can declare more than one variable on a line at a time, as long as they all have the same type:



int myFirstVar, mySecondVar, myThirdVar;

Data Type

§  A data type can be described as being either:   

§  A built-in data type, such as an int or char, or

§  A user-defined data type, such as a class or interface.



Data types can also be defined as being either:

§  Value Types (C# Reference), which store values, or

§  Reference Types (C# Reference), which store references to the actual data.

الأحد، 6 يونيو 2010

Compile Errors vs. Run-Time Errors

Compile Errors vs. Run-Time Errors

Compile errors occur each time the program is compiled. If the error exists, the compiler will find it. Run-time errors get past the compiler, but show up when the program is running. Run-time errors are not reliable; they may occur with some runs of the program, but not with others. Compile errors (sometimes referred to as compile time errors) are caught by the developer. Your Quality Assurance team may catch runtime errors, but if not, they will certainly be caught by your customers. Compile time errors are easier to find, easier to fix, and less embarrassing

الثلاثاء، 17 مارس 2009

Synchronize Data in Secondary User Control(s) Based Upon User Selections

This code shows how to create two DropDownList controls where selecting an item in the first list populates the items in the second list।


public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

if (!Page.IsPostBack)

{

DropDownList1.Items.Add(new ListItem("Select Country", "0"));

DropDownList1.Items.Add(new ListItem("Egypt", "1"));

DropDownList1.Items.Add(new ListItem("Saudi Arabia", "2"));

DropDownList2.Enabled = false;

}

}

public void GetGovernora(string index)

{

DropDownList2.Enabled = true;

switch (index)

{

case "1":

DropDownList2.Items.Clear();

DropDownList2.Items.Add(new ListItem("Cairo","1"));

DropDownList2.Items.Add(new ListItem("Alex","2"));

DropDownList2.Items.Add(new ListItem("Mansoura","3"));

DropDownList2.Items.Add(new ListItem("Domiatta","4"));

break;

case "2":

DropDownList2.Items.Clear();

DropDownList2.Items.Add(new ListItem("Ryiad","1"));

DropDownList2.Items.Add(new ListItem("Gada", "2"));

DropDownList2.Items.Add(new ListItem("Jezan", "3"));

break;

default:

DropDownList2.Items.Clear();

DropDownList2.Items.Add("No Avaliable Country");

DropDownList2.Enabled = false;

break;

}

}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)

{

GetGovernora(DropDownList1.SelectedValue);

}

}


الأربعاء، 11 فبراير 2009

Text scroll effect

Text scroll effect

Introduction

In this tutorial, you will learn how to make a text scrolling effect using a label control. It's really quite simple, and it has a cool visual effect. To follow this tutorial step-by-step you will need .NET Framework and Visual Studio .NET installed on your machine.

Getting to work

Let's begin by creating a new C# Project using Visual Studio .NET. Select File -> New Project -> Visual C# Project -> Windows Application. Name your project however you want, I will call it TextScroll.

You are now in front of the Design view of your interface. First, we must create the user interface, after witch we will begin the coding part. The first thing we will do is add a Label control. To do that, select View -> Toolbox (or press Ctrl + Alt +X ). Select the Label control, drag and drop it onto our form. Now, we will need to adjust some properties of the Label. Select the Property window (if it's not visible, select View -> Properties Window, or just press F4). Change the TextAlign property to MiddleCenter ( by doing that, the text of the label will be displayed centered ). Also, the Text property of the label needs to display no text(from the Properties window, remove the text "label1", witch Visual Studio .NET adds it by default). It is preferred that we change the BackColor property (I changed it to SlateGray color, but you can use almost any color as long as the BackColor and ForeColor are different). Now change the ForeColor to LightSalmon. Let's add a Button for starting the scroll. Set its Text property to Start Scrolling and the Name to btn_start. The next thing we need to add is a TextBox control, to allow the user to input the string that he wants to scroll. Visual Studio .NET will name the TextBox to textBox1, we will change this Name to tb_scroll. Go to the Text property and remove "textBox1" string.

Another property we will need to change is MaxLength property to 30. This is the maximum number of characters that we allow the user to type into this control. The reason that we do this is that for a rather large number of characters, let's say 50, the label that we created earlier will display the text on two columns, making the scroll look rather ugly.

Put a Label control above the TextBox created earlier, and set the Text property to "Please enter the string to be scrolled:". For now, the design part is over.

After there steps, your form should look something like this:


Let's start creating some code, shall we?

Double-click the TextBox control. Visual Studio .NET created a method called tb_text_TextChanged. As its name says, this method occurs whenever the Text property of the TextBox changes. What we want to do is disable btn_start if we have no text in the TextBox. To do this, we need to add the following code:

if (tb_text.Text.Trim()="")

btn_start.Enabled = false;

else

btn_start.Enabled = true;

The Trim() method, called with no argument, removes the extra spaces from the beginning and the end of the text. If the text property of tb_text is "", we want btn_start to be disabled, else we enable it.

In the Design view, double-click the form's surface and a method called Form1_Load is created. In this method, we need to add the following:

btn_start.Enabled=false;
The reason we do this is that when our application starts, the TextBox has no text in it, and we want btn_start to be disabled, because we have no text to scroll.

Let's go back to Design view and double-click btn_start. Visual Studio will create a method called btn_start_Click. In this method we will write some code to begin the scrolling.

First, we must understand how this scrolling works. We have a string, let's say "string to test the scrolling effect ". To create the effect, we must remove the last character of the string and set the label's Text property to the new string "string to test the scrolling effect". Now we must place the removed character(' ') in the first position of the string, so that we have " string to test the scrolling effect". We must repeat this action until we have the same string that we had when we started. The steps are:

string to test the scrolling effect
string to test the scrolling effect
t string to test the scrolling effec
ct string to test the scrolling effe
ect string to test the scrolling eff
fect string to test the scrolling ef
ffect string to test the scrolling e
effect string to test the scrolling
effect string to test the scrolling
g effect string to test the scrollin
......................................................
string to test the scrolling effect

So we will have to create a function that executes the scrolling until the form is closed.

Now, we have to create a method that handles the scrolling, and call this method in the btn_start_Click method. Let's create the following method:

private void ScrollText()
{
}

Now we need to create the code that does the job.

System.Text.StringBuilder sb = new System.Text.StringBuilder(tb_text.Text+" ");

StringBuilder class helps up to manipulate strings. We call the constructor that takes a string that we will play with. The reason that a space is appended at the end of the text is to separate the last and the first character. We need this class' methods Insert (to insert the character we remove from the end at the beginning of the string ) and Remove ( to remove the last character from the string ).

while (true)
{

char ch = sb[sb.Length-1];
sb.Remove(sb.Length-1,1);
sb.Insert(0,ch);
label1.Text = sb.ToString();
label1.Refresh();
System.Threading.Thread.Sleep(100);

}

We do the scrolling until the user closes the window. We declare a variable of type char to hold the last character from the string,whitch we will remove using Remove() method. Next, we insert that character into the beginning of the string. We set the label text as the new text, refresh it and then we use the Sleep() method to pause the execution for 100 miliseconds. And that's the scroll.

All we have to do now is call the ScrollText() method in the btn_start_Click method. We also need to add some extra code:

btn_start.Enabled=false;
ScrollText();

Run the application and see this working.

The main problem of the application is a non-responsive user interface. That's because we do the scroll operation is performed on the same thread that the user interface function run on. To avoid this, we need to create an asynchronous delegate.

The first step is to declare a delegate at the beginning of the class and create an instance of it.

public delegate void ScrollDelegate();
private ScrollDelegate s_del;

The next step is to initialize it in the Form_Load method.

s_del = new ScrollDelegate(ScrollText);

Now, when we call the BeginInvoke() method of s_del, the scrolling will occur. We win call BeginInvoke() in the btn_start_Click method, replacing the call to ScrollText method.

s_del.BeginInvoke(null,null);

Let's run the application again now. You notice how improvement we've created by adding 4 lines of code?

Here is the application when I run it on my computer:

You can play around with the sleep interval(make the interval smaller to have a faster and smoother scroll, and make it bigger to have a "lazy" scroll).

Well, we've reached the end of this lesson. I hope you had as much fun as I did!

Attachments:

Project Files: TextScroll.जिप

Source

http://www.codersource.net/csharp_scrolling_text.aspx