using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using com.vrm.database;
using System.Data;
using com.vrm.com;
using
System.Collections.Specialized;
using System.Text;
namespace StarTrack
{
public partial class
ContractThreeGridView :
System.Web.UI.Page
{
private vrm_database vrmdb
= new vrm_database();
private String
viewStateGVName = "gvCriticalTerms";
private const int
GVContractID = 10;//columns to reference
protected void
Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Set the
sortExpression
ViewState[this.ToString() + "_SortExpression1"]
= "terms";
ViewState[this.ToString() + "_SortDirection1"]
= "ASC";
//Set the
sortExpression
ViewState[this.ToString() + "_SortExpression2"]
= "filename";
ViewState[this.ToString() + "_SortDirection2"]
= "ASC";
//populate the
criticalterms datatable
DataTable tmpdt =
vrmdb.Get_CriticalTerms().Tables[0];
//tmpdt.PrimaryKey = new DataColumn[] { tmpdt.Columns[0]
};
ViewState[viewStateGVName] = tmpdt;
BindGrid();
}
}
private void BindGrid()
{
DataTable dtgvCriticalTerms = null;
//retrieve the
ViewState object datatable
dtgvCriticalTerms = ViewState[viewStateGVName] as DataTable;
dtgvCriticalTerms.DefaultView.Sort = ViewState[this.ToString()
+
"_SortExpression1"].ToString() + " "
+
ViewState[this.ToString() + "_SortDirection1"].ToString();
if (dtgvCriticalTerms != null)
{
if (dtgvCriticalTerms.Rows.Count > 0)
{
ViewState[viewStateGVName] = dtgvCriticalTerms;
gvCriticalTerms.DataSource = ViewState[viewStateGVName];
gvCriticalTerms.DataBind();
}
else
{
dtgvCriticalTerms.Rows.Add(dtgvCriticalTerms.NewRow());
ViewState[viewStateGVName] = dtgvCriticalTerms;
gvCriticalTerms.DataSource = ViewState[viewStateGVName];
gvCriticalTerms.DataBind();
int TotalColumns =
gvCriticalTerms.Rows[0].Cells.Count;
gvCriticalTerms.Rows[0].Cells.Clear();
gvCriticalTerms.Rows[0].Cells.Add(new TableCell());
gvCriticalTerms.Rows[0].Cells[0].ColumnSpan = TotalColumns;
gvCriticalTerms.Rows[0].Cells[0].Text = "No Record Found";
}
}
}
protected void
gvCriticalTerms_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
gvCriticalTerms.EditIndex = -1;
BindGrid();
}
protected void
gvCriticalTerms_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("AddNew"))
{
TextBox txtTermsID = (TextBox)gvCriticalTerms.FooterRow.FindControl("txtTermsID");
TextBox txtTerms = (TextBox)gvCriticalTerms.FooterRow.FindControl("txtTerms");
TextBox txtDefaultValue = (TextBox)gvCriticalTerms.FooterRow.FindControl("txtDefaultValue");
TextBox txtActualValue = (TextBox)gvCriticalTerms.FooterRow.FindControl("txtActualValue");
TextBox txtReasonForDeviation = (TextBox)gvCriticalTerms.FooterRow.FindControl("txtReasonForDeviation");
TextBox txtAlert = (TextBox)gvCriticalTerms.FooterRow.FindControl("txtAlert");
TextBox txtContractID = (TextBox)gvCriticalTerms.FooterRow.FindControl("txtContractID");
vrmdb.Insert_CriticalTermsRecords(txtTermsID.Text,txtTerms.Text,
txtDefaultValue.Text, txtActualValue.Text, txtReasonForDeviation.Text,
txtAlert.Text, txtContractID.Text);
BindGrid();
Response.Redirect("ContractThreeGridView.aspx");
}
}
protected void
gvCriticalTerms_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
vrmdb.Delete_CriticalTermsRecords(gvCriticalTerms.DataKeys[e.RowIndex].Values[0].ToString());
BindGrid();
}
protected void
gvCriticalTerms_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox txtTermsID = (TextBox)gvCriticalTerms.Rows[e.RowIndex].FindControl("txtTermsID");
TextBox txtTerms = (TextBox)gvCriticalTerms.Rows[e.RowIndex].FindControl("txtTerms");
TextBox txtDefaultValue = (TextBox)gvCriticalTerms.Rows[e.RowIndex].FindControl("txtDefaultValue");
TextBox txtActualValue = (TextBox)gvCriticalTerms.Rows[e.RowIndex].FindControl("txtActualValue");
TextBox txtReasonForDeviation = (TextBox)gvCriticalTerms.Rows[e.RowIndex].FindControl("txtReasonForDeviation");
TextBox txtAlerts = (TextBox)gvCriticalTerms.Rows[e.RowIndex].FindControl("txtAlerts");
//Console.WriteLine(txtTerms.Text);
//Console.WriteLine(txtDefaultValue.Text);
//Console.WriteLine(txtActualValue.Text);
//Console.WriteLine(txtReasonForDeviation.Text);
//Console.WriteLine(txtAlerts.Text);
vrmdb.Update_CriticalTermsRecords(txtTermsID.Text,txtTerms.Text,
txtDefaultValue.Text, txtActualValue.Text, txtReasonForDeviation.Text,
txtAlerts.Text);
gvCriticalTerms.EditIndex = -1;
BindGrid();
Response.Redirect("ContractThreeGridView.aspx");
}
protected void
gvCriticalTerms_RowEditing(object sender, GridViewEditEventArgs e)
{
gvCriticalTerms.EditIndex = e.NewEditIndex;
BindGrid();
}
protected void
gvCriticalTerms_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvCriticalTerms.PageIndex = e.NewPageIndex;
BindGrid();
}
protected void
gvCriticalTerms_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
GridView header = (GridView)sender;
GridViewRow gvr = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
TableCell tCell = new TableCell();
tCell.Text = "Critical Terms";
tCell.ColumnSpan = 10;
tCell.HorizontalAlign = HorizontalAlign.Left;
tCell.CssClass = "trWithBorder";
gvr.Cells.Add(tCell);
// Add the
Merged TableCell to the GridView Header
Table tbl = gvCriticalTerms.Controls[0]
as Table;
if (tbl != null)
{
tbl.Rows.AddAt(0, gvr);
}
}
}
protected void
chkSelectAll_CheckedChanged(object sender, EventArgs e)
{
CheckBox chk;
foreach (GridViewRow rowItem
in gvCriticalTerms.Rows)
{
chk = (CheckBox)(rowItem.Cells[0].FindControl("selected"));
chk.Checked = ((CheckBox)sender).Checked;
}
}
}
}
|