Beispiel #1
0
        void calendarControl_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
            {
                return;
            }
            IEntity ent = calendarControl.GetEntityOnClick() as IEntity;

            using (ReceptionInfoEdit receptionEditForm = new ReceptionInfoEdit())
            {
                if (ent == null)
                {
                    ent         = database.EntityFactory.NewEntity();
                    ent.Cabinet = database.CabinetList.List.Find(x => x.Name == calendarControl.GetColumnNameOnClick());

                    IEntity nearestTopEntity            = (calendarControl.GetNearestTopEntity() as IEntity);
                    int     nearestTopEntityBottomLevel = nearestTopEntity == null ? -1 : nearestTopEntity.BottomLevel;
                    int     clickLevel   = calendarControl.GetVerticalValueOfClick(e.Location);
                    int     nearestLevel = clickLevel;
                    try
                    {
                        nearestLevel = receptionEntitiesTable.GetDescripptionsToValueLevels().Keys.Where(i => i <= clickLevel).Max();
                    }
                    catch (InvalidOperationException)
                    {
                    }

                    var maximum      = Math.Max(Math.Max(nearestTopEntityBottomLevel, nearestLevel), receptionEntitiesTable.MinValue);
                    var timeInterval = database.EntityFactory.NewTimeInterval();
                    timeInterval.StartDate    = schedule_date + receptionEntitiesTable.ConvertLevelToTime(maximum).TimeOfDay;
                    timeInterval.EndDate      = timeInterval.StartDate + new TimeSpan(1, 0, 0);
                    ent.ReceptionTimeInterval = timeInterval;

                    receptionEditForm.Mode      = Scheduler_Controls.ReceptionInfo.ShowModes.CreateNew;
                    receptionEditForm.Reception = ent;
                    if (receptionEditForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        database.AddReception(ent);
                    }
                }
                else
                {
                    receptionEditForm.Mode      = Scheduler_Controls.ReceptionInfo.ShowModes.ReadExist;
                    receptionEditForm.Reception = ent;
                    var dresult = receptionEditForm.ShowDialog();

                    switch (dresult)
                    {
                    case System.Windows.Forms.DialogResult.Abort:
                        database.RemoveReception(ent);
                        break;

                    case System.Windows.Forms.DialogResult.OK:
                        database.UpdateReception(ent);
                        break;
                        //case System.Windows.Forms.DialogResult.Yes:
                        //    database.AddReception((IEntity)receptionEditForm.Reception);
                        //    break;
                    }
                }

                ReloadEntities();
            }
        }