-->

Saturday, November 2, 2013

Creating an XML Document

Problem Statement

CyberShoppe, Inc. sells toys and books in the United States. It has three branches in different parts of the country. Currently, the three branches maintain data on their local computer systems. The IT manager at CyberShoppe has identified that a centralized data repository on the products sold through its e-commerce site is required. The data from all branches must be collated and housed in a centralized location. This data must be made available to the accounts and sales sections at the individual branches, regardless of the hardware and software platforms being used at the branches. In addition, the sales personnel require access to the data using palmtops and cellular phones.
The product details of CyberShoppe consists of the product name, a brief description, the price, and the available quantity on hand. A product ID uniquely identified each product.

Solution
To solve the preceding problem, you need to perform the following tasks:

  1. Identify the method to store data in a device-independent format.
  2. Identify the structure of the document in which data is to be stored.
  3. Create an XML document to store the data.
  4. View the XML document in a browser.

Task 1: Identifying the method to store the Data in a Device-Independent Format

In the given problem statement, device ranging from mainframe computers to mobile phones must be able to access information from the data store. For example, the employee of the sales department may need to access product costs using an IBM PC. XML enables different types of devices to access information. Therefore, XML can be used to create the data store in the given scenario.

Task 2 : Identifying the Structure of the Document in Which Data is to be stored.

In the given scenario, PRODUCTDATA has been Identified as the root element. It has one child element, PRODUCT. The PRODUCT element can occur one or more times in the XML document. It acts as the container element for the PRODUCTNAME , DESCRIPTION, PRICE, AND QUANTITY elements. PRODUCTNAME has one attribute called PRODID, which is used to uniquely identify each product. The following figure illustrate the structure of the elements used in the XML document to store the product data.

Creating an XML Document
Structure of the XML Document to Store Product Data

Task 3: Creating an XML Document to Store Data

To create an XML file that contains information about the products sold by CyberShoppe, type the following code in Notepad, and save the file as cyber_products.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!-- PRODUCTDATA is the root element -->
<PRODUCTDATA>
<PRODUCT PRODID="P001">
<PRODUCTNAME>Barbie Doll</PRODUCTNAME>
<DESCRIPTION>This is a toy for children in the age group of 5-10 years </DESCRIPTION>
<PRICE>12</QUANTITY>
</PRODUCT>
</PRODUCTDATA>

Task 4: Viewing the XML Document in a Browser

To View the XML document in the browser, open the cyber_products.xml file in Internet Explorer . IE provides a default tree view layout for an XML document. You can expand and collapse the tree.

The tree-view structure of the cyber_products.xml document is shown in the following figure

Creating an XML Document



Future of XML

XML has revolutionized the web and the nature of distributed computing. It is the preferred file format for web development, document interchange, and data interchange. Currently, news organizations and wireless services exchange news articles, stock information, and other similar information through proprietary formats. XML will enable wider use and exchange of such information in future. XML will also help global businesses exchange data in a customized and universally acceptable format.
The future uses of XML can be summarized as:

  • XML will be widely used in e-commerce.
  • XML will have a huge core market in the form of B2B.
  • XML will be used for mobile devices, such as mobile phones, PDAs, and palmtops due to its ability to easily convert into the appropriate format for any device.
  • XML will be used to solve communication problems in EDI and Enterprise Application Integration(EAI) as it provides interoperability between disparate  applications.
Lets us look at some real life examples of XML implementation.
identifying Real-Life implementation of XML 
The Microsoft site, http://msdn.microsoft.com/xml/, provides information about customers who have successfully implemented XML in real-life. A few of these customers are listed as follows:
  • FreeEDGAR.com, Inc. is an organization that provides updated information on finance, institutional holdings, and insider trading patterns to its customers. To provide this information, FreeEDGAR.com uses an XML based delivery service. This service is based on real-time filling from the US securities and Exchange commission. One of the project requirements was that FreeEDGAR's customers should be able to use the service on multiple platforms. The service had to be independent of any database technology. FreeEDGAR also had to ensure are able to query and access the structured information easily. The development team realized that XML was the perfect solution for its project's requirements. The team used a processing server and built its XML service on top of it. To generate Web Pages, it used MSXML DLL along with some XSL style sheets that were used to convert XML into HTML. The team used MSXML inside a Web page created using Visual InterDev and Visual Basic components. This approach reduced code maintenance and resulted in the development of more readable code.
  • Shopping.com is another example of the real life implementation of XML. Shopping.com uses context based shopping to ensure that its uses get relevant results for their searches. The organization had to ensure that the users who conduct keyword searches through AltaVista Search also receive suitable product offers from Shopping.com for example, The keyword , "CD player", on AltaVista Search will return Web search results along with relevant CD players and electronics merchandise available for purchase from shopping.com. The development team faced the challenge of ensuring quick transfer of data between two different operating systems. Since the XML syntax is simple to learn and can be used quickly , they decided to use XML for the project. The use of XML enabled them to reduce the size of the data file and the time taken to transfer the data file to a great extent.

Programmatically change CheckBoxList text color in ASP.NET

Introduction

If you want to change foreColor of the font for better visibility then you must change font color according to users. Highly rich content website change font color , font name/face and font size according to users. Get lots of visitors or viewers from your website  using website functionality (better presentation, better look and better theme) .

lets take an simple example

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

<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:CheckBoxList ID="CheckBoxList1" runat="server" Height="45px" Width="239px">
            <asp:ListItem>Adrotator</asp:ListItem>
            <asp:ListItem>BulletedList</asp:ListItem>
            <asp:ListItem>Button</asp:ListItem>
            <asp:ListItem>CheckBox</asp:ListItem>
        </asp:CheckBoxList>
        <br />
        <asp:Button ID="Button1" runat="server" Height="35px" onclick="Button1_Click"
            Text="Change forecolor" Width="119px" />
   
    </div>
    </form>
</body>

</html>
Codebehind

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        CheckBoxList1.ForeColor = System.Drawing.Color.Red;


    }
}
Output
Programmatically change CheckBoxList text color in ASP.NET

Programmatically change CheckBoxList text color in ASP.NET

Programmatically change CheckBoxList font size in ASP.NET

Introduction

If you want to change size of the font for better visibility then you must change font size according to users. Highly rich content website change font color , font name/face and font size according to users. Get lots of visitors or viewers from your website  using website functionality (better presentation, better look and better theme) .

lets take an simple example


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

<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:CheckBoxList ID="CheckBoxList1" runat="server" Height="45px" Width="239px">
            <asp:ListItem>Adrotator</asp:ListItem>
            <asp:ListItem>BulletedList</asp:ListItem>
            <asp:ListItem>Button</asp:ListItem>
            <asp:ListItem>CheckBox</asp:ListItem>
        </asp:CheckBoxList>
        <br />
        <asp:Button ID="Button1" runat="server" Height="35px" onclick="Button1_Click"
            Text="Change Font" Width="119px" />
   
    </div>
    </form>
</body>

</html>

Codebehind Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        CheckBoxList1.Font.Size = FontUnit.Larger;

    }
}
Output
Programmatically change CheckBoxList font size in ASP.NET

Programmatically change CheckBoxList font size in ASP.NET

Friday, November 1, 2013

How to Access Record by DataGridViewButton: Windows Forms

I have created a DataGridViewButton for each particular record of DataGridView, as in my earlier post. Adding a button is not sufficient in programming, it should perform some functions when clicked, so we have to generate its click event.

In simple words, we can’t generate a click event of this DataGridViewButton using double click or from the events section. As this is in datagridview so generate Cell_Click event of this datagridview. Now, I have added this button in first column, so I can check it on the same.
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
MessageBox.Show("Column: " + e.ColumnIndex + " and Row: " + e.RowIndex);
}

By this simple code, the debugger will execute all your line of code, written in the space provided. ColumnIndex contains the column index and RowIndex contains row index, when this event triggered.

Let suppose, we want to access the record of the clicked row of datagridview. I have bound that datagridview with list of student class, so the following C# lines of code will get the instance of student, which is currently focused by mouse click event.
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
Student stu = dataGridView1.Rows[e.RowIndex].DataBoundItem as Student;
MessageBox.Show("Name: " + stu.Name + "\r" + "Age: " + stu.Age
+ "\r" + "City" + stu.City + "\r"
+ "Dob: " + stu.Dob);
}

The first line will get the particular record, which is of student type. When we run the project and click on the datagridviewbutton it will show a message box, containing the detail of particular student.

How to access record by Datagridviewbutton in C#: Windows Forms

Thursday, October 31, 2013

How to Add Commands with Binding in DataGridView: Windows Forms

After binding records with DataGridView, there may be some options to edit or to remove those records. To do these simple task we can provide either a button, which gets the selected record and perform operation, or we can provide the button with each particular record.

We will discuss here how to add a button with particular record with the following simple steps. Drag-n-drop a datagridview on the form and a task pop-up menu will automatically open, click on Add Columns link button to add a new column. It will show following Add Column window.

How to Add Commands with Binding in DataGridView: Windows Forms

By default Unbound column radio button have been checked, if not check it and use the following values in respective fields:
  • Type: DataGridViewButtonColumn
  • Header Text: Command (Changeable)
Sure the Visible check box is checked and click on Add button to add this column. Now you have successfully added a command button with empty text as shown in below image:

How to Add Commands with Binding in DataGridView: Windows Forms

To write text on the button generate Cell_Formatting event of dataGridview and set the value of first column as I do in the following c# code:
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
dataGridView1.Rows[e.RowIndex].Cells[0].Value = "Remove";
}

When you run the project now, it will show “remove” on the button. To check if this code will works for multiple records or not, add some records in data gridview like How to add Records in Datagridview. Run the project now and it will show the Remove button with each record as shown in the following image:

How to Add Commands with Binding in DataGridView: Windows Forms

In the next article I will remove the particular record with this command button.

How to Bind ComboBox with List of Items: C#

A list of items is used to store some temporary records, used in the program and do some operations like sorting, grouping and etc. In the previous post we have created a list and bind that list to the datagridview, using its DataSource property.

A combo box also have DataSource property to bind some data as I have discussed in my earlier article i.e. How to bind combobox with database. Combo Box is used to display a single field at a time and a list can contains multiple fields. I will use the same student class as in my earlier articles.
To show a single field, combo box have a property DisplayMember that will specify the field to display. In the following C# code the student list will bind with the combo box and name field will be shown.

List<Student> stuList = new List<Student>();
cmbBox.DataSource = stuList;
cmbBox.DisplayMember = "Name";

Before running this code, you have to sure that your list have some records to show. It will not throw an exception, but it will also not show any records because the list is empty.

Run the project and combo box will bind the list items and we can select any of them. The image shown the combo box items:

How to bind combobox with list of items: C# Windows forms

© Copyright 2013 Computer Programming | All Right Reserved