Guest User

Untitled

a guest
Sep 30th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.22 KB | None | 0 0
  1. private void BtnAdd_Click(object sender, EventArgs e)
  2. {
  3. MethEncryptionPassword(TxtBxPassword.Text);
  4. string StrEncryptedPassword = MethEncryptionPassword(TxtBxPassword.Text).ToString();
  5.  
  6. MethEncryptionConfirmPassword(TxtBxConfirmPassword.Text);
  7. string StrEncryptedConfirmPassword = MethEncryptionConfirmPassword(TxtBxConfirmPassword.Text).ToString();
  8.  
  9. ClsStandard.MethPasswordValidator(StrEncryptedPassword, StrEncryptedConfirmPassword);
  10. string StrCommonMessage = ClsStandard.StrCommonMessage;
  11.  
  12. if (StrCommonMessage == "Passwords are equal")
  13. {
  14. try
  15. {
  16. string StrDateTimeNow = DateTime.Now.ToString("dd-MMM-yyyy hhhh:mm tt");
  17. ClsConnectionOriented.MethAddUser(TxtBxFullName, TxtBxDesignation, TxtBxOfficeLocation, TxtBxPermanentAddress, TxtBxPhoneNumber, TxtBxEMailID, TxtBxUsername, StrEncryptedPassword, CmbBxAccessPrivilage, StrDateTimeNow);
  18. StrCommonMessage = ClsConnectionOriented.StrCommonMessage;
  19.  
  20. if (StrCommonMessage == "The Username is already exists")
  21. {
  22. MessageBox.Show("Sorry! The desired username is already exists. Please enter different username", "Add User", MessageBoxButtons.OK, MessageBoxIcon.Hand);
  23. TxtBxUsername.Focus();
  24. }
  25. else if (StrCommonMessage == "The Phone Number and EMail ID are already linked with other user")
  26. {
  27. MessageBox.Show("Sorry! The desired phone number and email id are already linked with other user. Please enter different phone number and email id", "Add User", MessageBoxButtons.OK, MessageBoxIcon.Hand);
  28. TxtBxPhoneNumber.Focus();
  29. }
  30. else if (StrCommonMessage == "The Phone Number is already linked with other user")
  31. {
  32. MessageBox.Show("Sorry! The desired phone number is already linked with other user. Please enter a different phone number", "Add User", MessageBoxButtons.OK, MessageBoxIcon.Hand);
  33. TxtBxPhoneNumber.Focus();
  34. }
  35. else if (StrCommonMessage == "The EMail ID is already linked with other user")
  36. {
  37. MessageBox.Show("Sorry! The desired email id is already linked with other user. Please enter a different email id", "Add User", MessageBoxButtons.OK, MessageBoxIcon.Hand);
  38. TxtBxEMailID.Focus();
  39. }
  40. else if (StrCommonMessage == "User added successfully")
  41. {
  42. MessageBox.Show("Congratulations! A new user has been added successfully", "Add User", MessageBoxButtons.OK, MessageBoxIcon.Information);
  43. ClsStandard.MethEmptyAllTextBoxes(Controls);
  44. CmbBxAccessPrivilage.SelectedIndex = -1;
  45. TxtBxFullName.Focus();
  46. PicBxSHIPassword.Image = Properties.Resources.password_blank;
  47. PicBxSHIConfirmPassword.Image = Properties.Resources.password_blank;
  48. }
  49. else
  50. {
  51. }
  52. }
  53. catch (Exception ExBtnAddUser)
  54. {
  55. MessageBox.Show(ExBtnAddUser.Message, "Add User", MessageBoxButtons.OK, MessageBoxIcon.Error);
  56. }
  57. }
  58. else if (StrCommonMessage == "Passwords are not equal")
  59. {
  60. MessageBox.Show("Sorry! The password does not match. Please retype the password", "Add User", MessageBoxButtons.OK, MessageBoxIcon.Hand);
  61. TxtBxPassword.Clear();
  62. TxtBxConfirmPassword.Clear();
  63. TxtBxPassword.Focus();
  64. }
  65. else
  66. {
  67. }
  68.  
  69. using MySql.Data.MySqlClient;
  70. using System;
  71. using System.Collections.Generic;
  72. using System.Data;
  73. using System.Linq;
  74. using System.Text;
  75. using System.Threading;
  76. using System.Threading.Tasks;
  77. using System.Windows.Forms;
  78.  
  79. namespace Spiral
  80. {
  81. class ClsConnectionOriented
  82. {
  83. private static string StrServerCS = "server=localhost;database=db_root;uid=root;pwd=root$123456;";
  84. public static string StrCommonMessage;
  85.  
  86. public static void MethAddUser(TextBox TxtBxFullName, TextBox TxtBxDesignation, TextBox TxtBxOfficeLocation, TextBox TxtBxPermanentAddress, TextBox TxtBxPhoneNumber, TextBox TxtBxEMailID, TextBox TxtBxUsername, string StrEncryptedPassword, ComboBox CmbBxAccessPrivilage, string StrRegistrationDataTime)
  87. {
  88. string StrQuerySPAddUser = "CALL SP_ADD_USER('" + TxtBxFullName.Text + "', '" + TxtBxDesignation.Text + "', '" + TxtBxOfficeLocation.Text + "', '" + TxtBxPermanentAddress.Text + "', '" + TxtBxPhoneNumber.Text + "', '" + TxtBxEMailID.Text + "', '" + TxtBxUsername.Text + "', '" + StrEncryptedPassword + "', '" + CmbBxAccessPrivilage.Text + "', '" + StrRegistrationDataTime + "');";
  89. MySqlConnection ConAddUser = new MySqlConnection(StrServerCS);
  90. MySqlCommand CmdAddUser = new MySqlCommand(StrQuerySPAddUser, ConAddUser);
  91.  
  92. try
  93. {
  94. ConAddUser.Open();
  95. MySqlDataReader DrAddUser = CmdAddUser.ExecuteReader();
  96.  
  97. while (DrAddUser.Read())
  98. {
  99. StrCommonMessage = (string)DrAddUser["MESSAGE"];
  100. }
  101. DrAddUser.Close();
  102. ConAddUser.Close();
  103. }
  104. catch (Exception ExMethAddUser)
  105. {
  106. MessageBox.Show(ExMethAddUser.Message, "Add User", MessageBoxButtons.OK, MessageBoxIcon.Error);
  107. }
  108. }
  109. }
  110. }
  111.  
  112. CREATE DEFINER=`root`@`%` PROCEDURE `SP_ADD_USER`(IN VAR_FULL_NAME VARCHAR(1000), IN VAR_DESIGNATION VARCHAR(500), IN VAR_OFFICE_LOCATION VARCHAR(500), IN VAR_PERMANENT_ADDRESS VARCHAR(2000), IN VAR_PHONE_NUMBER VARCHAR(20), IN VAR_EMAIL_ID VARCHAR(1000), IN VAR_USERNAME VARCHAR(100), IN VAR_ENCRYPTED_PASSWORD VARCHAR(2000), IN VAR_STATUS VARCHAR(10), IN VAR_PRIVILAGE_NAME VARCHAR(15), IN VAR_REGISTRATON_DATE_TIME VARCHAR(20))
  113. BEGIN
  114. DECLARE VAR_USER_ID BIGINT(20);
  115. DECLARE VAR_PRIVILAGE_ID TINYINT(1);
  116. DECLARE VAR_LOGIN_ID BIGINT(20);
  117. DECLARE VAR_STATUS_ID TINYINT(1);
  118. DECLARE VAR_EXIST_CHECK_USERNAME INT;
  119. DECLARE VAR_EXIST_CHECK_PHONE_NUMBER INT;
  120. DECLARE VAR_EXIST_CHECK_EMAIL_ID INT;
  121. DECLARE VAR_MESSAGE VARCHAR(65);
  122. SELECT COUNT(*) INTO VAR_EXIST_CHECK_USERNAME FROM `tbl_login` WHERE `tbl_lgn_username` = VAR_USERNAME;
  123. SELECT COUNT(*) INTO VAR_EXIST_CHECK_PHONE_NUMBER FROM `tbl_user` WHERE `tbl_usr_phone_number` = VAR_PHONE_NUMBER;
  124. SELECT COUNT(*) INTO VAR_EXIST_CHECK_EMAIL_ID FROM `tbl_user` WHERE `tbl_usr_email_id` = VAR_EMAIL_ID;
  125. IF (VAR_EXIST_CHECK_USERNAME > 0) THEN
  126. SET VAR_MESSAGE = 'The Username is already exists';
  127. ELSEIF (VAR_EXIST_CHECK_USERNAME = 0) THEN
  128. IF (VAR_EXIST_CHECK_PHONE_NUMBER > 0 AND VAR_EXIST_CHECK_EMAIL_ID > 0) THEN
  129. SET VAR_MESSAGE = 'The Phone Number and EMail ID are already linked with other user';
  130. ELSEIF (VAR_EXIST_CHECK_PHONE_NUMBER > 0) THEN
  131. SET VAR_MESSAGE = 'The Phone Number is already linked with another user';
  132. ELSEIF (VAR_EXIST_CHECK_EMAIL_ID > 0) THEN
  133. SET VAR_MESSAGE = 'The EMail ID is already linked with other user';
  134. ELSE
  135. SET VAR_USER_ID = (SELECT FN_GET_NEW_USER_ID());
  136. SET VAR_PRIVILAGE_ID = (SELECT FN_GET_PRIVILAGE_ID(VAR_PRIVILAGE_NAME));
  137. SET VAR_LOGIN_ID = (SELECT FN_GET_NEW_LOGIN_ID());
  138. SET VAR_STATUS_ID = (SELECT FN_GET_STATUS_ID(VAR_STATUS));
  139. INSERT INTO `tbl_user`(`tbl_usr_id`, `tbl_usr_full_name`, `tbl_usr_designation`, `tbl_usr_office_location`, `tbl_usr_permanent_address`, `tbl_usr_phone_number`, `tbl_usr_email_id`, `tbl_usr_registration_date_time`) VALUES(VAR_USER_ID, VAR_FULL_NAME, VAR_DESIGNATION, VAR_OFFICE_LOCATION, VAR_PERMANENT_ADDRESS, VAR_PHONE_NUMBER, VAR_EMAIL_ID, VAR_REGISTRATON_DATE_TIME);
  140. INSERT INTO `tbl_login`(`tbl_lgn_id`, `tbl_lgn_user_id`, `tbl_lgn_prvlg_id`, `tbl_lgn_username`, `tbl_lgn_password`, `tbl_lgn_status_id`) VALUES(VAR_LOGIN_ID, VAR_USER_ID, VAR_PRIVILAGE_ID, VAR_USERNAME, VAR_ENCRYPTED_PASSWORD, VAR_STATUS_ID);
  141. SET VAR_MESSAGE = 'User added successfully';
  142. END IF;
  143. END IF;
  144. SELECT VAR_MESSAGE AS MESSAGE;
  145. END
Add Comment
Please, Sign In to add comment