Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ADD.APX.CS
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data;
- using System.Data.SqlClient;
- using System.Web.UI.HtmlControls;
- using System.Collections.Specialized;
- using System.Text;
- public partial class addcustomer : System.Web.UI.Page
- {
- readonly static string ConnectionString = "Data Source=172.16.2.24\\SQLExpress2005;Initial Catalog=Test;User ID=test;Password=test";
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void LoginCheck(object sender, EventArgs e)
- {
- if (Textlogin.Text != string.Empty)
- {
- SqlConnection _connection = new SqlConnection(ConnectionString);
- _connection.Open();
- string strSelectCustomer = "select * from customers WHERE login_id=@login_id";
- SqlCommand selectCustomerCommand = new SqlCommand(strSelectCustomer, _connection);
- SqlParameter user = new SqlParameter("@login_id", SqlDbType.VarChar);
- user.Value = Textlogin.Text.Trim().ToString();
- selectCustomerCommand.Parameters.Add(user);
- SqlDataReader readLogin = selectCustomerCommand.ExecuteReader();
- if (readLogin.HasRows)
- //int result = (Int32)cmd.ExecuteScalar();
- //if (result >= 1)
- {
- //lblStatus.Enabled = true;
- lblStatus.Text = "Login not available";
- lblStatus.ForeColor = System.Drawing.Color.Red;
- }
- else
- {
- //lblStatus.Enabled = true;
- lblStatus.Text = "Login available";
- lblStatus.ForeColor = System.Drawing.Color.Green;
- }
- _connection.Close();
- }
- }
- protected void ButtonAddCustomer_Click(object sender, EventArgs e)
- {
- SqlConnection _connection = new SqlConnection(ConnectionString);
- _connection.Open();
- SqlCommand insertCustomerCommand = _connection.CreateCommand();
- string insertQuery1 = "insert into customers(first_name,last_name,photo,date_of_birth,address,pin_code,phone_number,email,is_male,visa,amex,master_card,customer_type,login_id,password,is_active) values(@first_name,@last_name,@photo,@date_of_birth,@address,@pin_code,@phone_number,@email,@is_male,@visa,@amex,@master_card,@customer_type,@login_id,@password,@is_active)" + "Select Scope_Identity()";
- insertCustomerCommand = new SqlCommand(insertQuery1, _connection);
- insertCustomerCommand.Parameters.AddWithValue("@first_name", Textfirstnm.Text.Trim());
- insertCustomerCommand.Parameters.AddWithValue("@last_name", Textlastnm.Text.Trim());
- string file_name = FilePhotoUpload.FileName;
- FilePhotoUpload.PostedFile.SaveAs(Server.MapPath("~/images/" + file_name));
- insertCustomerCommand.Parameters.AddWithValue("@photo", "~/images/" + file_name.ToString());
- insertCustomerCommand.Parameters.AddWithValue("@date_of_birth", Textdob.Text);
- insertCustomerCommand.Parameters.AddWithValue("@address", Textaddress.Text);
- insertCustomerCommand.Parameters.AddWithValue("@pin_code", Textpin.Text);
- insertCustomerCommand.Parameters.AddWithValue("@phone_number", Textphone.Text);
- insertCustomerCommand.Parameters.AddWithValue("@email", Textemail.Text);
- if (RadioButtonGender.SelectedValue == "0")
- {
- insertCustomerCommand.Parameters.AddWithValue("@is_male", RadioButtonGender.SelectedValue);
- }
- if (RadioButtonGender.SelectedValue == "1")
- {
- insertCustomerCommand.Parameters.AddWithValue("@is_male", RadioButtonGender.SelectedValue);
- }
- insertCustomerCommand.Parameters.AddWithValue("@visa", CheckBoxVisaCard.Checked);
- insertCustomerCommand.Parameters.AddWithValue("@amex", CheckBoxAmexCard.Checked);
- insertCustomerCommand.Parameters.AddWithValue("@master_card", CheckBoxMasterCard.Checked);
- if (DropDownListCustomerType.SelectedValue == "1")
- {
- insertCustomerCommand.Parameters.AddWithValue("@customer_type", DropDownListCustomerType.SelectedValue);
- }
- if (DropDownListCustomerType.SelectedValue == "2")
- {
- insertCustomerCommand.Parameters.AddWithValue("@customer_type", DropDownListCustomerType.SelectedValue);
- }
- if (DropDownListCustomerType.SelectedValue == "3")
- {
- insertCustomerCommand.Parameters.AddWithValue("@customer_type", DropDownListCustomerType.SelectedValue);
- }
- insertCustomerCommand.Parameters.AddWithValue("@login_id", Textlogin.Text);
- insertCustomerCommand.Parameters.AddWithValue("@password", Textpass.Text);
- if (RadioButtonActive.SelectedValue == "1")
- {
- insertCustomerCommand.Parameters.AddWithValue("@is_active", RadioButtonActive.SelectedValue);
- }
- if (RadioButtonActive.SelectedValue == "0")
- {
- insertCustomerCommand.Parameters.AddWithValue("@is_active", RadioButtonActive.SelectedValue);
- }
- int customer_id = Convert.ToInt32(insertCustomerCommand.ExecuteScalar());
- if (ListBoxHobbies.Items.Count > 0)
- {
- for (int i = 0; i < ListBoxHobbies.Items.Count; i++)
- {
- if (ListBoxHobbies.Items[i].Selected)
- {
- string selectedItem = ListBoxHobbies.Items[i].Value;
- //Response.Write("value=" + selectedItem);
- string insertquery2 = "insert into customer_hobbies(cust_id,hobby_id) values(@customer_id,@hobby_id)";
- SqlCommand insertCustomerHobbies = new SqlCommand(insertquery2, _connection);
- insertCustomerHobbies.Parameters.AddWithValue("@customer_id", customer_id);
- insertCustomerHobbies.Parameters.AddWithValue("@hobby_id", selectedItem);
- insertCustomerHobbies.ExecuteNonQuery();
- }
- }
- }
- Response.AppendHeader("Refresh", "5;url=Default.aspx");
- LabelSuccessMessage.Text = "Customer added successfully";
- _connection.Close();
- }
- protected void ButtonCancel_Click(object sender, EventArgs e)
- {
- Response.Redirect("Default.aspx");
- }
- }
Add Comment
Please, Sign In to add comment