This presentation emphasis on How to connect a Play Application with Mysql as database in Scala.Play includes a simple data access layer called Anorm that uses plain SQL to interact with the database and provides an API to parse and transform the resulting datasets.
Nagios Conference 2014 - Troy Lea - JavaScript and jQuery - Nagios XI Tips, T...Nagios
Troy Lea's presentation on JavaScript and jQuery - Nagios XI Tips, Tricks and How-To.
The presentation was given during the Nagios World Conference North America held Oct 13th - Oct 16th, 2014 in Saint Paul, MN. For more information on the conference (including photos and videos), visit: http://go.nagios.com/conference
This presentation emphasis on How to connect a Play Application with Mysql as database in Scala.Play includes a simple data access layer called Anorm that uses plain SQL to interact with the database and provides an API to parse and transform the resulting datasets.
Nagios Conference 2014 - Troy Lea - JavaScript and jQuery - Nagios XI Tips, T...Nagios
Troy Lea's presentation on JavaScript and jQuery - Nagios XI Tips, Tricks and How-To.
The presentation was given during the Nagios World Conference North America held Oct 13th - Oct 16th, 2014 in Saint Paul, MN. For more information on the conference (including photos and videos), visit: http://go.nagios.com/conference
Rails, Postgres, Angular, and Bootstrap: The Power StackDavid Copeland
Rails, Postgres, Angular, and Bootstrap are all powerful technologies in and of themselves. When used together, however, you get a powerful web application development stack that reduces friction between what you want for your users and what you can deliver.
Build over 20 mini JavaScript Projects with full source code
https://skl.sh/3yJdYM0
Web Developer Setup use of Editor for JavaScript Code
JavaScript Projects DOM Interactive Dynamic web pages Introduction web development Course Resource Guide.
Getting started with JavaScript DOM coding and development
Web Developer Setup use of Editor for JavaScript Code
JavaScript Resources to explore more about JavaScript
JavaScript DOM Object Selecting Page elements and more
JavaScript querySelectorAll Get Page Elements Select ALL
Page Events Element Event Listener access page content with JavaScript
JavaScript and Page Input Values from Page Elements
How to use JavaScript Request Animation Frame
JavaScript Starter Projects DOM Simple Projects to Start Coding
How to make Interactive DOM list saving to localstorage
JavaScript Component Create a Star Rating Project
JavaScript Game within the DOM Coin Toss Game Project
JavaScript Typing Challenge Game with JavaScript DOM
JavaScript DOM fun with Page Elements Moving Storing Keypress
JavaScript Combo Guessing Game Exercise
JavaScript Shape Clicker Game Click the shape quickly to win
JavaScript Number Guessing Game with Game Logic
JavaScript DOM Interactive Components and Useful Projects
Pure JavaScript Accordion hide and show page elements
JavaScript Drag and Drop Simple Boxes Component
Dynamic Drag and Drop
JavaScript Email Extractor Mini Project
Create a Quiz with Javascript JSON quiz tracker
JavaScript Image Preview File Reader Example
JavaScript Interactive Dice Game with Page elements
JavaScript Dice Game Challenge Lesson
JavaScript DOM Fun Projects Interactive DOM Elements
JavaScript Tip Calculator Project
Tip Calculator Project Part 1
Tip Calculator Project Part 2
Pure JavaScript Calculator DOM page elements Project
JavaScript Calculator Part 1
JavaScript Calculator Part 2
JavaScript Calculator Part 3
JavaScript Bubble Popping DOM Game Coding project
How to move a Page Element With JavaScript DOM Mover Example
Collision Detection between Page elements with JavaScript DOM
JavaScript DOM Interactive Game
DjangoGirls Seoul 2017 11월 세미나에서 발표한 문서입니다.
- 소스 코드 : https://github.com/hannal/pieces-of-django-admin-djangogirls-seoul
- 각종 소식 : https://fb.com/hello.kaycha
Why and when you need end-to-end tests, a spooky story with a 15 years software beast, and how to develop concise, maintainable functional tests using Groovy, Spock and Geb.
Rails, Postgres, Angular, and Bootstrap: The Power StackDavid Copeland
Rails, Postgres, Angular, and Bootstrap are all powerful technologies in and of themselves. When used together, however, you get a powerful web application development stack that reduces friction between what you want for your users and what you can deliver.
Build over 20 mini JavaScript Projects with full source code
https://skl.sh/3yJdYM0
Web Developer Setup use of Editor for JavaScript Code
JavaScript Projects DOM Interactive Dynamic web pages Introduction web development Course Resource Guide.
Getting started with JavaScript DOM coding and development
Web Developer Setup use of Editor for JavaScript Code
JavaScript Resources to explore more about JavaScript
JavaScript DOM Object Selecting Page elements and more
JavaScript querySelectorAll Get Page Elements Select ALL
Page Events Element Event Listener access page content with JavaScript
JavaScript and Page Input Values from Page Elements
How to use JavaScript Request Animation Frame
JavaScript Starter Projects DOM Simple Projects to Start Coding
How to make Interactive DOM list saving to localstorage
JavaScript Component Create a Star Rating Project
JavaScript Game within the DOM Coin Toss Game Project
JavaScript Typing Challenge Game with JavaScript DOM
JavaScript DOM fun with Page Elements Moving Storing Keypress
JavaScript Combo Guessing Game Exercise
JavaScript Shape Clicker Game Click the shape quickly to win
JavaScript Number Guessing Game with Game Logic
JavaScript DOM Interactive Components and Useful Projects
Pure JavaScript Accordion hide and show page elements
JavaScript Drag and Drop Simple Boxes Component
Dynamic Drag and Drop
JavaScript Email Extractor Mini Project
Create a Quiz with Javascript JSON quiz tracker
JavaScript Image Preview File Reader Example
JavaScript Interactive Dice Game with Page elements
JavaScript Dice Game Challenge Lesson
JavaScript DOM Fun Projects Interactive DOM Elements
JavaScript Tip Calculator Project
Tip Calculator Project Part 1
Tip Calculator Project Part 2
Pure JavaScript Calculator DOM page elements Project
JavaScript Calculator Part 1
JavaScript Calculator Part 2
JavaScript Calculator Part 3
JavaScript Bubble Popping DOM Game Coding project
How to move a Page Element With JavaScript DOM Mover Example
Collision Detection between Page elements with JavaScript DOM
JavaScript DOM Interactive Game
DjangoGirls Seoul 2017 11월 세미나에서 발표한 문서입니다.
- 소스 코드 : https://github.com/hannal/pieces-of-django-admin-djangogirls-seoul
- 각종 소식 : https://fb.com/hello.kaycha
Why and when you need end-to-end tests, a spooky story with a 15 years software beast, and how to develop concise, maintainable functional tests using Groovy, Spock and Geb.
IndiaStack is a set of APIs that allows governments, businesses, startups and developers to utilise an unique digital Infrastructure to solve India’s hard problems towards presence-less, paperless, and cashless service delivery.
The presentation focuses on Rails scaffolding as a good starting point for playing with Ext. The biggest integration task from a Rails point of view is providing the correct JSON data structures that Ext can process - a task that can be solved in a re-usable way. Passing data around between Rails controllers and views and the actual JavaScript code is another focal point.
The presentation features a preview version of Martin Rehfeld's Ext Scaffold Generator, soon to be announced as a official Rails plugin.
by Martin Rehfeld
.NET Fest 2017. Михаил Щербаков. Механизмы предотвращения атак в ASP.NET CoreNETFest
Посмотрим на новый веб-фреймворк Microsoft с точки зрения безопасности. ASP.NET Core является продолжением развития платформы ASP.NET и, в отличие от старшего брата, код его полностью открыт и поддерживается сообществом. Архитектура фреймворка была переосмыслена, появились новые security features, часть существующих сильно переписана.
В докладе поговорим об этих различиях и разберем как теперь работают встроенные механизмы защиты от XSS и CSRF, какие возможности криптографии доступны из коробки, как устроено управление сессиями.
Доклад будет интересен в первую очередь разработчикам, пишущим защищенные ASP.NET-приложения, специалистам, проводящим security review .NET-проектов, и всем желающим разобраться в реализации компонентов безопасности на примере этой платформы.
What inner joins are all about and how to use them.
Inner Joins move data from two tables into their own columns.
Unions move data into the same columns and won't duplicate unless it is a "Union ALL".
Techniques to optimize the pagerank algorithm usually fall in two categories. One is to try reducing the work per iteration, and the other is to try reducing the number of iterations. These goals are often at odds with one another. Skipping computation on vertices which have already converged has the potential to save iteration time. Skipping in-identical vertices, with the same in-links, helps reduce duplicate computations and thus could help reduce iteration time. Road networks often have chains which can be short-circuited before pagerank computation to improve performance. Final ranks of chain nodes can be easily calculated. This could reduce both the iteration time, and the number of iterations. If a graph has no dangling nodes, pagerank of each strongly connected component can be computed in topological order. This could help reduce the iteration time, no. of iterations, and also enable multi-iteration concurrency in pagerank computation. The combination of all of the above methods is the STICD algorithm. [sticd] For dynamic graphs, unchanged components whose ranks are unaffected can be skipped altogether.
Opendatabay - Open Data Marketplace.pptxOpendatabay
Opendatabay.com unlocks the power of data for everyone. Open Data Marketplace fosters a collaborative hub for data enthusiasts to explore, share, and contribute to a vast collection of datasets.
First ever open hub for data enthusiasts to collaborate and innovate. A platform to explore, share, and contribute to a vast collection of datasets. Through robust quality control and innovative technologies like blockchain verification, opendatabay ensures the authenticity and reliability of datasets, empowering users to make data-driven decisions with confidence. Leverage cutting-edge AI technologies to enhance the data exploration, analysis, and discovery experience.
From intelligent search and recommendations to automated data productisation and quotation, Opendatabay AI-driven features streamline the data workflow. Finding the data you need shouldn't be a complex. Opendatabay simplifies the data acquisition process with an intuitive interface and robust search tools. Effortlessly explore, discover, and access the data you need, allowing you to focus on extracting valuable insights. Opendatabay breaks new ground with a dedicated, AI-generated, synthetic datasets.
Leverage these privacy-preserving datasets for training and testing AI models without compromising sensitive information. Opendatabay prioritizes transparency by providing detailed metadata, provenance information, and usage guidelines for each dataset, ensuring users have a comprehensive understanding of the data they're working with. By leveraging a powerful combination of distributed ledger technology and rigorous third-party audits Opendatabay ensures the authenticity and reliability of every dataset. Security is at the core of Opendatabay. Marketplace implements stringent security measures, including encryption, access controls, and regular vulnerability assessments, to safeguard your data and protect your privacy.
Adjusting primitives for graph : SHORT REPORT / NOTESSubhajit Sahu
Graph algorithms, like PageRank Compressed Sparse Row (CSR) is an adjacency-list based graph representation that is
Multiply with different modes (map)
1. Performance of sequential execution based vs OpenMP based vector multiply.
2. Comparing various launch configs for CUDA based vector multiply.
Sum with different storage types (reduce)
1. Performance of vector element sum using float vs bfloat16 as the storage type.
Sum with different modes (reduce)
1. Performance of sequential execution based vs OpenMP based vector element sum.
2. Performance of memcpy vs in-place based CUDA based vector element sum.
3. Comparing various launch configs for CUDA based vector element sum (memcpy).
4. Comparing various launch configs for CUDA based vector element sum (in-place).
Sum with in-place strategies of CUDA mode (reduce)
1. Comparing various launch configs for CUDA based vector element sum (in-place).
Explore our comprehensive data analysis project presentation on predicting product ad campaign performance. Learn how data-driven insights can optimize your marketing strategies and enhance campaign effectiveness. Perfect for professionals and students looking to understand the power of data analysis in advertising. for more details visit: https://bostoninstituteofanalytics.org/data-science-and-artificial-intelligence/
ASP.Net, move data to and from a SQL Server Database
1. Programmed By: Christopher Singleton ASP.Net, HTML, C# Date: 06/14/2016
User (Logged-In)User (Not Logged-In)
Purpose: Create an ASP.Net application web page
***User can Log-In (Update Log-In)
***User can create products.
***User can send purchase emails.
Note: Display of information during process.
Page 1
2. Create Log-In Show Newly Created Log-In
Update Log-In Show Updated Log-In
Log-In in the SQL Database (Shown Below)
Page 2
3. Create the Products in the SQL Database.
Show the Products created.
Product Clicked On
(Link to Product)
Page 3
7. {
//Don't allow the user to update any info until log-in.
UpdateUserInfo.Visible = false;
}
protected void submitButton_Click(object sender, System.EventArgs e)
{
//Pass the user's textbox inputs into variables.
string uName = Request.Form["ctl00$cpd_Main$txb_SignInUName"];
string pass = Request.Form["ctl00$cpd_Main$txb_SignInPWord"];
/*1. Open a connection using the connection string in the Web.config
file under AppSettings.*/
string connStr = ConfigurationManager.AppSettings["connectionString"];
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
/* 2. Create a command that gets the firstName from the database
using a where clause from the user input using the SQL Server Database.
Then define the query with the connection.*/
string query = "SELECT [firstName], [id] FROM [dbo].[person]" +
"WHERE userName = '" + uName + "' AND password = '" + pass + "'";
SqlCommand cmd = new SqlCommand(query);
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = conn;
/* 3. Create a reader, read the firstName and id into the variables as a string, then pass the variables
into session variables. Finally, display output to the label or textbox and hide the Log-In form.*/
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
string strfName = reader["firstName"].ToString();
string strID = reader["id"].ToString();
Session["firstName"] = strfName;
Session["userID"] = strID;
lbl_WelcomeUser.Text = "<spanIndex>Welcome</spanIndex> " + strfName + "<spanIndex>!</spanIndex>";
Form.Visible = false;
SignUp.Visible = false;
UpdateUserInfo.Visible = true;
}
else
{
txb_SignInUName.Text = "Log-In Failed!";
SignUp.Visible = true;
UpdateUserInfo.Visible = false;
}
//4. Close the connection.
conn.Close();
}
}
}
Index Page (C# Continued)
Page 7
9. <%@ Page Title="Show Log-In" Language="C#" MasterPageFile="~/Master.Master" AutoEventWireup="true" CodeBehind="ShowUserLogInInfo.aspx.cs"
Inherits="PCPartsSuperStore.userManagement.ShowUserLogInInfo" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpd_Main" runat="server">
<form id="formSULII" runat="server">
<fieldset class="fieldset1SULII">
<legend class="legendSULII">Newly Created Log-In Data</legend>
<!-- Labels to display the hard coded text using flexbox side by side again -->
<div class="flexLabelsWrapper">
<div class="flexTextLabels">
<asp:Label ID="lbl_FName" CSSclass="TextLabelsSULII" runat="server" >First Name:</asp:Label><br />
<asp:Label ID="lbl_LName" CSSclass="TextLabelsSULII" runat="server" >Last Name:</asp:Label><br />
<asp:Label ID="lbl_UserName" CSSclass="TextLabelsSULII" runat="server" >User Name:</asp:Label><br />
<asp:Label ID="lbl_Password" CSSclass="TextLabelsSULII" runat="server" >Password:</asp:Label><br />
<asp:Label ID="lbl_Address" CSSclass="TextLabelsSULII" runat="server" >Address:</asp:Label><br />
<asp:Label ID="lbl_Email" CSSclass="TextLabelsSULII" runat="server" >Email:</asp:Label><br />
<asp:Label ID="lbl_PhoneNumber" CSSclass="TextLabelsSULII" runat="server" >Phone Number:</asp:Label>
</div>
<!-- Use label ID to display the information being passed, Display in the label -->
<div class="flexPassedText">
<asp:Label ID="lbl2_fName" Cssclass="ResultTextStyleSULII" runat="server" ></asp:Label><br />
<asp:Label ID="lbl2_LName" Cssclass="ResultTextStyleSULII" runat="server" ></asp:Label><br />
<asp:Label ID="lbl2_UserName" Cssclass="ResultTextStyleSULII" runat="server" ></asp:Label><br />
<asp:Label ID="lbl2_Password" Cssclass="ResultTextStyleSULII" runat="server" ></asp:Label><br />
<asp:Label ID="lbl2_Address" Cssclass="ResultTextStyleSULII" runat="server" ></asp:Label><br />
<asp:Label ID="lbl2_Email" Cssclass="ResultTextStyleSULII" runat="server" ></asp:Label><br />
<asp:Label ID="lbl2_PhoneNumber" Cssclass="ResultTextStyleSULII" runat="server" ></asp:Label><br />
</div>
</div>
</fieldset>
<fieldset class="fieldset2SULII">
<legend class="legendSULII">Capture Row ID</legend>
<asp:Label ID="lbl_Identity" Cssclass="ResultTextStyleSULII" runat="server" ></asp:Label><br />
<asp:HyperLink ID="UpdateLogIn" runat="server" Target="_blank" NavigateUrl="~/userManagement/UpdateUserLogIn.aspx">
Update User Info</asp:HyperLink>
</fieldset>
</form>
</asp:Content>
Show User Log-In ASPX (HTML)
Page 9
10. using System;
using System.Configuration;
using System.Data.SqlClient;
namespace PCPartsSuperStore.userManagement
{
public partial class ShowUserLogInInfo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Pass the information from the text box to the variable.
string fName = Request.Form["ctl00$cpd_Main$txb_FName"];
string lName = Request.Form["ctl00$cpd_Main$txb_LName"];
string uName = Request.Form["ctl00$cpd_Main$txb_UserName"];
string pWord = Request.Form["ctl00$cpd_Main$txb_Password"];
string address = Request.Form["ctl00$cpd_Main$txb_Address"];
string email = Request.Form["ctl00$cpd_Main$txb_Email"];
string phone = Request.Form["ctl00$cpd_Main$txb_PhoneNumber"];
//Note: Request.Form["ctl00$cpd_main$txtBox"] instead of Request.Form["txtBox"] because of Master Page.
//Define the label object to display what is in the variable.
lbl2_fName.Text = fName;
lbl2_LName.Text = lName;
lbl2_UserName.Text = uName;
lbl2_Password.Text = pWord;
lbl2_Address.Text = address;
lbl2_Email.Text = email;
lbl2_PhoneNumber.Text = phone;
/*1. Open a connection using the connection string in the Web.config file under AppSettings.*/
string connStr = ConfigurationManager.AppSettings["connectionString"];
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
/* 2. Create a command that inserts the data into the SQL Database using variables with values that shows as text in the labels.*/
string query = ("INSERT INTO [dbo].[person]([firstName],[lastName],[userName]" +
",[password],[address],[email],[phone]) VALUES (" +
" '" + fName + "'," +
" '" + lName + "'," +
" '" + uName + "'," +
" '" + pWord + "'," +
" '" + address + "'," +
" '" + email + "'," +
" '" + phone + "') SELECT SCOPE_IDENTITY(); ");
SqlCommand cmd = new SqlCommand(query);
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = conn;
/* 3. Create a reader to read back the identity information, then close the connection after reading the column id into a variable.*/
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
string id = reader[0].ToString();
conn.Close();
//Take the id value and place it into text inside the label.
lbl_Identity.Text = "Dataset Created, Line ID: " + "<span>" + id + "</span>";
//Pass the Session Variable to the UpdateLogIn Page (Third Page).
Session["userID"] = id;
}
}
}
Show User Log-In (C#)
Page 10
12. using System;
using System.Configuration;
using System.Data.SqlClient;
namespace PCPartsSuperStore.userManagement
{
public partial class UpdateUserLogIn : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
/*1. Get the Session User ID.*/
string id = Session["userID"].ToString();
/*2. Open a connection using the connection string in the Web.config file under AppSettings.*/
string connStr = ConfigurationManager.AppSettings["connectionString"];
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
/* 3. Create a command that Selects all the data from the id row SQL Database using the where clause in showing
what row to select by using what is stored in the id variable.*/
string query = "SELECT * FROM [dbo].[person] WHERE id = " + id;
SqlCommand cmd = new SqlCommand(query);
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = conn;
/* 4 Create a reader to read the line in the SQL database into the text boxes*/
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
/* 5. Show the info in the textboxes that need updating.*/
string fName = reader["firstName"].ToString();
string lName = reader["lastName"].ToString();
string uName = reader["userName"].ToString();
string pWord = reader["password"].ToString();
string address = reader["address"].ToString();
string email = reader["email"].ToString();
string phone = reader["phone"].ToString();
// 6. Close the connection.
conn.Close();
// 7. Show the variable information inside the text boxes.
txbUpD_FName.Text = fName;
txbUpD_LName.Text = lName;
txbUpD_UserName.Text = uName;
txbUpD_Password.Text = pWord;
txbUpD_Address.Text = address;
txbUpD_Email.Text = email;
txbUpD_PhoneNumber.Text = phone;
}
}
}
}
Update Log-In (C#)
Page 12
14. using System;
using System.Configuration;
using System.Data.SqlClient;
namespace PCPartsSuperStore.userManagement
{
public partial class UserUpdatedShowInfo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Create the Variable for the Session.
string id = Session["userID"].ToString();
//Pass the information from the text box to the variable.
string strfName = Request.Form["ctl00$cpd_Main$txbUpD_FName"];
string strlName = Request.Form["ctl00$cpd_Main$txbUpD_LName"];
string struName = Request.Form["ctl00$cpd_Main$txbUpD_UserName"];
string strpWord = Request.Form["ctl00$cpd_Main$txbUpD_Password"];
string strAddress = Request.Form["ctl00$cpd_Main$txbUpD_Address"];
string strEmail = Request.Form["ctl00$cpd_Main$txbUpD_Email"];
string strPhone = Request.Form["ctl00$cpd_Main$txbUpD_PhoneNumber"];
//Define the label object to display what is in the variable.
lbl_fName.Text = strfName;
lbl_LName.Text = strlName;
lbl_UserName.Text = struName;
lbl_Password.Text = strpWord;
lbl_Address.Text = strAddress;
lbl_Email.Text = strEmail;
lbl_PhoneNumber.Text = strPhone;
/*1. Open a connection using the connection string in the Web.config file under AppSettings.*/
string connStr = ConfigurationManager.AppSettings["connectionString"];
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
/* 2. Create a command that updates the data into the SQL Database using variables with values that shows as text
in the labels.*/
string query = "UPDATE [dbo].[person] SET" +
"[firstName]= '" + strfName + "'," +
"[lastName]= '" + strlName + "'," +
"[userName]= '" + struName + "'," +
"[password]= '" + strpWord + "'," +
"[address]= '" + strAddress + "'," +
"[email]= '" + strEmail + "'," +
"[phone]= '" + strPhone + "' WHERE id =" + id;
SqlCommand cmd = new SqlCommand(query);
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = conn;
/* 3. Create a reader to read back the identity information, then close the connection after reading the column
id into a variable.*/
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
conn.Close();
//Take the id value and place it into text inside the label.
lbl_Identity.Text = "Dataset Updated, Line ID: " + "<spanUUSI>" + id + "</spanUUSI>";
}
}
}
Updated Log-In Info (C#)
Page 14
15. <%@ Page Title="Create Products" Language="C#" MasterPageFile="~/Master.Master" AutoEventWireup="true" CodeBehind="newProduct.aspx.cs"
Inherits="PCPartsSuperStore.productManagement.newProduct" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpd_Main" runat="server">
<asp:HyperLink ID="UpdateUserInfo" Cssclass="UpdateUserInfoNP" runat="server" Target="_blank"
NavigateUrl="~/userManagement/UpdateUserLogIn.aspx" >Update Log-In</asp:HyperLink>
<form id="formNP" class="form" method="post" runat="server" defaultfocus="txb_prodName" >
<!-- Display objects for input/output -->
<fieldset id="fieldset1NP" class="fieldset1NP">
<legend id="legendNP" class="legendNP">Create New Product</legend>
<!-- flexbox both the textbox and labels together side by side -->
<div class="flexTBoxesWrapper">
<div class="flexText">
<asp:Label ID="lbl1_prodName" Cssclass="LabelStyleNP" runat="server" >Product Name:</asp:Label><br />
<asp:Label ID="lbl1_prodDesc" Cssclass="LabelStyleNP" runat="server" >Product Description:</asp:Label><br />
<asp:Label ID="lbl1_prodPrice" Cssclass="LabelStyleNP" runat="server" >Product Price:</asp:Label><br />
<asp:Label ID="lbl1_prodAmount" Cssclass="LabelStyleNP" runat="server" >Product Amount:</asp:Label>
</div>
<!-- Allow user input into the textboxes and validate as needed. -->
<div class="flexTextBoxes">
<div id="pName"><asp:TextBox ID="txb_prodName" Cssclass="BoxStyleNP" placeholder="Product Name" runat ="server"
required ="required" ></asp:TextBox><br /></div>
<div id="pDesc"><asp:TextBox ID="txb_prodDesc" Cssclass="BoxStyleNP" placeholder="Product Description"
runat ="server" required ="required" ></asp:TextBox><br /></div>
<div id="pPrice"><asp:TextBox ID="txb_prodPrice" Cssclass="BoxStyleNP" placeholder="Product Price"
runat ="server" required ="required" ></asp:TextBox>
<asp:RegularExpressionValidator runat="server" ControlToValidate="txb_prodPrice"
ErrorMessage="*Not a valid price!" ValidationExpression="[+]?([.]d+|d+([.]d+)?)$"
></asp:RegularExpressionValidator>
<br />
</div>
<div id="pAmount">
<asp:TextBox ID="txb_prodAmount" Cssclass="BoxStyleNP" placeholder="Product Amount" runat ="server"
required ="true" ></asp:TextBox>
<asp:RegularExpressionValidator runat="server" ControlToValidate="txb_prodAmount"
ErrorMessage="*Only positive numbers!" ValidationExpression="^[1-9]d*$"
></asp:RegularExpressionValidator>
</div>
</div>
</div><br />
<asp:Label ID="lbl_Identity" Cssclass="ResultTextStyleNP" runat="server" ></asp:Label><br />
<!-- User submits the input to the next page -->
<asp:Button ID="submitButton" Cssclass="submitButton" runat="server" Text ="Submit" OnClick="submitButton_Click"
PostBackUrl="~/productManagement/newProduct.aspx"/>
</fieldset>
</form>
</asp:Content>
Create Products ASPX (HTML)
Page 15
16. using System;
using System.Configuration;
using System.Data.SqlClient;
namespace PCPartsSuperStore.productManagement
{
public partial class newProduct : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Check if the user is logged in.
if (Session["userID"] == null)
{
Response.Redirect("~/index.aspx");
}
}
protected void submitButton_Click(object sender, System.EventArgs e)
{
//Get the values from the user's product input boxes.
string prodName = txb_prodName.Text;
string prodDesc = txb_prodDesc.Text;
string prodPrice = txb_prodPrice.Text;
string prodAmount = txb_prodAmount.Text;
/*1. Open a connection using the connection string in the Web.config file under AppSettings.*/
string connStr = ConfigurationManager.AppSettings["connectionString"];
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
//Create a query.
/* 2. Create a command that inserts the data into the SQL Database using variables with values that shows
as text in the labels.*/
string query = ("INSERT INTO [dbo].[products]([productName],[description],[price]" +
",[currentAmount]) VALUES (" +
" '" + prodName + "'," +
" '" + prodDesc + "'," +
" '" + prodPrice + "'," +
" '" + prodAmount + "') SELECT SCOPE_IDENTITY(); ");
SqlCommand cmd = new SqlCommand(query);
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = conn;
/* 3. Create a reader to read back the identity information, then close the connection after reading the column id
into a variable.*/
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
string pid = reader[0].ToString();
conn.Close();
//Take the id value and place it into text inside the label.
lbl_Identity.Text = "Product: " + prodName + " created, Line ID: " + "<span>" + pid + "</span>";
//Clear the text boxes for the next input.
txb_prodName.Text = "";
txb_prodDesc.Text = "";
txb_prodPrice.Text = "";
txb_prodAmount.Text = "";
}
}
}
Create Products (C#) Page 16
17. <%@ Page Title="Available Products" Language="C#" MasterPageFile="~/Master.Master" AutoEventWireup="true"
CodeBehind="showAllProducts.aspx.cs" Inherits="PCPartsSuperStore.shopping.showAllProducts" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpd_Main" runat="server">
<asp:HyperLink ID="UpdateUserInfo" Cssclass="UpdateUserInfoAP" runat="server" Target="_blank"
NavigateUrl="~/userManagement/UpdateUserLogIn.aspx" >Update Log-In</asp:HyperLink>
<form id="formSAP" class="formSAP" method="post" runat="server" defaultfocus="prodName" >
<!-- Display objects for input/output -->
<fieldset id="fieldsetSAP" class="fieldsetSAP">
<legend id="legendSAP" class="legendSAP">Add Products to Shopping Cart</legend>
<!-- Show the table content -->
<div class="div_products" runat="server">
<asp:Label ID="div_products" Cssclass="ResultTextStyleSAP" runat="server" ></asp:Label><br />
</div>
<asp:Table runat="server" ID="tbl_Products">
<asp:TableRow>
<asp:TableCell CssClass="headCells">Product</asp:TableCell>
<asp:TableCell CssClass="headCellDesc">Description</asp:TableCell>
<asp:TableCell CssClass="headCells">Price</asp:TableCell>
<asp:TableCell CssClass="headCellBuyIt">Buy it</asp:TableCell>
</asp:TableRow>
</asp:Table>
</fieldset>
</form>
</asp:Content>
using System;
using System.Configuration;
using System.Data.SqlClient;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
namespace PCPartsSuperStore.shopping
{
public partial class showAllProducts : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Check if the user is logged in.
if (Session["userID"] == null)
{
Response.Redirect("~/index.aspx");
}
UpdateUserInfo.Visible = true;
/*1. Open a connection using the connection string in the Web.config file under AppSettings.*/
string connStr = ConfigurationManager.AppSettings["connectionString"];
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
Show All Products ASPX (HTML)
Page 17
18. /* 2. Create a query that selects all the data from the SQL Database.*/
string query = ("SELECT * FROM [dbo].[products] WHERE currentAmount > 0");
SqlCommand cmd = new SqlCommand(query);
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = conn;
//Read from the Database all the data.
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
string prodID = reader["pid"].ToString();
string prodName = reader["productName"].ToString();
string prodDesc = reader["description"].ToString();
string prodPrice = reader["price"].ToString();
//Create a table row.
TableRow tRow = new TableRow();
//Create a cell for the product name.
TableCell tcProdName = new TableCell();
tcProdName.Attributes.Add("class", "cells");
tcProdName.Text = prodName;
tRow.Cells.Add(tcProdName);
//Create a cell for Description.
TableCell tcProdDesc = new TableCell();
tcProdDesc.Attributes.Add("class", "cells");
tcProdDesc.Text = prodDesc;
tRow.Cells.Add(tcProdDesc);
//Create a cell for Price.
TableCell tcProdPrice = new TableCell();
tcProdPrice.Attributes.Add("class", "cells");
tcProdPrice.Text = "$" + prodPrice;
tRow.Cells.Add(tcProdPrice);
//Create a link.
HtmlAnchor link = new HtmlAnchor();
link.Attributes.Add("class", "cells");
link.HRef = "~/shopping/oneClickBuy.aspx?id=" + prodID;
link.InnerText = "OneClick Buy";
//Create a cell for Links.
TableCell tcBuy = new TableCell();
tcBuy.Attributes.Add("class", "cells");
tcBuy.Controls.Add(link);
tRow.Cells.Add(tcBuy);
//Add the Row to the Table.
tbl_Products.Rows.Add(tRow);
}
//Close the connection.
conn.Close();
}
}
}
Show All Products (C#)
Page 18
19. <%@ Page Title="One Click Buy" Language="C#" MasterPageFile="~/Master.Master" AutoEventWireup="true" CodeBehind="oneClickBuy.aspx.cs"
Inherits="PCPartsSuperStore.shopping.oneClickBuy" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpd_Main" runat="server">
<asp:HyperLink ID="UpdateUserInfoOCB" Cssclass="UpdateUserInfoOCB" runat="server" Target="_blank"
NavigateUrl="~/userManagement/UpdateUserLogIn.aspx" >Update Log-In</asp:HyperLink>
<form id="formOCB" class="form" method="post" runat="server" defaultfocus="prodName" >
<!-- Display objects for input/output -->
<fieldset class="fieldsetOCB">
<legend id="legendOCB">Thank You for Purchasing</legend>
<!-- Show the Thank You Message in the div. -->
<div id="div_purchase" runat="server">
</div>
</fieldset>
<asp:Button ID="submitButton" Cssclass="submitButton" runat="server" Text ="Email Receipt" OnClientClick="form.target ='_blank';"
PostBackUrl="~/WebEmail/WebMail.aspx" />
</form>
</asp:Content>
using System;
using System.Configuration;
using System.Data.SqlClient;
namespace PCPartsSuperStore.shopping
{
public partial class oneClickBuy : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Check if the user is logged in.
if (Session["userID"] == null)
{
Response.Redirect("~/index.aspx");
}
//Pass the Session userID to id when querying for the user.
string id = Session["userID"].ToString();
//Allow the user to update their info.
UpdateUserInfoOCB.Visible = true;
//Get the product from the query string.
string productID = Request.QueryString["id"].ToString();
/*1. Open a connection using the connection string in the Web.config
file under AppSettings.*/
string connStr = ConfigurationManager.AppSettings["connectionString"];
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
One Click Buy ASPX (HTML)
One Click Buy (C#)
Page 19
20. /*2. Get the product information using a query string.*/
string query = ("SELECT * FROM [dbo].[products] WHERE pid =" + productID);
SqlCommand cmd = new SqlCommand(query);
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = conn;
/*3. Read from the Database the Product Name and Product Price data that
you selected in the query with the pid that was filtered after opening
the new defined reader. Then close the reader to re-use it again.*/
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
string prodName = reader["productName"].ToString();
string prodPrice = reader["price"].ToString();
reader.Close();
/*4. Create a query with the user's First Name and Address based
on the user already logged on. Then execute and read the reader
once again from the database. After that close the reader.
Note: Do Not Close the Connection (Connection still open).*/
cmd.CommandText = "SELECT * FROM person WHERE id =" +id;
reader = cmd.ExecuteReader();
reader.Read();
string custName = reader["firstName"].ToString();
string custAddress = reader["address"].ToString();
string custEmail = reader["email"].ToString();
reader.Close();
/*5. Decrease the product from the selected pid (Product ID).
Then Close the Connection and display the thank you message.*/
cmd.CommandText = "UPDATE products SET currentAmount = (currentAmount-1)" +
" where pid =" + productID;
cmd.ExecuteNonQuery();
conn.Close();
//create a sesssion with info for emailing the customer.
Session["custName"] = custName;
Session["prodName"] = prodName;
Session["prodPrice"] = prodPrice;
Session["custAddress"] = custAddress;
//Send the customer's email info to the WebMail page.
Session["email"] = custEmail;
//Say thank you message and let the customer know about your interest in their purchase.
div_purchase.InnerHtml = "Hi <spanOCB><b>" + custName + "</b></spanOCB>," +
"<br/>Thank's for buying a <spanOCB><b>" + prodName + "</b></spanOCB>. Your " +
"credit card will be charged <spanOCB><b>$" + prodPrice + "</b></spanOCB> and your" +
" purchase will be shipped to <spanOCB><b>" + custAddress + "</b></spanOCB>." +
" Thanks for shopping with us. Come back soon. We like your money.";
}
}
}
One Click Buy (C# Continued)
Page 20
21. <%@ Page Title="Email Customer" Language="C#" MasterPageFile="~/Master.Master" AutoEventWireup="true" CodeBehind="WebMail.aspx.cs"
Inherits="PCPartsSuperStore.WebEmail.WebMail1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpd_Main" runat="server">
<form id="formWebMail" class="formWebMail" method="post" runat="server" defaultfocus="prodName" >
<fieldset class="WebMailHeader">
<legend class="legendWM">Please check your email:</legend>
<!-- Wrap the labels together -->
<div class="flexLabelsWrapper">
<div id="lbl_Email">
<asp:Label ID="lbl_WMText" CSSclass="lbl_WMText" runat="server" >Email Address:</asp:Label>
</div>
<div id="EmailAddress" class="EmailAddress" runat="server">
<asp:Label ID="lbl_WMAddress" CSSclass="WMAddress" runat="server" ></asp:Label>
</div>
</div>
</fieldset>
<!-- Display objects for input/output -->
<fieldset class="fieldsetWebMail">
<legend id="legendWM" class="legendWM">Your reciept has been sent.</legend>
<!-- Show the Thank You Message in the div. -->
<div id="div_purchase" runat="server">
</div>
</fieldset>
</form>
</asp:Content>
using System;
using System.Net;
using System.Net.Mail;
namespace PCPartsSuperStore.WebEmail
{
public partial class WebMail1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Check if the user is logged in.
if (Session["userID"] == null)
{
Response.Redirect("~/index.aspx");
}
/*1. Get the Session variables to display what is in the email.*/
string custName = (string)Session["custName"];
string prodName = (string)Session["prodName"];
string prodPrice = (string)Session["prodPrice"];
string custAddress = (string)Session["custAddress"];
Email Customer ASPX (HTML)
Email Customer (C#)
Page 21
22. /***************************************************************/
/***** Automatically gets the "to" email from the database *****/
/***************************************************************/
//Note: Database email must be a true email address in sending.
/*2. Get the Session variable for the customer email and display
it in the label. Then use the text in the label to send to the customer.*/
string custEmail = (string)Session["email"];
lbl_WMAddress.Text = custEmail.ToString();
/*3. Define the header of the email being sent.*/
string subject = "Thank you for shopping! (Test Email)";
/*4. Use what is in the label as an email address
of the user's email as a string and then define the body (message). */
string to = lbl_WMAddress.Text;
/***************************************************************/
/***************************************************************/
//Display what will be in the body of the email.
string body = "Hi <b>" + custName + "</ b >, <br/>Thank's for "+
"buying a <spanOCB><b>" + prodName + "</b></spanOCB>. Your credit card will be "+
"charged <spanOCB><b>$" + prodPrice + "</b></spanOCB> and your purchase will be shipped"+
" to <spanOCB><b>" + custAddress + "</b></spanOCB>."+
" Thanks for shopping with us. Come back soon. We like your money.";
/*5. Create a MailMessage object.*/
MailMessage mail = new MailMessage();
/***************************************************************/
/************************* Sender's Email **********************/
/***************************************************************/
/*6. Define what email address with password your sending from.
(Your own gmail credentials).*/
string senderEmail = "sender@gmail.com";
string senderPasswd = "sendersgmailpassword"; // a valid password for the email above*/
/***************************************************************/
/***************************************************************/
/*7. Define the objects of the email and link them to the variables as objects.*/
mail.From = new MailAddress(senderEmail);
mail.To.Add(to.ToString());
mail.Subject = subject;
mail.Body = body;
/*8. Allows HTML in the body.*/
mail.IsBodyHtml = true;
//Note: Code to add attachements, but not needed in this case(reference).
//mail.Attachments.Add(new Attachment("C:someFile.jpg"));
/*9. SMTP Client for gmail only. Other emails will have different
SMTP Client port numbers.*/
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587); //Port 587
Email Customer (C# Continued)
Page 22