private void OnLoad(object sender, EventArgs e)
        {
            if (!InOnLoad)
            {
                InOnLoad = true;
                Selected = Controller.ApsimData.Find(Controller.SelectedPath);

                ComponentVE.GetVisibleComponents(Selected, ref MyComponents);

                PopulateComponentFilter();
                PopulateVariableListView();
                InOnLoad = false;
            }
        }
Beispiel #2
0
        public override void OnRefresh()
        {
            // ----------------------------------
            // Refresh the variable grid
            // ----------------------------------

            DataTable Table = new DataTable();

            if (XmlHelper.Type(Data).ToLower() == "variables")
            {
                GridLabel.Text       = "Output file columns:";
                DictionaryLabel.Text = "Variables to drag onto grid:";
                Table.Columns.Add("Variable name", System.Type.GetType("System.String"));
            }
            else if (XmlHelper.Type(Data).ToLower() == "tracker")
            {
                GridLabel.Text       = "Tracker variables:";
                DictionaryLabel.Text = "Example tracker variables - drag to the grid.";
                Table.Columns.Add("Tracker variable", System.Type.GetType("System.String"));
            }
            else
            {
                GridLabel.Text       = "Output file frequencies:";
                DictionaryLabel.Text = "Frequency list - drag to the grid.";
                Table.Columns.Add("Output frequency", System.Type.GetType("System.String"));
            }

            // Fill data table.
            foreach (XmlNode Variable in XmlHelper.ChildNodes(Data, ""))
            {
                if (Variable.Name != "constants")
                {
                    DataRow NewRow = Table.NewRow();
                    NewRow[0] = Variable.InnerText;
                    Table.Rows.Add(NewRow);
                }
            }

            // Give data table to grid.
            Grid.DataSourceTable = Table;

            // We want to find the component that is a child of our paddock.

            ComponentVE.GetVisibleComponents(Controller.ApsimData.Find(NodePath), ref MyComponents);

            PopulateComponentFilter();
            ClearSearch();
            PopulateVariableListView();

            if (XmlHelper.Type(Data).ToLower() != "variables")
            {
                VariableListView.Columns[1].Width = 0;
                ConstantsPanel.Visible            = false;
            }
            else
            {
                VariableListView.Columns[1].Width = 45;
                ConstantsPanel.Visible            = true;
                PopulateConstants();
            }

            Grid.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            Grid.Columns[0].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
        }
Beispiel #3
0
        /// <summary>
        /// The grid is adding a new row. Format the row the way we want it.
        /// </summary>
        public void OnAddingNewRow(DataGridViewRow NewRow)
        {
            // Setup the Type combo box.
            Grid.CreateComboInCell(NewRow.Cells[1], TypeComboItems);

            // Create a list items edit box that can handle lots of chars.
            DataGridViewTextBoxCell ListItemTextBox = (DataGridViewTextBoxCell)NewRow.Cells[2];

            ListItemTextBox.MaxInputLength = 5000;

            // Now create the correct type of cell in the value field for this row.
            switch (NewRow.Cells[1].Value.ToString())
            {
            case "yesno":
            {
                Grid.CreateComboInCell(NewRow.Cells[4], YesNoItems);

                break;
            }

            case "list":
            case "multilist":
            {
                if (!Convert.IsDBNull(NewRow.Cells[2].Value))
                {
                    Grid.CreateComboInCell(NewRow.Cells[4], NewRow.Cells[2].Value.ToString().Split(new char[] { ',' }));
                }

                break;
            }

            case "multiedit":
            {
                DataGridViewTextBoxCell Text = (DataGridViewTextBoxCell)NewRow.Cells[4];
                Text.MaxInputLength = 5000;
                Text.Style.WrapMode = DataGridViewTriState.True;
                NewRow.Height       = 80;

                break;
            }

            case "filename":
            {
                Grid.CreateButtonInCell(NewRow.Cells[4]);

                break;
            }

            case "category":
            {
                NewRow.Cells[3].ReadOnly = !EditModeItem.Checked;
                // Make listitems field readonly
                NewRow.Cells[4].ReadOnly = true;
                // Make description field readonly
                NewRow.DefaultCellStyle.BackColor = System.Drawing.Color.LightSteelBlue;

                break;
            }

            case "modulename":
            {
                List <ComponentVE> MyComponents = new List <ComponentVE>();
                ComponentVE.GetVisibleComponents(Controller.ApsimData.Find(NodePath), ref MyComponents);
                string[] modulenames = new string[MyComponents.Count];
                int      i           = 0;
                foreach (ComponentVE ve in MyComponents)
                {
                    modulenames[i++] = ve.name;
                }

                Grid.CreateComboInCell(NewRow.Cells[4], modulenames);

                break;
            }

            case "crop":
            {
                ApsimFile.Component Paddock = Controller.ApsimData.Find(NodePath).FindContainingPaddock();
                while ((Paddock != null) && (Paddock.Type.ToLower() == "folder"))
                {
                    Paddock = Paddock.Parent;
                }
                if ((Paddock != null))
                {
                    List <string> Crops = new List <string>();
                    foreach (Component Child in Paddock.ChildNodes)
                    {
                        if (Types.Instance.MetaData(Child.Type, "IsCrop").ToLower() == "yes")
                        {
                            Crops.Add(Child.Name);
                        }
                    }
                    string[] CropNames = new string[Crops.Count];
                    Crops.CopyTo(CropNames);
                    Grid.CreateComboInCell(NewRow.Cells[4], CropNames);
                }

                break;
            }

            case "cultivars":
            {
                // Try and locate a row with crop as the name.
                int CropRow = 0;
                for (CropRow = 0; CropRow <= Grid.RowCount - 1; CropRow++)
                {
                    if (Grid.Rows[CropRow].Cells[0].Value != null &&
                        Grid.Rows[CropRow].Cells[0].Value.ToString().ToLower() == "crop")
                    {
                        break;         // TODO: might not be correct. Was : Exit For
                    }
                }

                // If we found a crop row then go and get all cultivars for that crop.
                if (CropRow < Grid.RowCount && !Convert.IsDBNull(Grid.Rows[CropRow].Cells[4].Value))
                {
                    string    CropName      = Grid.Rows[CropRow].Cells[4].Value.ToString();
                    Component CropComponent = Controller.ApsimData.Find(NodePath).FindComponentInPaddock(Controller.ApsimData.Find(NodePath), CropName);
                    if ((CropComponent != null))
                    {
                        CropName = CropComponent.Type;
                    }
                    string[] Cultivars = Types.Instance.Cultivars(CropName);
                    Grid.CreateComboInCell(NewRow.Cells[4], Cultivars);
                }

                break;
            }

            case "classes":
            {
                // Try and locate a row with crop as the name.
                int CropRow = 0;
                for (CropRow = 0; CropRow <= Grid.RowCount - 1; CropRow++)
                {
                    if (Grid.Rows[CropRow].Cells[0].Value != null &&
                        Grid.Rows[CropRow].Cells[0].Value.ToString().ToLower() == "crop")
                    {
                        break;         // TODO: might not be correct. Was : Exit For
                    }
                }

                // If we found a crop row then go and get all cultivars for that crop.
                if (CropRow < Grid.RowCount && !Convert.IsDBNull(Grid.Rows[CropRow].Cells[4].Value))
                {
                    string    CropName      = Grid.Rows[CropRow].Cells[4].Value.ToString();
                    Component CropComponent = Controller.ApsimData.Find(NodePath).FindComponentInPaddock(Controller.ApsimData.Find(NodePath), CropName);
                    if ((CropComponent != null))
                    {
                        CropName = CropComponent.Type;
                    }
                    string[] Classes = Types.Instance.Classes(CropName);
                    Grid.CreateComboInCell(NewRow.Cells[4], Classes);
                }

                break;
            }

            case "date":
            {
                if (InRefresh && !string.IsNullOrEmpty(NewRow.Cells[4].Value.ToString()))
                {
                    try
                    {
                        DateTime Value = DateTime.ParseExact(NewRow.Cells[4].Value.ToString(), "d/M/yyyy", null);
                        NewRow.Cells[4].Value = Value.ToShortDateString();
                    }
                    catch (Exception)
                    {
                        NewRow.Cells[4].Value = "";
                    }
                }
                DateTimeFormatInfo DateFormat = CultureInfo.CurrentCulture.DateTimeFormat;
                NewRow.Cells[4].ToolTipText = "Format: " + DateFormat.ShortDatePattern;
                break;
            }
            }
        }