Wednesday, December 26, 2012

how to set product key to windows application

write into registry         
           
            int z = 14;                   
     string productkey="giveyourproductkey";
            try
            {
                if (txtproductkey.Text == productkey)
                {
                    RegistryKey softwareKey =
                    Registry.LocalMachine.OpenSubKey("Software", true);
                    RegistryKey wroxKey = softwareKey.CreateSubKey("HOTEL");
                    RegistryKey selfPlacingWindowKey =
                                wroxKey.CreateSubKey("SelfPlacingWindow");
                    selfPlacingWindowKey.SetValue("HT", (int)z);
                    selfPlacingWindowKey.SetValue("WindowState",
                        (object)WindowState.ToString());
                    MessageBox.Show("Registered Successfully,Login Now", "Hotel Taj", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
         }


read from registry


        int redComponent;

            RegistryKey softwareKey =
               Registry.LocalMachine.OpenSubKey("Software");
            RegistryKey wroxKey = softwareKey.OpenSubKey("HOTEL");
            if (wroxKey == null)
            {
                Productkey pr = new Productkey();
                pr.Show();
                return;
            }    
               
            RegistryKey selfPlacingWindowKey =
                        wroxKey.OpenSubKey("SelfPlacingWindow");
            if (selfPlacingWindowKey == null)
                return;

(The above coding helps to check  product key before to use windows application software)


Wednesday, August 08, 2012

Friday, August 03, 2012

how to create dynamic menu using asp.net menu from sql database

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            getMenu();
        }
       

    }
    private void getMenu()
    {
        SqlConnection con = new SqlConnection(connStr);
        con.Open();
        DataSet ds = new DataSet();
        DataTable dt = new DataTable();
        string sql = "Select * from menu";
        SqlDataAdapter da = new SqlDataAdapter(sql, con);
        da.Fill(ds);
        dt = ds.Tables[0];
        DataRow[] drowpar = dt.Select("parentid=" + 0);

        foreach (DataRow dr in drowpar)
        {
            menubar.Items.Add(new MenuItem(dr["menuname"].ToString(),
                    dr["menuid"].ToString(), "",
                    dr["menulocation"].ToString()));
        }

        foreach (DataRow dr in dt.Select("parentid >" + 0))
        {
            MenuItem mnu = new MenuItem(dr["menuname"].ToString(),
                           dr["menuid"].ToString(),
                           "", dr["menulocation"].ToString());
            menubar.FindItem(dr["parentid"].ToString()).ChildItems.Add(mnu);
        }
        con.Close();
    }



database query
create table menu(menuid int,menuname varchar(150),menulocation varchar(150),parentid int)


Tuesday, July 17, 2012

Here's the way it can be used in ASP.NET Regular Expression Validator:

<asp:RegularExpressionValidator runat="server" ID="EmailAddress" Display="Dynamic" 
ControlToValidate="txtFirstName" ErrorMessage="Please enter a valid e-mail address"
 ValidationExpression="^([\w\d\-\.]+)@{1}(([\w\d\-]{1,67})|([\w\d\-]+\.[\w\d\-]
{1,67}))\.(([a-zA-Z\d]{2,4})(\.[a-zA-Z\d]{2})?)$"  ValidationGroup="CreateUserForm">
*</asp:RegularExpressionValidator>

Matches: name@domain.com | name@sub-domain.com.au | name@sub1.sub2.domain | name@organization.co.uk | name@domain.tv | name@domain.four | name@mailbox.com.us

Non-Matches: www.domain.com | name@.com | name@domain..com | name@anything@.com | name@com

Thursday, July 05, 2012

how to find by number's

--find no of stored procudere in a database
select count(*) from MMF..sysobjects where xtype='P'

----find no of table in a database
select count(*) from MMF..sysobjects where xtype='U'

--find no of columns in a table
select count(*) from information_schema.columns where table_name='login'

----find no of rows in a table
select count(*) from login

--note: here MMF is a database

Friday, April 06, 2012

Use of Partial Class.,.


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)
    {
        A a = new A();
        string ss = a.msg("umapathi");
        Response.Write(ss);
        string s2 = a.msg1("second");
        Response.Write(s2);
    }
}

public partial class A
{
 

    public string msg(string m)
    {
        return "first class";
    }
}

public partial class A
{
    public string msg1(string mm)
    {
        return "second class";
    }

}

Wednesday, March 21, 2012

How to use javascript inside aspx.cs

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('Invalid Username and Password')", true);

Saturday, March 17, 2012

send mail from asp.net to gmail

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net.Mail;

// Now open your .aspx page replace the page_load with below code

protected void Page_Load(object sender, EventArgs e)
{
MailMessage message = new MailMessage();

try
{
MailAddress fromAddress = new MailAddress("umapathi19@gmail.com", "Umapathi");
message.From = fromAddress;
message.To.Add(" umapathi19@gmail.com ");
message.Subject = "Feedback";
message.IsBodyHtml = false;
message.Body = "Hello Umapathi";
sendmails(message);
Label1.Text = "Email successfully sent.";
}
catch (Exception ex)
{
Label1.Text = "Send Email Failed." + ex.Message;
}
}

public void sendmails(MailMessage mm)
{
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com"; 
smtp.EnableSsl = true;
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = " umapathi19@gmail.com ";
NetworkCred.Password = "youe actual gmail password for the mail id mentionaed in the above code"; ;
smtp.UseDefaultCredentials = true; 
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm); 

}


Smtp settings:

note: smtp server should be installed in your computer.your system must have internet connection
1.go to start>run
2.type "inetmgr" in the run press ok
3.in the newly opened internet service manager navigate to "default smtp virtual server"
4.go to domain right click new>domain
5.select remote and click next"smtp.gmail.com" and click finish.
6.now go to "default smtp virtual server" right click choose "Properties" and click.
7.in the ip address dropdown choose your system ip.
8.go to "access" tab click on "Relay"
9.selectradio buton "only the list below" and also check "allow all the computers which success fully authenticate to relay.regardless of the list above" click ok.
10.in the connection select "only the list below" click ok.
11.click on "Authentication" button choose "Anonymous Acess" click ok.
12.close your iis window.

JavaScript Validations

Default.aspx Page Start
<%@ 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>Registration Form</title>
<script language="javascript" type="text/javascript">
function fnValidate()
{
//FName Validation.
fnValidateFirstName();
//LName Validation
fnValidateLastName();
//Mobile validation
fnValidateMobileNumber();
//PEmail validation
fnValidatePrimaryEmail();
//SEmail Validation
fnValidateSecondaryEmail();
//Counttry Validation
fnValidateCountries();
}
function fnValidateSecondaryEmail()
{
var semail=document.getElementById("txtsemail").value;
var semailregex=/^(?:\w+\.?)*\w+@(?:\w+\.)+\w+$/;
if(!semail.match(semailregex))
{
alert("enter valid emailid");
} 
}
function fnValidatePrimaryEmail()
{
var pemailno=document.getElementById("txtPemail").value;
if(pemailno=="")
{
alert("email id is mandatory");
}
var pemailregex=/^(?:\w+\.?)*\w+@(?:\w+\.)+\w+$/;
if(!pemailno.match(pemailregex))
{
alert("enter valid emailid");
} 
}
function fnValidateMobileNumber()
{
var mobile=document.getElementById("txtMobile").value;
if(mobile=="")
{
alert("Mobile number is mandatory");
}
var mno= /^((\+)?(\d{2}[-]))?(\d{10}){1}?$/;
if(!mobile.match(mno))
{
alert("1.Mobile Number should Have Only Digits .\n2.Mobile Number should contain 10 digits");
return false;
}
else
{
return true;
}
}
function fnValidateLastName()
{
var lname=document.getElementById("txtlname").value;
var alphaExp= /^[a-zA-Z]+$/;
if(!lname.match(alphaExp))
{
alert("Last name should have only alphabets");
return false;
}
else 
{
return true;
}
}
function fnValidateFirstName()
{
var fname=document.getElementById("txtfname").value;
if(fname=="")
{
alert("First Name Cannot be Blank.");
return false;
}
else
{
var alphaExp = /^[a-zA-Z]+$/;

if(!fname.match(alphaExp))
{
alert("First Name should contain Only Alphabets.");
return false;
}
return true;
}
}
function fnValidateCountries()
{
var index=document.getElementById("ddlCountry").selectedIndex;
alert(index);
if(index==0)
{
alert("Please Select a Country.");
return false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table width="100%">
<tr>
<td width="15%"></td>
<td width="70%">
<table>
<tr>
<td align="right">FirstName:</td>
<td><asp:TextBox ID="txtfname" runat="server" /></td>
<td align="right">Mobile:</td>
<td><asp:TextBox ID="txtMobile" runat="server" /></td>
</tr>
<tr>
<td align="right">LastName:</td>
<td><asp:TextBox ID="txtlname" runat="server" /></td>
<td align="right">Phone:</td>
<td><asp:TextBox Width="10%" ID="tbCountryCode" runat="server" />

<asp:TextBox Width="10%" ID="tbCityCode" runat="server" />

<asp:TextBox Width="29%" ID="tbPhone" runat="server" />
</td>
</tr>
<tr>
<td align="right">PrimaryMail: </td>
<td> 
<asp:TextBox ID="txtPemail" runat="server" />
</td>
<td align="right">SecondaryMail:</td>
<td>
<asp:TextBox ID="txtsemail" runat="server" />
</td>
</tr>
<tr>
<td align="right">Address1:</td>
<td>
<asp:TextBox ID="txtaddress1" runat="server" TextMode="MultiLine" rows="5"/>
</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Country:</td>
<td><asp:DropDownList ID="ddlCountry" runat="server"
width="80%"></asp:DropDownList></td>
<td></td>
<td><asp:Button ID="btnSubmit" runat="server" Text="Submit" 
OnClientClick="return fnValidate()" /></td>
</tr>
</table>
</td>
<td width="15%"></td>
</tr>
</table>
</div>
</form>
</body>
</html>
Default.aspx Page End


Default.aspx.cs Page Start

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            FillCountries();
        }
    }

    private void FillCountries()
    {
        ArrayList alCountries = new ArrayList();
        alCountries.Add("India");
        alCountries.Add("Pakistan");
        alCountries.Add("Srilanka");
        alCountries.Add("Australia");
        ddlCountry.DataSource = alCountries;
        ddlCountry.DataBind();
        ddlCountry.Items.Insert(0, "--Select--");
    }
}