web.config
<connectionStrings>
<add name="conString"
connectionString="Data Source=GOKUL-PC\GOKUL;
database=InvoicePrj;Integrated Security=true"/>
</connectionStrings>
protected void crudoperations(string status,string itemid, string ItemCode, string ItemDesc, string UOM, string Qty, double Rate)
{
String strConnString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
using (SqlConnection con = new SqlConnection(strConnString))
{
con.Open();
SqlCommand cmd = new SqlCommand("crudoperations", con);
cmd.CommandType = CommandType.StoredProcedure;
if (status == "INSERT")
{
cmd.Parameters.AddWithValue("@ItemId", itemid);
cmd.Parameters.AddWithValue("@ItemCode", ItemCode);
cmd.Parameters.AddWithValue("@ItemDesc", ItemDesc);
cmd.Parameters.AddWithValue("@UOM", UOM);
cmd.Parameters.AddWithValue("@Qty", Qty);
cmd.Parameters.AddWithValue("@Rate", Rate);
cmd.Parameters.AddWithValue("@status", status);
SqlParameter outPutParameter = new SqlParameter();
outPutParameter.ParameterName = "@ErrStatus";
outPutParameter.SqlDbType = System.Data.SqlDbType.VarChar;
outPutParameter.Size = 500;
outPutParameter.Direction = System.Data.ParameterDirection.Output;
cmd.Parameters.Add(outPutParameter);
cmd.ExecuteNonQuery();
string Errstatus = outPutParameter.Value.ToString();
if (Errstatus == "1")
{
Label1.Text = "New Dc Added!!";
string message = "New Dc Added!!"; System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("<script type = 'text/javascript'>"); sb.Append("window.onload=function(){"); sb.Append("alert('"); sb.Append(message); sb.Append("')};"); sb.Append("</script>"); ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString());
}
else
{
Label1.Text = "Error Adding Dc !!";
string message = "Error Adding Dc !!"; System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("<script type = 'text/javascript'>"); sb.Append("window.onload=function(){"); sb.Append("alert('"); sb.Append(message); sb.Append("')};"); sb.Append("</script>"); ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString());
}
gvDetails.EditIndex = -1;
int id = Convert.ToInt32(TextBox2.Text);
BindGridview(id);
}
}
Update---
else if (status == "UPDATE")
{
cmd.Parameters.AddWithValue("@ItemCode", ItemCode);
cmd.Parameters.AddWithValue("@ItemDesc", ItemDesc);
cmd.Parameters.AddWithValue("@UOM", UOM);
cmd.Parameters.AddWithValue("@Qty", Qty);
cmd.Parameters.AddWithValue("@Rate", Rate);
cmd.Parameters.AddWithValue("@status", status);
SqlParameter outPutParameter = new SqlParameter();
outPutParameter.ParameterName = "@ErrStatus";
outPutParameter.SqlDbType = System.Data.SqlDbType.VarChar;
outPutParameter.Size = 500;
outPutParameter.Direction = System.Data.ParameterDirection.Output;
cmd.Parameters.Add(outPutParameter);
cmd.ExecuteNonQuery();
string Errstatus = outPutParameter.Value.ToString();
if (Errstatus == "1")
{
Label1.Text = " Dc Updated!!";
string message = " Dc Updated!!"; System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("<script type = 'text/javascript'>"); sb.Append("window.onload=function(){"); sb.Append("alert('"); sb.Append(message); sb.Append("')};"); sb.Append("</script>"); ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString());
}
else
{
Label1.Text = " Error Updating Dc !!";
string message = "Error Updating Dc !!"; System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("<script type = 'text/javascript'>"); sb.Append("window.onload=function(){"); sb.Append("alert('"); sb.Append(message); sb.Append("')};"); sb.Append("</script>"); ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString());
}
gvDetails.EditIndex = -1;
int id = Convert.ToInt32(TextBox2.Text);
BindGridview(id);
}
}
--select---
Label1.Text = "";
Session["User_Id"] = txtUserId.Text.ToString();
String strConnString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "Validate_Login_Details";
cmd.Parameters.Add("@Role", SqlDbType.Char).Value = "";
cmd.Parameters.Add("@User_Id", SqlDbType.Char).Value = txtUserId.Text;
string pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPwd.Text.ToString(), "SHA1");
cmd.Parameters.Add("@Password", SqlDbType.Char).Value = pwd.ToString();
SqlParameter outPutParameter = new SqlParameter();
outPutParameter.ParameterName = "@Status";
outPutParameter.SqlDbType = System.Data.SqlDbType.Int;
outPutParameter.Direction = System.Data.ParameterDirection.Output;
cmd.Parameters.Add(outPutParameter);
SqlParameter outPutParameter1 = new SqlParameter();
outPutParameter1.ParameterName = "@UID";
outPutParameter1.SqlDbType = System.Data.SqlDbType.VarChar;
outPutParameter1.Size = 400;
outPutParameter1.Direction = System.Data.ParameterDirection.Output;
cmd.Parameters.Add(outPutParameter1);
cmd.Connection = con;
try
{
con.Open();
cmd.ExecuteNonQuery();
string status = outPutParameter.Value.ToString();
string uid = outPutParameter1.Value.ToString();
string Redirecturl = "http://localhost:52418/ResetPassword.aspx?UID=" + uid + "";
if (status == "1111")
{
Response.Redirect("AdministratorPanel.aspx");
}
else if (status == "10")
{
Label1.ForeColor = System.Drawing.Color.LightGreen;
Response.Redirect("UserHome.aspx");
}
else if (status == "20")
{
Label1.Text = "User Account is Locked !! Contact System Adminstrator!!";
}
}
}
<connectionStrings>
<add name="conString"
connectionString="Data Source=GOKUL-PC\GOKUL;
database=InvoicePrj;Integrated Security=true"/>
</connectionStrings>
protected void crudoperations(string status,string itemid, string ItemCode, string ItemDesc, string UOM, string Qty, double Rate)
{
String strConnString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
using (SqlConnection con = new SqlConnection(strConnString))
{
con.Open();
SqlCommand cmd = new SqlCommand("crudoperations", con);
cmd.CommandType = CommandType.StoredProcedure;
if (status == "INSERT")
{
cmd.Parameters.AddWithValue("@ItemId", itemid);
cmd.Parameters.AddWithValue("@ItemCode", ItemCode);
cmd.Parameters.AddWithValue("@ItemDesc", ItemDesc);
cmd.Parameters.AddWithValue("@UOM", UOM);
cmd.Parameters.AddWithValue("@Qty", Qty);
cmd.Parameters.AddWithValue("@Rate", Rate);
cmd.Parameters.AddWithValue("@status", status);
SqlParameter outPutParameter = new SqlParameter();
outPutParameter.ParameterName = "@ErrStatus";
outPutParameter.SqlDbType = System.Data.SqlDbType.VarChar;
outPutParameter.Size = 500;
outPutParameter.Direction = System.Data.ParameterDirection.Output;
cmd.Parameters.Add(outPutParameter);
cmd.ExecuteNonQuery();
string Errstatus = outPutParameter.Value.ToString();
if (Errstatus == "1")
{
Label1.Text = "New Dc Added!!";
string message = "New Dc Added!!"; System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("<script type = 'text/javascript'>"); sb.Append("window.onload=function(){"); sb.Append("alert('"); sb.Append(message); sb.Append("')};"); sb.Append("</script>"); ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString());
}
else
{
Label1.Text = "Error Adding Dc !!";
string message = "Error Adding Dc !!"; System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("<script type = 'text/javascript'>"); sb.Append("window.onload=function(){"); sb.Append("alert('"); sb.Append(message); sb.Append("')};"); sb.Append("</script>"); ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString());
}
gvDetails.EditIndex = -1;
int id = Convert.ToInt32(TextBox2.Text);
BindGridview(id);
}
}
Update---
else if (status == "UPDATE")
{
cmd.Parameters.AddWithValue("@ItemCode", ItemCode);
cmd.Parameters.AddWithValue("@ItemDesc", ItemDesc);
cmd.Parameters.AddWithValue("@UOM", UOM);
cmd.Parameters.AddWithValue("@Qty", Qty);
cmd.Parameters.AddWithValue("@Rate", Rate);
cmd.Parameters.AddWithValue("@status", status);
SqlParameter outPutParameter = new SqlParameter();
outPutParameter.ParameterName = "@ErrStatus";
outPutParameter.SqlDbType = System.Data.SqlDbType.VarChar;
outPutParameter.Size = 500;
outPutParameter.Direction = System.Data.ParameterDirection.Output;
cmd.Parameters.Add(outPutParameter);
cmd.ExecuteNonQuery();
string Errstatus = outPutParameter.Value.ToString();
if (Errstatus == "1")
{
Label1.Text = " Dc Updated!!";
string message = " Dc Updated!!"; System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("<script type = 'text/javascript'>"); sb.Append("window.onload=function(){"); sb.Append("alert('"); sb.Append(message); sb.Append("')};"); sb.Append("</script>"); ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString());
}
else
{
Label1.Text = " Error Updating Dc !!";
string message = "Error Updating Dc !!"; System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("<script type = 'text/javascript'>"); sb.Append("window.onload=function(){"); sb.Append("alert('"); sb.Append(message); sb.Append("')};"); sb.Append("</script>"); ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString());
}
gvDetails.EditIndex = -1;
int id = Convert.ToInt32(TextBox2.Text);
BindGridview(id);
}
}
--select---
Label1.Text = "";
Session["User_Id"] = txtUserId.Text.ToString();
String strConnString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "Validate_Login_Details";
cmd.Parameters.Add("@Role", SqlDbType.Char).Value = "";
cmd.Parameters.Add("@User_Id", SqlDbType.Char).Value = txtUserId.Text;
string pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPwd.Text.ToString(), "SHA1");
cmd.Parameters.Add("@Password", SqlDbType.Char).Value = pwd.ToString();
SqlParameter outPutParameter = new SqlParameter();
outPutParameter.ParameterName = "@Status";
outPutParameter.SqlDbType = System.Data.SqlDbType.Int;
outPutParameter.Direction = System.Data.ParameterDirection.Output;
cmd.Parameters.Add(outPutParameter);
SqlParameter outPutParameter1 = new SqlParameter();
outPutParameter1.ParameterName = "@UID";
outPutParameter1.SqlDbType = System.Data.SqlDbType.VarChar;
outPutParameter1.Size = 400;
outPutParameter1.Direction = System.Data.ParameterDirection.Output;
cmd.Parameters.Add(outPutParameter1);
cmd.Connection = con;
try
{
con.Open();
cmd.ExecuteNonQuery();
string status = outPutParameter.Value.ToString();
string uid = outPutParameter1.Value.ToString();
string Redirecturl = "http://localhost:52418/ResetPassword.aspx?UID=" + uid + "";
if (status == "1111")
{
Response.Redirect("AdministratorPanel.aspx");
}
else if (status == "10")
{
Label1.ForeColor = System.Drawing.Color.LightGreen;
Response.Redirect("UserHome.aspx");
}
else if (status == "20")
{
Label1.Text = "User Account is Locked !! Contact System Adminstrator!!";
}
}
}