コード例 #1
0
        private void buttonNewAnalysis_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Do you want to save current Identification Unit and create new Analysis for it?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.No)
                return;

            if (this.saveIU())
            {
                try
                {
                    // Erlaubte Analysen für taxonomoische Gruppe werden geladen
                    IList<Analysis> list = DataFunctions.Instance.RetrievePossibleAnalysis(TaxonomicGroup);

                    if (list.Count < 1)
                    {
                        MessageBox.Show("There is no selectable analysis", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        return;
                    }

                    NewAnalysisDialog nad = null;
                    try
                    {
                        if (UserProfiles.Instance.Current.LastAnalysisID != null)
                            nad = new NewAnalysisDialog((int)UserProfiles.Instance.Current.LastAnalysisID);
                        else
                            nad = new NewAnalysisDialog(true);

                        if (nad == null)
                            return;
                    }
                    catch (ContextCorruptedException ex)
                    {
                        Cursor.Current = Cursors.Default;
                        MessageBox.Show(ex.Message, "Context Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        return;
                    }

                    // Dialog zentrieren
                    nad.Location = new Point((this.Size.Width) / 2 - (nad.Size.Width) / 2, this.Location.Y);
                    nad.Analysis = list;

                    Cursor.Current = Cursors.Default;
                    if (nad.ShowDialog() == DialogResult.OK)
                    {
                        Cursor.Current = Cursors.WaitCursor;
                        String analysisValue = nad.Value;
                        int analysisPerformed = nad.PerformedAnalysis;
                        DateTime analysisDate = nad.AnalysisDate;
                        IdentificationUnitAnalysis iua;

                        try
                        {
                            if (this.current != null)
                                iua = DataFunctions.Instance.CreateIdentificationUnitAnalysis(this.current, analysisPerformed, analysisValue, analysisDate);
                            else
                            {
                                Cursor.Current = Cursors.Default;
                                MessageBox.Show("Associated Analysis with IU couldn't be created.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                return;
                            }

                        }
                        catch (Exception ex)
                        {
                            Cursor.Current = Cursors.Default;
                            MessageBox.Show("Associated Analysis with IU couldn't be created. ("+ex.Message+")", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                            return;
                        }

                        // edit last performed analysis in UserProfile
                        if (UserProfiles.Instance.Current != null)
                        {
                            int oldAnalysis = -1;
                            if (UserProfiles.Instance.Current.LastAnalysisID != null)
                                oldAnalysis = (int)UserProfiles.Instance.Current.LastAnalysisID;

                            UserProfiles.Instance.Current.LastAnalysisID = nad.PerformedAnalysis;

                            try
                            {
                                UserProfiles.Instance.Update(UserProfiles.Instance.Current);
                            }
                            catch (UserProfileCorruptedException ex)
                            {
                                Cursor.Current = Cursors.Default;
                                if (oldAnalysis > -1)
                                    UserProfiles.Instance.Current.LastAnalysisID = oldAnalysis;
                                else
                                    UserProfiles.Instance.Current.LastAnalysisID = null;

                                MessageBox.Show(ex.Message + " Last performed analysis remains: " + oldAnalysis.ToString());
                            }
                        }
                        Cursor.Current = Cursors.Default;
                    }
                }
                catch (ConnectionCorruptedException ex)
                {
                    Cursor.Current = Cursors.Default;
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    return;
                }
            }
        }
コード例 #2
0
        //private void pictureBoxNewAgent_Click(object sender, EventArgs e)
        //{
        //    if (this.treeViewFieldData.Nodes.Count == 0)
        //    {
        //        return;
        //    }
        //    NewAgentDialog dlg = new NewAgentDialog();
        //    // Dialog zentrieren
        //    dlg.Location = new Point((this.Size.Width) / 2 - (dlg.Size.Width) / 2, this.Location.Y);
        //    if (dlg.ShowDialog() == DialogResult.OK)
        //    {
        //        Cursor.Current = Cursors.WaitCursor;
        //        TreeViewNodeData data = this.treeViewFieldData.SelectedNode.Tag as TreeViewNodeData;
        //        // Collection Agent einbinden
        //        int collector = dlg.Collector;
        //        foreach (CollectionAgent item in DataFunctions.Instance.RetrieveAgentForCollectionSpecimen((int)data.ID))
        //        {
        //            // duplicate entries are not allowed
        //            if (item.CollectorsName.Equals(UserProfiles.Instance.List[collector].CombinedNameCache))
        //            {
        //                Cursor.Current = Cursors.Default;
        //                MessageBox.Show("Agent is already assigned");
        //                return;
        //            }
        //        }
        //        CollectionAgent agent = DataFunctions.Instance.CreateCollectionAgent((int)data.ID, collector);
        //        if (!(bool)UserProfiles.Instance.Current.HideAttribute)
        //        {
        //            TreeNode node = new TreeNode();
        //            this._tvOperations.parameterizeCollectionAgentNode(agent, node);
        //            this.treeViewFieldData.SelectedNode.Nodes.Insert(0, node);
        //            if (!this.treeViewFieldData.SelectedNode.IsExpanded)
        //            {
        //                this._expandTrigger = false;
        //                this.treeViewFieldData.SelectedNode.Expand();
        //                this._expandTrigger = true;
        //            }
        //            this.treeViewFieldData.SelectedNode = node;
        //            this.afterSelect(node);
        //        }
        //        Cursor.Current = Cursors.Default;
        //    }
        //}
        private void pictureBoxNewAnalysis_Click(object sender, EventArgs e)
        {
            if (this.treeViewFieldData.Nodes.Count == 0 || this.treeViewFieldData.SelectedNode == null)
            {
                return;
            }
            TreeViewNodeData data = this.treeViewFieldData.SelectedNode.Tag as TreeViewNodeData;
            if (data == null)
                return;

            if (data.NodeType != TreeViewNodeTypes.IdentificationUnitNode)
                return;

            try
            {
                IdentificationUnit iu = DataFunctions.Instance.RetrieveIdentificationUnit((int) data.ID);
                if (iu == null)
                {
                    MessageBox.Show("Associated Identification Unit couldn't be retrieved.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    return;
                }

                // Erlaubte Analysen für taxonomoische Gruppe werden geladen
                IList<Analysis> list = DataFunctions.Instance.RetrievePossibleAnalysis(iu.TaxonomicGroup);

                if (list.Count < 1)
                {
                    MessageBox.Show("There is no selectable analysis", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    return;
                }

                NewAnalysisDialog nad = null;
                try
                {
                    if (UserProfiles.Instance.Current.LastAnalysisID != null)
                        nad = new NewAnalysisDialog((int)UserProfiles.Instance.Current.LastAnalysisID);
                    else
                        nad = new NewAnalysisDialog(true);

                    if (nad == null)
                        return;
                }
                catch (ContextCorruptedException ex)
                {
                    Cursor.Current = Cursors.Default;
                    MessageBox.Show(ex.Message, "Context Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    return;
                }

                // Dialog zentrieren
                nad.Location = new Point((this.Size.Width) / 2 - (nad.Size.Width) / 2, this.Location.Y);
                nad.Analysis = list;

                Cursor.Current = Cursors.Default;
                if (nad.ShowDialog() == DialogResult.OK)
                {
                    Cursor.Current = Cursors.WaitCursor;
                    this.treeViewFieldData.BeginUpdate();
                    String analysisValue = nad.Value;
                    int analysisPerformed = nad.PerformedAnalysis;
                    DateTime analysisDate = nad.AnalysisDate;
                    IdentificationUnitAnalysis iua;

                    try
                    {
                        iua = DataFunctions.Instance.CreateIdentificationUnitAnalysis(iu, analysisPerformed, analysisValue, analysisDate);
                    }
                    catch (DataFunctionsException ex)
                    {
                        Cursor.Current = Cursors.Default;
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        return;
                    }

                    TreeNode node = new TreeNode();
                    this._tvOperations.parametrizeIUANode(iua, node);
                    this.treeViewFieldData.SelectedNode.Nodes.Insert(0, node);
                    this.treeViewFieldData.SelectedNode = node;

                    // edit last performed analysis in UserProfile
                    if (UserProfiles.Instance.Current != null)
                    {
                        int oldAnalysis = -1;
                        if (UserProfiles.Instance.Current.LastAnalysisID != null)
                            oldAnalysis = (int)UserProfiles.Instance.Current.LastAnalysisID;

                        UserProfiles.Instance.Current.LastAnalysisID = nad.PerformedAnalysis;

                        try
                        {
                            UserProfiles.Instance.Update(UserProfiles.Instance.Current);
                        }
                        catch (UserProfileCorruptedException ex)
                        {
                            Cursor.Current = Cursors.Default;
                            if (oldAnalysis > -1)
                                UserProfiles.Instance.Current.LastAnalysisID = oldAnalysis;
                            else
                                UserProfiles.Instance.Current.LastAnalysisID = null;

                            MessageBox.Show(ex.Message + " Last performed analysis remains: " + oldAnalysis.ToString());
                        }
                    }
                    this._actualLvl = TreeViewNodeTypes.AnalysisNode;
                    this.enableDisableButtons(_actualLvl);
                    this.enableDisableToolbarButtons(_actualLvl);
                    this.treeViewFieldData.EndUpdate();
                    Cursor.Current = Cursors.Default;
                }
            }
            catch (ConnectionCorruptedException ex)
            {
                Cursor.Current = Cursors.Default;
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                this.pictureBoxHome_Click(null, null);
                return;
            }
        }