Thursday, May 23, 2013

Create INVOICE using Asp.net:


step1: Create Aspx page with controles


                          

Phone/mobileNo.
Email
Date
Time
Number of Passengers
languages
Vehicle
pickup point
pickup Lan
dmark
                                                   







client side code for all controles:(print.aspx)

table align="center" style="width:100%;background-color:Background; height: 259px;">
<tr>
<td style="width:50%;height:250px"><table align="center"  style="background-image:url('image\black.jpg');width:50%; height: 150px;">
  <tr><td class="style3" style="color:Orange";>Name</td><td class="style1" style="color:Orange;"><asp:TextBox ID ="txtnam"  runat="server" />
    <asp:RequiredFieldValidator ID="reqfieldFname" runat="server" ControlToValidate="txtnam" Display="Dynamic" 
                    ErrorMessage="Please enter  your name"></asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="RegexpFname" runat="server" ControlToValidate="txtnam" 
                    ValidationExpression="^[A-Za-z]+$" ErrorMessage="Please enter charectrers only"></asp:RegularExpressionValidator>
  </td></tr>
<tr><td class="style3" style="color:Orange">Phone/mobileNo.</td><td class="style1" style="color:Orange;"><asp:TextBox ID="txtph"  runat="server" />
 <asp:RequiredFieldValidator ID="reqfieldContact" runat="server" ControlToValidate="txtph" Display="Dynamic"
                    ErrorMessage="Please enter mobile number"></asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="regexpContact" runat="server" ControlToValidate="txtph"  
                     ErrorMessage="Please enter correct mobile number" 
                        ValidationExpression="\d{10}"></asp:RegularExpressionValidator>
</td></tr>
<tr><td class="style3" style="color:Orange";>Email</td><td style="color:Orange;">
                    <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>                    
                    <asp:RequiredFieldValidator ID="reqfieldEmail" runat="server" ControlToValidate="txtEmail" Display="Dynamic"
                    ErrorMessage="Please enter Email Id"></asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="regexpEmailId" runat="server" ControlToValidate="txtEmail"  
                     ErrorMessage="Please enter Email Correctly" 
                        ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
                </td></tr>
<tr><td class="style3"style="color:Orange"> Date</td><td class="style1" style="color:Orange;"><asp:TextBox ID ="txtdat" runat="server" />
<asp:RegularExpressionValidator ID="RegularExpressdate" runat="server" 
                   ControlToValidate="txtdat" 
                   ValidationExpression="^(((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}|\d))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}|\d))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}|\d))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00|[048])))$">enter correct date formate</asp:RegularExpressionValidator>


</td></tr>
<tr><td class="style3"style="color:Orange">Time</td><td class="style1" style="color:Orange;"><asp:TextBox ID ="txttime" runat="server" />

                    <asp:RegularExpressionValidator id="RegularExprestime" runat="server" ErrorMessage="* Please enter in correct format for FROM Time." Display="Dynamic" ControlToValidate="txttime" ValidationExpression="^((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))$|^([01]\d|2[0-3])(:[0-5]\d){1,2}$"></asp:RegularExpressionValidator>
</td></tr>
<tr><td class="style3"style="color:Orange">Number of Passengers</td><td class="style1" style="color:Orange;"><asp:TextBox ID ="Txtpass" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFielpassengers" runat="server" ControlToValidate="Txtpass" Display="Dynamic"
                    ErrorMessage="Please enter passengers "></asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="RegularExpresspasseng" runat="server" ControlToValidate="Txtpass"  
                     ErrorMessage="Please enter correct number" 
                        ValidationExpression="\d{2}"></asp:RegularExpressionValidator>
</td></tr>
<tr><td class="style3"style="color:Orange">languages</td><td class="style1" style="color:Orange;"><asp:TextBox ID ="Txtlangue" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFiellan" runat="server" ControlToValidate="Txtlangue" Display="Dynamic" 
                    ErrorMessage="Please enter  your language"></asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="RegularExpreslang" runat="server" ControlToValidate="Txtlangue" 
                    ValidationExpression="^[A-Za-z]+$" ErrorMessage="Please enter charectrers only"></asp:RegularExpressionValidator>
</td></tr>
<tr><td class="style3"style="color:Orange">Vehicle</td><td class="style1">
    <asp:DropDownList ID="Dplist"  runat="server" 
        Width="150px">
        <asp:ListItem Text="--Select--" Value="-1"></asp:ListItem>
    <asp:ListItem>INDIGO</asp:ListItem>
    <asp:ListItem>SCARPIO</asp:ListItem>
    <asp:ListItem>INDIGO MERINA</asp:ListItem>
    <asp:ListItem>ENOVA</asp:ListItem>
    </asp:DropDownList>  <asp:RequiredFieldValidator ID="RequiredFielvehi" runat="server" ControlToValidate="Dplist" Display="Dynamic" 
                    ErrorMessage="Please select vehicle" InitialValue="-1"></asp:RequiredFieldValidator> </td></tr>
<tr><td class="style3"style="color:Orange">pickup point</td><td class="style1" style="color:Orange;"><asp:TextBox ID ="Txtpic" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldVapivpont" runat="server" ControlToValidate="Txtpic" Display="Dynamic" 
                    ErrorMessage="Please enter pic up point"></asp:RequiredFieldValidator>
</td></tr>
<tr><td class="style3"style="color:Orange">pickup Landmark</td><td class="style1" style="color:Orange;"><asp:TextBox ID ="Txtland" runat="server" /><asp:RequiredFieldValidator ID="RequiredFieldValand" runat="server" ControlToValidate="Txtland" Display="Dynamic" 
                    ErrorMessage="Please enter landmark"></asp:RequiredFieldValidator></td></tr>
<tr><td class="style3"style="color:Orange">Drop point</td><td class="style1" style="color:Orange;"><asp:TextBox ID ="Txtpoint" runat="server" /><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="Txtpoint" Display="Dynamic" 
                    ErrorMessage="Please entter drop point"></asp:RequiredFieldValidator></td></tr>
<tr>


        <asp:Button ID="btnprnt" Text="Print" runat="server" 
            Width="86px" onclick="btnprnt_Click1" /></td></tr>


Step2: Create One button(btnprnt_Click)
print.aspx.cs

         Button1:            
protected void btnprnt_Click1(object sender, EventArgs e)
        {
            string htmlcode = "";
            
            htmlcode += "<table width=97% class='mylabel' cellpadding=10 align=center>";
            htmlcode += "<tr><td colspan=2><hr></tr>";
            htmlcode += "<tr><td align=right>Name:</td><td> " + txtnam.Text + "</td></tr>";
            htmlcode += "<tr><td align=right>Phone Number:</td><td>"+txtph.Text+"</td></tr>";
            htmlcode += "<tr><td align=right>Date:</td><td>" + txtdat.Text + "</td></tr>";
            htmlcode += "<tr><td align=right>Time:</td><td>" + txttime.Text + "</td></tr>";
            htmlcode += "<tr><td align=right>No.of passengers:</td><td>" + Txtpass.Text + "</td></tr>";
            htmlcode += "<tr><td align=right>language:</td><td>" + Txtlangue.Text + " </td></tr>";
            htmlcode += "<tr><td align=right>:Vehicle:</td><td>" + Dplist.Text + "</td></tr>";
            htmlcode += "<tr><td align=right>Picup point:</td><td>" + Txtpic.Text + "</td></tr>";
            htmlcode += "<tr><td align=right>pickup landmark:</td><td>" + Txtland.Text + "</td></tr>";
            htmlcode += "<tr><td align=right>Drop point:</td><td>" + Txtpoint.Text + "</td></tr>";
            htmlcode += "</table>";
            Session["htmlcodetoprint"] = htmlcode;
            Response.Write("<script language='javascript'>window.open('print.aspx','prn','toolbar=no,menubar=no,scrollbars=yes,location=no');</script>");
        }

Step3: create one page write in that"Print.aspx"

 protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack == false)
            {
                string htmlcode = Convert.ToString(Session["htmlcodetoprint"]);
                Session["htmlcodetoprint"] = null;
                Response.Write(htmlcode);
                Response.Write("<script language='javascript'>window.print();</script>");
            }




Thank you friend,
Ramarao,
Regards.

No comments:

Post a Comment