Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void BtnAdd_Click(object sender, EventArgs e)
- {
- MethEncryptionPassword(TxtBxPassword.Text);
- string StrEncryptedPassword = MethEncryptionPassword(TxtBxPassword.Text).ToString();
- MethEncryptionConfirmPassword(TxtBxConfirmPassword.Text);
- string StrEncryptedConfirmPassword = MethEncryptionConfirmPassword(TxtBxConfirmPassword.Text).ToString();
- ClsStandard.MethPasswordValidator(StrEncryptedPassword, StrEncryptedConfirmPassword);
- string StrCommonMessage = ClsStandard.StrCommonMessage;
- if (StrCommonMessage == "Passwords are equal")
- {
- try
- {
- string StrDateTimeNow = DateTime.Now.ToString("dd-MMM-yyyy hhhh:mm tt");
- ClsConnectionOriented.MethAddUser(TxtBxFullName, TxtBxDesignation, TxtBxOfficeLocation, TxtBxPermanentAddress, TxtBxPhoneNumber, TxtBxEMailID, TxtBxUsername, StrEncryptedPassword, CmbBxAccessPrivilage, StrDateTimeNow);
- StrCommonMessage = ClsConnectionOriented.StrCommonMessage;
- if (StrCommonMessage == "The Username is already exists")
- {
- MessageBox.Show("Sorry! The desired username is already exists. Please enter different username", "Add User", MessageBoxButtons.OK, MessageBoxIcon.Hand);
- TxtBxUsername.Focus();
- }
- else if (StrCommonMessage == "The Phone Number and EMail ID are already linked with other user")
- {
- 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);
- TxtBxPhoneNumber.Focus();
- }
- else if (StrCommonMessage == "The Phone Number is already linked with other user")
- {
- 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);
- TxtBxPhoneNumber.Focus();
- }
- else if (StrCommonMessage == "The EMail ID is already linked with other user")
- {
- 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);
- TxtBxEMailID.Focus();
- }
- else if (StrCommonMessage == "User added successfully")
- {
- MessageBox.Show("Congratulations! A new user has been added successfully", "Add User", MessageBoxButtons.OK, MessageBoxIcon.Information);
- ClsStandard.MethEmptyAllTextBoxes(Controls);
- CmbBxAccessPrivilage.SelectedIndex = -1;
- TxtBxFullName.Focus();
- PicBxSHIPassword.Image = Properties.Resources.password_blank;
- PicBxSHIConfirmPassword.Image = Properties.Resources.password_blank;
- }
- else
- {
- }
- }
- catch (Exception ExBtnAddUser)
- {
- MessageBox.Show(ExBtnAddUser.Message, "Add User", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else if (StrCommonMessage == "Passwords are not equal")
- {
- MessageBox.Show("Sorry! The password does not match. Please retype the password", "Add User", MessageBoxButtons.OK, MessageBoxIcon.Hand);
- TxtBxPassword.Clear();
- TxtBxConfirmPassword.Clear();
- TxtBxPassword.Focus();
- }
- else
- {
- }
- using MySql.Data.MySqlClient;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Spiral
- {
- class ClsConnectionOriented
- {
- private static string StrServerCS = "server=localhost;database=db_root;uid=root;pwd=root$123456;";
- public static string StrCommonMessage;
- public static void MethAddUser(TextBox TxtBxFullName, TextBox TxtBxDesignation, TextBox TxtBxOfficeLocation, TextBox TxtBxPermanentAddress, TextBox TxtBxPhoneNumber, TextBox TxtBxEMailID, TextBox TxtBxUsername, string StrEncryptedPassword, ComboBox CmbBxAccessPrivilage, string StrRegistrationDataTime)
- {
- string StrQuerySPAddUser = "CALL SP_ADD_USER('" + TxtBxFullName.Text + "', '" + TxtBxDesignation.Text + "', '" + TxtBxOfficeLocation.Text + "', '" + TxtBxPermanentAddress.Text + "', '" + TxtBxPhoneNumber.Text + "', '" + TxtBxEMailID.Text + "', '" + TxtBxUsername.Text + "', '" + StrEncryptedPassword + "', '" + CmbBxAccessPrivilage.Text + "', '" + StrRegistrationDataTime + "');";
- MySqlConnection ConAddUser = new MySqlConnection(StrServerCS);
- MySqlCommand CmdAddUser = new MySqlCommand(StrQuerySPAddUser, ConAddUser);
- try
- {
- ConAddUser.Open();
- MySqlDataReader DrAddUser = CmdAddUser.ExecuteReader();
- while (DrAddUser.Read())
- {
- StrCommonMessage = (string)DrAddUser["MESSAGE"];
- }
- DrAddUser.Close();
- ConAddUser.Close();
- }
- catch (Exception ExMethAddUser)
- {
- MessageBox.Show(ExMethAddUser.Message, "Add User", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- }
- 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))
- BEGIN
- DECLARE VAR_USER_ID BIGINT(20);
- DECLARE VAR_PRIVILAGE_ID TINYINT(1);
- DECLARE VAR_LOGIN_ID BIGINT(20);
- DECLARE VAR_STATUS_ID TINYINT(1);
- DECLARE VAR_EXIST_CHECK_USERNAME INT;
- DECLARE VAR_EXIST_CHECK_PHONE_NUMBER INT;
- DECLARE VAR_EXIST_CHECK_EMAIL_ID INT;
- DECLARE VAR_MESSAGE VARCHAR(65);
- SELECT COUNT(*) INTO VAR_EXIST_CHECK_USERNAME FROM `tbl_login` WHERE `tbl_lgn_username` = VAR_USERNAME;
- SELECT COUNT(*) INTO VAR_EXIST_CHECK_PHONE_NUMBER FROM `tbl_user` WHERE `tbl_usr_phone_number` = VAR_PHONE_NUMBER;
- SELECT COUNT(*) INTO VAR_EXIST_CHECK_EMAIL_ID FROM `tbl_user` WHERE `tbl_usr_email_id` = VAR_EMAIL_ID;
- IF (VAR_EXIST_CHECK_USERNAME > 0) THEN
- SET VAR_MESSAGE = 'The Username is already exists';
- ELSEIF (VAR_EXIST_CHECK_USERNAME = 0) THEN
- IF (VAR_EXIST_CHECK_PHONE_NUMBER > 0 AND VAR_EXIST_CHECK_EMAIL_ID > 0) THEN
- SET VAR_MESSAGE = 'The Phone Number and EMail ID are already linked with other user';
- ELSEIF (VAR_EXIST_CHECK_PHONE_NUMBER > 0) THEN
- SET VAR_MESSAGE = 'The Phone Number is already linked with another user';
- ELSEIF (VAR_EXIST_CHECK_EMAIL_ID > 0) THEN
- SET VAR_MESSAGE = 'The EMail ID is already linked with other user';
- ELSE
- SET VAR_USER_ID = (SELECT FN_GET_NEW_USER_ID());
- SET VAR_PRIVILAGE_ID = (SELECT FN_GET_PRIVILAGE_ID(VAR_PRIVILAGE_NAME));
- SET VAR_LOGIN_ID = (SELECT FN_GET_NEW_LOGIN_ID());
- SET VAR_STATUS_ID = (SELECT FN_GET_STATUS_ID(VAR_STATUS));
- 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);
- 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);
- SET VAR_MESSAGE = 'User added successfully';
- END IF;
- END IF;
- SELECT VAR_MESSAGE AS MESSAGE;
- END
Add Comment
Please, Sign In to add comment