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.Data;
public partial class ProductDetail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] GetCompletionList(string prefixText, int count, string contextKey)
{
SqlConnection conn = new SqlConnection("Data Source=LGTUSHI-PC\\SQLTUSHI;AttachDbFilename=D:\\da\\DataDictionary.mdf;Integrated Security=True");
conn.Open();
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter("select ProductName from ProductDetails", conn);
sda.Fill(ds, "ProductDetails");
conn.Close();
string[] main = new string[0];
for (int i = 0; i < ds.Tables[0].Rows.Count - 1; i++)
{
if (ds.Tables[0].Rows[i].ItemArray[0].ToString().ToLower().StartsWith(prefixText.ToLower()))
{
Array.Resize(ref main, main.Length + 1);
main[main.Length - 1] = ds.Tables[0].Rows[i].ItemArray[0].ToString();
if (main.Length == 10)
break;
}
}
Array.Sort(main);
return main;
}
protected void btnSave_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=LGTUSHI-PC\\SQLTUSHI;AttachDbFilename=D:\\da\\DataDictionary.mdf;Integrated Security=True");
conn.Open();
string Query = "if not exists(select * from ProductDetails where ProductName ='" + txtProductName.Text.Trim() + "')insert into ProductDetails (ProductName,ModelNumber,CompanyName,Description,Color,Quantity,Price,SaleInPercentage,SalePrice,StandardPrice,PrimePrice,AveragePrice)values('" + txtProductName.Text.Trim() + "','" + txtmodelnumber + "','" +txtCompanyName.Text.Trim() + "','" + txtDescription.Text.Trim() + "','" + txtColor.Text.Trim() + "','" + txtQuantity.Text.Trim() + "','" + txtPrice.Text.Trim() + "','" + txtSaleinPercantage.Text.Trim() + "','" + txtSalePrice.Text.Trim() + "','" + txtStandardPrice.Text.Trim() + "','" + txtPrimePrice.Text.Trim() + "','" + txtAveragePrice.Text.Trim() + "') ";
SqlCommand cmd = new SqlCommand(Query,conn);
if (cmd.ExecuteNonQuery() > 0)
{
lblMessage.Text = "Data Inserted Successfully";
}
else
{
lblMessage.Text = "Error ";
}
conn.Close();
}
}
my aspx page code :
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ProductDetail.aspx.cs" Inherits="ProductDetail" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 80%;
}
.style2
{
height: 20px;
}
.form_error
.style3
{
width: 151px;
}
.style4
{
height: 20px;
width: 151px;
}
.style5
{
width: 210px;
}
.style6
{
height: 20px;
width: 210px;
}
</style>
</head>
<body>
<script language="javascript" type="text/javascript">
function sumCalc() {
var _txtPrice = document.getElementById('<%= txtPrice.ClientID %>');
var _txtSaleinPercantage = document.getElementById('<%= txtSaleinPercantage.ClientID %>');
var _txtSalePrice = document.getElementById('<%= txtSalePrice.ClientID %>');
var t1 = 0, t2 = 0;
if (_txtPrice != "") t1 = _txtPrice.value;
if (_txtSaleinPercantage != "") t2 = _txtSaleinPercantage.value;
var t3 = (parseInt(t2) * parseInt(t1));
_txtSalePrice.value = (parseInt(t1) + (t3 / 100));
}
function colorChanged(sender) {
sender.get_element().style.color = "#" + sender.get_selectedColor();
}
</script>
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="toolkit1" runat="server"></asp:ToolkitScriptManager>
<table class="style1">
<tr>
<td colspan="2">
<h1>
Product Detail</h1>
</td>
<td colspan="2" style="text-align: center">
<asp:Image ID="Image1" runat="server" Height="154px" ImageUrl="~/lg.gif"
style="text-align: right" />
</td>
</tr>
<tr>
<td class="style5">
</td>
<td class="style3">
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style5">
ProductName</td>
<td class="style3">
:</td>
<td>
<asp:TextBox ID="txtProductName" runat="server" Height="23px" Width="300px"></asp:TextBox>
<asp:AutoCompleteExtender ID="txtProductName_AutoCompleteExtender"
runat="server" CompletionSetCount="1" DelimiterCharacters="" Enabled="True"
FirstRowSelected="True" ServiceMethod="GetCompletionList" ServicePath=""
TargetControlID="txtProductName" UseContextKey="True">
</asp:AutoCompleteExtender>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvProductName" runat="server"
ControlToValidate="txtProductName" Display="Dynamic"
ErrorMessage="Enter ProductName" ForeColor="Red" SetFocusOnError="True"
ValidationGroup="Save"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style5">
ModelNumber</td>
<td class="style3">
:</td>
<td>
<asp:TextBox ID="txtmodelnumber" runat="server" Height="23px" Width="300px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvmodelnumber" runat="server"
ControlToValidate="txtmodelnumber" Display="Dynamic"
ErrorMessage="Enter ModelNumber" ForeColor="Red" SetFocusOnError="True"
ValidationGroup="Save"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style5">
CompanyName</td>
<td class="style3">
:</td>
<td>
<asp:TextBox ID="txtCompanyName" runat="server" Height="23px" Width="300px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvCompanyName" runat="server"
ControlToValidate="txtCompanyName" Display="Dynamic"
ErrorMessage="Enter CompanyName" ForeColor="Red" ValidationGroup="Save"
SetFocusOnError="True"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style6">
Description</td>
<td class="style4">
:</td>
<td class="style2">
<asp:TextBox ID="txtDescription" runat="server" Height="23px" Width="300px"></asp:TextBox>
</td>
<td class="style2">
</td>
</tr>
<tr>
<td class="style5">
Color
</td>
<td class="style3">
:</td>
<td>
<asp:TextBox ID="txtColor" runat="server" Height="23px" Width="300px"></asp:TextBox>
<asp:ColorPickerExtender runat="server" ID="ColorPickerExtender1" TargetControlID="txtColor" SampleControlID="txtsample"></asp:ColorPickerExtender>
<asp:TextBox ID="txtsample" runat="server" Width="30px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvColor" runat="server"
ControlToValidate="txtColor" Display="Dynamic" ErrorMessage="Enter Color"
ForeColor="Red" ValidationGroup="Save" SetFocusOnError="True"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style5">
Quantity</td>
<td class="style3">
:</td>
<td>
<asp:TextBox ID="txtQuantity" runat="server" Height="23px" Width="300px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvQuantity" runat="server"
ControlToValidate="txtQuantity" Display="Dynamic" ErrorMessage="Enetr Quantity"
ForeColor="Red" SetFocusOnError="True" ValidationGroup="Save"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="refQuantity" runat="server"
ControlToValidate="txtQuantity" Display="Dynamic" ErrorMessage="Enter In Digit"
ForeColor="Red" SetFocusOnError="True" ValidationExpression="^\d+$"
ValidationGroup="Save"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="style5">
Price</td>
<td class="style3">
:</td>
<td>
<asp:TextBox ID="txtPrice" runat="server" Height="23px" Width="300px" onkeypress="sumCalc();"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvPrice" runat="server"
ControlToValidate="txtPrice" ErrorMessage="Enter Price" ForeColor="Red"
SetFocusOnError="True" ValidationGroup="Save"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="refPrice" runat="server"
ControlToValidate="txtPrice" Display="Dynamic" ErrorMessage="Enter In Digit"
ForeColor="Red" SetFocusOnError="True" ValidationExpression="^\d+$"
ValidationGroup="Save"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="style5">
SaleInPercantage</td>
<td class="style3">
:</td>
<td>
<asp:TextBox ID="txtSaleinPercantage" runat="server" Height="23px"
Width="300px" onkeypress="sumCalc();"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvSaleinpercentage" runat="server"
ControlToValidate="txtSaleinPercantage" Display="Dynamic"
ErrorMessage="Enter SaleInPercentage" ForeColor="Red"
ValidationGroup="Save" SetFocusOnError="True"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revsaleinpercentage" runat="server"
ControlToValidate="txtSaleinPercantage" Display="Dynamic"
ErrorMessage="Enter digit" ForeColor="Red" ValidationExpression="^\d+$"
ValidationGroup="Save"></asp:RegularExpressionValidator>
<asp:RangeValidator ID="rvsaleinpercentage" runat="server"
ControlToValidate="txtSaleinPercantage" Display="Dynamic"
ErrorMessage="Enter percentage between 0 to 100" ForeColor="Red"
MaximumValue="100" MinimumValue="0" SetFocusOnError="True" Type="Integer"
ValidationGroup="Save"></asp:RangeValidator>
</td>
</tr>
<tr>
<td class="style5">
SalePrice</td>
<td class="style3">
:</td>
<td>
<asp:TextBox ID="txtSalePrice" runat="server" Height="23px" Width="300px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvSalePrice" runat="server"
ControlToValidate="txtSalePrice" Display="Dynamic"
ErrorMessage="Enter SalePrice" ForeColor="Red" SetFocusOnError="True"
ValidationGroup="Save"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="refSalePrice" runat="server"
ControlToValidate="txtSalePrice" Display="Dynamic"
ErrorMessage="Enter In Digit" ForeColor="Red" SetFocusOnError="True"
ValidationExpression="^\d+$" ValidationGroup="Save"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="style6">
PrimePrice</td>
<td class="style4">
:</td>
<td class="style2">
<asp:TextBox ID="txtPrimePrice" runat="server" Height="23px" Width="300px"></asp:TextBox>
</td>
<td class="style2">
<asp:RegularExpressionValidator ID="refPrimeprice" runat="server"
ControlToValidate="txtPrimePrice" Display="Dynamic"
ErrorMessage="Enter In Digit" ForeColor="Red" SetFocusOnError="True"
ValidationExpression="^\d+$" ValidationGroup="Save"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="style5">
SatndardPrice</td>
<td class="style3">
:</td>
<td>
<asp:TextBox ID="txtStandardPrice" runat="server" Height="23px" Width="300px"></asp:TextBox>
</td>
<td>
<asp:RegularExpressionValidator ID="refStandardPrice" runat="server"
ControlToValidate="txtStandardPrice" Display="Dynamic"
ErrorMessage="Enter In Digit" ForeColor="Red" SetFocusOnError="True"
ValidationExpression="^\d+$" ValidationGroup="Save"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="style5">
AveragePrice</td>
<td class="style3">
:</td>
<td>
<asp:TextBox ID="txtAveragePrice" runat="server" Height="23px" Width="300px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvAveragePrice" runat="server"
ControlToValidate="txtAveragePrice" Display="Dynamic"
ErrorMessage="Enter AveragePrice" ForeColor="Red" SetFocusOnError="True"
ValidationGroup="Save"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="refAveragePrice" runat="server"
ControlToValidate="txtAveragePrice" Display="Dynamic"
ErrorMessage="Enter In Digit" ForeColor="Red" SetFocusOnError="True"
ValidationExpression="^\d+$" ValidationGroup="Save"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="style5">
</td>
<td class="style3">
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style5">
<asp:Button ID="btnupdate" runat="server" Text="Update" Height="26px"
Width="65px" />
</td>
<td class="style3">
</td>
<td>
<asp:Button ID="btnSave" runat="server" Text="Save" Height="26px"
onclick="btnSave_Click" ValidationGroup="Save" Width="65px" />
<asp:Button ID="btnCancel" runat="server" Height="26px" Text="Cancel"
Width="65px" />
</td>
<td>
</td>
</tr>
<tr>
<td class="style5">
</td>
<td class="style3">
</td>
<td>
<asp:Label ID="lblMessage" runat="server"></asp:Label>
</td>
<td>
</td>
</tr>
<tr>
<td class="style5">
</td>
<td class="style3">
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
<div>
</div>
</form>
</body>
</html>