Showing posts with label sql server database. Show all posts
Showing posts with label sql server database. Show all posts

Tuesday, August 7, 2018

how to create event management system website | Sradha WebCreations

how to create event management system website /Web applications / database management 


<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>

<script runat="server">

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (upImage.HasFile)
        {
            if (CheckFileType(upImage.FileName))
            {
                upImage.SaveAs(MapPath(upImage.FileName));
            }
        }
    }

    bool CheckFileType(string fileName)
    {
        string ext = Path.GetExtension(fileName);
        switch (ext.ToLower())
        {
            case ".gif":
                return true;
            case ".png":
                return true;   
            case ".jpg":
                return true;           
            case ".jpeg":
                return true;
            default:
                return false;       
        }
    }

    void Page_PreRender()
    {
        string upFolder = MapPath(".");
        DirectoryInfo dir = new DirectoryInfo(upFolder);
        dlstImages.DataSource = dir.GetFiles();
        dlstImages.DataBind();
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>FileUpload File</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <asp:Label
        id="lblImageFile"
        Text="Image File:"
        AssociatedControlID="upImage"
        Runat="server" />

    <asp:FileUpload
        id="upImage"
        Runat="server" />

    <br /><br />
    
    <asp:Button
        id="btnAdd"
        Text="Add Image"
        OnClick="btnAdd_Click"
        Runat="server" />

    <hr />
   
    <asp:DataList
        id="dlstImages"
        RepeatColumns="4"
        runat="server" Width="764px">
        <ItemTemplate>
        <asp:Image ID="Image1"
            ImageUrl='<%# Eval("Name", "./{0}") %>'
            style="width:200px"
            Runat="server" />
        <br />
        <%# Eval("Name") %>   
        </ItemTemplate>
    </asp:DataList>
   
    </div>
    </form>
</body>
</html>


fileUpload.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FileUpload.aspx.cs" Inherits="FileUpload" %>

<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:FileUpload ID="FileUpload1" runat="server" />
        <br />
        <asp:Button ID="UPloadButton" runat="server" onclick="UPloadButton_Click"
            Text="Upload" />
        <br />
        <asp:Label ID="Status_Label" runat="server" Text="Up Load Status"></asp:Label>
   
    </div>
    </form>
</body>
</html>

fileUpload.aspx.cs

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



public partial class FileUpload : System.Web.UI.Page
{
   
    protected void UPloadButton_Click(object sender, EventArgs e)
    {
       
    if (FileUpload1.HasFile)
    {
        try
        {
            string filename =Path.GetFileName(FileUpload1.FileName);
           FileUpload1.SaveAs(Server.MapPath("~/") + filename);
            Status_Label.Text = "Upload status: File uploaded!";
        }
        catch(Exception ex)
        {
            Status_Label.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
        }
    }

        if(FileUpload1.HasFile)
        {
            try
            {
                if(FileUpload1.PostedFile.ContentType=="image/jpeg")
                {
                    if(FileUpload1.PostedFile.ContentLength<200)
                    {
           string filename = Path.GetFileName(FileUpload1.FileName);
                           
              FileUpload1. SaveAs(Server.MapPath("~/") + filename);
               Status_Label.Text = "Upload status: File uploaded!";
                    }
                    Else
Status_Label.Text = "Upload status: The file has to be less than 100 kb!";
                }
                else
  Status_Label.Text = "Upload status: Only JPEG files are accepted!";
            }
            catch (Exception ex)
            {
Status_Label.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
            }
        }
    }
}





Wednesday, July 25, 2018

news paper advisement calculation | sradha webcreations

News paper advisement calculation 


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


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

    }
    protected void TOTAL_Click(object sender, EventArgs e)
    {
        string sNewPaperName;
        string sDate;
        string sFirmName;
        float fHeight;
        float fWidth;
        float fSqCm;
        float fPerSqCm;
        float Ftotal;

        sNewPaperName = TextBoxPAPER.Text;
        sDate = TextBoxDATE.Text;
        sFirmName = TextBoxFIRM.Text;
       
        fHeight = Convert.ToInt32(TextBoxHEIGHT.Text);
        fWidth = Convert.ToInt32(TextBoxWIDTH.Text);
       
        fSqCm = fHeight * fWidth;
        TextBoxSQ.Text = Convert.ToString(fSqCm);

        fSqCm = Convert.ToInt32(TextBoxSQ.Text);
        fPerSqCm = Convert.ToInt32(TextBoxPERSQ.Text);   
        Ftotal = fPerSqCm * fSqCm;
        TextBoxTOTAL.Text = Convert.ToString(Ftotal);
    }
    protected void ButtonSAVE_Click(object sender, EventArgs e)
    {
        string connectionstring = ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString;

        string insertsql = "insert into advertisement(newpaper,date,firmname,width,height,sqcm,persqcm,total)values(@newpaper,@date,@firmname,@width,@height,@sqcm,@persqcm,@total)";
        using (SqlConnection myconnection = new SqlConnection(connectionstring))
        {
            myconnection.Open();
  SqlCommand mycommand = new SqlCommand(insertsql,myconnection);
            mycommand.Parameters.AddWithValue("@newpaper",TextBoxPAPER.Text);
            mycommand.Parameters.AddWithValue("@date",TextBoxDATE.Text);
            mycommand.Parameters.AddWithValue("@firmname",TextBoxFIRM.Text);
            mycommand.Parameters.AddWithValue("@width",TextBoxWIDTH.Text);
            mycommand.Parameters.AddWithValue("@height",TextBoxHEIGHT.Text);  mycommand.Parameters.AddWithValue("@sqcm",TextBoxSQ.Text);
            mycommand.Parameters.AddWithValue("@persqcm",TextBoxPERSQ.Text);
            mycommand.Parameters.AddWithValue("@total",TextBoxTOTAL.Text);

            mycommand.ExecuteNonQuery();
            myconnection.Close();
        }
        TextBoxPAPER.Text = string.Empty;
        TextBoxDATE.Text = string.Empty;
        TextBoxFIRM.Text = string.Empty;
        TextBoxWIDTH.Text = string.Empty;
        TextBoxHEIGHT.Text = string.Empty;
        TextBoxSQ.Text = string.Empty;
        TextBoxPERSQ.Text = string.Empty;
        TextBoxTOTAL.Text = string.Empty; 
    }
}