C# DHTMLX计划程序重复事件
我在DHTMLX调度程序方面遇到了问题,特别是在重复事件方面 我试图按照这里找到的文档进行操作。然而,它似乎无法工作 我可以创建基本的调度程序,没有任何问题。我现在遇到的问题是,创建的任何事件都不会保存到数据库中。这就是我目前所拥有的 型号:C# DHTMLX计划程序重复事件,c#,asp.net-mvc,dhtmlx,C#,Asp.net Mvc,Dhtmlx,我在DHTMLX调度程序方面遇到了问题,特别是在重复事件方面 我试图按照这里找到的文档进行操作。然而,它似乎无法工作 我可以创建基本的调度程序,没有任何问题。我现在遇到的问题是,创建的任何事件都不会保存到数据库中。这就是我目前所拥有的 型号: [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] [DHXJson(Alias = "id")] public int Id { get; set; } [DHXJson(Alias
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[DHXJson(Alias = "id")]
public int Id { get; set; }
[DHXJson(Alias = "text")]
public string Description { get; set; }
[DHXJson(Alias = "start_date")]
public DateTime StartDate { get; set; }
[DHXJson(Alias = "end_date")]
public DateTime EndDate { get; set; }
[DHXJson(Alias="event_length")]
public int event_length { get; set; }
[DHXJson(Alias = "rec_type")]
public string rec_type { get; set; }
[DHXJson(Alias = "event_pid")]
public int event_pid { get; set; }
public ActionResult Save(int? id, FormCollection actionValues)
{
var action = new DataAction(actionValues);
ApplicationDbContext data = new ApplicationDbContext();
try
{
var changedEvent = (Appointment)DHXEventsHelper.Bind(typeof(Appointment), actionValues);
//operations with recurring events require some additional handling
bool isFinished = deleteRelated(action, changedEvent, data);
if (!isFinished)
{
switch (action.Type)
{
case DataActionTypes.Insert:
data.Appointment.Add(changedEvent);
if (changedEvent.rec_type == "none")//delete one event from the serie
action.Type = DataActionTypes.Delete;
break;
case DataActionTypes.Delete:
changedEvent = data.Appointment.SingleOrDefault(ev => ev.Id == action.SourceId);
data.Appointment.Remove(changedEvent);
break;
default:// "update"
var eventToUpdate = data.Appointment.SingleOrDefault(ev => ev.Id == action.SourceId);
DHXEventsHelper.Update(eventToUpdate, changedEvent, new List<string>() { "id" });
break;
}
}
data.SaveChanges();
action.TargetId = changedEvent.Id;
}
catch
{
action.Type = DataActionTypes.Error;
}
return (new AjaxSaveResponse(action));
}
protected bool deleteRelated(DataAction action, Appointment changedEvent, ApplicationDbContext context)
{
bool finished = false;
if ((action.Type == DataActionTypes.Delete || action.Type == DataActionTypes.Update) && !string.IsNullOrEmpty(changedEvent.rec_type))
{
// context.Recurrings.DeleteAllOnSubmit(from ev in context.Recurrings where ev.event_pid == changedEvent.id select ev);
}
if (action.Type == DataActionTypes.Delete && (changedEvent.event_pid != 0 && changedEvent.event_pid != null))
{
// Recurring changed = (from ev in context.Recurrings where ev.id == action.TargetId select ev).Single();
// changed.rec_type = "none";
finished = true;
}
return finished;
}
控制器:
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[DHXJson(Alias = "id")]
public int Id { get; set; }
[DHXJson(Alias = "text")]
public string Description { get; set; }
[DHXJson(Alias = "start_date")]
public DateTime StartDate { get; set; }
[DHXJson(Alias = "end_date")]
public DateTime EndDate { get; set; }
[DHXJson(Alias="event_length")]
public int event_length { get; set; }
[DHXJson(Alias = "rec_type")]
public string rec_type { get; set; }
[DHXJson(Alias = "event_pid")]
public int event_pid { get; set; }
public ActionResult Save(int? id, FormCollection actionValues)
{
var action = new DataAction(actionValues);
ApplicationDbContext data = new ApplicationDbContext();
try
{
var changedEvent = (Appointment)DHXEventsHelper.Bind(typeof(Appointment), actionValues);
//operations with recurring events require some additional handling
bool isFinished = deleteRelated(action, changedEvent, data);
if (!isFinished)
{
switch (action.Type)
{
case DataActionTypes.Insert:
data.Appointment.Add(changedEvent);
if (changedEvent.rec_type == "none")//delete one event from the serie
action.Type = DataActionTypes.Delete;
break;
case DataActionTypes.Delete:
changedEvent = data.Appointment.SingleOrDefault(ev => ev.Id == action.SourceId);
data.Appointment.Remove(changedEvent);
break;
default:// "update"
var eventToUpdate = data.Appointment.SingleOrDefault(ev => ev.Id == action.SourceId);
DHXEventsHelper.Update(eventToUpdate, changedEvent, new List<string>() { "id" });
break;
}
}
data.SaveChanges();
action.TargetId = changedEvent.Id;
}
catch
{
action.Type = DataActionTypes.Error;
}
return (new AjaxSaveResponse(action));
}
protected bool deleteRelated(DataAction action, Appointment changedEvent, ApplicationDbContext context)
{
bool finished = false;
if ((action.Type == DataActionTypes.Delete || action.Type == DataActionTypes.Update) && !string.IsNullOrEmpty(changedEvent.rec_type))
{
// context.Recurrings.DeleteAllOnSubmit(from ev in context.Recurrings where ev.event_pid == changedEvent.id select ev);
}
if (action.Type == DataActionTypes.Delete && (changedEvent.event_pid != 0 && changedEvent.event_pid != null))
{
// Recurring changed = (from ev in context.Recurrings where ev.id == action.TargetId select ev).Single();
// changed.rec_type = "none";
finished = true;
}
return finished;
}
public ActionResult保存(int?id,FormCollection actionvalue)
{
var action=新的数据操作(actionValues);
ApplicationDbContext数据=新的ApplicationDbContext();
尝试
{
var changedEvent=(约会)DHXEventsHelper.Bind(typeof(约会),actionValues);
//具有重复事件的操作需要一些额外的处理
bool isFinished=deleteRelated(操作、变更、数据);
如果(!isFinished)
{
开关(动作类型)
{
案例数据操作类型。插入:
数据。约会。添加(变更);
if(changedEvent.rec_type==“none”)//从序列中删除一个事件
action.Type=DataActionTypes.Delete;
打破
案例数据操作类型。删除:
changedEvent=data.Appointment.SingleOrDefault(ev=>ev.Id==action.SourceId);
数据。约会。删除(changedEvent);
打破
默认值:/“更新”
var eventToUpdate=data.Appointment.SingleOrDefault(ev=>ev.Id==action.SourceId);
更新(eventToUpdate,changedEvent,new List(){“id”});
打破
}
}
data.SaveChanges();
action.TargetId=changedEvent.Id;
}
接住
{
action.Type=DataActionTypes.Error;
}
返回(新的AjaxSaveResponse(操作));
}
受保护的bool deleteRelated(数据操作操作、约会更改、应用程序上下文)
{
bool finished=false;
if((action.Type==DataActionTypes.Delete | | | action.Type==DataActionTypes.Update)和&!string.IsNullOrEmpty(changedEvent.rec_Type))
{
//context.Recurrings.DeleteAllOnSubmit(从context.Recurrings中的ev开始,其中ev.event_pid==changedEvent.id选择ev);
}
if(action.Type==DataActionTypes.Delete&(changedEvent.event\u pid!=0&&changedEvent.event\u pid!=null))
{
//Recurrence changed=(从上下文中的ev.Recurrengs,其中ev.id==action.TargetId选择ev)。Single();
//changed.rec_type=“无”;
完成=正确;
}
返回完成;
}
有什么帮助或想法吗?尝试将更改保存方法返回值更改为“ContentResult”。同时查看ApplicationDbContext,看看在加载索引时是否可以从该表中提取一些硬编码的db值。这是我的一份。在使用linq to类创建模型/EF之前,我也遇到过同样的问题,而我的上下文就是基于此。当我创建自己的“轻量级”界面时,我也遇到了同样的问题,因为我不想使用EF
public ContentResult Save(int? id, FormCollection actionValues)
{
var action = new DataAction(actionValues);
var context = new SchedulerDataContext();
Int64 source_id = Int64.Parse(actionValues["id"]);
try
{
var changedDelEvent = (Delivery)DHXEventsHelper.Bind(typeof(Delivery), actionValues);
var changedRecEvent = (Recurring)DHXEventsHelper.Bind(typeof(Recurring), actionValues);
//operations with recurring events require some additional handling
bool isFinished = deleteRelated(action, changedRecEvent, context);
if (!isFinished)
{
switch (action.Type)
{
case DataActionTypes.Insert:
context.Recurrings.InsertOnSubmit(changedRecEvent);
context.SubmitChanges();
break;
case DataActionTypes.Delete:
changedRecEvent = context.Recurrings.SingleOrDefault(d => d.id == source_id);
if (changedRecEvent != null)
{
context.Recurrings.DeleteOnSubmit(changedRecEvent);
}
context.SubmitChanges();
break;
default:// "update"
var eventToUpdate = context.Deliveries.SingleOrDefault(d => d.DeliveryID == source_id);
DHXEventsHelper.Update(eventToUpdate, changedRecEvent, new List<string> { "id" });
if (eventToUpdate != null && eventToUpdate.RouteID != changedRecEvent.id)
{
var routeToUpdate = context.Routes.SingleOrDefault(d => d.RouteID == changedRecEvent.id);
eventToUpdate.Route = routeToUpdate;
}
context.SubmitChanges();
break;
}
action.TargetId = changedRecEvent.id;
}
}
catch
{
action.Type = DataActionTypes.Error;
}
return (new AjaxSaveResponse(action));
}
public ContentResult保存(int?id,FormCollection actionValues)
{
var action=新的数据操作(actionValues);
var context=new SchedulerDataContext();
Int64 source_id=Int64.Parse(actionValues[“id]”);
尝试
{
var changedelevent=(Delivery)DHXEventsHelper.Bind(typeof(Delivery),actionvalue);
var changedRecEvent=(循环)DHXEventsHelper.Bind(typeof(循环),actionvalue);
//具有重复事件的操作需要一些额外的处理
bool isFinished=deleteRelated(操作、变更事件、上下文);
如果(!isFinished)
{
开关(动作类型)
{
案例数据操作类型。插入:
context.Recurrings.insertonsumit(changedRecEvent);
context.SubmitChanges();
打破
案例数据操作类型。删除:
changedRecEvent=context.Recurrings.SingleOrDefault(d=>d.id==source\u id);
if(changedRecEvent!=null)
{
context.Recurrings.deleteosubmit(changedRecEvent);
}
context.SubmitChanges();
打破
默认值:/“更新”
var eventToUpdate=context.Deliveries.SingleOrDefault(d=>d.DeliveryID==source\u id);
更新(eventToUpdate、changedRecEvent、新列表{“id”});
if(eventToUpdate!=null&&eventToUpdate.RouteID!=changedRecEvent.id)
{
var routeToUpdate=context.Routes.SingleOrDefault(d=>d.RouteID==changedRecEvent.id);
eventToUpdate.Route=routeToUpdate;
}
context.SubmitChanges();
打破
}
action.TargetId=changedRecEvent.id;
}
}
接住
{
action.Type=DataActionTypes.Error;
}
返回(新的AjaxSaveResponse(操作));
}
循环扩展(dhtmlxscheduler_recurrence.js)无法识别您在实体类属性上使用的DHXJson别名注释(非常令人沮丧)。因此,您必须按照dhtmlxscheduler_recurtive.js的预期来命名实体类列/属性,即使基本调度器API为您提供了使用DHXJson别名注释自定义命名的选项。您会注意到我正在尝试使循环工作,这就是为什么我有两个“更改”,但crud