0

MVC3 プロジェクトで DHTMLX Recurring イベントを実行する必要があります。定期的なイベントの場合、rec_type、event_pid などの追加の DB 値を格納および取得するようにコントローラー コードをセットアップする必要があります。

簡単なイベントの基本的なコーディングを行いました。しかし、定期的なイベントの書き方がわかりません。PHPでそれを示すデモサイト自体。これはチュートリアルのリンクです (ここ)。C#環境のロジックを教えてください。

シンプルイベントの作成・更新・削除

    public ActionResult Save(Event changedEvent, FormCollection actionValues)
    {
        var a = "Z";
        String action_type = actionValues["!nativeeditor_status"];
        Int64 source_id = Int64.Parse(actionValues["id"]);
        Int64 target_id = source_id;
        string category = actionValues["category"];
        string title = actionValues["title"];
        string description = actionValues["text"];
        if (actionValues["rec_type"] != "")
        {
            changedEvent.Rec_Type = actionValues["rec_type"];
        }
        else
            changedEvent.Rec_Type = "";
        if (actionValues["event_length"] != "")
        {
            changedEvent.Event_Length = Convert.ToInt32(actionValues["event_length"]);
        }
        else
            changedEvent.Event_Length = 0;
        if (actionValues["event_pid"] != "")
        {
            changedEvent.Event_Pid = Convert.ToInt16(actionValues["event_pid"]);
        }
        else
            changedEvent.Event_Pid = 0;
        String catg = category;
        changedEvent.UserId = 1;
        changedEvent.Category = catg;
        changedEvent.Description = description;
        changedEvent.Title = title;
        try
        {
            switch (action_type)
            {
                case "inserted":
                    changedEvent.UserId = 1;
                    changedEvent.Category = catg;
                    db.Events.AddObject(changedEvent);

                    break;
                case "deleted":
                    changedEvent = db.Events.SingleOrDefault(ev => ev.Id == source_id);
                    db.Events.DeleteObject(changedEvent);
                    break;
                default: // "updated"
                    db.Events.Attach(changedEvent);
                    db.ObjectStateManager.ChangeObjectState(changedEvent, System.Data.EntityState.Modified);
                    db.SaveChanges();
                    break;
            }
            db.SaveChanges();
            target_id = changedEvent.Id;
        }
        catch
        {
            action_type = "error";
        }

        return View(new CalendarActionResponseModel(action_type, source_id, target_id, catg));
    }

ありがとう。

4

1 に答える 1

0

データの取得は、3 つの追加フィールド (event_length、event_pid、rec_type) をレンダリングすることを除いて、単純なイベントの場合と同じである必要があります。rec_type のデフォルト値 (イベントが繰り返されないことを意味します) は、null の空文字列です。

保存については、この記事の「コントローラーの変更」の段落を確認して ください。 http://scheduler-net.com/docs/recurring_events.html#controller_changes

別のコンポーネントである .Net 用の dhtmlxScheduler を対象としていますが、処理ロジックは同じです。

一般に、定期的なイベントの保存は単純なものと同じように機能します (同じ方法で単純な定期的なイベントを処理できます) が、次の場合には追加のロジックを追加する必要があります。

  1. ( rec_type == "none" ) のイベントが挿入された場合 - 応答のステータスは "削除済み" でなければなりません。
  2. ( !string.IsNullOrEmpty(rec_type) && rec_type != "none" ) を持つイベントが更新または削除された場合 - 関連する event_pid を持つすべてのレコードを削除する必要があります。
  3. デフォルト以外のevent_pid値を持つイベントが削除された場合、削除する代わりにrec_type = "none"で更新する必要があります。

UPD、コードサンプル

最終的なコードは次のようになります (実際に実行していないため、いくつかの間違いが含まれている可能性があります)。

単純なバージョンと比較して、すべての変更点は、「deleteRelated」メソッド (deleteRelated が true を返す場合、switch-case を省略する必要があることに注意してください) と、「inserted」ケースでの Rec_Type のチェックです。

public ActionResult Save(Event changedEvent, FormCollection actionValues){
    String action_type = actionValues["!nativeeditor_status"];
    Int64 source_id = Int64.Parse(actionValues["id"]);
    Int64 target_id = source_id;
    string category = actionValues["category"];
    string title = actionValues["title"];
    string description = actionValues["text"];


    if (!string.IsNullOrEmpty(actionValues["rec_type"]))
        changedEvent.Rec_Type = actionValues["rec_type"];

    if (!string.IsNullOrEmpty(actionValues["event_length"]))
        changedEvent.Event_Length = Convert.ToInt32(actionValues["event_length"]);

    if (!string.IsNullOrEmpty(actionValues["event_pid"]))
        changedEvent.Event_Pid = Convert.ToInt16(actionValues["event_pid"]);

    String catg = category;
    changedEvent.UserId = 1;
    changedEvent.Category = catg;
    changedEvent.Description = description;
    changedEvent.Title = title;
    try
    {
        if (!deleteRelated(action_type, changedEvent, db))//some logic specific for recurring events
        {
            switch (action_type)
            {
                case "inserted":
                    changedEvent.UserId = 1;
                    changedEvent.Category = catg;
                    db.Events.AddObject(changedEvent);

                    if (changedEvent.Rec_Type == "none")
                        action_type = "deleted";//if an event with (rec_type == "none") was inserted - the response must have "deleted" status

                    break;
                case "deleted":
                    changedEvent = db.Events.SingleOrDefault(ev => ev.Id == source_id);
                    db.Events.DeleteObject(changedEvent);
                    break;
                default: // "updated"
                    db.Events.Attach(changedEvent);
                    db.ObjectStateManager.ChangeObjectState(changedEvent, System.Data.EntityState.Modified);
                    db.SaveChanges();
                    break;
            }
        }
        db.SaveChanges();
        target_id = changedEvent.Id;
    }
    catch
    {
        action_type = "error";
    }

    return View(new CalendarActionResponseModel(action_type, source_id, target_id, catg));
}
protected bool deleteRelated(string action_type, Event changedEvent, RecurringEntities db)//
{
    bool finished = false;
    if ((action_type == "deleted" || action_type == "updated")
        && !string.IsNullOrEmpty(changedEvent.Rec_Type))
    {
        //if an event with (!string.IsNullOrEmpty(rec_type) && rec_type != "none") was updated or deleted - all records with the related event_pid must be deleted;
        db.ExecuteStoreCommand("DELETE FROM Films WHERE Event_Pid = {0}", changedEvent.Id);
    }
    if (action_type == "deleted"
            && (changedEvent.Event_Pid != 0 && changedEvent.Event_Pid != default<Int16>))
    {
        //if an event with non-default event_pid value was deleted - it need to be updated with rec_type = "none" instead of deleting.
        var item = db.Events.SingleOrDefault(ev => ev.Id == changedEvent.Id);
        item.Rec_Type = "none";
        db.SaveChanges();
        finished = true; //in this case no more processing is needed
    }
    return finished;
}
于 2012-12-06T09:19:25.293 に答える