Showing posts with label ms visual studio. Show all posts
Showing posts with label ms visual studio. Show all posts

Saturday, August 18, 2018

How to create login form for website | Sradha Webcreations

How to create login form for website control panel or registration form  using asp.net sql server 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Security;
using System.IO;


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

    }
    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        String username;
        String pwd;
        String pName;

        username = Login1.UserName;
        pwd = Login1.Password;
        pName = "";
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString);
        con.Open();

        SqlCommand cmd = new SqlCommand("select * from AccountCreation where UserName=@userName and password=@password", con);
       
        cmd.Parameters.AddWithValue("@UserName", username);
        cmd.Parameters.AddWithValue("@Password", pwd);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);
        if (dt.Rows.Count > 0)
        {
            Response.Redirect("journalsubmition.aspx");
        }
        else
        {
           // ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>");
        }
    }
}

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



Thursday, August 2, 2018

how to create Book Management system in Asp.net : Sradha WebCreations

how to create Book Management system in Asp.net

 http://sradhawebcreations.com/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Security;
using System.Configuration;

public partial class COMBO_BOX_DISCOUNT_ON_BOOKS : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DropDownListCUSTOMERTYPE.Items.Add("SELECT 1");
        DropDownListCUSTOMERTYPE.Items.Add("LIBRARY");
        DropDownListCUSTOMERTYPE.Items.Add("BOOK STORE");
        DropDownListCUSTOMERTYPE.Items.Add("PRIVATE");
        DropDownListCUSTOMERTYPE.Items.Add("OTHER");
    }
    protected void DropDownListCUSTOMERTYPE_SelectedIndexChanged(object sender, EventArgs e)
    {
        int iNumberOfBook = Convert.ToInt32(TextBoxNUMBEROFBOOK.Text);
        double dPerBookCost = Convert.ToDouble(TextBoxPERBOOKCOST.Text);
        double dTotal;
        double dTotalCostAfterDiscount;
        double dDiscount;
        double DdiscountAmount;
        //string sCustomerType = DropDownListCUSTOMERTYPE.Text;
       
        //if (sCustomerType == "library" || sCustomerType == "book store" || sCustomerType == "private")
        if (DropDownListCUSTOMERTYPE.SelectedIndex == 1 || DropDownListCUSTOMERTYPE.SelectedIndex == 2 || DropDownListCUSTOMERTYPE.SelectedIndex == 3)
        {
            dDiscount = 20;
            TextBoxDISCONT.Text = Convert.ToString(dDiscount + "%");

            dTotal = dPerBookCost * iNumberOfBook;
            TextBoxTOTALCOST.Text = Convert.ToString("Rs" + dTotal);

            DdiscountAmount = dTotal * dDiscount / 100;
            TextBoxDISCOUNTAMOUNT.Text = Convert.ToString("Rs" + DdiscountAmount);

            dTotalCostAfterDiscount = dTotal - DdiscountAmount;
            TextBoxTOTALCOSTAFTERDISCOUNT.Text = Convert.ToString("Rs" + dTotalCostAfterDiscount);

        }
        else
        {
            if (iNumberOfBook >= 10 && iNumberOfBook <= 30)
            {
                dDiscount = 5;
             TextBoxDISCONT.Text = Convert.ToString(dDiscount + "%");
                dTotal = dPerBookCost * iNumberOfBook;
             TextBoxTOTALCOST.Text = Convert.ToString("Rs" + dTotal);

                DdiscountAmount = dTotal * dDiscount / 100;
TextBoxDISCOUNTAMOUNT.Text = Convert.ToString("Rs" + DdiscountAmount);
                dTotalCostAfterDiscount = dTotal - DdiscountAmount;
TextBoxTOTALCOSTAFTERDISCOUNT.Text = Convert.ToString("Rs" + dTotalCostAfterDiscount);
            }
            else if (iNumberOfBook > 30 && iNumberOfBook <= 60)
            {
                dDiscount = 10;
           TextBoxDISCONT.Text = Convert.ToString(dDiscount + "%");

                dTotal = dPerBookCost * iNumberOfBook;
             TextBoxTOTALCOST.Text = Convert.ToString("Rs" + dTotal);

                DdiscountAmount = dTotal * dDiscount / 100;
TextBoxDISCOUNTAMOUNT.Text = Convert.ToString("Rs" + DdiscountAmount);

dTotalCostAfterDiscount = dTotal - DdiscountAmount;
                TextBoxTOTALCOSTAFTERDISCOUNT.Text = Convert.ToString("Rs" + dTotalCostAfterDiscount);
            }
            else
            {
                dDiscount = 20;
         TextBoxDISCONT.Text = Convert.ToString(dDiscount + "%");

                dTotal = dPerBookCost * iNumberOfBook;
         TextBoxTOTALCOST.Text = Convert.ToString("Rs" + dTotal);

                DdiscountAmount = dTotal * dDiscount / 100;
TextBoxDISCOUNTAMOUNT.Text = Convert.ToString("Rs" + DdiscountAmount);

                dTotalCostAfterDiscount = dTotal - DdiscountAmount;
TextBoxTOTALCOSTAFTERDISCOUNT.Text = Convert.ToString("Rs" + dTotalCostAfterDiscount);
            }
        }

    }
    protected void ButtonSAVE_Click(object sender, EventArgs e)
    {
        String connectionString= ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString;
        string insertsql = "insert into discount1 (numberofbook,perbook,customertype,discount,totalcost,discountamount,totalcostafterdiscount)values(@numberofbook,@perbook,@customertype,@discount,@totalcost,@discountamount,@totalcostafterdiscount)";

        using (SqlConnection myconnection = new SqlConnection(connectionString))
        {
            myconnection.Open();
            SqlCommand mycommand = new SqlCommand(insertsql, myconnection);
            mycommand.Parameters.AddWithValue("@numberofbook", TextBoxNUMBEROFBOOK.Text);
            mycommand.Parameters.AddWithValue("@perbook", TextBoxPERBOOKCOST.Text);
            mycommand.Parameters.AddWithValue("@customertype", DropDownListCUSTOMERTYPE.Text);
            mycommand.Parameters.AddWithValue("@discount", TextBoxDISCONT.Text);
            mycommand.Parameters.AddWithValue("@totalcost", TextBoxTOTALCOST.Text);
            mycommand.Parameters.AddWithValue("@discountamount", TextBoxDISCOUNTAMOUNT.Text);
            mycommand.Parameters.AddWithValue("@totalcostAfterDiscount", TextBoxTOTALCOSTAFTERDISCOUNT.Text);

            mycommand.ExecuteNonQuery();
            myconnection.Close();
        }
        TextBoxNUMBEROFBOOK.Text = string.Empty;
        TextBoxPERBOOKCOST.Text = string.Empty;
        //DropDownListCUSTOMERTYPE.Text = string.Empty;
        TextBoxDISCONT.Text = string.Empty;
        TextBoxTOTALCOST.Text = string.Empty;
        TextBoxDISCOUNTAMOUNT.Text = string.Empty;
        TextBoxTOTALCOSTAFTERDISCOUNT.Text = string.Empty;
        Label1.Text = "DATA INSERT SUCCESSFULLY";
         }
}