有关重复的疑问,不允许

有关重复的疑问,不允许

问题描述:

大家好,
我需要帮助.在我的项目中,有一个页面可以让任何员工从该页面预订会议室.我的疑问是,是否有人在特定时间预定了会议室,没有其他员工可以同时预定,即不允许重复预定.应该会打开一个弹出窗口,该窗口会在当时完成的优先预订中选择其他时间.

请给我建议.

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.

关于此的其他问题,您已经使用一些业务对象\图层来创建预订.

因此,您可以使用以下工作流程在业务层中处理此问题

用户提交请求->业务层流程-> sql查询->会议室已预订(sql返回指定范围的结果->从业务层引发异常->在UI中捕获异常

在您的业务层代码中

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
}





在您的UI代码中





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
}



您的spAddConferenceRoom应该检查现有记录,如果存在则抛出错误……例如



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




我会更进一步.创建一个过程,在尝试保存之前 检查可用性.然后,您可以从AJAX调用它,以便当用户选择开始\结束日期时,您可以显示一些反馈,例如房间可用"或房间不可用"




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!!