public Boolean enableField(DataBinding dataBinding, DataRow dataRow, Boolean enabled)
        {
            switch ((Net7.Table_item_base)dataBinding.enumeration)
            {
            case Net7.Table_item_base._item_base_id:
            {
                Boolean customItem = dataRow != null &&
                                     ColumnData.GetBoolean(dataRow, Net7.Table_item_base._custom_flag);
                if (customItem == false && enabled == true)
                {
                    enabled = false;
                }
                dataBinding.control.Enabled = enabled;
                return(true);
            }

            case Net7.Table_item_base._category:
            {
                if (enabled == true)
                {
                    if (m_gui.getCurrentEditor().getTableHandlers()[0].getTableIO().getState().Equals(TableIO.State.Add))
                    {
                        // Always enable in Add mode
                    }
                    else
                    {
                        Int32 code = (dataRow == null) ? 0 : ColumnData.GetInt32(dataRow, dataBinding.enumeration);
                        Items.ItemCategory category = (Items.ItemCategory)code;
                        enabled = Items.isComponent(category);
                    }
                }
            }
                dataBinding.control.Enabled = enabled;
                return(true);

            case Net7.Table_item_base._sub_category:
            {
                if (enabled == true)
                {
                    if (m_gui.getCurrentEditor().getTableHandlers()[0].getTableIO().getState().Equals(TableIO.State.Add))
                    {
                        // Always enable in Add mode
                    }
                    else
                    {
                        Int32 code = (dataRow == null) ? 0 : ColumnData.GetInt32(dataRow, dataBinding.enumeration);
                        Items.ItemSubCategory subCategory  = (Items.ItemSubCategory)code;
                        TabPage[]             listTabPages = getTabPages(subCategory);
                        enabled = listTabPages.Length == 1;
                    }
                }
            }
                dataBinding.control.Enabled = enabled;
                return(true);
            } // switch

            return(false);
        }
        public Boolean displayField(DataBinding dataBinding, DataRow dataRow)
        {
            if (dataBinding.enumeration.Equals(Net7.Table_item_base._id))
            {
                String code = (dataRow == null) ? "" : ColumnData.GetString(dataRow, dataBinding.enumeration);
                m_baseManufacturingBtn.ForeColor = (code.Length == 0 || Database.hasManufacturing(code)) ? Color.Black : Color.Red;
            }
            else if (dataBinding.enumeration.Equals(Net7.Table_item_base._category))
            {
                // Show the relevant tab pages given the category
                Int32 code = (dataRow == null) ? 50 : ColumnData.GetInt32(dataRow, dataBinding.enumeration);
                Items.ItemCategory category = (Items.ItemCategory)code;
                TabPage[]          listTabPages;
                if (m_categoryTabPages.TryGetValue(category, out listTabPages))
                {
                    m_gui.setTabPages(listTabPages);
                }
            }
            else if (dataBinding.enumeration.Equals(Net7.Table_item_base._sub_category))
            {
                // Show the relevant tab pages given the sub-category
                Int32 code = (dataRow == null) ? 0 : ColumnData.GetInt32(dataRow, dataBinding.enumeration);
                Items.ItemSubCategory subCategory = (Items.ItemSubCategory)code;
                TabPage[]             listTabPages;
                if (m_subCategoryTabPages.TryGetValue(subCategory, out listTabPages))
                {
                    m_gui.setTabPages(listTabPages);
                }
                else if (m_subCategoryTabPages.TryGetValue(Items.ItemSubCategory.Other, out listTabPages))
                {
                    // Assume that the sub-category refers to a component
                    m_gui.setTabPages(listTabPages);
                }
                Int32       category        = (dataRow == null) ? 0 : ColumnData.GetInt32(dataRow, Net7.Table_item_base._category);
                CodeValue[] listSubCategory = Database.getItemSubCategories((int)category);
                ComboBox    subCategories   = (ComboBox)dataBinding.control;
                subCategories.Items.Clear();
                subCategories.Items.AddRange(listSubCategory);

                // Rely on the child tables (i.e. Devices, Beams, Missile/Projectile Launcher)
                // to activate the restrictions when needed
                Restrictions.displayField(null, null, null);
                Restrictions.enableField(false);

                Int32 subCategoryId = (dataRow == null) ? 0 : ColumnData.GetInt32(dataRow, dataBinding.enumeration);
                m_gui.setEditor(Items.getEditorType(subCategory), false);
            }
            else if (dataBinding.enumeration.Equals(Net7.Table_item_base._description))
            {
                // Convert from E&B style
                String description = (dataRow == null) ? "" : ColumnData.GetString(dataRow, dataBinding.enumeration);
                dataBinding.control.Text = Utility.ParseDescription(description);
                return(true);
            }
            else if (dataBinding.enumeration.Equals(Net7.Table_item_base._custom_flag))
            {
                ((CheckBox)dataBinding.control).Checked = (dataRow == null) ? false : ColumnData.GetBoolean(dataRow, dataBinding.enumeration);
                return(true);
            }
            else if (dataBinding.enumeration.Equals(Net7.Table_item_base._2d_asset))
            {
                dataBinding.control.Text = (dataRow == null) ? "744" : ColumnData.GetString(dataRow, dataBinding.enumeration);
                return(true);
            }
            else if (dataBinding.enumeration.Equals(Net7.Table_item_base._max_stack))
            {
                dataBinding.control.Text = (dataRow == null) ? "1" : ColumnData.GetString(dataRow, dataBinding.enumeration);
                return(true);
            }
            else if (dataBinding.enumeration.Equals(Net7.Table_item_base._3d_asset))
            {
                dataBinding.control.Text = (dataRow == null) ? "69" : ColumnData.GetString(dataRow, dataBinding.enumeration);
                return(true);
            }
            else if (dataBinding.enumeration.Equals(Net7.Table_item_base._price))
            {
                dataBinding.control.Text = (dataRow == null) ? "0" : ColumnData.GetString(dataRow, dataBinding.enumeration);
                return(true);
            }
            return(false);
        }
Beispiel #3
0
        public void viewRecord()
        {
            // Suspend the value changed event notification since the user is
            // not actually changing the values
            m_suspendValueChanged = true;

            // Process each widget bound to a database field
            foreach (DataBinding dataBinding in listDataBinding)
            {
                // Is there an override within the record manager?
                if (dataBinding.enumeration != null && !m_recordManager.displayField(dataBinding, m_dataRow))
                {
                    // Use the standard data manager
                    if (dataBinding.control != null)
                    {
                        if (dataBinding.control.GetType() == typeof(CheckBox))
                        {
                            ((CheckBox)dataBinding.control).Checked = (m_dataRow == null)
                                                                    ? false
                                                                    : ColumnData.GetBoolean(m_dataRow, dataBinding.enumeration);
                        }
                        else if (dataBinding.control.GetType() == typeof(ListBox))
                        {
                            // TODO: If the DB value is not available in the list then select first entry and enter edit mode
                            ListBox   listBox   = (ListBox)dataBinding.control;
                            CodeValue codeValue = new CodeValue();
                            codeValue.code = (m_dataRow == null) ? 0 : ColumnData.GetInt32(m_dataRow, dataBinding.enumeration);
                            if (m_dataRow == null)
                            {
                                codeValue = listBox.Items.Count == 0 ? null : (CodeValue)listBox.Items[0];
                            }
                            else
                            {
                                codeValue.code = ColumnData.GetInt32(m_dataRow, dataBinding.enumeration);
                            }
                            listBox.SelectedItem = codeValue;
                        }
                        else if (dataBinding.control.GetType() == typeof(ComboBox))
                        {
                            // TODO: If the DB value is not available in the list then select first entry and enter edit mode
                            ComboBox  comboBox  = (ComboBox)dataBinding.control;
                            CodeValue codeValue = new CodeValue();
                            codeValue.code = (m_dataRow == null) ? 0 : ColumnData.GetInt32(m_dataRow, dataBinding.enumeration);
                            if (m_dataRow == null)
                            {
                                codeValue = comboBox.Items.Count == 0 ? null : (CodeValue)comboBox.Items[0];
                            }
                            else
                            {
                                codeValue.code = ColumnData.GetInt32(m_dataRow, dataBinding.enumeration);
                            }
                            comboBox.SelectedItem = codeValue;
                        }
                        else
                        {
                            dataBinding.control.Text = (m_dataRow == null)
                                                     ? ""
                                                     : ColumnData.GetString(m_dataRow, dataBinding.enumeration);
                        }
                    }
                }
            }
            m_suspendValueChanged = false;

            // There's a record available so enable the fields
            enableFields(true);

            // There's a record available so we can add a new one, delete the current
            // one, but cannot save nor cancel it (it's not being added nor modified)
            if (!m_suspendGuiChanged)
            {
                m_gui.setGuiEnabled(true, true, false);
            }
        }