<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="ProductGrid.aspx.cs" Inherits="ProductGrid" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script type = "text/javascript">
function MouseEvents(objRef, evt) {
var checkbox = objRef.getElementsByTagName("input")[0];
if (evt.type == "mouseover") {
objRef.style.backgroundColor = "orange";
}
else {
if (checkbox.checked) {
objRef.style.backgroundColor = "aqua";
}
else if (evt.type == "mouseout") {
if (objRef.rowIndex % 2 == 0) {
objRef.style.backgroundColor = "white";
}
else {
objRef.style.backgroundColor = "#E6E6E6";
}
}
}
}
</script>
<%----%>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<div class="contentHeader">
<br />
<br />
<asp:Label ID="lbllistofprd" Text="List of Products" runat="server" ></asp:Label>
<hr />
</div>
<table align="right" >
<%----%>
<tr>
<td >
<%----%>
<asp:Button ID="btn_addProductDetails" runat="server" Text=" + Add Items " CssClass="button"
Height="40px" Font-Bold="True"
Enabled="False" Width="125px" OnClientClick="return displayFancybox('ProductItemsDetails.aspx');" /><%----%></td>
<%----%>
<td>
<asp:Button ID="btn_addNewProduct"
runat="server" Text="+ Add New Product" CssClass="addButton"
Font-Bold="True" Height="40px" OnClientClick="return displayFancybox('NewProduct.aspx');" /></td>
<%----%>
<td><asp:Button ID="btn_delProduct" runat="server" Text=" X Delete " CssClass="button"
Font-Bold="True" Height="40px"
Enabled="False" Width="100px" onclick="btn_delProduct_Click1"></asp:Button>
<asp:ConfirmButtonExtender ID="btn_delProduct_ConfirmButtonExtender"
runat="server" ConfirmText="are you sure to delete product" Enabled="True" TargetControlID="btn_delProduct">
</asp:ConfirmButtonExtender>
</td>
<td><asp:Button ID="btnUpdate"
runat="server" Text="Edit" CssClass="button"
Font-Bold="True" Height="40px" Width="100px"
Enabled="False" OnClientClick="return displayFancybox('NewProduct.aspx?U=');" ></asp:Button></td>
<%----%>
</tr>
</table>
<table style="height:100px; width: 100%; padding:10px;">
<tr ><td align="center">
<asp:GridView ID="GVProduct" runat="server" AutoGenerateColumns="False" CssClass="datatable "
GridLines ="None" style="margin-right: 50px" CellPadding="4" CellSpacing="1"
Font-Size="Small" BackColor="#E6E6E6" ForeColor="#0B3861"
AllowPaging="True" PageSize ="15"
Width="100%"
onrowcreated="GVProduct_RowCreated"
onrowdatabound="GVProduct_RowDataBound" ondatabound="GVProduct_DataBound"
onpageindexchanging="GVProduct_PageIndexChanging1"
onselectedindexchanged="GVProduct_SelectedIndexChanged" >
<%----%>
<AlternatingRowStyle BackColor ="White" />
<%----%>
<Columns>
<asp:TemplateField ControlStyle-Width="15px" ItemStyle-HorizontalAlign="Center">
<HeaderTemplate>Select</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkselect" runat="server" AutoPostBack="true"
OnCheckedChanged="chkselect_CheckedChanged" />
<asp:MutuallyExclusiveCheckBoxExtender ID="chkselect_MutuallyExclusiveCheckBoxExtender"
runat="server" Enabled="True" Key="gridchk" TargetControlID="chkselect">
</asp:MutuallyExclusiveCheckBoxExtender>
</ItemTemplate>
<ControlStyle Width="15px"></ControlStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Product Name" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="productname" Text='<%# Eval("product_name") %>' runat="server" CssClass="paddingItemDes"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="product_description"
HeaderText="Product Description" SortExpression="roduct_description"
ItemStyle-HorizontalAlign="Left" ItemStyle-CssClass="paddingItemDes" >
<ItemStyle HorizontalAlign="Left" CssClass="paddingItemDes"></ItemStyle>
</asp:BoundField>
<%----%>
<asp:TemplateField HeaderText="In Stock" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="instock" runat="server"
Text='<%# Eval("Stock") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Committed" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="committed" runat="server"
Text='<%# Eval("Commited") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="On Order" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="onorder" runat="server"
Text='<%# Eval("Inorder") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Wholesale" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="wholesale" runat="server"
Text='<%# Eval("wholesalePrice") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<%----%>
<%----%>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#0078AE" HorizontalAlign="Right" CssClass ="margin5x " />
<PagerStyle BackColor="#0078AE" HorizontalAlign="Right" CssClass="paddingItemDes" Width ="100%" Height ="25px" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333"/>
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White"/>
<EditRowStyle BackColor="#0078AE" />
<AlternatingRowStyle BackColor="White"/>
<PagerTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Page" CommandArgument="First" CssClass="Linkbutton">First</asp:LinkButton>
<asp:Label ID="pmore" runat="server" Text=""></asp:Label>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="Page" CommandArgument="Prev" CssClass="Linkbutton">Pre</asp:LinkButton>
<asp:LinkButton ID="p0" runat="server" CssClass="Linkbutton">LinkButton</asp:LinkButton>
<asp:LinkButton ID="p1" runat="server" CssClass="Linkbutton">LinkButton</asp:LinkButton>
<asp:LinkButton ID="p2" runat="server" CssClass="Linkbutton">LinkButton</asp:LinkButton>
<asp:Label ID="CurrentPage" runat="server" Text="Label" ForeColor ="#EEE000" Font-Size ="Medium" ></asp:Label>
<asp:LinkButton ID="p4" runat="server" CssClass="Linkbutton">LinkButton</asp:LinkButton>
<asp:LinkButton ID="p5" runat="server" CssClass="Linkbutton">LinkButton</asp:LinkButton>
<asp:LinkButton ID="p6" runat="server" CssClass="Linkbutton">LinkButton</asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server" CommandName="Page" CommandArgument="Next" CssClass="Linkbutton">Next</asp:LinkButton>
<asp:Label ID="nmore" runat="server" Text=""></asp:Label>
<asp:LinkButton ID="LinkButton4" runat="server" CommandName="Page" CommandArgument="Last" CssClass="Linkbutton">Last</asp:LinkButton>
</PagerTemplate>
<%----%>
</asp:GridView>
</td> </tr>
<asp:Label ID="lblresult" runat="server" Text=""></asp:Label>
<asp:Literal runat="server" ID="Literal1" />
</table>
</asp:Content>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Xml;
public partial class ProductGrid : System.Web.UI.Page
{
static string PN;
static DataSet ds;
SqlConnection con = new SqlConnection(IMS.ConnectionString.getValue());
protected void Page_Load(object sender, EventArgs e)
{
sessions.getsessions();
btn_delProduct.Enabled=btn_addProductDetails.Enabled=btnUpdate.Enabled = false;
if (Page.IsPostBack == false)
{
getdata();
}
}
public string getVal()
{
return PN;
}
public void getdata()
{
SqlDataAdapter da = new SqlDataAdapter("select * from product", con);
ds = new DataSet();
da.Fill(ds, "Product");
GVProduct.DataSource = ds.Tables["Product"];
GVProduct.DataBind();
}
public string getPName()
{
return IMSNiana.ProductName;
}
protected void GVProduct_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#EEFF00'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.originalstyle;");
}
if (e.Row.RowType == DataControlRowType.Pager)
{
GridViewRow gvr = e.Row;
LinkButton lb = (LinkButton)gvr.Cells[0].FindControl("p0");
lb.Command += new CommandEventHandler(lb_Command);
lb = (LinkButton)gvr.Cells[0].FindControl("p1");
lb.Command += new CommandEventHandler(lb_Command);
lb = (LinkButton)gvr.Cells[0].FindControl("p2");
lb.Command += new CommandEventHandler(lb_Command);
lb = (LinkButton)gvr.Cells[0].FindControl("p4");
lb.Command += new CommandEventHandler(lb_Command);
lb = (LinkButton)gvr.Cells[0].FindControl("p5");
lb.Command += new CommandEventHandler(lb_Command);
lb = (LinkButton)gvr.Cells[0].FindControl("p6");
lb.Command += new CommandEventHandler(lb_Command);
}
}
protected void GVProduct_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "MouseEvents(this, event)");
e.Row.Attributes.Add("onmouseout", "MouseEvents(this, event)");
}
}
protected void chkselect_CheckedChanged(object sender, EventArgs e)
{
foreach (GridViewRow gvr in GVProduct.Rows)
{
CheckBox chk = (CheckBox)gvr.FindControl("chkselect");
if (chk.Checked == true)
{
btn_addProductDetails.Enabled = btn_delProduct.Enabled = btnUpdate.Enabled = true;
Label pn = (Label)gvr.FindControl("productname");
IMSNiana.ProductName = pn.Text;
break;
}
else
{
btn_addProductDetails.Enabled = btn_delProduct.Enabled = btnUpdate.Enabled = false;
}
}
}
protected void GVProduct_DataBound(object sender, EventArgs e)
{
try
{
GridViewRow gvrow = GVProduct.BottomPagerRow;
Label lblcurrentpage = (Label)gvrow.Cells[0].FindControl("CurrentPage");
lblcurrentpage.Text = Convert.ToString(GVProduct.PageIndex + 1);
int[] page = new int[7];
page[0] = GVProduct.PageIndex - 2;
page[1] = GVProduct.PageIndex - 1;
page[2] = GVProduct.PageIndex;
page[3] = GVProduct.PageIndex + 1;
page[4] = GVProduct.PageIndex + 2;
page[5] = GVProduct.PageIndex + 3;
page[6] = GVProduct.PageIndex + 4;
for (int i = 0; i < 7; i++)
{
if (i != 3)
{
if (page[i] < 1 || page[i] > GVProduct.PageCount)
{
LinkButton lnkbtn = (LinkButton)gvrow.Cells[0].FindControl("p" + Convert.ToString(i));
lnkbtn.Visible = false;
}
else
{
LinkButton lnkbtn = (LinkButton)gvrow.Cells[0].FindControl("p" + Convert.ToString(i));
lnkbtn.Text = Convert.ToString(page[i]);
lnkbtn.CommandName = "PageNo";
lnkbtn.CommandArgument = lnkbtn.Text;
}
}
}
if (GVProduct.PageIndex == 0)
{
LinkButton lnkbtn = (LinkButton)gvrow.Cells[0].FindControl("LinkButton1");
lnkbtn.Visible = false;
lnkbtn = (LinkButton)gvrow.Cells[0].FindControl("LinkButton2");
lnkbtn.Visible = false;
}
if (GVProduct.PageIndex == GVProduct.PageCount - 1)
{
LinkButton lnkbtn = (LinkButton)gvrow.Cells[0].FindControl("LinkButton3");
lnkbtn.Visible = false;
lnkbtn = (LinkButton)gvrow.Cells[0].FindControl("LinkButton4");
lnkbtn.Visible = false;
}
if (GVProduct.PageIndex > GVProduct.PageCount - 5)
{
Label lbmore = (Label)gvrow.Cells[0].FindControl("nmore");
lbmore.Visible = false;
}
if (GVProduct.PageIndex < 4)
{
Label lbmore = (Label)gvrow.Cells[0].FindControl("pmore");
lbmore.Visible = false;
}
}
catch
{
}
}
public void lb_Command(object sender, CommandEventArgs e)
{
GVProduct.PageIndex = Convert.ToInt32(e.CommandArgument) - 1;
getdata();
}
protected void GVProduct_PageIndexChanging1(object sender, GridViewPageEventArgs e)
{
GVProduct.PageIndex = e.NewPageIndex;
getdata();
}
protected void GVProduct_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void btn_delProduct_Click1(object sender, EventArgs e)
{
SqlDataAdapter da = new SqlDataAdapter("select product_id from Product where product_name='" + IMSNiana.ProductName + "'", con);
DataSet ds = new DataSet();
da.Fill(ds, "PN");
string PId = ds.Tables["PN"].Rows[0][0].ToString();
da = new SqlDataAdapter(" delete from ProductDetails where product_id='" + PId + "' delete from Product where product_id='" + PId + "'", con);
ds = new DataSet();
da.Fill(ds, "Product");
getdata();
XmlDocument doc = new XmlDocument();
string p = Server.MapPath("Charts\\line_settings.xml");
doc.Load(p);
XmlElement f = doc.DocumentElement;
XmlElement graphs = (XmlElement)f.ChildNodes[64];
XmlElement cd = (XmlElement)graphs.LastChild;
cd.ParentNode.RemoveChild(cd);
doc.Save(p);
}
}