-->

Monday, January 6, 2014

Computer Programming: Department table for shopping cart in ASP.NET, Example

In computer Programming, database is the important concept of any one project. In this article we will learn the first step of e-commerce project, which is database (table) design. Follow the steps for designing department table.

Step-1: In server explorer, expand the database node, right-click the Tables node, and select Add New Table from the context menu.
Step-2: A form appears where you can add columns to the new table. Using this form, add three columns, with the properties described in table.

Computer Programming : Design Department table for shopping cart in asp.net

Note : You set a column to be the primary key by right-clicking it and clicking the Set Primary Key item from the context menu. You set a column to be an identity column by expanding the Identity Specification item from its Column Properties window, and setting the (Is Identity) node to yes. You can also access the identity increment and Identity Seed vales, if you should ever want to use values other than the defaults.

Step-3: After adding these fields, the form should look like.

Computer Programming : department table for shopping cart in asp.net


Step-4: Now that everything is in place, you need to save the newly created table. Press Ctrl+S, write table name in appeared popup.
Computer Programming : Save table in sql

Step-5: After creating the table in the database, you can open it to add some data. To open the Department table for editing, right-click it in Server explorer and select Show Table Data from the context menu.
(Alternatively, you can choose Database->Show Table Data after selecting the table in server explorer)

Using the integrated editor, you can start adding rows. Because DepartmentID is an identity column, you cannot manually edit its data--SQL Server automatically fills this field, depending on the identity seed and identity increment values that you specified when creating the table.

Step-6: Add two departments.

Computer Programming : filling data into database table

Sunday, January 5, 2014

Computer Programming:inline code or Code render block in ASP.NET, Example

Code render blocks define the inline code or inline expressions that are executed when a web page is rendered. The inline code is then executed by the server and the output is displayed on the client browser that requested for the page. The code render blocks are capable of displaying information on the client browser without customarily calling the write method. The code render blocks are represented on a page by the <% %> symbols. The code present inside these symbols is executed in the top-down manner. Now, let's put the concept of code render bock into use by creating an application, CodeRenderBlock. This application use a code render block to implement a loop used for changing the text size.

Lets take a simple example, change font size in asp.net using loop

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Change Font size inline code model</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <% for(int i=0;i<6;i++)
           
       { %>
       <font size="<%=i %>" >Hello World ! </font><br />
       <% } %>

    </div>
    </form>
</body>
</html>

Code generate following output

Computer Programming : code render block

Saturday, January 4, 2014

How to Create a GUI application displaying a String in NetBeans: Java Programming

NetBeans provides a simple and easy way to create a new project and display a string in sql programming. The article will let the programmer do the same thing.
  • Start NetBeans and create a new project as explained in earlier article. You can change the name of the project otherwise it will automatically set. Add new frame in the same way discussed earlier. By default the name of frame will be NewJFrame.
  • Draw a Label control on your frame by dragging it from the Swing Controls section of the Palette.
  • To change the name of this Label, right click on its default name, which is JLabel1, under the Inspector window and select Change Variable Name……. command as shown in the image.
How to Create a GUI application displaying a String in NetBeans: Java Programming
  • Keeping the label control selected in its design space, do in the Properties window :

    Click the ellipsis button of the font property and selected font as:
    Type: Comic Sans MS (you may choose any other font if you wish)
    Style: Bold
    Size: 18
  • Type "Computer Programming" (without quotes) in the text property's box or by clicking at its ellipsis button. Now your project window will appear something like:
How to Create a GUI application displaying a String in NetBeans: Java Programming
  • Adjust the placement of the title label, whose properties you set just now, by dragging it, so that it appears in the middle horizontally.
  • On the same lines, add one more Label to your frame by dragging it from the Palette. Set its font as per you wish. Select the colour of the font by clicking the ellipsis of the foreground property in Properties window. Now specify its text as: "A Complete Programming Blog with SQL, JAVA, C, C#".
  • Adjust its placement as per you wishes. Now your project window will appear somewhat like:
How to Create a GUI application displaying a String in NetBeans: Java Programming
  • Right click on the jFrame you have created and click on Run File, it will show the frame which will look like:
How to Create a GUI application displaying a String in NetBeans: Java Programming

In this workshop you have learnt about following properties of jLabel control.
  • font: The property used to specify the display font, style and size for the display text of the jlabel. Font is selected by clicking ellipsis button in font property's box.
  • foreground: The property used to specify foreground color of jLabel, you can select desired colors by clicking of the foreground property.
  • text: The property used to specify the display text. You can either type the display text directly in front of text property’s name click to type it in a separate box. Small texts you can type directly, for big texts, its better them separately.

Ranking Functions to Generate Sequential Numbers in Sql Server: SQL Programming

In SQL Programming, ranking functions are used to operate with numeric values. Programmer can easily perform all type of ranking functions to generate sequential numbers for each row based on specific criteria.

You can use ranking functions to generate sequential numbers for each row or to give a rank based on specific criteria. For example, in a manufacturing organization, the management wants to rank the employees based on their salary. To rank the employees, you can use the rank function.

Ranking function return a ranking value for each row. However, based on the criteria, more than one row can get the same rank. You can use the following functions to rank the records:
  • row_number
  • rank
  • dense_rank
All these functions make use of the OVER clause. This clause determines the ascending or descending sequence in which rows are assigned a rank. The row_number function returns the sequential numbers, starting at 1, for the rows in a result set based on a column.

For example, the following SQL query displays the sequential number on a column by using the row_number function:

SELECT BusinessEntityID, Rate, row_number ( ) OVER (ORDER BY Rate desc) AS RANK 
FROM HumanResources.EmployeePayHistory

The following figure displays the output of the preceding query.

Ranking Functions to Generate Sequential Numbers in Sql Server: SQL Programming

dense_rank Function

The dense_rank( ) function is used where consecutive ranking values need to be given based on a specified criteria. It performs the same ranking task as the rank function, but provides consecutive ranking values to an output.

For example, you want to rank the products based on the sales done for that product during a year. If two products A and B have same sale values, both will be assigned a common rank. The next product in the order of sales values, both will be assigned a common rank. The next product in the order of sales values would be assigned the next rank value.

If in the preceding example of the rank function, you need to give the same rank to the employees with the same salary rate and the consecutive rank to the next one. You need to write the following query:

SELECT BusinessEntityID, Rate, dense_rank( ) OVER (ORDER BY Rate desc) AS rank 
FROM HumanResources.EmployeePayHistory

Ranking Functions to Generate Sequential Numbers in Sql Server: SQL Programming

Friday, January 3, 2014

Computer Programming : How to Generate random number in ASP.NET, Example

You can generate random number using Random class. According to msdn library:
Represents a pseudo-random number generator, a device that produces a sequence of numbers that meet certain statistical requirements for randomness.
A Random class exists in System namespace, used to display pseudo-random numbers. The Class has many methods, such as Next() method. Overloaded Next method take different parameters such as zero argument, one argument and two argument.

Random class instance . Next () : Following Code gives Non-negative integer number like 1 to further.
Random class instance . Next (Int32) : You can specify a number, which is maximum for generated output.
Random class instance . Next (Int32, Int32): You can specify minimum and maximum number in parameter, following output generated between specified argument.

Application

  1. Mathematical CAPTCHA Design
  2. Kids Game.

Lets take an simple example

 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Random Number</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server"></asp:Label>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" Height="37px" onclick="Button1_Click" 
            Text="Random Number " />
    </div>
    </form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Random r1 = new Random();
        string s = r1.Next(10, 100).ToString ();
        Label1.Text = s;


    }

}


Code generate following output

Computer Programming : How to Generate random number in ASP.NET, Example

Computer Programming : How to Generate random number in ASP.NET, Example
      

Computer Programming : How to get System information in ASP.NET, Example

Computer Programming : Easily you can get operating System information using OperatingSystem Class. This class exist in System Namespace. It has single constructor with specified platform identifier and version object. Also contain four public properties, such as Platform, ServicePack, Version and VersionString.

Need of it  

  1. Install driver online, if you know about operating system.
Note : Output depends on class constructor parameter.

Lets take a simple

        <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Operating System Information</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server"></asp:Label>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" Height="37px" onclick="Button1_Click" 
            Text="System Information " />
    </div>
    </form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Version ver = new Version();

        OperatingSystem os = new OperatingSystem(PlatformID.Win32S, ver);

        string version = os.Version.ToString();
        string StringVersion = os.VersionString;
        string platform = os.Platform.ToString();
        string servicepack = os.ServicePack.ToString();
        Label1.Text = "Operating System Version=" + version + "<br/>version String=" + StringVersion + "<br/>platform=" + platform + "<br/>Service Pack=" + servicepack;


    }
}

Code generates the following outputs
computer Programming: get operating system information

Thursday, January 2, 2014

Computer Programming : Different DateTime format in ASP.NET, Example

DateTime class is used to print date and time of the system/server. Its very useful class in application development or project development. Suppose you want to print current date and time of the system, use DateTime class with Now property.

Label1.Text = DateTime.Now.ToString();


Dotprogramming : Print current date and time
If you want to print only date with special format like date/month/year. Now, use dd/MM/yyyy in ToString() method. Lets take an simple example

Label1.Text = DateTime.Now.ToString("dd/MM/yyyy");

Dotprogramming : print date with specific format

 Similarly again, if you want to print only day of current date then you should take only "dd" in the string parameter.

Label1.Text = DateTime.Now.ToString("dd");

day of the current datetime in asp.net

© Copyright 2013 Computer Programming | All Right Reserved