Пример #1
0
    protected void DayPilotCalendar1_EventDelete(object sender, EventDeleteEventArgs e)
    {
        #region Simulation of database update

        DataRow dr = table.Rows.Find(e.Id);

        if (e.Recurrent)
        {
            if (e.RecurrentException)  // replace this exception with a deleted exception
            {
                if (dr != null)
                {
                    // save the original start
                    DateTime start = RecurrenceRule.DecodeStart((string)dr["recurrence"]);

                    // delete the "modified" exception
                    table.Rows.Remove(dr);
                    table.AcceptChanges();

                    // add "deleted" exception
                    dr               = table.NewRow();
                    dr["id"]         = Guid.NewGuid().ToString();
                    dr["start"]      = start;
                    dr["end"]        = start;
                    dr["recurrence"] = RecurrenceRule.EncodeExceptionDeleted(e.RecurrentMasterId, start);
                    table.Rows.Add(dr);
                    table.AcceptChanges();
                }
            }
            else
            {
                // not an exception, look for the request
                string which = (string)e.Data["which"];
                switch (which)
                {
                case "this":
                    // add "deleted" exception
                    dr               = table.NewRow();
                    dr["id"]         = Guid.NewGuid().ToString();
                    dr["start"]      = e.Start;
                    dr["end"]        = e.End;
                    dr["recurrence"] = RecurrenceRule.EncodeExceptionDeleted(e.RecurrentMasterId, e.Start);
                    table.Rows.Add(dr);
                    table.AcceptChanges();

                    break;

                case "series":
                    // delete the master
                    DataRow master = table.Rows.Find(e.RecurrentMasterId);
                    table.Rows.Remove(master);

                    // delete all exceptions
                    string    prefix = RecurrenceRule.Prefix(e.RecurrentMasterId);
                    DataRow[] rows   = table.Select(String.Format("recurrence like '{0}%'", prefix));
                    foreach (DataRow r in rows)
                    {
                        table.Rows.Remove(r);
                    }
                    table.AcceptChanges();
                    break;
                }
            }
        }
        else
        {
            if (dr != null)
            {
                table.Rows.Remove(dr);
                table.AcceptChanges();
            }
        }

        #endregion

        DayPilotCalendar1.DataBind();
        DayPilotCalendar1.Update("Event deleted.");
    }