public void Create(Model.Appointment.ItemCode itemType)
        {
            Appointment appointment = schedulerStorage.CreateAppointment(AppointmentType.Normal);

            appointment.CustomFields["ItemType"]         = itemType;
            appointment.CustomFields["CompletionStatus"] = (int)Model.Appointment.CompletionCode.NotStarted;
            appointment.Start = DateTime.Now;
            appointment.End   = DateTime.Now;

            using (AppointmentEditor editror = new AppointmentEditor(schedulerControl, appointment)) {
                editror.LookAndFeel.ParentLookAndFeel = this.LookAndFeel.ParentLookAndFeel;

                editror.ShowDialog();
            }

            if (appointment.Type == AppointmentType.Pattern &&

                schedulerControl.SelectedAppointments.Contains(appointment))
            {
                schedulerControl.SelectedAppointments.Remove(appointment);
            }

            schedulerControl.Refresh();
            gridControl.RefreshDataSource();
        }
        private void OnInitAppointmentDisplayText(object sender, AppointmentDisplayTextEventArgs e)
        {
            try {
                Model.Appointment.ItemCode itemType
                    = (Model.Appointment.ItemCode)e.Appointment.CustomFields["ItemType"];

                e.Text = Enum.GetName(typeof(Model.Appointment.ItemCode), itemType) + ": " +
                         e.Appointment.Subject;
            } catch {
            }
        }
        void OnAppointmentsInserted(object sender, PersistentObjectsEventArgs e)
        {
            using (new WaitCursor()) {
                Model.Service service = new Model.Service(Program.Service);

                foreach (Appointment apt in e.Objects)
                {
                    Model.Appointment.ItemCode defaultValue = apt.AllDay ?
                                                              Model.Appointment.ItemCode.Task : Model.Appointment.ItemCode.Event;

                    if (apt.CustomFields["ItemType"] == null)
                    {
                        apt.CustomFields["ItemType"] = defaultValue;
                    }

                    if (apt.CustomFields["CompletionStatus"] == null)
                    {
                        apt.CustomFields["CompletionStatus"] = (int)Model.Appointment.CompletionCode.NotStarted;
                    }

                    if (Filter.Current.User != null)
                    {
                        if (apt.ResourceId == null || !(apt.ResourceId is Guid) ||
                            ((Guid)apt.ResourceId == Guid.Empty))
                        {
                            apt.ResourceId = Filter.Current.User.ID;
                        }
                    }

                    Model.Appointment obj
                        = apt.GetSourceObject((SchedulerStorage)sender) as Model.Appointment;

                    if (obj != null)
                    {
                        bool bIsNew = false;

                        if (obj.ID == Guid.Empty)
                        {
                            bIsNew = true;
                            obj.ID = Guid.NewGuid();
                        }

                        if (obj.AssignedTo == null &&
                            Filter.Current.User != null)
                        {
                            obj.AssignedTo = Filter.Current.User.ID;
                        }

                        obj.ItemType         = (int)apt.CustomFields["ItemType"];
                        obj.CompletionStatus = (int)apt.CustomFields["CompletionStatus"];

                        Model.Appointment utc = obj.Clone(DateTimeKind.Utc);

                        if (bIsNew)
                        {
                            service.AddToAppointments(utc);
                        }
                        else
                        {
                            service.AttachTo("Appointments", utc);
                            service.UpdateObject(utc);
                        }

                        BindingList <Model.Appointment> taskDataSource
                            = gridControl.DataSource as BindingList <Model.Appointment>;

                        if (taskDataSource != null)
                        {
                            if (obj != null &&
                                !taskDataSource.Any <Model.Appointment>(it => it.ID == obj.ID) &&
                                obj.AppointmentType == (int)AppointmentType.Normal)
                            {
                                taskDataSource.Add(obj);
                            }
                        }
                    }
                }

                service.SaveChanges(System.Data.Services.Client.SaveChangesOptions.Batch);
            }
        }