Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Imhiralmehta authored Aug 21, 2016
1 parent 8aad209 commit cb3ced0
Show file tree
Hide file tree
Showing 11 changed files with 1,159 additions and 0 deletions.
131 changes: 131 additions & 0 deletions Available.aspx
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<%@ Page Title="" Language="C#" MasterPageFile="~/SiteMaster.Master" AutoEventWireup="true" CodeBehind="Available.aspx.cs" Inherits="HiralMehta_Project.WebForm2"%>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

<style type="text/css">
.auto-style1 {
width: 99px;
}
.auto-style2 {
width: 229px;
}
.auto-style3 {
}
</style>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div id ='available'>Advertise toy
<table class='toy' >
<tr>
<td class="auto-style2">Name</td>
<td>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">City*</td>
<td>
<asp:TextBox ID="txtCity" runat="server" Width="106px"></asp:TextBox>
<asp:RequiredFieldValidator ID="reqVald1" runat="server" ControlToValidate="txtCity" ErrorMessage="Required field" Font-Size="Small" ForeColor="Red">*Required</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style2">Phone</td>
<td>
<asp:TextBox ID="txtPhone" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">Email*</td>
<td>
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="reqVald2" runat="server" ControlToValidate="txtEmail" ErrorMessage="Required" Font-Size="Small" ForeColor="Red">*Required</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style2">Type of Toy/Game*</td>
<td>
<asp:DropDownList ID="ddlType" runat="server">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="reqVald3" runat="server" ControlToValidate="ddlType" ErrorMessage="Required" Font-Size="Small" ForeColor="Red" InitialValue="-1">*Required</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style2">Toy Description</td>
<td>
<asp:TextBox ID="txtDesc" runat="server" Height="70px" Width="240px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">Good for kids in age group*</td>
<td class="auto-style1">

<asp:RadioButtonList ID="rblAvailAgeGroup" runat="server" Width="229px">
<asp:ListItem>Infant</asp:ListItem>
<asp:ListItem>Toddler</asp:ListItem>
<asp:ListItem>Between 5 - 8</asp:ListItem>
<asp:ListItem>Between 8 - 12</asp:ListItem>
</asp:RadioButtonList>

<asp:RequiredFieldValidator ID="reqVald5" runat="server" ControlToValidate="rblAvailAgeGroup" ErrorMessage="Required" Font-Size="Small" ForeColor="Red">*Required</asp:RequiredFieldValidator>

</td>
</tr>
<tr>
<td class="auto-style2">Availability in weeks*</td>
<td>
<asp:TextBox ID="txtAvail" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="reqVald4" runat="server" ControlToValidate="txtAvail" ErrorMessage="Required" Font-Size="Small" ForeColor="Red">*Required</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="center" class="auto-style2" colspan="2" style="color: #FF0000;">fields marked with * are Required fields</td>
</tr>

<tr>
<td align ="center" class="auto-style2" colspan ="2" >
<asp:Button ID="btnSubmitAvail" runat="server" Text="Submit" OnClick="btnSubmitAvail_Click" />
<br />
</td>
</tr>


<tr>
<td align ="center" class="auto-style2" colspan ="2" >
<asp:Label ID="lblAvailable" runat="server" BorderStyle="None" Width="391px"></asp:Label>
</td>
</tr>
</table>
<br /><br />
<table class='toy' id="del" >Delete a toy? Provide your email
<tr>
<td class="auto-style3">Your Email:</td>
<td>
<asp:TextBox ID="txtEmailDel" runat="server" Width="166px"></asp:TextBox>
<asp:Button ID="btnLoad" runat="server" Text="Search" OnClick="btnLoad_Click" CausesValidation="False" />
<asp:Button ID="btnDelete" runat="server" Text="Delete" CausesValidation="False" OnClick="btnDelete_Click" />
</td>
</tr>
<tr>
<td class="auto-style3" colspan="2">
<asp:Label ID="lblDel" runat="server" Text=""></asp:Label>
</td>
</tr>
</table>
<asp:GridView ID="gvDel" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
</asp:GridView>

</div>


</asp:Content>
151 changes: 151 additions & 0 deletions Available.aspx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Drawing;

namespace HiralMehta_Project
{
public partial class WebForm2 : System.Web.UI.Page
{
string cs = ConfigurationManager.ConnectionStrings["ToyDB"].ConnectionString;

//On page load event, if page is not postback from server, dropdownlist will be populated with following data
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ddlType.Items.Add("Soft toy");
ddlType.Items.Add("Doll");
ddlType.Items.Add("Board game");
ddlType.Items.Add("Lego");
ddlType.Items.Add("Plastic toys");
ddlType.Items.Add("Automobile");
ddlType.Items.Add("VideoGame");
ListItem liSelect = new ListItem("Select a type", "-1");
ddlType.Items.Insert(0, liSelect);
}
}

/*Author of the below method is Hiral Mehta. It is used to submit data into toy database based on data input by advertiser. Some fields are compulsory while others are not, so those data will be inserted as NULL values in database*/
protected void btnSubmitAvail_Click(object sender, EventArgs e)
{
string selectQuery = "SELECT ClientName,ClientCity,ClientPhone,ClientEmail,ToyType,ToyDesc,AgeGroup,AvailabilityWeeks FROM ToyData;";

SqlConnection conn = new SqlConnection(cs);//Establish connection

SqlDataAdapter da = new SqlDataAdapter(selectQuery, conn);//Instantiating new data adapter

DataSet ds = new DataSet();

da.Fill(ds, "ToyData");//New dataset ds filled with ToyData table

DataTable tblToyData = ds.Tables["ToyData"];

DataRow newRow = tblToyData.NewRow();

newRow["ClientName"] = txtName.Text.Trim();
newRow["ClientCity"] = txtCity.Text.Trim().ToUpper();
newRow["ClientPhone"] = txtPhone.Text.Trim();
newRow["ClientEmail"] = txtEmail.Text.Trim();
newRow["ToyType"] = ddlType.Text;
newRow["ToyDesc"] = txtDesc.Text.Trim();
newRow["AgeGroup"] = rblAvailAgeGroup.Text;
newRow["AvailabilityWeeks"] = txtAvail.Text.Trim();

tblToyData.Rows.Add(newRow);//Insert a new row based on field values


SqlCommandBuilder builder = new SqlCommandBuilder(da);

int rowsInserted = da.Update(ds, "ToyData");

if (rowsInserted > 0)//If row will be inserted, a message will be populated.
{
lblAvailable.Text = "Toy successfully inserted to database";
lblAvailable.ForeColor = Color.Green;
}
else
{
lblAvailable.Text = "Toy could not be inserted to database, please try again!!";
lblAvailable.ForeColor = Color.Red;
}
//All fields will be set to blank after data insertion
txtName.Text = "";
txtCity.Text = "";
txtPhone.Text = "";
txtEmail.Text = "";
txtDesc.Text = "";
txtAvail.Text = "";
ddlType.SelectedIndex = -1;

}

/*Author of the below method is Hiral Mehta. It is used to search existing toys from toy database based on client email provided initially when advertising a toy*/
private bool searchToy()
{
string selectQueryDel =
"Select ClientName,ToyType,ToyDesc,AgeGroup,AvailabilityWeeks from ToyData where ClientEmail=@ClientEmail1;";

SqlConnection conn = new SqlConnection(cs);

SqlDataAdapter da1 = new SqlDataAdapter(selectQueryDel, conn);

da1.SelectCommand.Parameters.AddWithValue("@ClientEmail1", txtEmailDel.Text);

DataSet ds1 = new DataSet();
Cache["DataSet"] = ds1;

da1.Fill(ds1, "ToyData");

DataTable tblToy = ds1.Tables["ToyData"];

if (tblToy.Rows.Count > 0)
{
gvDel.DataSource = ds1;
gvDel.DataBind();
return true;
}
else
{
return false;
}
}

/*The below method uses search toydatabase method and if toy found, a lable will display the message*/
protected void btnLoad_Click(object sender, EventArgs e)
{
if (searchToy())
{
lblDel.Text = "Here are your toys in the database";
lblDel.ForeColor = System.Drawing.Color.DarkGreen;
}
else
{
lblDel.Text = "No toy found with matching your email";
lblDel.ForeColor = System.Drawing.Color.Red;
}
}

/*The below method uses search toydatabase method and if toy found, the method will delete that toy from database and display message*/
protected void btnDelete_Click(object sender, EventArgs e)
{
if (searchToy())
{
DataSet ds1 = (DataSet)Cache["DataSet"];
DataRow dr = ds1.Tables["ToyData"].Rows[0];
dr.Delete();
lblDel.Text = "Toy deleted";
lblDel.ForeColor = System.Drawing.Color.Red;
gvDel.Visible = false;
txtEmailDel.Text = "";
}

}
}
}
Loading

0 comments on commit cb3ced0

Please sign in to comment.