using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;

namespace IntranetApp
{
	/// <summary>
	/// Summary description for ManagerList.
	/// </summary>
	public partial class ManagerList : System.Web.UI.Page
	{
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
			Label3.Text="";
			if (!IsPostBack)
			{
				display();
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
			this.DataGrid1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_DeleteCommand);

		}
		#endregion

		SqlCommand cmd;
		int id;
		SqlConnection con=new SqlConnection(ConfigurationSettings.AppSettings.Get("con"));

		private void display()
		{
			if (con.State==ConnectionState.Closed) con.Open();
			SqlDataAdapter da=new SqlDataAdapter("select docno from data where status is null",con);
			DataSet ds=new DataSet();
			da.Fill(ds,"data");
			DataGrid1.DataSource=ds.Tables[0];
			DataGrid1.DataBind();
			con.Close();
		}

		private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			if (con.State==ConnectionState.Closed) con.Open();
			SqlCommand cmd=new SqlCommand("select subject from data where docno=" + e.Item.Cells[1].Text ,con);
			TextBox1.Text=cmd.ExecuteScalar().ToString();
			con.Close();
			Panel1.Visible=true;
		}

		private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
		{
			DataGrid1.CurrentPageIndex=e.NewPageIndex;
			display();
		}

		protected void Button1_Click(object sender, System.EventArgs e)
		{
			Panel1.Visible=false;
			try
			{
				foreach (DataGridItem c in DataGrid1.Items)
				{
					if ((((CheckBox)(c.FindControl("chk"))).Checked) == true)
					{
						con.Open();
						id = Convert.ToInt32(c.Cells[1].Text);
						cmd = new SqlCommand("update data set status='yes' where docno=" + id,con);
						cmd.ExecuteNonQuery();
						con.Close();
					}
				}
			}
			catch (Exception ex)
			{
				Label3.Text = ex.Message;
			}
			display();
		}
	}
}
