Esempio n. 1
0
        private void CreateReactionsList()
        {
            rxcontainer.RemoveAll();
            rxcontainer.Clear();

            foreach (var rx in flowsheet.Reactions.Values)
            {
                string rname = "";
                switch (rx.ReactionType)
                {
                case Interfaces.Enums.ReactionType.Conversion:
                    rname = "[CON] " + rx.Name;
                    break;

                case Interfaces.Enums.ReactionType.Equilibrium:
                    rname = "[EQL] " + rx.Name;
                    break;

                case Interfaces.Enums.ReactionType.Kinetic:
                    rname = "[KIN] " + rx.Name;
                    break;

                case Interfaces.Enums.ReactionType.Heterogeneous_Catalytic:
                    rname = "[HET] " + rx.Name;
                    break;
                }

                rxcontainer.CreateAndAddLabelAndTwoButtonsRow(rname, "Edit", null, "Remove", null,
                                                              (sender, e) =>
                {
                    switch (rx.ReactionType)
                    {
                    case Interfaces.Enums.ReactionType.Conversion:
                        var myview = s.GetDefaultContainer();
                        var cre    = new ConversionReaction(flowsheet, rx, myview);
                        Form alert = null;
                        myview.CreateAndAddTwoButtonsRow("Cancel", null, "Update", null, (sender2, e2) => alert.Close(),
                                                         (sender2, e2) =>
                        {
                            flowsheet.Reactions[cre.rx.ID] = (IReaction)cre.rx;
                            CreateReactionsList();
                            alert.Close();
                        });
                        alert        = s.GetDefaultEditorForm("Edit Conversion Reaction", 500, 400, myview);
                        alert.Shown += (s1, e1) =>
                        {
                            myview.Invalidate();
                            alert.Height = myview.Height + 40;
                        };
                        alert.Topmost = true;
                        alert.Show();
                        break;

                    case Interfaces.Enums.ReactionType.Equilibrium:
                        var myview2 = s.GetDefaultContainer();
                        var cre2    = new EquilibriumReaction(flowsheet, rx, myview2);
                        Form alert2 = null;
                        myview2.CreateAndAddTwoButtonsRow("Cancel", null, "Update", null, (sender2, e2) => alert2.Close(),
                                                          (sender2, e2) =>
                        {
                            flowsheet.Reactions[cre2.rx.ID] = (IReaction)cre2.rx;
                            CreateReactionsList();
                            alert2.Close();
                        });
                        alert2        = s.GetDefaultEditorForm("Edit Equilibrium Reaction", 500, 400, myview2);
                        alert2.Shown += (s1, e1) =>
                        {
                            myview2.Invalidate();
                            alert2.Height = myview2.Height + 40;
                        };
                        alert2.Topmost = true;
                        alert2.Show();
                        break;

                    case Interfaces.Enums.ReactionType.Kinetic:
                        var myview3 = s.GetDefaultContainer();
                        var cre3    = new KineticReaction(flowsheet, rx, myview3);
                        Form alert3 = null;
                        myview3.CreateAndAddTwoButtonsRow("Cancel", null, "Update", null, (sender2, e2) => alert3.Close(),
                                                          (sender2, e2) =>
                        {
                            flowsheet.Reactions[cre3.rx.ID] = (IReaction)cre3.rx;
                            CreateReactionsList();
                            alert3.Close();
                        });
                        alert3        = s.GetDefaultEditorForm("Edit Kinetic Reaction", 850, 760, myview3);
                        alert3.Shown += (s1, e1) =>
                        {
                            myview3.Invalidate();
                            alert3.Height = myview3.Height + 40;
                        };
                        alert3.Topmost = true;
                        alert3.Show();
                        break;

                    case Interfaces.Enums.ReactionType.Heterogeneous_Catalytic:
                        var myview4 = s.GetDefaultContainer();
                        var cre4    = new HetCatReaction(flowsheet, rx, myview4);
                        Form alert4 = null;
                        myview4.CreateAndAddTwoButtonsRow("Cancel", null, "Update", null, (sender2, e2) => alert4.Close(),
                                                          (sender2, e2) =>
                        {
                            flowsheet.Reactions[cre4.rx.ID] = (IReaction)cre4.rx;
                            CreateReactionsList();
                            alert4.Close();
                        });
                        alert4        = s.GetDefaultEditorForm("Edit Heterogeneous Reaction", 850, 680, myview4);
                        alert4.Shown += (s1, e1) =>
                        {
                            myview4.Invalidate();
                            alert4.Height = myview4.Height + 40;
                        };
                        alert4.Topmost = true;
                        alert4.Show();
                        break;
                    }
                },
                                                              (sender, e) =>
                {
                    if (MessageBox.Show("Are you sure you want to remove this reaction from the flowsheet?", "Remove selected reaction", MessageBoxButtons.YesNo, MessageBoxType.Question, MessageBoxDefaultButton.No) == DialogResult.Yes)
                    {
                        flowsheet.Reactions.Remove(rx.ID);
                        flowsheet.ReactionSets["DefaultSet"].Reactions.Remove(rx.ID);
                        CreateReactionsList();
                    }
                });
            }

            rxcontainer.Create();
        }