Dear Sir,
I want to avoid update duplicate Voucher No. while click on Settled button.
please sir help me.
namespace BPM
{
public partial class vw : System.Web.UI.Page
{
int empno = 0;
protected void Page_Load(object sender, EventArgs e)
{
empno = Convert.ToInt32(Request.QueryString["Id"].ToString());
Session["EmpId"] = empno;
String EmplooyeId = Session["emp_id"].ToString();
Label12.Text = " " + EmplooyeId + "";
String emp_nm = Session["emp_nm"].ToString();
Label14.Text = "" + emp_nm + " ";
String dept = Session["dept"].ToString();
Label15.Text = "" + dept + " ";
if (!IsPostBack)
{
BindTextBoxvalues();
// BindGrid();
}
TextBox10.Visible = false;
Button6.Visible = false;
Button7.Visible = false;
Label16.Text = String.Format("{0}", DateTime.Now.ToString("dd/MM/yyyy"));
}
private void BindTextBoxvalues()
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand("select * from bpms where Id=" + empno, con);
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
Label1.Text = dt.Rows[0][0].ToString();
Label3.Text = dt.Rows[0][1].ToString();
Label2.Text = dt.Rows[0][2].ToString();
Label13.Text = dt.Rows[0][3].ToString();
Label4.Text = dt.Rows[0][4].ToString();
Label5.Text = dt.Rows[0][5].ToString();
Label6.Text = dt.Rows[0][6].ToString();
TextBox11.Text = dt.Rows[0][7].ToString();
TextBox12.Text = dt.Rows[0][8].ToString();
Label9.Text = dt.Rows[0][9].ToString();
Label10.Text = dt.Rows[0][10].ToString();
TextBox14.Text = dt.Rows[0][11].ToString();
Label19.Text = dt.Rows[0][33].ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd1 = new SqlCommand("SELECT * FROM bpms WHERE vchr_no=@vchr_no", con))
{
using (SqlDataAdapter da1 = new SqlDataAdapter(cmd1))
{
con.Open();
cmd1.Parameters.AddWithValue("@vchr_no", this.TextBox13.Text.Trim());
DataSet ds1 = new DataSet();
da1.Fill(ds1);
if (ds1.Tables[0].Rows.Count > 0)
{
string message = "Duplicate Voucher No. Number Not Allowed !!";
string script = "window.onload = function(){ alert('";
script += message;
script += "');";
script += "window.location = '";
script += Request.Url.AbsoluteUri;
script += "'; }";
ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true);
//this.lblMessage.Text = "Duplicate PO Number Not Allowed !!";
}
using (SqlCommand cmd = new SqlCommand("UPDATE bpms SET amt_rls = @amt_rls,amt_rls_dt=@amt_rls_dt,tds_gst=@tds_gst,tds_it=@tds_it,ld=@ld,sd_pbg=@sd_pbg,instl_chrg=@instl_chrg,othr_ded=@othr_ded,othr_ded_rsn=@othr_ded_rsn,tda=@tda,gt=@gt,Fa_updt_dt=@Fa_updt_dt,updt_b_id=@updt_b_id,updt_b_nm=@updt_b_nm,updt_b_dpt=@updt_b_dpt WHERE Id = @Id"))
{
cmd.Parameters.AddWithValue("@Id", Label1.Text);
cmd.Parameters.AddWithValue("@amt_rls", TextBox1.Text);
cmd.Parameters.AddWithValue("@amt_rls_dt", TextBox2.Text);
cmd.Parameters.AddWithValue("@tds_gst", TextBox3.Text);
cmd.Parameters.AddWithValue("@tds_it", TextBox4.Text);
cmd.Parameters.AddWithValue("@ld", TextBox5.Text);
cmd.Parameters.AddWithValue("@sd_pbg", TextBox6.Text);
cmd.Parameters.AddWithValue("@instl_chrg", TextBox7.Text);
cmd.Parameters.AddWithValue("@othr_ded", TextBox8.Text);
cmd.Parameters.AddWithValue("@othr_ded_rsn", TextBox9.Text);
cmd.Parameters.AddWithValue("@gnrl_rmk", TextBox10.Text);
cmd.Parameters.AddWithValue("@tda", TextBox15.Text);
cmd.Parameters.AddWithValue("@gt", TextBox16.Text);
cmd.Parameters.AddWithValue("@Fa_updt_dt", Label16.Text);
cmd.Parameters.AddWithValue("@updt_b_id", Label14.Text);
cmd.Parameters.AddWithValue("@updt_b_nm", Label12.Text);
cmd.Parameters.AddWithValue("@updt_b_dpt", Label15.Text);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
string message = "Bill details have been saved successfully.";
string script = "window.onload = function(){ alert('";
script += message;
script += "');";
script += "window.location = '";
script += Request.Url.AbsoluteUri;
script += "'; }";
ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true);
}
}
// Response.Redirect("fa.aspx");
}
}
}
}
}
CREATE TABLE [dbo].[bpms] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[emp_id] VARCHAR (50) NULL,
[emp_nm] VARCHAR (50) NULL,
[dept] VARCHAR (50) NULL,
[p_n] NCHAR (10) NULL,
[agcy] VARCHAR (50) NULL,
[srv_no] NVARCHAR (50) NULL,
[srv_dt] VARCHAR (50) NULL,
[srv_amt] VARCHAR (50) NULL,
[prk_amnt] VARCHAR (50) NULL,
[prk_nm] VARCHAR (50) DEFAULT ('NA') NULL,
[prk_dt] VARCHAR (50) DEFAULT ('NA') NULL,
[mrk_in_fa] VARCHAR (10) DEFAULT ('NO') NULL,
[amt_rls] VARCHAR (50) DEFAULT ('NA') NULL,
[amt_rls_dt] VARCHAR (50) DEFAULT ('NA') NULL,
[tds_gst] VARCHAR (50) DEFAULT ('NA') NULL,
[tds_it] VARCHAR (50) DEFAULT ('NA') NULL,
[ld] VARCHAR (50) DEFAULT ('NA') NULL,
[sd_pbg] VARCHAR (50) DEFAULT ('NA') NULL,
[instl_chrg] VARCHAR (50) DEFAULT ('NA') NULL,
[othr_ded] VARCHAR (50) DEFAULT ('NA') NULL,
[othr_ded_rsn] VARCHAR (500) DEFAULT ('NA') NULL,
[gnrl_rmk] VARCHAR (500) DEFAULT ('NA') NULL,
[stl] VARCHAR (50) DEFAULT ('Pending') NULL,
[tda] VARCHAR (MAX) NULL,
[gt] VARCHAR (MAX) NULL,
[Fa_updt_dt] VARCHAR (50) NULL,
[updt_b_id] VARCHAR (50) NULL,
[updt_b_nm] VARCHAR (50) NULL,
[updt_b_dpt] VARCHAR (50) NULL,
[cnm_inst_dt] VARCHAR (50) NULL,
[phn] VARCHAR (12) NULL,
[eml] VARCHAR (50) NULL,
[inv_no_agnst_srv] VARCHAR (1000) NULL,
[vchr_no] VARCHAR (500) DEFAULT ('NA') NULL,
[LODGE_DATE] DATE DEFAULT (getdate()) NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);