Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8376377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:25:07+00:00 2026-06-09T15:25:07+00:00

I am struggling with a little strange problem that I don’t know how to

  • 0

I am struggling with a little strange problem that I don’t know how to solve it. I am developing a small web-based events management system. When the user clicks on the Register Button that will be shown in a ModalPopUpExtender control, the system will do the following:
it will check if the user is in the database or not. if not, it will pull his information from the Active Directory.
Then, the system should check if the user has been registered in this event or not. if not, he will be registered in that event and a confirmation email will be sent to him. If yes, a message will be displayed saying “You already have a booking in this event.”

My problem now is: the system sends a confirmation email whether the user has booking or not in that event. So what I should do to modify my code in order to send a confirmation email to the user in the only case that he has no booking in that event?

C# Code (sorry for the lengthy code, but I put it for clarification):

protected void btnSendConfirmationEmail_Click(object sender, EventArgs e)
    {

        checkUserID(userNetworkID);


        SmtpClient sc = new SmtpClient("MailServer");
        StringBuilder sb = new StringBuilder();
        MailMessage msg = new MailMessage();


        //Variables for retrieving the Booking Information
        string title = lblTitle.Text;
        string description = lblDescription.Text;
        string location = lblLocation.Text;
        string startDateTime = lblStartDateTime.Text;
        string endDateTime = lblEndDateTime.Text;

        //Message Information
        string toAddress = userNetworkID + "@mailServer.com";
        string fromAddress = "test@mailServer.com";
        string mailSubject = "Registration Notification";
        string messageBody = @".........................";

        try
        {
            msg.To.Add(toAddress);
            msg.From = new MailAddress(fromAddress, "Reg. Test System");
            msg.Subject = mailSubject;
            msg.Body = messageBody;
            msg.IsBodyHtml = true;

            sc.Send(msg);
        }

        catch (Exception ex)
        {
            throw ex;
            // something bad happened
            //Response.Write("Something bad happened!");

        }

        finally
        {

            if (msg != null)
            {
                msg.Dispose();
            }

        }
    }

    protected void checkUserID(string userID)
    {

        int eventID = Convert.ToInt32(HiddenField1.Value);

        string NetworkID = userID;
        string Name = Service.GetName;
        string BadgeNo = Service.GetBadgeNo;
        string DepartmentCode = Service.GetDeptCode;

        string connString = "Data Source=localhost;Initial Catalog=TestSysDB;Integrated Security=True;";

        //if the user is not in the system database, add him
        if (Security.isExisted(NetworkID) == false)
        {
            //string connString = "Data Source=localhost;Initial Catalog=TestSysDB;Integrated Security=True;";
            string insertCommand = "INSERT INTO Users (NetworkID, Name, BadgeNo, DepartmentCode) values (@NetworkID, @Name, @BadgeNo, @DepartmentCode)";

            using(SqlConnection conn = new SqlConnection(connString))
            {
                //Open DB Connection
                conn.Open();
                using(SqlCommand cmd = new SqlCommand(insertCommand, conn))
                {
                    cmd.Parameters.Clear();
                    cmd.Parameters.AddWithValue("@NetworkID", NetworkID);
                    cmd.Parameters.AddWithValue("@Name", Name);
                    cmd.Parameters.AddWithValue("@BadgeNo", BadgeNo);
                    cmd.Parameters.AddWithValue("@DepartmentCode", DepartmentCode);
                    cmd.ExecuteNonQuery();
                }
                conn.Close();
            }
        }

        string insertBooking = "INSERT INTO BookingDetails (EventID, NetworkID) values (@EventID, @NetworkID)";
        string selectCommand = "SELECT count(*) as UserBookings FROM BookingDetails WHERE NetworkID = NetworkID AND EventID = @EventID";
        using (SqlConnection conn = new SqlConnection(connString))
        {
            //Open DB Connection
            conn.Open();
            using (SqlCommand cmd = new SqlCommand(selectCommand, conn))
            {
                cmd.Parameters.AddWithValue("@EventID", eventID);
                cmd.Parameters.AddWithValue("@NetworkID", NetworkID);
                if ((int)cmd.ExecuteScalar() == 0)
                {
                    SqlCommand cmd2 = new SqlCommand(insertBooking, conn);
                    cmd2.Parameters.Clear();
                    cmd2.Parameters.AddWithValue("@EventID", eventID);
                    cmd2.Parameters.AddWithValue("@NetworkID", NetworkID);
                    cmd2.ExecuteNonQuery();
                }
                else
                {
                    errorSpan.InnerText = "You already have a booking in this event";
                }
            }
            //Close the connection
            conn.Close();
        }


    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:25:09+00:00Added an answer on June 9, 2026 at 3:25 pm

    Something like this

    create a new method UserHasBooking

    private bool UserHasBooking(int userId, int eventID)
    {
        bool result = false;
    
    string connString = "Data Source=localhost\\sqlexpress;Initial Catalog=RegistrationSysDB;Integrated Security=True;";
    string selectCommand = "SELECT count(*) as UserBookingsCount FROM BookingDetails WHERE NetworkID = NetworkID AND EventID = @EventID";
    using (SqlConnection conn = new SqlConnection(connString))
    {
        //Open DB Connection
        conn.Open();
        using (SqlCommand cmd = new SqlCommand(selectCommand, conn))
        {
            cmd.Parameters.AddWithValue("@EventID", eventID);
            cmd.Parameters.AddWithValue("@NetworkID", userId);
            if ((int)cmd.ExecuteScalar() > 0)
            {
                result = true;
            }
        }
        //Close the connection
        conn.Close();
    }
    
        return result;
    }
    
    
    protected void btnSendConfirmationEmail_Click(object sender, EventArgs e)
        {
            int eventID = Convert.ToInt32(HiddenField1.Value);
    
    
    
            if(!UserHasBooking(userNetworkID, eventID))
            {
    
            checkUserID(userNetworkID);
    
    
            SmtpClient sc = new SmtpClient("MAIL.Aramco.com");
            StringBuilder sb = new StringBuilder();
            MailMessage msg = new MailMessage();
    
    
            //Variables for retrieving the Booking Information
            string title = lblTitle.Text;
            string description = lblDescription.Text;
            string location = lblLocation.Text;
            string startDateTime = lblStartDateTime.Text;
            string endDateTime = lblEndDateTime.Text;
    
            //Message Information
            string toAddress = userNetworkID + "@aramco.com";
            string fromAddress = "erms@aramco.com";
            string mailSubject = "Registration Notification";
            string messageBody = @"Greetings, <br /><br />
                                   Your booking information is as following: <br /><br />
                                   <b><u>Event Details</u></b> <br /><br />
                                   <b>Title: </b>" + title +
                                   "<br /> <b>Description: </b>" + description +
                                   "<br /> <b>Location: </b>" + location +
                                   "<br /> <b>Start Date & Time: </b>" + startDateTime +
                                   "<br /> <b>End Date & Time: </b>" + endDateTime +
                                   @"<br /><br /><br /><br /> 
                                     This email was generated using the <a href='http://pmv/PM_Registration_System/Default.aspx'>Events Registration Management System (ERMS) </a>. 
                                     Please do not reply to this email.";
    
            try
            {
                msg.To.Add(toAddress);
                msg.From = new MailAddress(fromAddress, "Events Registration Management System");
                msg.Subject = mailSubject;
                msg.Body = messageBody;
                msg.IsBodyHtml = true;
    
                sc.Send(msg);
            }
    
            catch (Exception ex)
            {
                throw ex;
                // something bad happened
                //Response.Write("Something bad happened!");
    
            }
    
            finally
            {
    
                if (msg != null)
                {
                    msg.Dispose();
                }
    
            }
    
           }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My apologies if this is a little broad, but I'm struggling to know where
I'm struggling with a little problem and starting to arrive at the conclusion it's
So I'm just struggling with a lot of little things in the web app
I'm still struggling with the view-based NSOutlineView in my little Cocoa application. I'm trying
I've been struggling on an issue for days and I don't know what to
Im struggling to find good material about developing web applications in Ruby without using
Currently I am struggling a little with the Unit test framework... what I am
I'm fairly new to vbscript and I'm struggling a little as I'm more familiar
I'm brand new to Moq (using v 4) and am struggling a little with
I'm struggling to create a little Blackjack console game in C++. I've written almost

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.