using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
public partial class AddDocuments : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            setDocNo();
        }
    }
    SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings.Get("con"));

    private void setDocNo()
    {
        if (con.State == ConnectionState.Closed) con.Open();
        SqlCommand cmd = new SqlCommand("select isnull(max(docno)+1,1) from data", con);
        txtdocNo.Text = cmd.ExecuteScalar().ToString();
        con.Close();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (con.State == ConnectionState.Closed) con.Open();
        SqlCommand cmd = new SqlCommand("insert into data values(" + txtdocNo.Text + ",'" + txtdesc.Text + "'," + Session["eid"].ToString() + ",'" + DateTime.Now.ToString("dd-MMM-yyyy") + "',NULL)", con);
        cmd.ExecuteNonQuery();
        con.Close();
        lbltext.Text = "Information Posted";
        Button1.Enabled = false;

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        txtdocNo.Text = "";
        txtdesc.Text = "";
        setDocNo();
        Button1.Enabled = true;
        Button2.Enabled = false;

    }
}
