c# - Compare two dates, not allowed to overlap the first agenda event -



c# - Compare two dates, not allowed to overlap the first agenda event -

i have calendar, , can set appointments on agenda, not allowed have sec appointment on th first appointment. not allowed intersect witch each other. seek this:

public bool isoverlapping(agendaeventviewmodel viewmodel, agendaeventviewmodel newitem) { bool isoverlapping = false; datetime? begin = datetime.parse(viewmodel.start); datetime? end = datetime.parse(viewmodel.end); newitem = new agendaeventviewmodel(); datetime begin2 = datetime.parse(newitem.start); datetime end2 = datetime.parse(newitem.end); // todo: check if event overlapping other events :) dynamic roomrules check should implemented here if (begin > end || begin2 > end2) isoverlapping = false; if (begin == end || begin2 == end2) isoverlapping = false; // no actual date range if (begin > end || begin2 > end2) { isoverlapping = false; } if (begin == begin2 && end == end2 ) { isoverlapping = true; this.showmessage(message.type.info, resources.agendaevent.isoverlapping); } if (begin < begin2) { if (end > begin2 && end < end2) isoverlapping = true; // possible1 if (end > end2) isoverlapping = true; // possible 3 } else { if (end2 > begin && end2 < end) isoverlapping = true; // possible 2 if (end2 > end) isoverlapping = true; // possible 4 } homecoming isoverlapping; }

and agendaeventviewmodel:

public class agendaeventviewmodel { public string returnurl { get; set; } public string id { get; set; } public int? funeralid { get; set; } public int? reservationid { get; set; } public int? roomid { get; set; } [display(name = "title", resourcetype = typeof(resources.agendaevent))] public string title { get; set; } [display(name = "start", resourcetype = typeof(resources.agendaevent))] public string start { get; set; } [display(name = "end", resourcetype = typeof(resources.agendaevent))] public string end { get; set; } public string top { get; set; } public string left { get; set; } public list<roomitemmodel> roomitems { get; set; } public list<cateringitemmodel> cateringitems { get; set; } [display(name = "seatingcapacity", resourcetype = typeof(resources.agendaevent))] public int? seatingcapacity { get; set; } //max room seatingcapacity [display(name = "expectedseatingcapacity", resourcetype = typeof(resources.agendaevent))] public int? expectedseatingcapacity { get; set; } // user chosen }

but error on line:

datetime begin2 = datetime.parse(newitem.start); error:

an exception of type 'system.argumentnullexception' occurred in mscorlib.dll not handled in user code

additional information: string reference not set instance of string.

thank you

ok, have now, this:

public bool isoverlapping(agendaeventviewmodel viewmodel, agendaeventviewmodel newitem) { bool isoverlapping = false; // reservationmodel r = new reservationmodel(int.parse(viewmodel.id)); datetime? begin = datetime.parse(viewmodel.start); datetime? end = datetime.parse(viewmodel.end); newitem = new agendaeventviewmodel(); newitem.start = "2014-08-11 10:00:00.000"; newitem.end = "2014-08-11 11:00:00.000"; datetime? begin2 = datetime.parse(newitem.start); datetime? end2 = datetime.parse(newitem.end); // todo: check if event overlapping other events :) dynamic roomrules check should implemented here if (begin > end || begin2 > end2) isoverlapping = false; if (begin == end || begin2 == end2) isoverlapping = false; // no actual date range if (begin > end || begin2 > end2) { isoverlapping = false; } //if ((begin <= end2) && (begin2 <= end)) //{ // this.showmessage(message.type.info, resources.agendaevent.isoverlapping); // isoverlapping = true; //} if (begin == begin2 && end == end2) { this.showmessage(message.type.info, resources.agendaevent.isoverlapping); isoverlapping = true; } if (begin < begin2) { if (end > begin2 && end < end2) isoverlapping = true; // possible1 if (end > end2) isoverlapping = true; // possible 3 } else { if (end2 > begin && end2 < end) isoverlapping = true; // possible 2 if (end2 > end) isoverlapping = true; // possible 4 } homecoming isoverlapping; }

but if set sec agenda item on calendar, begin en end override through end2 , begin2.

your newitem.start null, when seek parse it, throws system.argumentnullexception. create sure set date of new item before seek parse it.

c# asp.net-mvc-4

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -