Created
September 6, 2016 01:26
-
-
Save Daviddonadze/f50803d219cad713aebe552bb48620cd to your computer and use it in GitHub Desktop.
Auction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//----------MakeModel.aspx------------------------------------------- | |
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="MakeModel.aspx.cs" Inherits="Auction.MakeModel" %> | |
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"> | |
<table> | |
<tr> | |
<td>All Make: | |
</td> | |
<td> | |
<asp:DropDownList ID="ddlMake" runat="server"></asp:DropDownList> | |
</td> | |
<td> | |
All Model: | |
</td> | |
<td> | |
<asp:DropDownList ID="ddlModel" runat="server"></asp:DropDownList> | |
</td> | |
</tr> | |
<tr> | |
<td>New Make: | |
</td> | |
<td> | |
<asp:TextBox ID="txtNewMake" runat="server" Width="200px"></asp:TextBox> | |
</td> | |
<td id="pnMain"> | |
New Model: | |
</td> | |
<td> | |
<asp:TextBox ID="txtNewModel" runat="server"></asp:TextBox> | |
</td> | |
</tr> | |
</table> | |
<div style="text-align: right"> | |
<asp:Label ID="lblMessage" runat="server" Text="MSG"></asp:Label> | |
</div> | |
<div style="text-align: center"> | |
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" /> | |
</div> | |
</asp:Content> | |
//---------------------MakeModel.aspx.cs--------------------------------------------------------------- | |
using System; | |
using System.Collections.Generic; | |
using System.Data; | |
using System.Linq; | |
using System.Web; | |
using System.Web.UI; | |
using System.Web.UI.WebControls; | |
namespace Auction | |
{ | |
public partial class MakeModel : System.Web.UI.Page | |
{ | |
DBAccess db = new DBAccess(); | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
if (!IsPostBack) | |
{ | |
LoadModel(); | |
LoadMake(); | |
} | |
} | |
private void LoadModel() | |
{ | |
db = new DBAccess(); | |
DataTable dt = db.SatModel(); | |
foreach (DataRow items in dt.Rows) | |
{ | |
var item = new ListItem { Value = items[0].ToString(), Text = items[1].ToString() }; | |
ddlModel.Items.Add(item); | |
} | |
ddlModel.Items.Insert(0, "Select Model"); | |
} | |
private void LoadMake() | |
{ | |
db = new DBAccess(); | |
DataTable dt = db.SatMake(); | |
foreach (DataRow items in dt.Rows) | |
{ | |
var item = new ListItem { Value = items[0].ToString(), Text = items[1].ToString() }; | |
ddlMake.Items.Add(item); | |
} | |
ddlMake.Items.Insert(0, "Select Make"); | |
} | |
protected void btnSave_Click(object sender, EventArgs e) | |
{ | |
string make = txtNewMake.Text; | |
string model = txtNewModel.Text; | |
int ddlmake = Convert.ToInt32(ddlMake.SelectedValue); | |
int ddlmodel = Convert.ToInt32(ddlModel.SelectedValue); | |
var db = new DBAccess(); | |
int ModelMakeID = db.SetMakeModel(make, model, ddlmake, ddlmodel); | |
if (ModelMakeID > 0) | |
{ | |
lblMessage.Text = "You are Best"; | |
} | |
else | |
{ | |
lblMessage.Text = "Problem P_SetMakeModel"; | |
} | |
} | |
} | |
} | |
//----------------------BuyerAdd.aspx---------------------------------------------------------------------------- | |
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="BuyerAdd.aspx.cs" Inherits="Auction.BuyerAdd" %> | |
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"> | |
<div style="text-align: right"> | |
<asp:Label ID="lblMessage1" runat="server" Text="MSG1"></asp:Label> | |
</div> | |
<fieldset> | |
<table> | |
<tr> | |
<td>First Name: | |
</td> | |
<td> | |
<asp:TextBox ID="txtFirstName" runat="server" Width="128px"></asp:TextBox> | |
</td> | |
<td> | |
Last Name: | |
</td> | |
<td> | |
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox> | |
</td> | |
</tr> | |
<tr> | |
<td>Gender: | |
</td> | |
<td> | |
<asp:DropDownList ID="ddlGender" runat="server"></asp:DropDownList> | |
</td> | |
<td> | |
Race: | |
</td> | |
<td> | |
<asp:DropDownList ID="ddlRace" runat="server"></asp:DropDownList> | |
</td> | |
</tr> | |
<tr> | |
<td>Address: | |
</td> | |
<td> | |
<asp:TextBox ID="txtAddress" runat="server" Width="200px"></asp:TextBox> | |
</td> | |
<td id="pnMain"> | |
City: | |
</td> | |
<td> | |
<asp:TextBox ID="txtCity" runat="server"></asp:TextBox> | |
</td> | |
</tr> | |
</table> | |
<table> | |
<tr> | |
<td> | |
<asp:RadioButtonList ID="rdoState" runat="server" AutoPostBack="True" RepeatDirection="Horizontal" RepeatColumns="3" OnSelectedIndexChanged="rdolState_SelectedIndexChanged"> | |
<asp:ListItem Value="chkUSA">USA</asp:ListItem> | |
<asp:ListItem Value="chkCanada">Canada</asp:ListItem> | |
</asp:RadioButtonList> | |
</td> | |
</tr> | |
</table> | |
<table id="TB" runat="server" visible="false"> | |
<tr> | |
<td>State: | |
</td> | |
<td> | |
<asp:DropDownList ID="ddlState" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlState_SelectedIndexChanged"></asp:DropDownList> | |
</td> | |
<td> | |
Zip: | |
</td> | |
<td> | |
<asp:TextBox ID="txtZip" runat="server" Width="60" MaxLength="5"></asp:TextBox> | |
</td> | |
</tr> | |
</table> | |
<table> | |
<tr> | |
<td>Phone: | |
</td> | |
<td> | |
<asp:TextBox ID="txtPhone" runat="server" Width="128px" MaxLength="10" TextMode="Phone"></asp:TextBox> | |
</td> | |
<td> | |
Email: | |
</td> | |
<td> | |
<asp:TextBox ID="txtEmail" runat="server" TextMode="Email"></asp:TextBox> | |
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" | |
ControlToValidate="txtEmail" runat="server" ForeColor="Red" ErrorMessage="Please Enter Valid Email" | |
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator> | |
</td> | |
</tr> | |
</table> | |
</fieldset> | |
<div style="text-align: right"> | |
<asp:Label ID="lblMessage2" runat="server" Text="MSG2"></asp:Label> | |
</div> | |
<div style="text-align: center"> | |
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" /> | |
</div> | |
</asp:Content> | |
//--------------------------BuyerAdd.aspx.cs------------------------------------------------------------------- | |
using System; | |
using System.Collections.Generic; | |
using System.Data; | |
using System.Linq; | |
using System.Text.RegularExpressions; | |
using System.Web; | |
using System.Web.UI; | |
using System.Web.UI.WebControls; | |
namespace Auction | |
{ | |
public partial class BuyerAdd : System.Web.UI.Page | |
{ | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
if (!IsPostBack) | |
{ | |
LoadDropDown(); | |
} | |
} | |
private void LoadDropDown() | |
{ | |
var entity = Session["GetLookUp"] as List<List<ReaderHelper>>; | |
if (entity == null) | |
Response.Redirect("http://localhost:50026/"); | |
var genders = entity[0]; | |
ddlGender.Items.Insert(0, "Select Gender"); | |
foreach (var gender in genders) | |
{ | |
var item = new ListItem { Value = gender.Id.ToString(), Text = gender.Name }; | |
ddlGender.Items.Add(item); | |
} | |
var Race = entity[1]; | |
ddlRace.Items.Insert(0, "Select Race"); | |
foreach (var race in Race) | |
{ | |
var item = new ListItem { Value = race.Id.ToString(), Text = race.Name }; | |
ddlRace.Items.Add(item); | |
} | |
} | |
protected void btnSave_Click(object sender, EventArgs e) | |
{ | |
if (!CheckIfValid()) | |
{ | |
return; | |
} | |
else | |
{ | |
string firstName = txtFirstName.Text; | |
string lastName = txtLastName.Text; | |
int genderID = Convert.ToInt32(ddlGender.SelectedValue); | |
int raceID = Convert.ToInt32(ddlRace.SelectedValue); | |
string address = txtAddress.Text; | |
string city = txtCity.Text; | |
int stateID = Convert.ToInt32(ddlState.SelectedValue); | |
string zip = txtZip.Text; | |
string phone = txtPhone.Text; | |
string email = txtEmail.Text; | |
var db = new DBAccess(); | |
int ReturnID = db.SetBuyer(firstName, lastName, genderID, raceID, address, city, | |
stateID, zip, phone, email); | |
if (ReturnID > 0) | |
{ | |
lblMessage2.Text = "Updated seccesfuly"; | |
} | |
else | |
{ | |
lblMessage2.Text = "Problem with SQL insert P_SetBuyer"; | |
} | |
} | |
} | |
//---------------------Validation--------------------------- | |
private bool CheckIfValid() | |
{ | |
string firstName = txtFirstName.Text; | |
string lastName = txtLastName.Text; | |
int genderID = Convert.ToInt32(ddlGender.SelectedValue == null ? ddlGender.SelectedValue : "0"); | |
int raceID = Convert.ToInt32(ddlRace.SelectedValue == null ? ddlRace.SelectedValue : "0"); | |
string address = txtAddress.Text; | |
string city = txtCity.Text; | |
int stateID = Convert.ToInt32(ddlState.SelectedValue); | |
string zip = txtZip.Text; | |
string phone = txtPhone.Text; | |
string email = txtEmail.Text; | |
if (!firstName.IsValidString()) | |
{ | |
lblMessage2.Text = "Enter First Name"; | |
return false; | |
} | |
if (!lastName.IsValidString()) | |
{ | |
lblMessage2.Text = "Enter Last Name"; | |
return false; | |
} | |
if (ddlGender.SelectedIndex == 0) | |
{ | |
lblMessage2.Text = "Choose Gender"; | |
return false; | |
} | |
if (ddlRace.SelectedIndex == 0) | |
{ | |
lblMessage2.Text = "Choose Race"; | |
return false; | |
} | |
if (!address.IsValidString()) | |
{ | |
lblMessage2.Text = " Enter Address"; | |
return false; | |
} | |
if (!city.IsValidString()) | |
{ | |
lblMessage2.Text = "Enter City"; | |
return false; | |
} | |
if (ddlState.SelectedIndex <= 0) | |
{ | |
lblMessage2.Text = "Choose State"; | |
return false; | |
} | |
if (!zip.IsValidString()) | |
{ | |
lblMessage2.Text = "Please enter valid Zip"; | |
return false; | |
} | |
if (!phone.IsValidString()) | |
{ | |
lblMessage2.Text = "PLease Enter Phone#"; | |
return false; | |
} | |
if (!email.IsValidEmail()) | |
{ | |
lblMessage2.Text = "Please enter valid Email"; | |
return false; | |
} | |
return true; | |
} | |
#region | |
//--------------ZIP--------------------------- | |
// string _usZipRegEx = @"^\d{5}(?:[-\s]\d{4})?$"; | |
// string _caZipRegEx = @"^([ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ])\ {0,1}(\d[ABCEGHJKLMNPRSTVWXYZ]\d)$"; | |
// private bool IsUsorCanadianZipCode(string zipCode) | |
// { | |
// bool validZipCode = true; | |
// if ((!Regex.Match(zipCode, _usZipRegEx).Success) && (!Regex.Match(zipCode, _caZipRegEx).Success)) | |
// { | |
// validZipCode = false; | |
// } | |
// return validZipCode; | |
// } | |
//} | |
//------------Email------------------- | |
//public static class Validator | |
//{ | |
// static Regex ValidEmailRegex = CreateValidEmailRegex(); | |
// private static Regex CreateValidEmailRegex() | |
// { | |
// string validEmailPattern = @"^(?!\.)(""([^""\r\\]|\\[""\r\\])*""|" | |
// + @"([-a-z0-9!#$%&'*+/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)" | |
// + @"@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$"; | |
// return new Regex(validEmailPattern, RegexOptions.IgnoreCase); | |
// } | |
// internal static bool EmailIsValid(string emailAddress) | |
// { | |
// bool isValid = ValidEmailRegex.IsMatch(emailAddress); | |
// return isValid; | |
// } | |
//} | |
#endregion | |
private void LoadStates(int countryID) | |
{ | |
DBAccess db = new DBAccess(); | |
DataTable dt = db.GetStates(countryID); | |
ddlState.DataSource = dt; | |
ddlState.DataTextField = "State"; | |
ddlState.DataValueField = "StateID"; | |
ddlState.DataBind(); | |
ddlState.Items.Insert(0, "Please Select"); | |
} | |
protected void rdolState_SelectedIndexChanged(object sender, EventArgs e) | |
{ | |
if (rdoState.SelectedIndex == 0 || rdoState.SelectedIndex == 1) | |
{ | |
TB.Visible = true; | |
LoadStates(rdoState.SelectedIndex + 1); | |
} | |
else | |
{ | |
TB.Visible = false; | |
} | |
} | |
protected void ddlState_SelectedIndexChanged(object sender, EventArgs e) | |
{ | |
lblMessage1.Text = ddlState.SelectedValue; | |
} | |
} | |
} | |
//-------------------------EditBuyer.aspx-------------------------------------------------------------------------- | |
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="EditBuyer.aspx.cs" Inherits="Auction.EditBuyer" %> | |
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"> | |
<div> | |
<asp:DropDownList ID="ddlBuyersForEdit" runat="server" OnSelectedIndexChanged="ddlBuyersForEdit_SelectedIndexChanged" AutoPostBack="True"></asp:DropDownList> | |
</div> | |
<div style="text-align: right" runat="server" id="editPanel" visible="false"> | |
<asp:Label ID="lblMessage1" runat="server" Text="MSG1"></asp:Label> | |
<fieldset> | |
<legend style="text-align: center "><h4>Edit Buyer</h4></legend> | |
<table> | |
<tr> | |
<td>First Name: | |
</td> | |
<td> | |
<asp:TextBox ID="txtFirstName" runat="server" Width="128px"></asp:TextBox> | |
</td> | |
<td> | |
Last Name: | |
</td> | |
<td> | |
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox> | |
</td> | |
</tr> | |
<tr> | |
<td>Gender: | |
</td> | |
<td> | |
<asp:DropDownList ID="ddlGender" runat="server"></asp:DropDownList> | |
</td> | |
<td> | |
Race: | |
</td> | |
<td> | |
<asp:DropDownList ID="ddlRace" runat="server"></asp:DropDownList> | |
</td> | |
</tr> | |
<tr> | |
<td>Address: | |
</td> | |
<td> | |
<asp:TextBox ID="txtAddress" runat="server" Width="200px"></asp:TextBox> | |
</td> | |
<td id="pnMain"> | |
City: | |
</td> | |
<td> | |
<asp:TextBox ID="txtCity" runat="server"></asp:TextBox> | |
</td> | |
</tr> | |
</table> | |
<table> | |
<tr> | |
<td> | |
<asp:RadioButtonList ID="rdoState" runat="server" AutoPostBack="True" RepeatDirection="Horizontal" RepeatColumns="3" > | |
<asp:ListItem Value="chkUSA">USA</asp:ListItem> | |
<asp:ListItem Value="chkCanada">Canada</asp:ListItem> | |
</asp:RadioButtonList> | |
</td> | |
</tr> | |
</table> | |
<table id="TB" runat="server"> | |
<tr> | |
<td>State: | |
</td> | |
<td> | |
<asp:DropDownList ID="ddlState" runat="server" AutoPostBack="True"></asp:DropDownList> | |
</td> | |
<td> | |
Zip: | |
</td> | |
<td> | |
<asp:TextBox ID="txtZip" runat="server" Width="60" MaxLength="5"></asp:TextBox> | |
</td> | |
</tr> | |
</table> | |
<table> | |
<tr> | |
<td>Phone: | |
</td> | |
<td> | |
<asp:TextBox ID="txtPhone" runat="server" Width="128px" MaxLength="10" TextMode="Phone"></asp:TextBox> | |
</td> | |
<td> | |
Email: | |
</td> | |
<td> | |
<asp:TextBox ID="txtEmail" runat="server" TextMode="Email"></asp:TextBox> | |
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" | |
ControlToValidate="txtEmail" | |
runat="server" | |
ForeColor="Red" | |
ErrorMessage="Please Enter Valid Email" | |
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"> | |
</asp:RegularExpressionValidator> | |
</td> | |
</tr> | |
</table> | |
<div style="text-align: right"> | |
<asp:Label ID="lblMessage2" runat="server" Text="MSG2"></asp:Label> | |
</div> | |
<div style="text-align: center"> | |
<asp:Button ID="btnSave" runat="server" Text="Edit Buyer--Save" OnClick="btnSave_Click" /> | |
</div> | |
</fieldset> | |
</div> | |
</asp:Content> | |
//------------------------------------------------EditBuyer.aspx.cs-------------------------------------------------------- | |
using System; | |
using System.Collections.Generic; | |
using System.Data; | |
using System.Linq; | |
using System.Web; | |
using System.Web.UI; | |
using System.Web.UI.WebControls; | |
namespace Auction | |
{ | |
public partial class EditBuyer : System.Web.UI.Page | |
{ | |
DBAccess db = new DBAccess(); | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
if (!IsPostBack) | |
{ | |
GetBuyerForEdit(); | |
LoadDropDown(); | |
editPanel.Visible = false; | |
} | |
} | |
private void LoadDropDown() | |
{ | |
var entity = Session["GetLookUp"] as List<List<ReaderHelper>>; | |
if (entity == null) | |
Response.Redirect("http://localhost:50026/"); | |
var genders = entity[0]; | |
ddlGender.Items.Insert(0, "Select Gender"); | |
foreach (var gender in genders) | |
{ | |
var item = new ListItem { Value = gender.Id.ToString(), Text = gender.Name }; | |
ddlGender.Items.Add(item); | |
} | |
var Race = entity[1]; | |
ddlRace.Items.Insert(0, "Select Race"); | |
foreach (var race in Race) | |
{ | |
var item = new ListItem { Value = race.Id.ToString(), Text = race.Name }; | |
ddlRace.Items.Add(item); | |
} | |
var State = entity[2]; | |
ddlState.Items.Insert(0, "Select Sate"); | |
foreach (var state in State) | |
{ | |
var item = new ListItem { Value = state.Id.ToString(), Text = state.Name }; | |
ddlState.Items.Add(item); | |
} | |
} | |
// -------------- Papulate DropDown List Buyer names ONLY -------------------- | |
private void GetBuyerForEdit() | |
{ | |
db = new DBAccess(); | |
DataTable dt = db.GetBuyerForEdit(); | |
foreach (DataRow items in dt.Rows) | |
{ | |
var item = new ListItem { Value = items[0].ToString(), Text = items[1].ToString() }; | |
ddlBuyersForEdit.Items.Add(item); | |
} | |
ddlBuyersForEdit.Items.Insert(0, "Select Buyer"); | |
} | |
// -----SetBuyer------save and send Parameners into SQL ---------- | |
protected void btnSave_Click(object sender, EventArgs e) | |
{ | |
if (!CheckIfValid()) | |
{ | |
return; | |
} | |
else | |
{ | |
string firstName = txtFirstName.Text; | |
string lastName = txtLastName.Text; | |
int genderID = Convert.ToInt32(ddlGender.SelectedValue); | |
int raceID = Convert.ToInt32(ddlRace.SelectedValue); | |
string address = txtAddress.Text; | |
string city = txtCity.Text; | |
int stateID = ddlState.SelectedIndex + 1; | |
string zip = txtZip.Text; | |
string phone = txtPhone.Text; | |
string email = txtEmail.Text; | |
var db = new DBAccess(); | |
int buyerid = Convert.ToInt32(ddlBuyersForEdit.SelectedValue); | |
int NewBuyerID = db.SetBuyer(firstName, lastName, genderID, raceID, address, city, | |
stateID, zip, phone, email, buyerid); | |
if (NewBuyerID > 0) | |
{ | |
lblMessage2.Text = "Updated seccesfuly"; | |
} | |
else | |
{ | |
lblMessage2.Text = "Problem with SQL insert P_GetBuyer"; | |
} | |
} | |
} | |
//---------------------Validation--------------------------- | |
private bool CheckIfValid() | |
{ | |
string firstName = txtFirstName.Text; | |
string lastName = txtLastName.Text; | |
int genderID = Convert.ToInt32(ddlGender.SelectedValue == null ? ddlGender.SelectedValue : "0"); | |
int raceID = Convert.ToInt32(ddlRace.SelectedValue == null ? ddlRace.SelectedValue : "0"); | |
string address = txtAddress.Text; | |
string city = txtCity.Text; | |
string stateID = ddlState.SelectedValue; | |
string zip = txtZip.Text; | |
string phone = txtPhone.Text; | |
string email = txtEmail.Text; | |
if (!firstName.IsValidString()) | |
{ | |
lblMessage2.Text = "Enter First Name"; | |
return false; | |
} | |
if (!lastName.IsValidString()) | |
{ | |
lblMessage2.Text = "Enter Last Name"; | |
return false; | |
} | |
if (ddlGender.SelectedIndex == 0) | |
{ | |
lblMessage2.Text = "Choose Gender"; | |
return false; | |
} | |
if (ddlRace.SelectedIndex == 0) | |
{ | |
lblMessage2.Text = "Choose Race"; | |
return false; | |
} | |
if (!address.IsValidString()) | |
{ | |
lblMessage2.Text = " Enter Address"; | |
return false; | |
} | |
if (!city.IsValidString()) | |
{ | |
lblMessage2.Text = "Enter City"; | |
return false; | |
} | |
if (ddlState.SelectedIndex <= 0) | |
{ | |
lblMessage2.Text = "Choose State"; | |
return false; | |
} | |
if (!zip.IsInt()) | |
{ | |
lblMessage2.Text = "Please enter valid Zip"; | |
return false; | |
} | |
if (!phone.IsValidString()) | |
{ | |
lblMessage2.Text = "PLease Enter Phone#"; | |
return false; | |
} | |
if (!email.IsValidString()) | |
{ | |
lblMessage2.Text = "PLease enter Email"; | |
} | |
return true; | |
} | |
//-----------------Load DropDown LIst ( ddlBuyersForEdit ) | |
protected void ddlBuyersForEdit_SelectedIndexChanged(object sender, EventArgs e) | |
{ | |
if (ddlBuyersForEdit.SelectedIndex > 0) | |
{ | |
editPanel.Visible = true; | |
int buyerId = Convert.ToInt32(ddlBuyersForEdit.SelectedValue); | |
db = new DBAccess(); | |
DataTable dt = db.GetBuyerInfo(buyerId); | |
if (dt.Rows.Count > 0) | |
{ | |
DataRow dr = dt.Rows[0]; | |
txtFirstName.Text = dr["firstName"].ToString(); | |
txtLastName.Text = dr["lastname"].ToString(); | |
ddlGender.SelectedValue = dr["genderId"].ToString(); | |
ddlRace.SelectedValue = dr["raceId"].ToString(); | |
txtAddress.Text = dr["address"].ToString(); | |
txtZip.Text = dr["Zip"].ToString(); | |
txtCity.Text = dr["city"].ToString(); | |
ddlState.SelectedValue= Convert.ToString(dr["StateID"]); | |
txtPhone.Text = dr["phone"].ToString(); | |
txtEmail.Text = dr["email"].ToString(); | |
rdoState.Visible = true; | |
if (dr["CountryID"].ToString() == "1") | |
rdoState.SelectedIndex = 0; | |
else | |
rdoState.SelectedIndex = 1; | |
} | |
} | |
} | |
} | |
} | |
//------------------------------SellerMaintenance.aspx------------------------------ | |
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="SellerMaintenance.aspx.cs" Inherits="Auction.SellerMaintenance" %> | |
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"> | |
<fieldset runat="server" id="pnMain" visible="false"> | |
<table> | |
<tr> | |
<td>First Name: | |
</td> | |
<td> | |
<asp:TextBox ID="txtFirstName" runat="server" Width="128px"></asp:TextBox> | |
</td> | |
<td> | |
Last Name: | |
</td> | |
<td> | |
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox> | |
</td> | |
</tr> | |
<tr> | |
<td>Gender: | |
</td> | |
<td> | |
<asp:DropDownList ID="ddlGender" runat="server"></asp:DropDownList> | |
</td> | |
<td> | |
Race: | |
</td> | |
<td> | |
<asp:DropDownList ID="ddlRace" runat="server"></asp:DropDownList> | |
</td> | |
</tr> | |
<tr> | |
<td>Address: | |
</td> | |
<td> | |
<asp:TextBox ID="txtAddress" runat="server" Width="200px"></asp:TextBox> | |
</td> | |
<td id="pnMain"> | |
City: | |
</td> | |
<td> | |
<asp:TextBox ID="txtCity" runat="server"></asp:TextBox> | |
</td> | |
</tr> | |
</table> | |
<table> | |
<tr> | |
<td> | |
<asp:RadioButtonList ID="rdoState" runat="server" AutoPostBack="True" RepeatDirection="Horizontal" RepeatColumns="3" > | |
<asp:ListItem Value="chkUSA">USA</asp:ListItem> | |
<asp:ListItem Value="chkCanada">Canada</asp:ListItem> | |
</asp:RadioButtonList> | |
</td> | |
</tr> | |
</table> | |
<table id="TB" runat="server"> | |
<tr> | |
<td>State: | |
</td> | |
<td> | |
<asp:DropDownList ID="ddlState" runat="server" AutoPostBack="True"></asp:DropDownList> | |
</td> | |
<td> | |
Zip: | |
</td> | |
<td> | |
<asp:TextBox ID="txtZip" runat="server" Width="60" MaxLength="5"></asp:TextBox> | |
</td> | |
</tr> | |
</table> | |
<table> | |
<tr> | |
<td>Phone: | |
</td> | |
<td> | |
<asp:TextBox ID="txtPhone" runat="server" Width="128px" MaxLength="10" TextMode="Phone"></asp:TextBox> | |
</td> | |
<td> | |
Email: | |
</td> | |
<td> | |
<asp:TextBox ID="txtEmail" runat="server" TextMode="Email"></asp:TextBox> | |
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" | |
ControlToValidate="txtEmail" runat="server" ForeColor="Red" ErrorMessage="Please Enter Valid Email" | |
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator> | |
</td> | |
</tr> | |
</table> | |
</fieldset> | |
<div style="text-align: center"> | |
<asp:Button ID="btnEdit" runat="server" Text="Edit" OnClick="Save_Click" /> | |
| |
<asp:Button ID="btnOk" runat="server" Text="Ok" OnClick="Ok_Click" /> | |
| |
<asp:Button ID="btnDelete" runat="server" Text="Delete" OnClick="Delete_Click" /> | |
</div> | |
<div style="text-align: left"> | |
<asp:Label ID="lblMessage2" runat="server" Text="MSG"></asp:Label> | |
</div> | |
</asp:Content> | |
//------------------------------SellerMaintenance.aspx.cs--------------------------------------- | |
using System; | |
using System.Collections.Generic; | |
using System.Data; | |
using System.Linq; | |
using System.Web; | |
using System.Web.UI; | |
using System.Web.UI.WebControls; | |
namespace Auction | |
{ | |
public partial class SellerMaintenance : System.Web.UI.Page | |
{ | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
if (!IsPostBack) | |
{ | |
string action = Request.QueryString["Action"].ToString(); | |
int sellerId = int.Parse(Request.QueryString["SellerID"]); | |
ViewState["SellerID"] = sellerId; | |
LoadDropDown(); | |
LoadSellerInfo(action, sellerId); | |
} | |
} | |
private void LoadDropDown() | |
{ | |
var entity = Session["GetLookUp"] as List<List<ReaderHelper>>; | |
if (entity == null) | |
Response.Redirect("http://localhost:50026/"); | |
var genders = entity[0]; | |
ddlGender.Items.Insert(0, "Select Gender"); | |
foreach (var gender in genders) | |
{ | |
var item = new ListItem { Value = gender.Id.ToString(), Text = gender.Name }; | |
ddlGender.Items.Add(item); | |
} | |
var Race = entity[1]; | |
ddlRace.Items.Insert(0, "Select Race"); | |
foreach (var race in Race) | |
{ | |
var item = new ListItem { Value = race.Id.ToString(), Text = race.Name }; | |
ddlRace.Items.Add(item); | |
} | |
var State = entity[2]; | |
ddlState.Items.Insert(0, "Select State"); | |
foreach (var state in State) | |
{ | |
var item = new ListItem { Value = state.Id.ToString(), Text = state.Name }; | |
ddlState.Items.Add(item); | |
} | |
} | |
private void LoadStates(int countryID) | |
{ | |
DBAccess db = new DBAccess(); | |
DataTable dt = db.GetStates(countryID); | |
ddlState.DataSource = dt; | |
ddlState.DataTextField = "State"; | |
ddlState.DataValueField = "StateID"; | |
ddlState.DataBind(); | |
ddlState.Items.Insert(0, "Please Select"); | |
} | |
private void LoadSellerInfo(string action, int sellerId) | |
{ | |
pnMain.Visible = true; | |
if (action == "Delete") | |
{ | |
pnMain.Visible = false; | |
} | |
else | |
if (action == "Details") | |
{ | |
LoadInfo(sellerId); | |
ProtectControls(); | |
} | |
else | |
if (action == "Edit") | |
{ | |
LoadInfo(sellerId); | |
} | |
} | |
private void ProtectControls() | |
{ | |
txtAddress.ReadOnly = true; | |
ddlGender.Enabled = false; | |
txtCity.ReadOnly = true; | |
txtEmail.ReadOnly = true; | |
txtFirstName.ReadOnly = true; | |
txtLastName.ReadOnly = true; | |
txtPhone.ReadOnly = true; | |
txtZip.ReadOnly = true; | |
ddlRace.Enabled = false; | |
ddlState.Enabled = false; | |
} | |
private void LoadInfo(int sellerId) | |
{ | |
var db = new DBAccess(); | |
DataTable dt = db.GetSeller(sellerId); | |
if (dt.Rows.Count > 0) | |
{ | |
DataRow dr = dt.Rows[0]; | |
txtFirstName.Text = dr["FirstName"].ToString(); | |
txtLastName.Text = dr["LastName"].ToString(); | |
ddlGender.SelectedValue = dr["GenderID"].ToString(); | |
ddlRace.SelectedValue = dr["RaceID"].ToString(); | |
txtAddress.Text = dr["Address"].ToString(); | |
txtCity.Text = dr["City"].ToString(); | |
ddlState.SelectedValue = dr["StateID"].ToString(); | |
txtZip.Text = dr["Zip"].ToString(); | |
txtPhone.Text = dr["Phone"].ToString(); | |
txtEmail.Text = dr["Email"].ToString(); | |
rdoState.SelectedValue = dr["CountryID"].ToString(); | |
} | |
} | |
protected void Save_Click(object sender, EventArgs e) | |
{ | |
if (!CheckIfValid()) | |
{ | |
return; | |
} | |
else | |
{ | |
string firstName = txtFirstName.Text; | |
string lastName = txtLastName.Text; | |
int genderID = Convert.ToInt32(ddlGender.SelectedValue); | |
int raceID = Convert.ToInt32(ddlRace.SelectedValue); | |
string address = txtAddress.Text; | |
string city = txtCity.Text; | |
int stateID = Convert.ToInt32(ddlState.SelectedValue); | |
string zip = txtZip.Text; | |
string phone = txtPhone.Text; | |
string email = txtEmail.Text; | |
string action = "Edit"; | |
int sellerId = (int)ViewState["SellerID"]; | |
var db = new DBAccess(); | |
int ReturnID = db.SetSeller(action, firstName, lastName, genderID, raceID, address, city, | |
stateID, zip, phone, email, sellerId); | |
if (ReturnID > 0) | |
{ | |
lblMessage2.Text = "Updated seccesfuly"; | |
} | |
else | |
{ | |
lblMessage2.Text = "Problem with SQL insert P_SetSeller"; | |
} | |
} | |
} | |
//---------------------Validation--------------------------- | |
private bool CheckIfValid() | |
{ | |
string firstName = txtFirstName.Text; | |
string lastName = txtLastName.Text; | |
int genderID = Convert.ToInt32(ddlGender.SelectedValue == null ? ddlGender.SelectedValue : "0"); | |
int raceID = Convert.ToInt32(ddlRace.SelectedValue == null ? ddlRace.SelectedValue : "0"); | |
string address = txtAddress.Text; | |
string city = txtCity.Text; | |
int stateID = Convert.ToInt32(ddlState.SelectedValue); | |
string zip = txtZip.Text; | |
string phone = txtPhone.Text; | |
string email = txtEmail.Text; | |
if (!firstName.IsValidString()) | |
{ | |
lblMessage2.Text = "Enter First Name"; | |
return false; | |
} | |
if (!lastName.IsValidString()) | |
{ | |
lblMessage2.Text = "Enter Last Name"; | |
return false; | |
} | |
if (ddlGender.SelectedIndex == 0) | |
{ | |
lblMessage2.Text = "Choose Gender"; | |
return false; | |
} | |
if (ddlRace.SelectedIndex == 0) | |
{ | |
lblMessage2.Text = "Choose Race"; | |
return false; | |
} | |
if (!address.IsValidString()) | |
{ | |
lblMessage2.Text = " Enter Address"; | |
return false; | |
} | |
if (!city.IsValidString()) | |
{ | |
lblMessage2.Text = "Enter City"; | |
return false; | |
} | |
if (ddlState.SelectedIndex <= 0) | |
{ | |
lblMessage2.Text = "Choose State"; | |
return false; | |
} | |
if (!zip.IsValidString()) | |
{ | |
lblMessage2.Text = "Please enter valid Zip"; | |
return false; | |
} | |
if (!phone.IsValidString()) | |
{ | |
lblMessage2.Text = "PLease Enter Phone#"; | |
return false; | |
} | |
if (!email.IsValidEmail()) | |
{ | |
lblMessage2.Text = "Please enter valid Email"; | |
return false; | |
} | |
return true; | |
} | |
protected void Ok_Click(object sender, EventArgs e) | |
{ | |
Response.Redirect("~/Seller.aspx"); | |
} | |
protected void Delete_Click(object sender, EventArgs e) | |
{ | |
int sellerId = (int)ViewState["SellerID"]; | |
string action = "Delete"; | |
DBAccess db = new DBAccess(); | |
int newseller = db.SetSeller(action, "", "", 0, 0, "", "", 0, "", "", "", sellerId); | |
if (newseller > 0) | |
lblMessage2.Text = "Seller was successuly deleted"; | |
} | |
} | |
} | |
//-----------------------------Seller.aspx---------------------------------------------------------------------- | |
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Seller.aspx.cs" Inherits="Auction.SellerAdd" %> | |
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"> | |
<div style="text-align: center" runat="server"> | |
<asp:Button ID="btnAddSeller" runat="server" Text="Add Seller" OnClick="btnAddSeller_Click" /> | |
</div> | |
<div style="text-align: center" runat="server" id="mnPanel" visible="false"> | |
<asp:GridView ID="gvView" runat="server" AutoGenerateColumns="False" | |
DataKeyNames = "SellerId" | |
PageSize = "3" | |
AllowPaging = "true" | |
AllowSorting = "false" | |
PagerStyle-CssClass = "pgr" | |
AlternatingRowStyle-CssClass = "alt" | |
Visible="true" | |
Width="100%" OnPageIndexChanging="gvView_PageIndexChanging" OnSelectedIndexChanged="gvView_SelectedIndexChanged" > | |
<AlternatingRowStyle CssClass="alt"></AlternatingRowStyle> | |
<Columns> | |
<asp:BoundField DataField="SellerId" | |
HeaderText="Seller Id" | |
ItemStyle-HorizontalAlign="Left" | |
ItemStyle-BorderColor="Black" | |
ReadOnly="true"> | |
<HeaderStyle CssClass="gridHeader"/> | |
<ItemStyle Width="100px" Wrap="False"/> | |
</asp:BoundField> | |
<asp:BoundField DataField="FirstName" | |
HeaderText="First Name" | |
ItemStyle-HorizontalAlign="Left" | |
ItemStyle-BorderColor="Black" | |
ReadOnly="true"> | |
<HeaderStyle CssClass="gridHeader"/> | |
<ItemStyle Width="200px" Wrap="False"/> | |
</asp:BoundField> | |
<asp:BoundField DataField="LastName" | |
HeaderText="Last Name" | |
ItemStyle-HorizontalAlign="Left" | |
ItemStyle-BorderColor="Black" | |
ReadOnly="true"> | |
<HeaderStyle CssClass="gridHeader"/> | |
<ItemStyle Width="200px" Wrap="False" /> | |
</asp:BoundField> | |
<asp:TemplateField HeaderText="Action"> | |
<ItemTemplate> | |
<asp:LinkButton ID="lnkEdit" CommandName="Edit" OnClick="Edit_Click" runat="server" Text="Edit" /> | |
<asp:LinkButton ID="lnkDetails" CommandName="Details" OnClick="Details_Click" runat="server" Text="Details" /> | |
<asp:LinkButton ID="lnkDelete" runat="server" Text="Delete" OnClick="Delete_Click"></asp:LinkButton> | |
</ItemTemplate> | |
</asp:TemplateField> | |
</Columns> | |
<PagerStyle CssClass="pgr"></PagerStyle> | |
</asp:GridView> | |
</div> | |
</asp:Content> | |
//--------------------------------------Seller.aspx.cs-------------------------------------------------------------- | |
using System; | |
using System.Collections.Generic; | |
using System.Data; | |
using System.Linq; | |
using System.Web; | |
using System.Web.UI; | |
using System.Web.UI.WebControls; | |
namespace Auction | |
{ | |
public partial class SellerAdd : System.Web.UI.Page | |
{ | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
if (!IsPostBack) | |
{ | |
mnPanel.Visible = true; | |
BindGridView(); | |
} | |
} | |
protected void btnAddSeller_Click(object sender, EventArgs e) | |
{ | |
Response.Redirect("~/SellerAdd.aspx"); | |
} | |
protected void Edit_Click(object sender, EventArgs e) | |
{ | |
int SellerID = GetId(sender); | |
Response.Redirect("~/SellerMaintenance.aspx?SellerID=" + SellerID + "&Action=Edit"); | |
} | |
protected void Details_Click(object sender, EventArgs e) | |
{ | |
int SellerID = GetId(sender); | |
Response.Redirect("~/SellerMaintenance.aspx?SellerID=" + SellerID + "&Action=Details"); | |
} | |
protected void Delete_Click(object sender, EventArgs e) | |
{ | |
int SellerID = GetId(sender); | |
Response.Redirect("~/SellerMaintenance.aspx?SellerID=" + SellerID + "&Action=Delete"); | |
} | |
private int GetId(object sender) | |
{ | |
GridViewRow gvRow = (GridViewRow)((Control)sender).Parent.Parent; | |
int index = gvRow.RowIndex; | |
int Id = ((int)this.gvView.DataKeys[index]["SellerId"]); | |
return Id; | |
} | |
protected void gvView_PageIndexChanging(object sender, GridViewPageEventArgs e) | |
{ | |
gvView.PageIndex = e.NewPageIndex++; | |
BindGridView(); | |
} | |
public void BindGridView() | |
{ | |
DBAccess db = new DBAccess(); | |
DataTable dt = db.GetSeller(); | |
if (dt != null) | |
{ | |
gvView.DataSource = dt; | |
gvView.DataBind(); | |
mnPanel.Visible = true; | |
} | |
} | |
} | |
} | |
//-------------------------------------DBAccess------------------------------------------------------- | |
using System; | |
using System.Collections.Generic; | |
using System.Configuration; | |
using System.Data; | |
using System.Data.SqlClient; | |
using System.Linq; | |
using System.Web; | |
using System.Web.UI.WebControls; | |
namespace Auction | |
{ | |
public class DBAccess | |
{ | |
public List<List<ReaderHelper>> ListOfReader { get; set; } | |
public DBAccess() | |
{ | |
ListOfReader = new List<List<ReaderHelper>>(); | |
} | |
//-----------LOGIN-----DB----------------------- | |
internal int AthenticateUser(string userName, string password) | |
{ | |
int userId = 0; | |
{ | |
using (SqlConnection cn = new SqlConnection()) | |
{ | |
cn.ConnectionString = GetConnectionStr(); | |
cn.Open(); | |
using (SqlCommand cmd = new SqlCommand("spAthenticateUser")) | |
{ | |
cmd.Connection = cn; | |
cmd.CommandType = CommandType.StoredProcedure; | |
cmd.Parameters.Add("@UserName", SqlDbType.VarChar).Value = userName; | |
cmd.Parameters.Add("@password", SqlDbType.VarChar).Value = password; | |
userId = Convert.ToInt32(cmd.ExecuteScalar()); | |
} | |
cn.Close(); | |
} | |
return userId; | |
} | |
} | |
//-----------------P_GetSeller------Bind GridView | |
internal DataTable GetSeller(int Id = 0) | |
{ | |
DataTable dt = null; | |
using (SqlConnection cn = new SqlConnection()) | |
{ | |
cn.ConnectionString = GetConnectionStr(); | |
cn.Open(); | |
using (SqlCommand cmd = new SqlCommand("P_GetSeller")) | |
{ | |
cmd.Connection = cn; | |
cmd.CommandType = CommandType.StoredProcedure; | |
if (Id > 0) | |
cmd.Parameters.Add("@SellerID", SqlDbType.Int).Value = Id; | |
dt = LoadTable(cmd); | |
} | |
cn.Close(); | |
} | |
return dt; | |
} | |
//---------------save Param in SQL---------- | |
public int SetMakeModel(string make, string model, int ddlmake, int ddlmodel) | |
{ | |
SqlConnection cn = new SqlConnection(); | |
SqlCommand cmd = new SqlCommand("P_SetMakeModel", cn); | |
int MakeModelId = 0; | |
try | |
{ | |
cn.ConnectionString = GetConnectionStr(); | |
cn.Open(); | |
cmd.Parameters.Add("@MakeModelId", SqlDbType.Int).Direction = ParameterDirection.Output; | |
cmd.ExecuteNonQuery(); | |
MakeModelId = (int)cmd.Parameters["@MakeModelId"].Value; | |
cn.Close(); | |
return MakeModelId; | |
} | |
catch (Exception ex) | |
{ | |
cn.Close(); | |
return MakeModelId; | |
} | |
finally | |
{ | |
cn.Close(); | |
} | |
} | |
//--------P_SetSeller--------Resieve Info From SQL----------- | |
public DataTable SetSellers() | |
{ | |
DataTable dt = null; | |
using (SqlConnection cn = new SqlConnection()) | |
{ | |
cn.ConnectionString = GetConnectionStr(); | |
cn.Open(); | |
using (SqlCommand cmd = new SqlCommand("P_SetSeller")) | |
{ | |
cmd.Connection = cn; | |
cmd.CommandType = CommandType.StoredProcedure; | |
dt = LoadTable(cmd); | |
} | |
cn.Close(); | |
} | |
return dt; | |
} | |
//-------------GridView----get Info from SQL------- | |
internal DataTable GetBuyerDetails(int Id) | |
{ | |
DataTable dt = null; | |
using (SqlConnection cn = new SqlConnection()) | |
{ | |
cn.ConnectionString = GetConnectionStr(); | |
cn.Open(); | |
using (SqlCommand cmd = new SqlCommand("P_GetBuyerDetails")) | |
{ | |
cmd.Connection = cn; | |
cmd.CommandType = CommandType.StoredProcedure; | |
cmd.Parameters.Add("@buyerID", SqlDbType.Int).Value = Id; | |
dt = LoadTable(cmd); | |
} | |
cn.Close(); | |
} | |
return dt; | |
} | |
//--------P_SetBuyer--------Resieve Info From SQL----------- | |
public DataTable SetBuyer() | |
{ | |
DataTable dt = null; | |
using (SqlConnection cn = new SqlConnection()) | |
{ | |
cn.ConnectionString = GetConnectionStr(); | |
cn.Open(); | |
using (SqlCommand cmd = new SqlCommand("P_SetBuyer")) | |
{ | |
cmd.Connection = cn; | |
cmd.CommandType = CommandType.StoredProcedure; | |
dt = LoadTable(cmd); | |
} | |
cn.Close(); | |
} | |
return dt; | |
} | |
//------------Cinnection------------ | |
private string GetConnectionStr() | |
{ | |
string StrCon = ConfigurationManager.ConnectionStrings["SQL_Connection"].ConnectionString; | |
return StrCon; | |
} | |
//----------Fill DataTable-------- | |
private DataTable LoadTable(SqlCommand cmd) | |
{ | |
DataTable dt = new DataTable(); | |
SqlDataAdapter adapter = new SqlDataAdapter(cmd); | |
adapter.Fill(dt); | |
return dt; | |
} | |
//---------Fill DataSet------------ | |
private DataSet LoadDataSet(SqlCommand cmd) | |
{ | |
DataSet ds = new DataSet(); | |
SqlDataAdapter adapter = new SqlDataAdapter(cmd); | |
adapter.Fill(ds); | |
return ds; | |
} | |
//-------Load DDL Gender, Race and States------------ | |
public DataSet GetLookUp(ref List<List<ReaderHelper>> entity) | |
{ | |
DataSet ds = null; | |
using (SqlConnection cn = new SqlConnection()) | |
{ | |
cn.ConnectionString = GetConnectionStr(); | |
cn.Open(); | |
// Getting Multiple Select statments | |
using (SqlCommand cmd = new SqlCommand("P_GetLookUp")) | |
{ | |
cmd.Connection = cn; | |
using (IDataReader reader = cmd.ExecuteReader()) | |
{ | |
var count = reader.FieldCount; // To see Results | |
List<ReaderHelper> table1 = new List<ReaderHelper>(); | |
while (reader.Read()) //.read() <-- single select in SQL | |
{ | |
table1.Add(new ReaderHelper { Id = (int)reader["GenderID"], Name = (string)reader["Gender"] }); | |
} | |
entity.Add(table1); | |
reader.NextResult();//<----- take to another select in SQL | |
var Count = reader.FieldCount; | |
List<ReaderHelper> table2 = new List<ReaderHelper>(); | |
while (reader.Read()) | |
{ | |
table2.Add(new ReaderHelper { Id = (int)reader["RaceID"], Name = (string)reader["Race"] }); | |
} | |
entity.Add(table2); | |
reader.NextResult();//<----- take to another select in SQL | |
var State = reader.FieldCount; | |
List<ReaderHelper> table3 = new List<ReaderHelper>(); | |
while (reader.Read()) | |
{ | |
table3.Add(new ReaderHelper { Id = Convert.ToInt32(reader["StateId"]), Name = (string)reader["State"] }); | |
} | |
entity.Add(table3); | |
reader.NextResult();//<----- take to another select in SQL | |
} | |
ds = LoadDataSet(cmd); | |
} | |
cn.Close(); | |
} | |
return ds; | |
} | |
public DataTable GetBuyerInfo(int Id) | |
{ | |
DataTable rtn = null; | |
SqlConnection cn = new SqlConnection(); | |
SqlCommand cmd = new SqlCommand("P_GetBuyerInfo", cn); | |
try | |
{ | |
cn.ConnectionString = GetConnectionStr(); | |
cn.Open(); | |
cmd.CommandType = CommandType.StoredProcedure; | |
cmd.Parameters.Add("@buyerID", SqlDbType.Int).Value = Id; | |
cmd.ExecuteNonQuery(); | |
rtn = LoadTable(cmd); | |
cn.Close(); | |
return rtn; | |
} | |
catch (Exception ex) | |
{ | |
cn.Close(); | |
return rtn; | |
} | |
finally | |
{ | |
cn.Close(); | |
} | |
} | |
// -------------- Papulate DropDown List Buyer names ONLY -------------------- | |
public DataTable GetBuyerForEdit() | |
{ | |
DataTable dt = null; | |
using (SqlConnection cn = new SqlConnection()) | |
{ | |
cn.ConnectionString = GetConnectionStr(); | |
cn.Open(); | |
using (SqlCommand cmd = new SqlCommand("P_GetBuyerForEdit", cn)) | |
{ | |
cmd.CommandType = CommandType.StoredProcedure; | |
dt = LoadTable(cmd); | |
} | |
cn.Close(); | |
} | |
return dt; | |
} | |
//----------------Papulate ddlModel ----------------------- | |
public DataTable SatModel() | |
{ | |
DataTable dt = null; | |
using (SqlConnection cn = new SqlConnection()) | |
{ | |
cn.ConnectionString = GetConnectionStr(); | |
cn.Open(); | |
using (SqlCommand cmd = new SqlCommand("P_SetMakeModel", cn)) | |
{ | |
cmd.CommandType = CommandType.StoredProcedure; | |
dt = LoadTable(cmd); | |
} | |
cn.Close(); | |
} | |
return dt; | |
} | |
//----------------Papulate ddlMake ---------------------- | |
public DataTable SatMake() | |
{ | |
DataTable dt = null; | |
using (SqlConnection cn = new SqlConnection()) | |
{ | |
cn.ConnectionString = GetConnectionStr(); | |
cn.Open(); | |
using (SqlCommand cmd = new SqlCommand("P_SetMakeModel", cn)) | |
{ | |
cmd.CommandType = CommandType.StoredProcedure; | |
dt = LoadTable(cmd); | |
} | |
cn.Close(); | |
} | |
return dt; | |
} | |
// ---------SetBuyer------save and send Paeameners into SQL ---------- | |
public int SetBuyer(string firstName, string lastName, int genderID, int raceID, string address, string city, | |
int stateID, string zip, string phone, string email, int buyerid = 0) | |
{ | |
SqlConnection cn = new SqlConnection(); | |
SqlCommand cmd = new SqlCommand("P_SetBuyer", cn); | |
int NewBuyerID = 0; //returning ID from SQL | |
try | |
{ | |
cn.ConnectionString = GetConnectionStr(); | |
cn.Open(); | |
cmd.CommandType = CommandType.StoredProcedure; | |
cmd.Parameters.Add("@firstName", SqlDbType.VarChar).Value = firstName; | |
cmd.Parameters.Add("@lastName", SqlDbType.VarChar).Value = lastName; | |
cmd.Parameters.Add("@genderID", SqlDbType.Int).Value = genderID; | |
cmd.Parameters.Add("@raceID", SqlDbType.Int).Value = raceID; | |
cmd.Parameters.Add("@address", SqlDbType.VarChar).Value = address; | |
cmd.Parameters.Add("@city", SqlDbType.VarChar).Value = city; | |
cmd.Parameters.Add("@stateID", SqlDbType.Int).Value = stateID; | |
cmd.Parameters.Add("@zip", SqlDbType.VarChar).Value = zip; | |
cmd.Parameters.Add("@phone", SqlDbType.VarChar).Value = phone; | |
cmd.Parameters.Add("@email", SqlDbType.VarChar).Value = email; | |
//if(buyerid > 0) // ask Liza | |
cmd.Parameters.Add("@BuyerId", SqlDbType.Int).Value = buyerid; // ask Liza | |
cmd.Parameters.Add("@NewBuyerID", SqlDbType.Int).Direction = ParameterDirection.Output;//ask liza | |
cmd.ExecuteNonQuery(); | |
NewBuyerID = (int)cmd.Parameters["@NewBuyerID"].Value; | |
cn.Close(); | |
return NewBuyerID; | |
} | |
catch (Exception ex) | |
{ | |
cn.Close(); | |
return NewBuyerID; | |
} | |
finally | |
{ | |
cn.Close(); | |
} | |
} | |
public int DeleteSeller(int Sellerid) | |
{ | |
SqlConnection cn = new SqlConnection(); | |
SqlCommand cmd = new SqlCommand("P_DelSeller", cn); | |
int delSeller = 0; //returning ID from SQL | |
try | |
{ | |
cn.ConnectionString = GetConnectionStr(); | |
cn.Open(); | |
cmd.CommandType = CommandType.StoredProcedure; | |
cmd.Parameters.Add("@SellerId", SqlDbType.Int).Value = Sellerid; | |
cmd.Parameters.Add("@NewSellerID", SqlDbType.Int).Direction = ParameterDirection.Output; | |
cmd.ExecuteNonQuery(); | |
delSeller = (int)cmd.Parameters["@NewSellerID"].Value; | |
cn.Close(); | |
return delSeller; | |
} | |
catch (Exception ex) | |
{ | |
cn.Close(); | |
return delSeller; | |
} | |
finally | |
{ | |
cn.Close(); | |
} | |
} | |
// ---------SetSeller------save and send Paeameners into SQL ---------- | |
public int SetSeller(string action, string firstName, string lastName, int genderID, int raceID, string address, string city, | |
int stateID, string zip, string phone, string email, int ? Sellerid = null) | |
{ | |
SqlConnection cn = new SqlConnection(); | |
SqlCommand cmd = new SqlCommand("P_SetSeller", cn); | |
int NewSellerID = 0; //returning ID from SQL | |
try | |
{ | |
cn.ConnectionString = GetConnectionStr(); | |
cn.Open(); | |
cmd.CommandType = CommandType.StoredProcedure; | |
cmd.Parameters.Add("@Action", SqlDbType.VarChar).Value = action; | |
cmd.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = firstName; | |
cmd.Parameters.Add("@LastName", SqlDbType.VarChar).Value = lastName; | |
cmd.Parameters.Add("@GenderID", SqlDbType.Int).Value = genderID; | |
cmd.Parameters.Add("@RaceID", SqlDbType.Int).Value = raceID; | |
cmd.Parameters.Add("@Address", SqlDbType.VarChar).Value = address; | |
cmd.Parameters.Add("@City", SqlDbType.VarChar).Value = city; | |
cmd.Parameters.Add("@StateID", SqlDbType.Int).Value = stateID; | |
cmd.Parameters.Add("@Zip", SqlDbType.VarChar).Value = zip; | |
cmd.Parameters.Add("@Phone", SqlDbType.VarChar).Value = phone; | |
cmd.Parameters.Add("@Email", SqlDbType.VarChar).Value = email; | |
cmd.Parameters.Add("@SellerId", SqlDbType.Int).Value = Sellerid; | |
cmd.Parameters.Add("@NewSellerID", SqlDbType.Int).Direction = ParameterDirection.Output; | |
cmd.ExecuteNonQuery(); | |
NewSellerID = (int)cmd.Parameters["@NewSellerID"].Value; | |
cn.Close(); | |
return NewSellerID; | |
} | |
catch (Exception ex) | |
{ | |
cn.Close(); | |
return NewSellerID; | |
} | |
finally | |
{ | |
cn.Close(); | |
} | |
} | |
public DataTable GetStates(int countryID) | |
{ | |
DataTable dt = null; | |
using (SqlConnection cn = new SqlConnection()) | |
{ | |
cn.ConnectionString = GetConnectionStr(); | |
cn.Open(); | |
using (SqlCommand cmd = new SqlCommand("P_GetStates")) | |
{ | |
cmd.Connection = cn; | |
cmd.CommandType = CommandType.StoredProcedure; | |
cmd.Parameters.Add(new SqlParameter("@CountryID", SqlDbType.Int)).Value = countryID; | |
dt = LoadTable(cmd); | |
} | |
cn.Close(); | |
} | |
return dt; | |
} | |
} | |
} | |
public class ReaderHelper | |
{ | |
public int Id { get; set; } | |
public string Name { get; set; } | |
} | |
//------------------------------------Web.convig--------------------------------------------------------------- | |
<!--Connection Natasha--> | |
<connectionStrings> | |
<add name="SQL_Connection" connectionString="Data Source= (Local); Initial Catalog = Auction; Integrated Security=True" | |
providerName="System.Data.SqlClient" /> | |
<add name="AuctionConnectionString" connectionString="Data Source=(Local);Initial Catalog=Auction;Integrated Security=True" | |
providerName="System.Data.SqlClient" /> | |
</connectionStrings> | |
//-------------------------------------Valiadator---------------------------------------------- | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using System.Web.UI.WebControls; | |
namespace Auction | |
{ | |
public static class Validator | |
{ | |
public static bool IsValidString(this string val) | |
{ | |
return (!string.IsNullOrEmpty(val)) ? true : false; | |
} | |
public static bool IsDecimal(this string val) | |
{ | |
decimal dc; | |
return decimal.TryParse(val, out dc) ? true : false; | |
} | |
public static bool IsDouble(this string val) | |
{ | |
double db; | |
return double.TryParse(val, out db) ? true : false; | |
} | |
public static bool IsInt(this string val) | |
{ | |
int x; | |
return int.TryParse(val, out x) ? true : false; | |
} | |
public static bool IsValidEmail(this string email) | |
{ | |
try | |
{ | |
var addr = new System.Net.Mail.MailAddress(email); | |
return addr.Address == email; | |
} | |
catch | |
{ | |
return false; | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment