using System;
using System.Configuration;
using System.Data;
using System.Linq;
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.Xml.Linq;
using System.Data.SqlClient;
using System.Drawing;
public partial class newuser : System.Web.UI.Page
{
Connection con = new Connection();
DataSet ds = new DataSet();
DataTable dtable;
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["constrwc"].ToString());
int uid;
DateTime dob;
string procedure_name = "";
string hobby = "";
string firstname, lastname, gender, country, state, uname, password, email, photo;
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack == false)
{
ddldayyear();
ddlcountryfill();
if (Session.Count > 1)
{
string operation = Session["ope"].ToString();
if (operation == "Edit")
{
string query = "select * from test_reg where Id=";
query += Session["test_reg_Id"].ToString();
dtable = con.sqlSelect(query);
txt_id.Text = dtable.Rows[0][0].ToString();
txt_id.Enabled = false;
txtfname.Text = dtable.Rows[0][1].ToString();
txtlname.Text = dtable.Rows[0][2].ToString();
txtemail.Text = dtable.Rows[0][9].ToString();
txtuname.Text = dtable.Rows[0][10].ToString();
txtpass.Text = dtable.Rows[0][11].ToString();
ddlcountry.SelectedItem.Text = dtable.Rows[0][5].ToString();
ddlstate.SelectedItem.Text = dtable.Rows[0][6].ToString();
// This code used for fill three DDL ......................
DateTime u_date = Convert.ToDateTime(dtable.Rows[0][3]);
ddl_day.SelectedValue = u_date.Day.ToString();
ddl_month.SelectedValue = u_date.Month.ToString();
ddl_year.SelectedValue = u_date.Year.ToString();
string chkstatus = dtable.Rows[0][4].ToString();
if (chkstatus == "Male")
RadioButtonList1.Items[0].Selected = true;
else
RadioButtonList1.Items[1].Selected = true;
string hobbyarr = dtable.Rows[0][7].ToString();
string[] arrval = hobbyarr.Split(',');
for (int i = arrval.GetLowerBound(0); i <= arrval.GetUpperBound(0); i++)
{
if (arrval[i].ToString() == "Reading")
{
chkhobby.Items[0].Selected = true;
}
if (arrval[i].ToString() == "Cricket")
{
chkhobby.Items[1].Selected = true;
}
if (arrval[i].ToString() == "Music")
{
chkhobby.Items[2].Selected = true;
}
}
}
}
else
{
ddlcountry.SelectedValue = "select ccountry";
string query1 = "select max(Id)+1 from dbo.test_reg";
dtable = con.sqlSelect(query1);
txt_id.Text = dtable.Rows[0][0].ToString();
txt_id.Enabled = false;
}
}
Button1.Attributes.Add("onclick", "return validate()");
}
protected void ddldayyear()
{
for (int i = 2011; i > 1950; i--)
{
ddl_year.Items.Add(i.ToString());
}
for (int j = 1; j <= 31; j++)
{
ddl_day.Items.Add(j.ToString());
}
for (int k = 1; k <= 12; k++)
{
ddl_month.Items.Add(k.ToString());
}
}
protected void ddlcountryfill()
{
ddlcountry.Items.Clear();
string query = "Select Country_name from Country_Master";
conn.Open();
SqlCommand cmd = new SqlCommand(query, conn);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
ddlcountry.Items.Add(dr["Country_name"].ToString());
}
conn.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
string bdate = ddl_day.SelectedItem.Text + "/" + ddl_month.SelectedItem.Text + "/" +
using System.Configuration;
using System.Data;
using System.Linq;
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.Xml.Linq;
using System.Data.SqlClient;
using System.Drawing;
public partial class newuser : System.Web.UI.Page
{
Connection con = new Connection();
DataSet ds = new DataSet();
DataTable dtable;
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["constrwc"].ToString());
int uid;
DateTime dob;
string procedure_name = "";
string hobby = "";
string firstname, lastname, gender, country, state, uname, password, email, photo;
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack == false)
{
ddldayyear();
ddlcountryfill();
if (Session.Count > 1)
{
string operation = Session["ope"].ToString();
if (operation == "Edit")
{
string query = "select * from test_reg where Id=";
query += Session["test_reg_Id"].ToString();
dtable = con.sqlSelect(query);
txt_id.Text = dtable.Rows[0][0].ToString();
txt_id.Enabled = false;
txtfname.Text = dtable.Rows[0][1].ToString();
txtlname.Text = dtable.Rows[0][2].ToString();
txtemail.Text = dtable.Rows[0][9].ToString();
txtuname.Text = dtable.Rows[0][10].ToString();
txtpass.Text = dtable.Rows[0][11].ToString();
ddlcountry.SelectedItem.Text = dtable.Rows[0][5].ToString();
ddlstate.SelectedItem.Text = dtable.Rows[0][6].ToString();
// This code used for fill three DDL ......................
DateTime u_date = Convert.ToDateTime(dtable.Rows[0][3]);
ddl_day.SelectedValue = u_date.Day.ToString();
ddl_month.SelectedValue = u_date.Month.ToString();
ddl_year.SelectedValue = u_date.Year.ToString();
string chkstatus = dtable.Rows[0][4].ToString();
if (chkstatus == "Male")
RadioButtonList1.Items[0].Selected = true;
else
RadioButtonList1.Items[1].Selected = true;
string hobbyarr = dtable.Rows[0][7].ToString();
string[] arrval = hobbyarr.Split(',');
for (int i = arrval.GetLowerBound(0); i <= arrval.GetUpperBound(0); i++)
{
if (arrval[i].ToString() == "Reading")
{
chkhobby.Items[0].Selected = true;
}
if (arrval[i].ToString() == "Cricket")
{
chkhobby.Items[1].Selected = true;
}
if (arrval[i].ToString() == "Music")
{
chkhobby.Items[2].Selected = true;
}
}
}
}
else
{
ddlcountry.SelectedValue = "select ccountry";
string query1 = "select max(Id)+1 from dbo.test_reg";
dtable = con.sqlSelect(query1);
txt_id.Text = dtable.Rows[0][0].ToString();
txt_id.Enabled = false;
}
}
Button1.Attributes.Add("onclick", "return validate()");
}
protected void ddldayyear()
{
for (int i = 2011; i > 1950; i--)
{
ddl_year.Items.Add(i.ToString());
}
for (int j = 1; j <= 31; j++)
{
ddl_day.Items.Add(j.ToString());
}
for (int k = 1; k <= 12; k++)
{
ddl_month.Items.Add(k.ToString());
}
}
protected void ddlcountryfill()
{
ddlcountry.Items.Clear();
string query = "Select Country_name from Country_Master";
conn.Open();
SqlCommand cmd = new SqlCommand(query, conn);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
ddlcountry.Items.Add(dr["Country_name"].ToString());
}
conn.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
string bdate = ddl_day.SelectedItem.Text + "/" + ddl_month.SelectedItem.Text + "/" +
ddl_year.SelectedItem.Text;
DateTime dob = Convert.ToDateTime(bdate);
string gender = RadioButtonList1.SelectedItem.Text;
uid = Convert.ToInt32(txt_id.Text);
firstname = txtfname.Text;
lastname = txtlname.Text;
country = ddlcountry.SelectedItem.Value;
state = ddlstate.SelectedItem.Value;
if (chkhobby.Items[0].Selected == true)
{
hobby = hobby + "," + chkhobby.Items[0].Text;
}
if (chkhobby.Items[1].Selected == true)
{
hobby = hobby + "," + chkhobby.Items[1].Text;
}
if (chkhobby.Items[2].Selected == true)
{
hobby = hobby + "," + chkhobby.Items[2].Text;
}
if (hobby != "")
{
hobby = hobby.ToString().Substring(1);
}
photo = txt_id.Text + ".JPEG";
FileUpload1.SaveAs(Server.MapPath("~/Image/") + photo);
email = txtemail.Text;
uname = txtuname.Text;
password = txtpass.Text;
if (Session.Count > 1)
{
string operation = Session["ope"].ToString();
if (operation == "Edit")
procedure_name = "update_procedure";
else
procedure_name = "insert_procedure";
}
else
{
procedure_name = "insert_procedure";
}
conn.Open();
string query2 = "select username from test_reg where username='" + txtuname.Text + "'";
SqlCommand cmd = new SqlCommand(query2, conn);
SqlDataReader dr = cmd.ExecuteReader();
lblavamsg.Text = "";
if (dr.Read())
{
lblavamsg.Text = "Username Exist...!";
lblavamsg.ForeColor = Color.Red;
}
else
{
con.sql_insert_data(procedure_name, uid, firstname, lastname, dob, gender, country, state, hobby, photo, email, uname, password);
if (procedure_name == "insert_procedure")
Response.Write("<script>alert('Record added successfuly....!');</script>");
else
Response.Write("<script> alert('Record updated successfuly....!'); </script>");
Server.Transfer("ShowData.aspx");
}
}
protected void ddlcountry_SelectedIndexChanged1(object sender, EventArgs e)
{
conn.Open();
ddlstate.Items.Clear();
string query2 = "select sn.State_name from State_Master sn, Country_Master cn where cn.Country_id = sn.Country_ID and Country_name ='" + ddlcountry.SelectedItem.Text + "'";
SqlCommand cmd = new SqlCommand(query2, conn);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
ddlstate.Items.Add(dr["State_name"].ToString());
}
conn.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
if (Session.Count > 1)
{
string operation = Session["ope"].ToString();
if (operation == "Edit")
Response.Redirect("ShowData.aspx");
else
Response.Redirect("Login.aspx");
}
else
{
Response.Redirect("Login.aspx");
}
}
protected void btncheckava_Click(object sender, EventArgs e)
{
conn.Open();
string query2 = "select username from test_reg where username='"+txtuname.Text+"'";
SqlCommand cmd = new SqlCommand(query2, conn);
SqlDataReader dr = cmd.ExecuteReader();
lblavamsg.Text = "";
if (dr.Read())
{
lblavamsg.Text = "Username Exist...!";
lblavamsg.ForeColor = Color.Red;
}
else
{
if (txtuname.Text != "")
{
lblavamsg.Text = "Username avaiable...!";
lblavamsg.ForeColor = Color.Green;
}
else
{
lblavamsg.Text = "Please enter username!";
lblavamsg.ForeColor = Color.Red;
}
}
conn.Close();
}
protected void Button3_Click(object sender, EventArgs e)
{
string photo1 = txt_id.Text + ".JPEG";
FileUpload1.SaveAs(Server.MapPath("~/Image/") + photo1);
Image1.ImageUrl = "Image/" + FileUpload1.PostedFile.FileName;
}
}
DateTime dob = Convert.ToDateTime(bdate);
string gender = RadioButtonList1.SelectedItem.Text;
uid = Convert.ToInt32(txt_id.Text);
firstname = txtfname.Text;
lastname = txtlname.Text;
country = ddlcountry.SelectedItem.Value;
state = ddlstate.SelectedItem.Value;
if (chkhobby.Items[0].Selected == true)
{
hobby = hobby + "," + chkhobby.Items[0].Text;
}
if (chkhobby.Items[1].Selected == true)
{
hobby = hobby + "," + chkhobby.Items[1].Text;
}
if (chkhobby.Items[2].Selected == true)
{
hobby = hobby + "," + chkhobby.Items[2].Text;
}
if (hobby != "")
{
hobby = hobby.ToString().Substring(1);
}
photo = txt_id.Text + ".JPEG";
FileUpload1.SaveAs(Server.MapPath("~/Image/") + photo);
email = txtemail.Text;
uname = txtuname.Text;
password = txtpass.Text;
if (Session.Count > 1)
{
string operation = Session["ope"].ToString();
if (operation == "Edit")
procedure_name = "update_procedure";
else
procedure_name = "insert_procedure";
}
else
{
procedure_name = "insert_procedure";
}
conn.Open();
string query2 = "select username from test_reg where username='" + txtuname.Text + "'";
SqlCommand cmd = new SqlCommand(query2, conn);
SqlDataReader dr = cmd.ExecuteReader();
lblavamsg.Text = "";
if (dr.Read())
{
lblavamsg.Text = "Username Exist...!";
lblavamsg.ForeColor = Color.Red;
}
else
{
con.sql_insert_data(procedure_name, uid, firstname, lastname, dob, gender, country, state, hobby, photo, email, uname, password);
if (procedure_name == "insert_procedure")
Response.Write("<script>alert('Record added successfuly....!');</script>");
else
Response.Write("<script> alert('Record updated successfuly....!'); </script>");
Server.Transfer("ShowData.aspx");
}
}
protected void ddlcountry_SelectedIndexChanged1(object sender, EventArgs e)
{
conn.Open();
ddlstate.Items.Clear();
string query2 = "select sn.State_name from State_Master sn, Country_Master cn where cn.Country_id = sn.Country_ID and Country_name ='" + ddlcountry.SelectedItem.Text + "'";
SqlCommand cmd = new SqlCommand(query2, conn);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
ddlstate.Items.Add(dr["State_name"].ToString());
}
conn.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
if (Session.Count > 1)
{
string operation = Session["ope"].ToString();
if (operation == "Edit")
Response.Redirect("ShowData.aspx");
else
Response.Redirect("Login.aspx");
}
else
{
Response.Redirect("Login.aspx");
}
}
protected void btncheckava_Click(object sender, EventArgs e)
{
conn.Open();
string query2 = "select username from test_reg where username='"+txtuname.Text+"'";
SqlCommand cmd = new SqlCommand(query2, conn);
SqlDataReader dr = cmd.ExecuteReader();
lblavamsg.Text = "";
if (dr.Read())
{
lblavamsg.Text = "Username Exist...!";
lblavamsg.ForeColor = Color.Red;
}
else
{
if (txtuname.Text != "")
{
lblavamsg.Text = "Username avaiable...!";
lblavamsg.ForeColor = Color.Green;
}
else
{
lblavamsg.Text = "Please enter username!";
lblavamsg.ForeColor = Color.Red;
}
}
conn.Close();
}
protected void Button3_Click(object sender, EventArgs e)
{
string photo1 = txt_id.Text + ".JPEG";
FileUpload1.SaveAs(Server.MapPath("~/Image/") + photo1);
Image1.ImageUrl = "Image/" + FileUpload1.PostedFile.FileName;
}
}
No comments:
Post a Comment