Guest User

Untitled

a guest
Aug 16th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.72 KB | None | 0 0
  1. ADD.APX.CS
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Data;
  9. using System.Data.SqlClient;
  10. using System.Web.UI.HtmlControls;
  11. using System.Collections.Specialized;
  12. using System.Text;
  13.  
  14. public partial class addcustomer : System.Web.UI.Page
  15. {
  16.  
  17.  
  18. readonly static string ConnectionString = "Data Source=172.16.2.24\\SQLExpress2005;Initial Catalog=Test;User ID=test;Password=test";
  19.  
  20. protected void Page_Load(object sender, EventArgs e)
  21. {
  22.  
  23. }
  24.  
  25. protected void LoginCheck(object sender, EventArgs e)
  26.  
  27. {
  28.  
  29.  
  30. if (Textlogin.Text != string.Empty)
  31.  
  32. {
  33.  
  34. SqlConnection _connection = new SqlConnection(ConnectionString);
  35. _connection.Open();
  36.  
  37.  
  38. string strSelectCustomer = "select * from customers WHERE login_id=@login_id";
  39.  
  40.  
  41.  
  42. SqlCommand selectCustomerCommand = new SqlCommand(strSelectCustomer, _connection);
  43.  
  44.  
  45.  
  46. SqlParameter user = new SqlParameter("@login_id", SqlDbType.VarChar);
  47.  
  48. user.Value = Textlogin.Text.Trim().ToString();
  49.  
  50. selectCustomerCommand.Parameters.Add(user);
  51.  
  52. SqlDataReader readLogin = selectCustomerCommand.ExecuteReader();
  53.  
  54. if (readLogin.HasRows)
  55. //int result = (Int32)cmd.ExecuteScalar();
  56. //if (result >= 1)
  57.  
  58. {
  59. //lblStatus.Enabled = true;
  60. lblStatus.Text = "Login not available";
  61.  
  62. lblStatus.ForeColor = System.Drawing.Color.Red;
  63.  
  64.  
  65. }
  66.  
  67. else
  68.  
  69. {
  70. //lblStatus.Enabled = true;
  71. lblStatus.Text = "Login available";
  72.  
  73. lblStatus.ForeColor = System.Drawing.Color.Green;
  74.  
  75.  
  76.  
  77.  
  78.  
  79. }
  80. _connection.Close();
  81.  
  82. }
  83. }
  84.  
  85. protected void ButtonAddCustomer_Click(object sender, EventArgs e)
  86. {
  87.  
  88. SqlConnection _connection = new SqlConnection(ConnectionString);
  89. _connection.Open();
  90.  
  91. SqlCommand insertCustomerCommand = _connection.CreateCommand();
  92. 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()";
  93. insertCustomerCommand = new SqlCommand(insertQuery1, _connection);
  94. insertCustomerCommand.Parameters.AddWithValue("@first_name", Textfirstnm.Text.Trim());
  95. insertCustomerCommand.Parameters.AddWithValue("@last_name", Textlastnm.Text.Trim());
  96. string file_name = FilePhotoUpload.FileName;
  97. FilePhotoUpload.PostedFile.SaveAs(Server.MapPath("~/images/" + file_name));
  98. insertCustomerCommand.Parameters.AddWithValue("@photo", "~/images/" + file_name.ToString());
  99. insertCustomerCommand.Parameters.AddWithValue("@date_of_birth", Textdob.Text);
  100.  
  101. insertCustomerCommand.Parameters.AddWithValue("@address", Textaddress.Text);
  102. insertCustomerCommand.Parameters.AddWithValue("@pin_code", Textpin.Text);
  103. insertCustomerCommand.Parameters.AddWithValue("@phone_number", Textphone.Text);
  104. insertCustomerCommand.Parameters.AddWithValue("@email", Textemail.Text);
  105. if (RadioButtonGender.SelectedValue == "0")
  106. {
  107. insertCustomerCommand.Parameters.AddWithValue("@is_male", RadioButtonGender.SelectedValue);
  108. }
  109. if (RadioButtonGender.SelectedValue == "1")
  110. {
  111.  
  112. insertCustomerCommand.Parameters.AddWithValue("@is_male", RadioButtonGender.SelectedValue);
  113. }
  114.  
  115. insertCustomerCommand.Parameters.AddWithValue("@visa", CheckBoxVisaCard.Checked);
  116. insertCustomerCommand.Parameters.AddWithValue("@amex", CheckBoxAmexCard.Checked);
  117. insertCustomerCommand.Parameters.AddWithValue("@master_card", CheckBoxMasterCard.Checked);
  118. if (DropDownListCustomerType.SelectedValue == "1")
  119. {
  120. insertCustomerCommand.Parameters.AddWithValue("@customer_type", DropDownListCustomerType.SelectedValue);
  121. }
  122. if (DropDownListCustomerType.SelectedValue == "2")
  123. {
  124. insertCustomerCommand.Parameters.AddWithValue("@customer_type", DropDownListCustomerType.SelectedValue);
  125. }
  126. if (DropDownListCustomerType.SelectedValue == "3")
  127. {
  128. insertCustomerCommand.Parameters.AddWithValue("@customer_type", DropDownListCustomerType.SelectedValue);
  129. }
  130. insertCustomerCommand.Parameters.AddWithValue("@login_id", Textlogin.Text);
  131. insertCustomerCommand.Parameters.AddWithValue("@password", Textpass.Text);
  132. if (RadioButtonActive.SelectedValue == "1")
  133. {
  134. insertCustomerCommand.Parameters.AddWithValue("@is_active", RadioButtonActive.SelectedValue);
  135.  
  136. }
  137.  
  138. if (RadioButtonActive.SelectedValue == "0")
  139. {
  140. insertCustomerCommand.Parameters.AddWithValue("@is_active", RadioButtonActive.SelectedValue);
  141.  
  142. }
  143.  
  144. int customer_id = Convert.ToInt32(insertCustomerCommand.ExecuteScalar());
  145.  
  146.  
  147. if (ListBoxHobbies.Items.Count > 0)
  148. {
  149. for (int i = 0; i < ListBoxHobbies.Items.Count; i++)
  150. {
  151.  
  152. if (ListBoxHobbies.Items[i].Selected)
  153. {
  154. string selectedItem = ListBoxHobbies.Items[i].Value;
  155. //Response.Write("value=" + selectedItem);
  156. string insertquery2 = "insert into customer_hobbies(cust_id,hobby_id) values(@customer_id,@hobby_id)";
  157. SqlCommand insertCustomerHobbies = new SqlCommand(insertquery2, _connection);
  158. insertCustomerHobbies.Parameters.AddWithValue("@customer_id", customer_id);
  159. insertCustomerHobbies.Parameters.AddWithValue("@hobby_id", selectedItem);
  160. insertCustomerHobbies.ExecuteNonQuery();
  161. }
  162. }
  163. }
  164.  
  165.  
  166. Response.AppendHeader("Refresh", "5;url=Default.aspx");
  167. LabelSuccessMessage.Text = "Customer added successfully";
  168. _connection.Close();
  169.  
  170. }
  171.  
  172. protected void ButtonCancel_Click(object sender, EventArgs e)
  173. {
  174.  
  175. Response.Redirect("Default.aspx");
  176. }
  177. }
Add Comment
Please, Sign In to add comment