Friday 19 April 2013

how to find factoral of large numbers


#include<stdio.h>
#include<conio.h>
#define MAX 10000
void factorial(int);
void multiply(int);
int l = 0;
int fact[MAX];

int main(){
    int n;
    int i;

    printf("Enter any integer number : ");
    scanf("%d",&n);
   
    fact[0]=1;

    factorial(n);
   
    printf("Factorial is : ");
    for(i=l;i>=0;i--){
         printf("%d",fact[i]);
    }
    return 0;
}
void factorial(int n){
    int i;
    for(i=2;i<=n;i++){
         multiply(i);
    }
}
void multiply(int n){
    long i,r=0;
    int arr[MAX];
    for(i=0;i<=l;i++){
                arr[i]=fact[i];
        }

    for(i=0;i<=l;i++){
         fact[i] = (arr[i]*n + r)%10;
         r = (arr[i]*n + r)/10;
         //printf("%d ",r);
    }
    if(r!=0){
         while(r!=0){
             fact[i]=r%10;
             r= r/10;
             i++;
         }
    }
    l = i-1;   
}

Tuesday 2 April 2013

AsyncFileUpload Control


Ajax (Asynchronous JavaScript and XML) is a new web development technique for interactive websites. With the help of AJAX we can develop web applications and retrieve a small amount of data from the web server. AJAX consists of a different type of technology.
  • JavaScript
  • XML
  • Asynchronous Call to the server
AsyncFileUpload Control
AsyncFileUpload is a new ASP.NET AJAX Control that allows you to asynchronously upload files to server. You don't need a separate upload button for this control. Add the AsyncFileUpload control and a label to the web form for the uploading and displaying of messages respectively. The file uploading results can be checked both in the server and client sides. You can save the uploaded file by calling the SaveAs() method in a handler for the server UploadedComplete event.
Property
  • OnClientUploadComplete
  • OnClientUploadError
  • UploaderStyle
  • CompleteBackColor
  • ThrobberID

Example

Code :
<title> My Ajax APPLICATION</title>  
  <script type = "text/javascript">    
    function uploadComplete(sender) {
            $get("<%=lblMesg.ClientID%>").innerHTML = "File Uploaded Successfully";
    }
    function uploadError(sender) {
            $get("<%=lblMesg.ClientID%>").innerHTML = "File upload failed.";}
    }
</script> 
   </head>  
  <body> 
   <form id="form1" runat="server" style="background-color: #453A42">   
 <asp:ScriptManager ID="ScriptManager1" runat="server">    </asp:ScriptManager> 
 <p style="background-color: #FF8080"> ASYNC FILE UPLOAD CONTROL IN AJAX</p>    <br />  
  <div style="background-color: #8C7384">
 <asp:UpdatePanel ID="UpdatePanel1"runat="server">       
 <ContentTemplate>   
 <asp:AsyncFileUpload  ID="AsyncFileUpload1" OnClientUploadComplete="uploadComplete" OnClientUploadError="uploadError"  runat="server" Width="400px" UploaderStyle="Modern" CompleteBackColor = "White" UploadingBackColor="#CCFFFF"  ThrobberID="Image1"OnUploadedComplete = "FileUploadComplete" BackColor="#54AB82" />    
    <asp:Image ID="Image1" runat="server" ImageUrl="~/images......jpg" />    <br />  
 <asp:Label ID="lblMesg" runat="server" BackColor="#CECACD"></asp:Label> 
  </ContentTemplate>  
</asp:UpdatePanel>  
 </div>
</form>

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 _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void FileUploadComplete(object sender, EventArgs e)
    {
        string filename = System.IO.Path.GetFileName(AsyncFileUpload1.FileName);
        AsyncFileUpload1.SaveAs(Server.MapPath("raj") + filename);
    }
} 

Sample Login form example using asp.net check user name and password


how to implement simple login form to check username and password details of user in database. If user details exist in database then we need to redirect user to welcome page otherwise we need to display “Invalid Username/Password”. Mostly it’s common for all the websites before access the website. I know that many of them feel it’s very easy but for the people who have started learning .NET they don’t know how to implement this because of that I decided to write post to help for the persons who is in need with this requirement. 

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Login Form</title>
</head>
<body>
<form id="form1" runat="server">
Username:
<asp:TextBox ID="txtUserName" runat="server"/>
<asp:RequiredFieldValidator ID="rfvUser" ErrorMessage="Please enter Username"ControlToValidate="txtUserName" runat="server" />
Password:
<asp:TextBox ID="txtPWD" runat="server" TextMode="Password"/>
<asp:RequiredFieldValidator ID="rfvPWD" runat="server" ControlToValidate="txtPWD"
ErrorMessage="Please enter Password"/>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click" />
</form>
</body>
</html>


protected void btnSubmit_Click(object sender, EventArgs e)
{
SqlConnection con = newSqlConnection(" your connection string");
con.Open();
SqlCommand cmd = new SqlCommand("select * from UserInformation where UserName =@username and Password=@password",con);
cmd.Parameters.AddWithValue("@username", txtUserName.Text);
cmd.Parameters.AddWithValue("@password", txtPWD.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if(dt.Rows.Count>0)
{
Response.Redirect("User..aspx",false);
}
else
{
ClientScript.RegisterStartupScript(Page.GetType(), "validation""<script language='javascript'>alert('Invalid Username and Password')</script>");
}
}

Wednesday 20 March 2013

Ajax Chart Control example



Chart Control

The Chart control include pie, area, range, point, circular, accumulation, data distribution, Ajax interactive, doughnut. We can statically declare chart data within the control declaration, or alternatively use data-binding to populate it dynamically. At runtime the server control generates an image (for example a .PNG file) that is referenced from the client HTML of the page using a <img/> element output by the <asp:chart/> control.  The server control supports the ability to cache the chart image, as well as save it on disk for persistent scenarios.  It does not require any other server software to be installed, and will work with any standard ASP.NET page.

Web Control for creating Chart

Line Charts
Smooth Line Charts
Column Charts
Area Charts
Scattered Charts
Stacked Column Charts
Pie Charts
Stacked Area Charts

Step 1 : Open Visual Studio 2010.
Go to File->New->WebSite
Select ASP.NET Empty WebSite

Step 2 : Go to Solution Explorer and right-click.
Select Add->New Item
Select WebForm

Default.aspx page open

 
Step 3 :  Go to Default.aspx page and click on the [Design] option and drag control from Toolbox.
Drag Chart control, ScriptManager control, UpdatePanel control

Create Table for Chart Control

Step 4 : Go to Solution Explorer and right-click.
Select Add->New Item
Select SqlDataSource

Step 5 : Go to Server Explorer and right-click.
Select Table option and right-click
Select Add New Table and define Field
 
Step 6 : Go to Table option and right-click.
Select Show Data Table

Define all Data Field
 

Step 7 :
Now go to the Default.aspx page and click on the Chart control.
Select New Data Source option
Define Data Source

 
Step 8 : Select SQLDataSource option and click in ConnectionString.
Select DataBase.mdf file

 
Step 9 : Now right-click on the Chart control.
Select Series property and click in button
Define DataSource
Define XValueMember, YValueMember
Step 10 : Now click on the chart control.
Select Chart Area Option
Visible True
Select Style:3D

Step 11 : Now go to Default.aspx [Source] option and write the below code.

Code :

<head runat="server">
    <title> my ajax chart</title>
</
head>
<
body>
    <form id="form1" runat="server" style="background-color: #0099FF">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div style="background-color: #99FF99">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
      <ContentTemplate>
    <br />
      <h1> MY AJAX CHART</h1>
       <
asp:Chart ID="Chart1" runat="server" BackColor="SandyBrown"
        BorderlineColor="Red" DataSourceID="SqlDataSource2" onload="Chart1_Load"
        Palette="Fire" BackGradientStyle="LeftRight" BackSecondaryColor="Maroon"
            Height="500px" Width="500px">
        <series>
            <asp:Series Legend="Legend1" Name="Series1"
                XValueType="Double" BorderColor="255, 224, 192" >
            </asp:Series>
            <asp:Series ChartArea="ChartArea1" Legend="Legend1" Name="Series4">
            </asp:Series>
        </series>
        <MapAreas>
            <asp:MapArea Coordinates="0,0,0,0" />
        </MapAreas>
        <chartareas>|
            <asp:ChartArea BackColor="255, 224, 192" Name="ChartArea1" BorderWidth="5">
                <AxisY Title="customer">
                </AxisY>
                <AxisX LineColor="BlanchedAlmond" Title="country">
                </AxisX>
            </asp:ChartArea>
             <asp:ChartArea Name="ChartArea2">
            </asp:ChartArea>
        </chartareas>
        <Legends>
            <asp:Legend BorderColor="128, 255, 128" Name="Legend1">
            </asp:Legend>
        </Legends>
    </asp:Chart>
          <asp:SqlDataSource ID="SqlDataSource2" runat="server"></asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="SELECT * FROM [my customer]"></asp:SqlDataSource>
        <br />
        </ContentTemplate>
        </asp:UpdatePanel>
        </div>
    </form>
</
body>
</
html>

Output: