search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

conflict detection still has some problems. Bug?

Asked by Anonymous
7 years ago.

I have tried the code you posted few days ago.
The conflict detection still has some problems.

I mod the code post little bit just to make it easier to see.

Inside detector, there are 8 events.
_event 0 and _event 1 are from normal().
_event 2 to 7 are from recurring()

start end
_event 0: 2012-11-08 07:00 2012-11-08 12:00
_event 1: 2012-11-09 16:00 2012-11-09 22:00
_event 2:2012-11-08 07:00 2012-11-08 12:00
_event 3:2012-11-09 07:00 2012-11-09 12:00
_event 4:2012-11-10 07:00 2012-11-10 12:00
_event 5:2012-11-11 07:00 2012-11-11 12:00
_event 6:2012-11-12 07:00 2012-11-12 12:00
_event 7:2012-11-13 07:00 2012-11-13 12:00

_event 0 and event 2 are conflict schedule, but detector ignores them.

If I don't insert this new row in normal():

dr = dt.NewRow();
dr["id"] = 2;
dr["start"] = Convert.ToDateTime("2012-11-09 16:00");
dr["end"] = Convert.ToDateTime("2012-11-09 22:00");
dr["name"] = "Event 2";
dr["resourceid"] = 20;
dt.Rows.Add(dr);

Detection has 7 events and it works fine.

Maybe a bug or due to my inexperience?

The following is the code:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using DayPilot.Web.Ui.Conflict;
using DayPilot.Web.Ui.Recurrence;

public partial class Test_ConflictDetector : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
RecurrenceRule r = RecurrenceRule.Decode("MzA5#2#C#T#5#RCAqICo=");
DateTime Today = new DateTime(2012,11,01,10,10,00);
DateTime NextYearToday = new DateTime(2013,11,01,10,00,00);
var detector = new ConflictDetector();
detector.Add(normal(), "start", "end", "resourceid");
detector.AddRecurring(recurring(), "start", "end", "resourceid", "recurrence", "id", "master");
detector.ForRange(Today, NextYearToday);

GridView1.DataSource = detector.List;

DataBind();
if (detector.Count > 0)
{
Label1.Text =Convert.ToString(detector.Count);
}
}

private DataTable normal()
{
DataTable dt;
dt = new DataTable();
dt.Columns.Add("start", typeof(DateTime));
dt.Columns.Add("end", typeof(DateTime));
dt.Columns.Add("name", typeof(string));
dt.Columns.Add("id", typeof(string));
dt.Columns.Add("column", typeof(string));
dt.Columns.Add("resourceid", typeof(int));

DataRow dr;

dr = dt.NewRow();
dr["id"] = 1;
dr["start"] = Convert.ToDateTime("2012-11-08 07:00");
dr["end"] = Convert.ToDateTime("2012-11-08 12:00");
dr["name"] = "Event 1";
dr["resourceid"] = 20;
dt.Rows.Add(dr);

/*
dr = dt.NewRow();
dr["id"] = 2;
dr["start"] = Convert.ToDateTime("2012-11-09 16:00");
dr["end"] = Convert.ToDateTime("2012-11-09 22:00");
dr["name"] = "Event 2";
dr["resourceid"] = 20;
dt.Rows.Add(dr);
*/

return dt;
}

private DataTable recurring()
{
DataTable dt;
dt = new DataTable();
dt.Columns.Add("start", typeof(DateTime));
dt.Columns.Add("end", typeof(DateTime));
dt.Columns.Add("name", typeof(string));
dt.Columns.Add("id", typeof(string));
dt.Columns.Add("column", typeof(string));
dt.Columns.Add("recurrence", typeof(string));
dt.Columns.Add("resourceid", typeof(int));

DataRow dr;

dr = dt.NewRow();
dr["id"] = 309;
dr["start"] = Convert.ToDateTime("2012-11-08 07:00");
dr["end"] = Convert.ToDateTime("2012-11-08 12:00");
dr["name"] = "Recurring";
dr["resourceid"] = 20;
dr["recurrence"] = "MzA5#2#C#T#5#RCAqICo=";
//dr["recurrence"] = RecurrenceRule.FromDateTime("3", (DateTime) dr["start"]).Daily().Times(5).Encode();
dt.Rows.Add(dr);

return dt;
}
}

Comment posted by Dan Letecky [DayPilot]
7 years ago.

Please let me check it.

Comment posted by Dan Letecky [DayPilot]
7 years ago.

If I run this code with the latest build (7.1.2727, see http://www.daypilot.org/sandbox/) it seems to work fine:

Start	End	Events in Conflict
11/8/2012 7:00:00 AM	11/8/2012 12:00:00 PM	 2

What's the version of DayPilot you are using?

Comment posted by Anonymous
7 years ago.

I use 7.1.2727 and old 7.1.2702.1.

I put a comment block on the above code. so

dr = dt.NewRow();
dr["id"] = 2;
dr["start"] = Convert.ToDateTime("2012-11-09 16:00");
dr["end"] = Convert.ToDateTime("2012-11-09 22:00");
dr["name"] = "Event 2";
dr["resourceid"] = 20;
dt.Rows.Add(dr);

will not execute.

If you remove the comment block /* and */ at line 57 and 65.
You will get an empty gridview and detect.Count=0.

The code should look like this

using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using DayPilot.Web.Ui.Conflict;
using DayPilot.Web.Ui.Recurrence;

public partial class Test_ConflictDetector : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{
RecurrenceRule r = RecurrenceRule.Decode("MzA5#2#C#T#5#RCAqICo=");
DateTime Today = new DateTime(2012, 11, 01, 10, 10, 00);
DateTime NextYearToday = new DateTime(2013, 11, 01, 10, 00, 00);
var detector = new ConflictDetector();
detector.Add(normal(), "start", "end", "resourceid");
detector.AddRecurring(recurring(), "start", "end", "resourceid", "recurrence", "id", "master");
detector.ForRange(Today, NextYearToday);

GridView1.DataSource = detector.List;

DataBind();
if (detector.Count > 0)
{
Label1.Text = Convert.ToString(detector.Count);
}
}

private DataTable normal()
{
DataTable dt;
dt = new DataTable();
dt.Columns.Add("start", typeof(DateTime));
dt.Columns.Add("end", typeof(DateTime));
dt.Columns.Add("name", typeof(string));
dt.Columns.Add("id", typeof(string));
dt.Columns.Add("column", typeof(string));
dt.Columns.Add("resourceid", typeof(int));

DataRow dr;

dr = dt.NewRow();
dr["id"] = 1;
dr["start"] = Convert.ToDateTime("2012-11-08 07:00");
dr["end"] = Convert.ToDateTime("2012-11-08 12:00");
dr["name"] = "Event 1";
dr["resourceid"] = 20;
dt.Rows.Add(dr);

dr = dt.NewRow();
dr["id"] = 2;
dr["start"] = Convert.ToDateTime("2012-11-09 16:00");
dr["end"] = Convert.ToDateTime("2012-11-09 22:00");
dr["name"] = "Event 2";
dr["resourceid"] = 20;
dt.Rows.Add(dr);

return dt;
}

private DataTable recurring()
{
DataTable dt;
dt = new DataTable();
dt.Columns.Add("start", typeof(DateTime));
dt.Columns.Add("end", typeof(DateTime));
dt.Columns.Add("name", typeof(string));
dt.Columns.Add("id", typeof(string));
dt.Columns.Add("column", typeof(string));
dt.Columns.Add("recurrence", typeof(string));
dt.Columns.Add("resourceid", typeof(int));

DataRow dr;

dr = dt.NewRow();
dr["id"] = 309;
dr["start"] = Convert.ToDateTime("2012-11-08 07:00");
dr["end"] = Convert.ToDateTime("2012-11-08 12:00");
dr["name"] = "Recurring";
dr["resourceid"] = 20;
dr["recurrence"] = "MzA5#2#C#T#5#RCAqICo=";
//dr["recurrence"] = RecurrenceRule.FromDateTime("3", (DateTime) dr["start"]).Daily().Times(5).Encode();
dt.Rows.Add(dr);

return dt;
}
}

The detection fails if there are additional row in normal().

Comment posted by Dan Letecky [DayPilot]
7 years ago.

Thanks! I can see the problem now.

Answer posted by Dan Letecky [DayPilot]
7 years ago.

It's fixed now in build 7.1.2728:

http://www.daypilot.org/sandbox/

See also:

http://www.daypilot.org/daypilot-pro-for-asp-net-webforms-7-2.html

The main algorithm requires a sorted list which was not the case if there were multiple data sources added using ConflictDetector.Add() and ConflictDetector.AddRecurring().

Please let me know if there is any problem.

Thanks for reporting the issue!

This question is more than 3 months old and has been closed. Please create a new question if you have anything to add.