Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,
i need help.In my project there is one webpage where any employee can book the conference room from that.my doubt is if any one books at a particular time no other employee should book at the same time i.e duplicate booking is not allowed.it should open a popup that alraedy booking done at that time choose some other time.

please suggest me.
Posted
Comments
Sunasara Imdadhusen 22-Feb-11 5:06am    
Did you try before?
Sandeep Mewara 22-Feb-11 5:14am    
Ok. We got the requirement. Now, what is the issue? Where are you stuck?
mandarapu 22-Feb-11 6:03am    
i need the condition that should not allow duplicates.At that time another booking should not allowed.

1 solution

From your other questions on this, you've using a few business objects \ layers to create the booking.

So, you could probably handle this in your business layer, using the following workflow

User submits request -> business layer processes -> sql query -> meeting room already booking (sql returns results for specified range -> throw exception from business layer -> catch exception in UI

In your Business Layer Code

public void SaveConferenceDetails(ConferenceBM conference)
{
    // Validate input parameters for conference object

    // Call database code to check for existing booking, get a DataTable back or whatever. Your stored procedure should check for any existing bookings within the range start date \ end date
    DataTable bookings = YourDatabaseCode.ExecuteDataTable("SomeStoredProceudre" conference.StartDate, conference.EndDate);

    if (bookings.Rows.Count > 0)
    {
        throw new ConferenceRoomAlreadyBookedException("The meeting room is already booked");

        // NB - maybe pass bookings.Rows as event arguments so you can show what is already booked
    }

    // It's not booked, normal save
}




In your UI code
ConferenceBM confBM = new ConferenceBM();
ConferenceBL confBL = new ConferenceBL();

confBM.EmployeeName = ddlEmployeeName.SelectedItem.Text;
confBM.PurposeOfBooking = txtPurpose.Text;
confBM.StartDate = Convert.ToDateTime(txtStartDate.Text);
confBM.EndDate = Convert.ToDateTime(txtEndDate.Text);
confBM.StartTime = Convert.ToDateTime(txtStartTime.Text);
confBM.EndTime = Convert.ToDateTime(txtEndTime.Text);
confBM.ConferenceRoom = dd1conference.SelectedItem.Text;

try
{
    confBL.SaveConferenceDetails(confBM);
}
catch (ConferenceRoomAlreadyBookedException ex)
{
    // Notify client that the meeting room was already booked
}


Your spAddConferenceRoom should check for existing records and throw an error if they exist....e.g.

ALTER PROCEDURE  [dbo].[spAddConferenceRoom]

	(
		@StartDate			DATETIME,
		@EndDate			DATETIME
	)

AS

SET NOCOUNT ON

IF EXISTS(SELECT * FROM Conferences
WHERE (@StartDate BETWEEN StartDate   AND EndDate)   OR
      (@EndDate   BETWEEN StartDate   AND EndDate)   OR
      (StartDate   BETWEEN @StartDate AND @EndDate) OR
      (EndDate     BETWEEN @StartDate AND @EndDate))
BEGIN
	RAISERROR ('Cannot save details, the specified conference date is already booked',16,1)
END

--Otherwise, normal save code here...


RETURN @@ERROR
SET NOCOUNT OFF



I'd go a bit further with this. Create a procedure to check the availability before trying to save. You could then call this from AJAX so that when a user selects start \ end dates, you can show some feedback to say 'Room Available' or 'Room Not Available'

CREATE PROCEDURE  spCheckConferenceAvailability

	(
		@StartDate			DATETIME,
		@EndDate			DATETIME
	)

AS

SET NOCOUNT ON

SELECT * FROM Conferences
WHERE (@StartDate BETWEEN StartDate   AND EndDate)   OR
      (@EndDate   BETWEEN StartDate   AND EndDate)   OR
      (StartDate   BETWEEN @StartDate AND @EndDate) OR
      (EndDate     BETWEEN @StartDate AND @EndDate))

RETURN @@ERROR
SET NOCOUNT OFF
GO


You could probably optimise the date overlap checking, but should work!!
 
Share this answer
 
v2
Comments
mandarapu 22-Feb-11 6:18am    
hai,what is your database code?in business layer i used like this.

public void AddConferenceRoom(ConferenceBM confBM) {

ConferenceDAL confDAL = new ConferenceDAL();

confDAL.AddConferenceRoom(confBM); }

in DAL layer i called all the parameters using sql parameter class and by using sqlhelper method i provided the connection and required storedprocedure.
Dylan Morley 22-Feb-11 6:22am    
I have no idea what you've written so was just giving you an example - that's not real database code.

However, the idea is exactly the same. In your ConferenceDAL, check for existing bookings by writing a bit of SQL in a stored procedure. If it exists, throw the exception which will be passed back through the layers.
mandarapu 22-Feb-11 6:37am    
code in DAL layer:

public void AddConferenceRoom(ConferenceBM confBM)
{ try
{
List<sqlparameter> paramList = new List<sqlparameter>();
SqlParameter parameter = new SqlParameter("@EmployeeName", confBM.EmployeeName);
parameter.DbType = DbType.String;
paramList.Add(parameter);

parameter = new SqlParameter("@PurposeOfBooking", confBM.PurposeOfBooking);
parameter.DbType = DbType.String;
paramList.Add(parameter);

parameter = new SqlParameter("@StartDate", confBM.StartDate);
parameter.DbType = DbType.DateTime;
paramList.Add(parameter);

parameter = new SqlParameter("@EndDate", confBM.EndDate);
parameter.DbType = DbType.DateTime;
paramList.Add(parameter);

SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionString(), CommandType.StoredProcedure, "spAddConferenceRoom", paramList.ToArray());
}
}

in these i need to write the condition are in the storedprocedure?
Dylan Morley 22-Feb-11 7:14am    
See my updated answer:

Throw an error in your save procedure if overlaps found.

Possibly consider checking for overlaps BEFORE saving, this will be a nicer experience for the user
mandarapu 22-Feb-11 9:38am    
thank u.it s working fine

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900