Showing posts with label how to create Book Management system in Asp.net. Show all posts
Showing posts with label how to create Book Management system in Asp.net. Show all posts

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";
         }
}