Exemple #1
0
        public TableLayout GetSpreadsheet(IFlowsheet obj)
        {
            grid = new GridView {
                DataStore = rowlist, RowHeight = 20
            };
            if (Application.Instance.Platform.IsWinForms)
            {
                grid.Height = 1100;
            }

            if (GlobalSettings.Settings.RunningPlatform() != GlobalSettings.Settings.Platform.Windows)
            {
                grid.Columns.Add(new GridColumn {
                    HeaderText = "", DataCell = new TextBoxCell {
                        Binding = Binding.Property <RowItem, string>(r => r.index)
                    }, Editable = false, AutoSize = false, Width = 50, Resizable = false
                });
            }
            grid.Columns.Add(new GridColumn {
                HeaderText = "A", DataCell = new TextBoxCell {
                    Binding = Binding.Property <RowItem, string>(r => r.A)
                }, AutoSize = false, Editable = false, Width = 80
            });
            grid.Columns.Add(new GridColumn {
                HeaderText = "B", DataCell = new TextBoxCell {
                    Binding = Binding.Property <RowItem, string>(r => r.B)
                }, AutoSize = false, Editable = false, Width = 80
            });
            grid.Columns.Add(new GridColumn {
                HeaderText = "C", DataCell = new TextBoxCell {
                    Binding = Binding.Property <RowItem, string>(r => r.C)
                }, AutoSize = false, Editable = false, Width = 80
            });
            grid.Columns.Add(new GridColumn {
                HeaderText = "D", DataCell = new TextBoxCell {
                    Binding = Binding.Property <RowItem, string>(r => r.D)
                }, AutoSize = false, Editable = false, Width = 80
            });
            grid.Columns.Add(new GridColumn {
                HeaderText = "E", DataCell = new TextBoxCell {
                    Binding = Binding.Property <RowItem, string>(r => r.E)
                }, AutoSize = false, Editable = false, Width = 80
            });
            grid.Columns.Add(new GridColumn {
                HeaderText = "F", DataCell = new TextBoxCell {
                    Binding = Binding.Property <RowItem, string>(r => r.F)
                }, AutoSize = false, Editable = false, Width = 80
            });
            grid.Columns.Add(new GridColumn {
                HeaderText = "G", DataCell = new TextBoxCell {
                    Binding = Binding.Property <RowItem, string>(r => r.G)
                }, AutoSize = false, Editable = false, Width = 80
            });
            grid.Columns.Add(new GridColumn {
                HeaderText = "H", DataCell = new TextBoxCell {
                    Binding = Binding.Property <RowItem, string>(r => r.H)
                }, AutoSize = false, Editable = false, Width = 80
            });
            grid.Columns.Add(new GridColumn {
                HeaderText = "I", DataCell = new TextBoxCell {
                    Binding = Binding.Property <RowItem, string>(r => r.I)
                }, AutoSize = false, Editable = false, Width = 80
            });
            grid.Columns.Add(new GridColumn {
                HeaderText = "J", DataCell = new TextBoxCell {
                    Binding = Binding.Property <RowItem, string>(r => r.J)
                }, AutoSize = false, Editable = false, Width = 80
            });
            grid.Columns.Add(new GridColumn {
                HeaderText = "K", DataCell = new TextBoxCell {
                    Binding = Binding.Property <RowItem, string>(r => r.K)
                }, AutoSize = false, Editable = false, Width = 80
            });
            grid.Columns.Add(new GridColumn {
                HeaderText = "L", DataCell = new TextBoxCell {
                    Binding = Binding.Property <RowItem, string>(r => r.L)
                }, AutoSize = false, Editable = false, Width = 80
            });
            grid.Columns.Add(new GridColumn {
                HeaderText = "M", DataCell = new TextBoxCell {
                    Binding = Binding.Property <RowItem, string>(r => r.M)
                }, AutoSize = false, Editable = false, Width = 80
            });
            grid.Columns.Add(new GridColumn {
                HeaderText = "N", DataCell = new TextBoxCell {
                    Binding = Binding.Property <RowItem, string>(r => r.N)
                }, AutoSize = false, Editable = false, Width = 80
            });
            grid.Columns.Add(new GridColumn {
                HeaderText = "O", DataCell = new TextBoxCell {
                    Binding = Binding.Property <RowItem, string>(r => r.O)
                }, AutoSize = false, Editable = false, Width = 80
            });
            grid.Columns.Add(new GridColumn {
                HeaderText = "P", DataCell = new TextBoxCell {
                    Binding = Binding.Property <RowItem, string>(r => r.P)
                }, AutoSize = false, Editable = false, Width = 80
            });
            grid.Columns.Add(new GridColumn {
                HeaderText = "Q", DataCell = new TextBoxCell {
                    Binding = Binding.Property <RowItem, string>(r => r.Q)
                }, AutoSize = false, Editable = false, Width = 80
            });
            grid.Columns.Add(new GridColumn {
                HeaderText = "R", DataCell = new TextBoxCell {
                    Binding = Binding.Property <RowItem, string>(r => r.R)
                }, AutoSize = false, Editable = false, Width = 80
            });
            grid.Columns.Add(new GridColumn {
                HeaderText = "S", DataCell = new TextBoxCell {
                    Binding = Binding.Property <RowItem, string>(r => r.S)
                }, AutoSize = false, Editable = false, Width = 80
            });
            grid.Columns.Add(new GridColumn {
                HeaderText = "T", DataCell = new TextBoxCell {
                    Binding = Binding.Property <RowItem, string>(r => r.T)
                }, AutoSize = false, Editable = false, Width = 80
            });
            grid.Columns.Add(new GridColumn {
                HeaderText = "U", DataCell = new TextBoxCell {
                    Binding = Binding.Property <RowItem, string>(r => r.U)
                }, AutoSize = false, Editable = false, Width = 80
            });
            grid.Columns.Add(new GridColumn {
                HeaderText = "V", DataCell = new TextBoxCell {
                    Binding = Binding.Property <RowItem, string>(r => r.V)
                }, AutoSize = false, Editable = false, Width = 80
            });
            grid.Columns.Add(new GridColumn {
                HeaderText = "W", DataCell = new TextBoxCell {
                    Binding = Binding.Property <RowItem, string>(r => r.W)
                }, AutoSize = false, Editable = false, Width = 80
            });
            grid.Columns.Add(new GridColumn {
                HeaderText = "X", DataCell = new TextBoxCell {
                    Binding = Binding.Property <RowItem, string>(r => r.X)
                }, AutoSize = false, Editable = false, Width = 80
            });
            grid.Columns.Add(new GridColumn {
                HeaderText = "Y", DataCell = new TextBoxCell {
                    Binding = Binding.Property <RowItem, string>(r => r.Y)
                }, AutoSize = false, Editable = false, Width = 80
            });
            grid.Columns.Add(new GridColumn {
                HeaderText = "Z", DataCell = new TextBoxCell {
                    Binding = Binding.Property <RowItem, string>(r => r.Z)
                }, AutoSize = false, Editable = false, Width = 80
            });

            grid.AllowColumnReordering  = false;
            grid.AllowMultipleSelection = false;
            grid.GridLines = GridLines.Both;
            grid.Style     = "spreadsheet";

            var table = new TableLayout();

            var cellcp = new Panel();

            var txtcell = new TextBox {
                Width = 80, ReadOnly = true
            };
            var txttype = new TextBox {
                Width = 200, ReadOnly = true
            };
            var txtformula = new TextBox()
            {
                PlaceholderText = "To enter a formula,  type '=' followed by the math expression and press ENTER to commit changes."
            };
            var btnImport = new Button {
                Text = "Import"
            };
            var btnExport = new Button {
                Text = "Export"
            };
            var btnClear = new Button {
                Text = "Clear"
            };
            var btnEvaluate = new Button {
                Text = "Evaluate"
            };
            var btnEvaluateAll = new Button {
                Text = "Evaluate All"
            };

            btnEvaluate.Click += (sender, e) =>
            {
                EvaluateAll(ccparams);
                grid.ReloadData(int.Parse(rowitem.index) - 1);
            };

            btnEvaluateAll.Click += (sender, e) =>
            {
                EvaluateAll();
            };


            btnClear.Click += (sender, e) =>
            {
                ccparams.Expression = "";
                ccparams.ObjectID   = "";
                ccparams.PropID     = "";
                ccparams.PropUnit   = "";
                ccparams.CurrVal    = "";
                ccparams.PrevVal    = "";
                ccparams.CellType   = VarType.None;
                UpdateValue(ccparams);
                grid.ReloadData(int.Parse(rowitem.index) - 1);
            };

            btnImport.Click += (sender, e) =>
            {
                var selector = new PropertySelector()
                {
                    Flowsheet = flowsheet, ObjList = ObjList
                };

                selector.btnOK.Click += (sender2, e2) =>
                {
                    ccparams.Expression = ":" + selector.list2.SelectedKey + "," + selector.list3.SelectedKey;
                    ccparams.CellType   = global::DWSIM.SharedClasses.Spreadsheet.VarType.Read;
                    UpdateValue(ccparams);
                    grid.ReloadData(int.Parse(rowitem.index) - 1);
                    selector.Close();
                };

                selector.ShowModal(grid);
            };

            btnExport.Click += (sender, e) =>
            {
                var selector = new PropertySelector()
                {
                    Flowsheet = flowsheet, ObjList = ObjList, mode = 1
                };

                selector.btnOK.Click += (sender2, e2) =>
                {
                    ccparams.ObjectID = selector.list2.SelectedKey;
                    ccparams.PropID   = selector.list3.SelectedKey;
                    ccparams.CellType = global::DWSIM.SharedClasses.Spreadsheet.VarType.Write;
                    UpdateValue(ccparams);
                    grid.ReloadData(int.Parse(rowitem.index) - 1);
                    selector.Close();
                };

                selector.ShowModal(grid);
            };

            var tr = new TableRow(new Label {
                Text = "Selected Cell", VerticalAlignment = VerticalAlignment.Center
            }, txtcell,
                                  new Label {
                Text = "Type", VerticalAlignment = VerticalAlignment.Center
            }, txttype,
                                  new Label {
                Text = "Contents", VerticalAlignment = VerticalAlignment.Center
            }, txtformula,
                                  btnImport, btnExport, btnClear, btnEvaluate, btnEvaluateAll);

            tr.Cells[5].ScaleWidth = true;

            var tb = new TableLayout {
                Spacing = new Size(5, 5), Padding = new Padding(10)
            };

            tb.Rows.Add(tr);
            if (GlobalSettings.Settings.RunningPlatform() == GlobalSettings.Settings.Platform.Mac)
            {
                tb.Height = 44;
            }

            cellcp.Content = tb;

            table.Rows.Add(new TableRow(cellcp));

            var cnt = new DynamicLayout {
                Padding = new Padding(10, 0)
            };

            s.CreateAndAddDescriptionRow(cnt, "Select cells by clicking or touching on them (using arrow keys on the keyboard won't change the currently selected data cell). After selecting the cell, edit its contents on the 'Contents' input box, or configure it to import or export data from/to the flowsheet by clicking on the corresponding buttons.", true);

            table.Rows.Add(new TableRow(cnt));

            txtformula.TextChanged += (sender, e) =>
            {
                rowitem.CellParams[selectedcell].Expression = txtformula.Text;
            };

            txtformula.KeyDown += (sender, e) =>
            {
                if (e.Key == Keys.Enter)
                {
                    UpdateValue(rowitem.CellParams[selectedcell]);
                    grid.ReloadData(int.Parse(rowitem.index) - 1);
                }
            };

            grid.CellDoubleClick += (sender, e) =>
            {
                if (txtformula.Enabled)
                {
                    txtformula.Focus();
                }
            };

            grid.CellClick += (sender, e) =>
            {
                if (e.Item == null)
                {
                    return;
                }
                if (e.GridColumn.HeaderText == "")
                {
                    return;
                }
                selectedcell = e.GridColumn.HeaderText + (e.Row + 1).ToString();
                txtcell.Text = selectedcell;
                rowitem      = ((RowItem)e.Item);
                var cellp = ((RowItem)e.Item).CellParams[selectedcell];
                ccparams = cellp;
                switch (cellp.CellType)
                {
                case VarType.Expression:
                    txttype.Text       = "Expression";
                    txtformula.Enabled = true;
                    break;

                case VarType.Read:
                    txttype.Text       = "Imported from " + flowsheet.SimulationObjects[ccparams.ObjectID].GraphicObject.Tag + ", " + flowsheet.GetTranslatedString(ccparams.PropID);
                    txtformula.Enabled = false;
                    break;

                case VarType.Write:
                    txttype.Text       = "Exported to " + flowsheet.SimulationObjects[ccparams.ObjectID].GraphicObject.Tag + ", " + flowsheet.GetTranslatedString(ccparams.PropID);
                    txtformula.Enabled = false;
                    break;

                case VarType.None:
                    txttype.Text       = "Text";
                    txtformula.Enabled = true;
                    break;
                }
                txttype.ToolTip    = txttype.Text;
                txtformula.Text    = cellp.Expression;
                txtformula.ToolTip = txtformula.Text;
            };

            table.Rows.Add(new TableRow(new Scrollable {
                Content = grid, Border = BorderType.None
            }));

            return(table);
        }
Exemple #2
0
        public Spreadsheet(Flowsheet fs)
        {
            Columns.AddRange(new[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" });

            flowsheet = fs;
            scontrol  = new ReoGridFullControl();
            Sheet     = scontrol.GridControl;
            SetCustomFunctions();
            flowsheet.GetSpreadsheetObjectFunc = () => { return(Sheet); };
            Sheet.CurrentWorksheet.Name        = "MAIN";

            scontrol.ImportDataMenuItem.Click += (sender, e) =>
            {
                Application.Instance.Invoke(() =>
                {
                    var selector = new PropertySelector()
                    {
                        Flowsheet = flowsheet, ObjList = ObjList
                    };

                    selector.btnOK.Click += (sender2, e2) =>
                    {
                        var units = "";
                        if (selector.list4.SelectedValue != null)
                        {
                            units = selector.list4.SelectedValue.ToString();
                        }
                        Sheet.CurrentWorksheet.Cells[Sheet.CurrentWorksheet.SelectionRange.StartPos].Formula =
                            String.Format("GETPROPVAL({3}{1}{3}{0}{3}{2}{3}{0}{3}{4}{3})",
                                          ';',
                                          selector.list2.SelectedKey,
                                          selector.list3.SelectedKey,
                                          '"', units);

                        selector.Close();

                        Sheet.CurrentWorksheet.EndEdit(EndEditReason.Cancel);
                    };

                    selector.ShowModal();
                });
            };

            scontrol.ExportDataMenuItem.Click += (sender, e) =>
            {
                Application.Instance.Invoke(() =>
                {
                    var selector = new PropertySelector()
                    {
                        Flowsheet = flowsheet, ObjList = ObjList
                    };

                    selector.btnOK.Click += (sender2, e2) =>
                    {
                        var units = "";
                        if (selector.list4.SelectedValue != null)
                        {
                            units = selector.list4.SelectedValue.ToString();
                        }
                        var scell     = Sheet.CurrentWorksheet.Cells[Sheet.CurrentWorksheet.SelectionRange.StartPos];
                        var currdata  = scell.Formula == null ? scell.Data : scell.Formula;
                        scell.Formula = String.Format("SETPROPVAL({3}{1}{3}{0}{3}{2}{3}{0}{3}{4}{3}{0}{3}{5}{3})",
                                                      ';',
                                                      selector.list2.SelectedKey,
                                                      selector.list3.SelectedKey,
                                                      '"',
                                                      currdata, units);

                        selector.Close();

                        Sheet.CurrentWorksheet.EndEdit(EndEditReason.Cancel);
                    };

                    selector.ShowModal();
                });
            };

            scontrol.CreateChartMenuItem.Click += (sender, e) =>
            {
                Application.Instance.Invoke(() =>
                {
                    CreateChartFromRange(sender, e);
                });
            };
        }