public EventSeriesVM(CollectionEventSeries ces)
     : base(ces)
 {
 }
        public EventSeriesDialog(CollectionEventSeries ceSeries)
            : this(true)
        {
            Cursor.Current = Cursors.WaitCursor;
            this.buttonOk.Enabled = false;

            if (ceSeries == null)
            {
                try
                {
                    this._eventSeries = EventSeriess.Instance.CreateNewEventSeries();
                    this._eventSeries.DateStart = DateTime.Now;
                }
                catch (ConnectionCorruptedException ex)
                {
                    Cursor.Current = Cursors.Default;
                    MessageBox.Show("New Collection Event Series couldn't be created. (" + ex.Message + ")", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    this.Close();
                }
                catch (DataFunctionsException ex)
                {
                    Cursor.Current = Cursors.Default;
                    MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    this.Close();
                }
            }
            else
            {
                this._isNewSeries = false;
                this._eventSeries = ceSeries;
                this.buttonFinish.Enabled = true;
            }
            this.fillData();
            Cursor.Current = Cursors.Default;
        }
        public bool Find(int id)
        {
            try
            {
                IRestriction restrict = RestrictionFactory.Eq(typeof(CollectionEventSeries), "_SeriesID", id);
                this._currentSeries = con.Load<CollectionEventSeries>(restrict);

                if (this._currentSeries == null)
                {
                    return false;
                }
                else
                {
                    this._ceIterator.SetIteratorTo(this._currentSeries);
                    return true;
                }
            }
            catch (Exception)
            {
                return false;
            }
        }
        public void Remove(CollectionEventSeries cs)
        {
            try
            {
                CollectionEventSeries newSeries;
                if (cs.CollectionEvents.First() != null)
                {
                    CollectionEvent ev = cs.CollectionEvents.First();
                    ev.SeriesID = null;
                    try
                    {
                        DataFunctions.Instance.Update(ev);

                        while (cs.CollectionEvents.HasNext())
                        {
                            ev = cs.CollectionEvents.Next();
                            ev.SeriesID = null;
                            DataFunctions.Instance.Update(ev);
                        }
                    }
                    catch (DataFunctionsException ex)
                    {
                        throw ex;
                    }
                }
                if (!this.HasNext)
                {
                    if (this.HasPrevious)
                    {
                        newSeries = this.Previous;
                        this.Current = newSeries;
                    }
                    else
                    {

                        newSeries = this.First;
                        this.Current = newSeries;

                    }
                }
                else
                {

                    newSeries = this.Next;
                    this.Current = newSeries;
                }

                con.Delete(cs);
            }
            catch (ConnectionCorruptedException ex)
            {
                throw ex;
            }
            catch (DataFunctionsException ex)
            {
                throw ex;
            }
        }
        protected void displayEventSeries(CollectionEventSeries es)
        {
            Cursor.Current = Cursors.WaitCursor;
            this.treeViewFieldData.BeginUpdate();
            this.treeViewFieldData.SuspendLayout();
            TreeNode node = treeViewFieldData.SelectedNode;
            try
            {
                this.treeViewFieldData.Nodes.Clear();
                this.treeViewFieldData.Update();
                TreeNode esNode = new TreeNode();
                esNode = _tvOperations.displayEventSeries(es);
                treeViewFieldData.Nodes.Add(esNode);
                this.treeViewFieldData.SelectedNode = esNode;
                this._expandTrigger = false;
                if (this._tvOperations.expandLvl <= ExpandLevel.EventSeries)
                    esNode.ExpandAll();
                else
                    esNode.Expand();
                this._expandTrigger = true;
                this._actualLvl = TreeViewNodeTypes.EventSeriesNode;
                this.enableDisableButtons(TreeViewNodeTypes.EventSeriesNode);

            }
            catch (Exception ex)
            {
                this.treeViewFieldData.EndUpdate();
                this.treeViewFieldData.ResumeLayout();
                this.treeViewFieldData.Refresh();
                Cursor.Current = Cursors.Default;
                MessageBox.Show("DisplayError: " + ex.Message);
                this.pictureBoxHome_Click(null, null);
                return;
            }
            this.treeViewFieldData.ResumeLayout();
            this.treeViewFieldData.EndUpdate();
            this.treeViewFieldData.Refresh();
            Cursor.Current = Cursors.Default;
        }
 public CollectionEventSeries CreateNewEventSeries()
 {
     try
     {
         CollectionEventSeries ceSeries = SERIALIZER.CreateISerializableObject<CollectionEventSeries>();
         con.Save(ceSeries);
         this._currentSeries = this._ceIterator.Last();
         return ceSeries;
     }
     catch (Exception ex)
     {
         throw new DataFunctionsException("New CollectionEventSeries couldn't be created. (" + ex.Message + ")");
     }
 }
        public void parametrizeEventSeriesNode(CollectionEventSeries ceSeries, TreeNode node)
        {
            if (node != null)
            {
                if (ceSeries == null)
                {
                    parametrizeEmptyEventSeriesNode(node);
                }
                else
                {
                    StringBuilder text = new StringBuilder();

                    text.Append(ceSeries.SeriesCode);

                    if (!ceSeries.Description.Equals(String.Empty))
                    {
                        text.Append(", ");
                        text.Append(ceSeries.Description);
                    }

                    if (ceSeries.DateStart != null)
                    {
                        text.Append(", ");
                        text.Append(((DateTime)ceSeries.DateStart).Day);
                        text.Append(".");
                        text.Append(((DateTime)ceSeries.DateStart).Month);
                        text.Append(".");
                        text.Append(((DateTime)ceSeries.DateStart).Year);
                        text.Append(" ");
                        text.Append(((DateTime)ceSeries.DateStart).ToShortTimeString());
                    }

                    node.Text =  text.ToString();
                    node.ImageIndex = node.SelectedImageIndex = (int)TreeViewIconIndex.EventSeries;
                    node.Tag = new TreeViewNodeData((int)ceSeries.SeriesID, TreeViewNodeTypes.EventSeriesNode);
                }
            }
            if (this.expandLvl == ExpandLevel.EventSeries)
                node.BackColor = System.Drawing.Color.BlanchedAlmond;
        }
        public TreeNode displayTopDownEventSeries(CollectionEventSeries es)
        {
            TreeNode esNode = new TreeNode();
            if (es != null)
            {
                parametrizeEventSeriesNode(es, esNode);
                if (es.CollectionEvents.First() != null)
                {
                    CollectionEvent first = es.CollectionEvents.First();
                    esNode.Nodes.Add(displayTopDownEvent(first));
                    while (es.CollectionEvents.HasNext())
                    {
                        CollectionEvent next = es.CollectionEvents.Next();
                        esNode.Nodes.Add(displayTopDownEvent(next));
                    }
                }
            }
            else
            {
                parametrizeEmptyEventSeriesNode(esNode);

                if (con != null)
                {
                    IRestriction r = RestrictionFactory.Eq(typeof(CollectionEvent), "_SeriesID", null);

                    IList<CollectionEvent> events = con.LoadList<CollectionEvent>(r);
                    foreach (CollectionEvent ev in events)
                    {
                        if(ev != null)
                            displayTopDownEvent(ev);
                    }
                }
            }
            return esNode;
        }
        public TreeNode displayEventSeries(CollectionEventSeries es)
        {
            TreeNode esNode = new TreeNode();

            if (expandLvl == ExpandLevel.EventSeries)
            {
                esNode = displayTopDownEventSeries(es);
            }
            else
            {
                parametrizeEventSeriesNode(es, esNode);
                if (es != null)
                {
                    if (es.CollectionEvents.First() != null)
                    {
                        TreeNode eventNode = new TreeNode();
                        CollectionEvent ev = es.CollectionEvents.First();
                        parametrizeEventNode(ev, eventNode);
                        if (ev.CollectionSpecimen.First() != null)
                            eventNode.Nodes.Insert(0,new TreeNode());
                        esNode.Nodes.Add(eventNode);
                    }
                    while (es.CollectionEvents.HasNext())
                    {
                        TreeNode eventNode = new TreeNode();
                        CollectionEvent ev = es.CollectionEvents.Next();
                        parametrizeEventNode(ev, eventNode);
                        if (ev.CollectionSpecimen.First() != null)
                            eventNode.Nodes.Insert(0,new TreeNode());
                        esNode.Nodes.Add(eventNode);
                    }
                }
                else
                {
                    IRestriction res = RestrictionFactory.Eq(typeof(CollectionEvent), "_SeriesID", null);
                    IList<CollectionEvent> ceList = con.LoadList<CollectionEvent>(res);
                    foreach (CollectionEvent ev in ceList)
                    {
                        if (ev != null)
                        {
                            TreeNode eventNode = new TreeNode();
                            parametrizeEventNode(ev, eventNode);
                            if (ev.CollectionSpecimen.First() != null)
                                eventNode.Nodes.Insert(0, new TreeNode());
                            esNode.Nodes.Add(eventNode);
                        }
                    }
                }
            }
            return esNode;
        }
        public TreeNode displayBottomUpEventSeries(CollectionEventSeries es, TreeNode childNode)
        {
            TreeNode esNode = new TreeNode();

            // CollectionEventSeries es darf null-Wert sein, wenn No-Event-Series gemeint ist
            parametrizeEventSeriesNode(es, esNode);

            if(childNode != null)
                esNode.Nodes.Add(childNode);

            return esNode;
        }
 public TreeNode displayAllEventSeries(CollectionEventSeries es)
 {
     TreeNode esNode = new TreeNode();
     this.parametrizeEventSeriesNode(es, esNode);
     if (es != null)
     {
         if (es.CollectionEvents.First() != null)
         {
             esNode.Nodes.Add(new TreeNode());
         }
     }
     else
     {
         IRestriction res = RestrictionFactory.Eq(typeof(CollectionEvent), "_SeriesID", null);
         IList<CollectionEvent> ceList = con.LoadList<CollectionEvent>(res);
         if (ceList.Count > 0)
             esNode.Nodes.Insert(0,new TreeNode());
     }
     return esNode;
 }