ASP.Net: Select Items using ImageMap control & generate and print the bill



1. Select Item web form

Default.aspx

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

<!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">
      <center>          
          <h1>Fast Food Billing Payment</h1>
          <asp:ImageMap ID="ImageMap1" runat="server"  ImageUrl="~/fastfood.png" 
              onclick="ImageMap1_Click">

     

       <asp:RectangleHotSpot  HotSpotMode="PostBack"  Top="0" Left="0" Bottom="100" Right="100"  
       PostBackValue="berger"    />

      
        <asp:RectangleHotSpot  HotSpotMode="PostBack" Top="0" Left="100" Bottom="200" Right="200"  
       PostBackValue="pasta" />

       <asp:RectangleHotSpot  HotSpotMode="PostBack" Top="0" Left="200" Bottom="300" Right="300"  
       PostBackValue="pizza" />

       <asp:RectangleHotSpot  HotSpotMode="PostBack" Top="0" Left="300" Bottom="400" Right="400"  
       PostBackValue="momo" />

          </asp:ImageMap>
      <table>
          <tr>
            
                <td>  Item Purchased</td> <td> 
                    
                    <asp:DropDownList Width="100%" ID="DropDownList1" runat="server" 
                        onselectedindexchanged="DropDownList1_SelectedIndexChanged" AutoPostBack="True">
                    
                    
                    </asp:DropDownList> 
                    </td>
            </tr>
            <tr>
            
                <td>  Customer Name</td> <td> 
                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
            </tr>
            
          <tr><td>Price:</td><td>
                    <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox></td></tr>
       <tr>
            
                <td>  Quantity</td> <td> 
                    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                    </td>
            </tr>

            <tr>
             <td>  <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Payment?" />       
                </td>
               <td> <asp:TextBox ID="TextBox3" runat="server" ReadOnly="true"></asp:TextBox>
            </td>

            
            </tr>

            <tr>
              <td>        
                </td>
             <td>
                 <asp:CheckBox ID="CheckBox1" runat="server"  AutoPostBack="true"/> Special Customer</td>
             
            </tr>
           <tr>
              <td>        
                </td>
             <td>
                 <asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="Pay Bill" />
                </td>
               
            </tr>
      </table>       
       

      </center>
    </form>
</body>
</html>

Default.aspx.cs

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


public partial class _Default : System.Web.UI.Page
{
    double[] pricesP = { 20, 15, 60 };
    double[] pricesB = { 40, 55, 90 };
    double[] pricesM = { 90, 98 };
    double[] pricesPs = { 100, 115 };

    int flag = 1;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            DropDownList1.Items.Add("Select Food item first");

        }
        
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        double amt;
    
        double qty = Convert.ToDouble(TextBox2.Text);
        int i = DropDownList1.SelectedIndex;
        amt = qty * Convert.ToDouble(TextBox4.Text);
        

        if (CheckBox1.Checked == true)
        {
            amt = amt - amt * .10;
        }
        TextBox3.Text = amt.ToString();

    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        TextBox2.Text = "";
        TextBox3.Text = "";
        int i = Convert.ToInt16(ViewState["f"]);
        switch (i)
        {
            case 1:
                TextBox4.Text = pricesP[DropDownList1.SelectedIndex].ToString();
                break;
            case 2:
                TextBox4.Text = pricesB[DropDownList1.SelectedIndex].ToString();
                break;
            case 3:
                TextBox4.Text = pricesM[DropDownList1.SelectedIndex].ToString();
                break;
            case 4:
                TextBox4.Text = pricesPs[DropDownList1.SelectedIndex].ToString();
                break;

        }

    }
    protected void ImageMap1_Click(object sender, ImageMapEventArgs e)
    {
        if (e.PostBackValue.Contains("pizza"))
        {
            DropDownList1.Items.Clear();
            DropDownList1.Items.Add("Panner Pizza");
            DropDownList1.Items.Add("Cheeze Pizza");
            DropDownList1.Items.Add("Mashroom Pizza");
            DropDownList1.SelectedIndex = 0;
            TextBox4.Text = pricesP[DropDownList1.SelectedIndex].ToString();
            flag = 1;
            ViewState["f"] = flag;

        }
        else if (e.PostBackValue.Contains("berger"))
        {
            DropDownList1.Items.Clear();
            DropDownList1.Items.Add("Panner Berger");
            DropDownList1.Items.Add("Cheeze Berger");
            DropDownList1.Items.Add("Cheken Berger");
            flag = 2;
            DropDownList1.SelectedIndex = 0;
            TextBox4.Text = pricesB[DropDownList1.SelectedIndex].ToString();
            ViewState["f"] = flag;
            
        }
        else if (e.PostBackValue.Contains("momo"))
        {
            DropDownList1.Items.Clear();
            DropDownList1.Items.Add("Veg momo");
            DropDownList1.Items.Add("Non-Veg momo");
            flag = 3;
            DropDownList1.SelectedIndex = 0;
            TextBox4.Text = pricesM[DropDownList1.SelectedIndex].ToString();
            ViewState["f"] = flag;
        }
        else if (e.PostBackValue.Contains("pasta"))
        {
            DropDownList1.Items.Clear();
            DropDownList1.Items.Add("Afgani Pasta");
            DropDownList1.Items.Add("Arbi Pasta");
            TextBox4.Text = pricesPs[DropDownList1.SelectedIndex].ToString();
            flag =4;
            ViewState["f"] = flag;
        }


    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        Session["name"] = TextBox1.Text;
        Session["item"] = DropDownList1.SelectedItem.Text;
        Session["price"]= TextBox4.Text;
        Session["qty"] = TextBox2.Text;
        Session["tot"] = TextBox3.Text;
        
        Response.Redirect("print.aspx");
        
       
        
    }
   
}


2. Print bill web form

print.aspx

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <script language="javascript" type="text/javascript">
          function CallPrint(strid) {
              var prtContent = document.getElementById(strid);
              var WinPrint = window.open('', '', '');
              WinPrint.document.write(prtContent.innerHTML);
              WinPrint.document.close();
              WinPrint.focus();
              WinPrint.print();
              WinPrint.close();
              prtContent.innerHTML = strOldOne;
          }
</script>
       
          <div id="bill" style="width:300px; margin:auto; line-height:25px "> 
              <fieldset>
<legend style="text-align:center">Fast Food Billing Payment</legend>
             
              <table>
              <tr>
                  <td> NAME: </td><td> <asp:Label ID="Label1" runat="server"></asp:Label></td>
              </tr>
               <tr>
                  <td> PURCHASED ITEM:</td><td> <asp:Label ID="Label2" runat="server" ></asp:Label></td>
              </tr>
               <tr>
                  <td> PRICE:</td><td> <asp:Label ID="Label3" runat="server" ></asp:Label></td>
              </tr>
               <tr>
                  <td> QUANTITY:</td><td> <asp:Label ID="Label4" runat="server" ></asp:Label></td>
              </tr>
               <tr>
                  <td>TOTAL:</td><td><asp:Label ID="Label5" runat="server"></asp:Label></td>
              </tr>

                         </table>
              <asp:Button ID="BtnPrint" runat="server" Text="Print" onclientclick="javascript:CallPrint('bill');" xmlns:asp="#unknown"  />
           </fieldset>
          </div>
           
    </div>
    </form>
</body>
</html>

print.aspx.cs

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

public partial class print : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       Label1.Text=  Session["name"].ToString();
       Label2.Text = Session["item"].ToString();
       Label3.Text = Session["price"].ToString();
       Label4.Text = Session["qty"].ToString();
       Label5.Text = Session["tot"].ToString();

    }
}

Output

bill printbill