/// <summary> /// <para> /// Display the value within the appropriate DataRow column into /// the field contained within DataBinding</para> /// </summary> /// <returns> /// <para>True: the field has been displayed.</para> /// <para>False: the field has not been displayed, use the default code </para> /// </returns> public Boolean displayField(DataBinding dataBinding, DataRow dataRow) { switch ((Net7.Table_item_ammo)dataBinding.enumeration) { case Net7.Table_item_ammo._ammo_type_id: { ComboBox ammoType = (ComboBox)dataBinding.control; ammoType.Items.Clear(); ammoType.Items.AddRange(Database.getItemAmmoTypes(102)); ammoType.Items.AddRange(Database.getItemAmmoTypes(101)); } return false; case Net7.Table_item_ammo._damage_type: { ComboBox damageType = (ComboBox)dataBinding.control; damageType.Items.Clear(); damageType.Items.AddRange(Database.getItemDamageTypes()); return false; } case Net7.Table_item_ammo._fire_effect: dataBinding.control.Text = (dataRow == null) ? "0" : ColumnData.GetString(dataRow, dataBinding.enumeration); return true; case Net7.Table_item_ammo._range_100: dataBinding.control.Text = (dataRow == null) ? "0" : ColumnData.GetString(dataRow, dataBinding.enumeration); return true; case Net7.Table_item_ammo._damage_100: dataBinding.control.Text = (dataRow == null) ? "10" : ColumnData.GetString(dataRow, dataBinding.enumeration); return true; } return false; }
/// <summary> /// <para> /// Display the value within the appropriate DataRow column into /// the field contained within DataBinding</para> /// </summary> /// <returns> /// <para>True: the field has been displayed.</para> /// <para>False: the field has not been displayed, use the default code </para> /// </returns> public Boolean displayField(DataBinding dataBinding, DataRow dataRow) { switch ((Net7.Table_item_beam)dataBinding.enumeration) { case Net7.Table_item_beam._rest_race: case Net7.Table_item_beam._rest_prof: // Handles both race and profession restrictions return Restrictions.displayField(dataRow, Net7.Table_item_beam._rest_race, Net7.Table_item_beam._rest_prof); case Net7.Table_item_beam._fire_effect: dataBinding.control.Text = (dataRow == null) ? "0" : ColumnData.GetString(dataRow, dataBinding.enumeration); return true; case Net7.Table_item_beam._range_100: dataBinding.control.Text = (dataRow == null) ? "1000" : ColumnData.GetString(dataRow, dataBinding.enumeration); return true; case Net7.Table_item_beam._energy_100: dataBinding.control.Text = (dataRow == null) ? "10" : ColumnData.GetString(dataRow, dataBinding.enumeration); return true; case Net7.Table_item_beam._reload_100: dataBinding.control.Text = (dataRow == null) ? "4" : ColumnData.GetString(dataRow, dataBinding.enumeration); return true; case Net7.Table_item_beam._damage_100: dataBinding.control.Text = (dataRow == null) ? "10" : ColumnData.GetString(dataRow, dataBinding.enumeration); return true; } return false; }
public Boolean enableField(DataBinding dataBinding, DataRow dataRow, Boolean enabled) { switch ((Net7.Table_item_device)dataBinding.enumeration) { case Net7.Table_item_device._rest_race: case Net7.Table_item_device._rest_prof: // Handles both race and profession restrictions return Restrictions.enableField(enabled); } return false; }
/// <summary> /// <para> /// Display the value within the appropriate DataRow column into /// the field contained within DataBinding</para> /// </summary> /// <returns> /// <para>True: the field has been displayed.</para> /// <para>False: the field has not been displayed, use the default code </para> /// </returns> public Boolean displayField(DataBinding dataBinding, DataRow dataRow) { Net7.Table_item_manufacture manuField = (Net7.Table_item_manufacture)dataBinding.enumeration; switch (manuField) { case Net7.Table_item_manufacture._difficulty: if(dataRow == null) { System.Windows.Forms.ComboBox difficulty = (System.Windows.Forms.ComboBox) dataBinding.control; difficulty.SelectedItem = difficulty.Items[0]; return true; } break; case Net7.Table_item_manufacture._comp_1: case Net7.Table_item_manufacture._comp_2: case Net7.Table_item_manufacture._comp_3: case Net7.Table_item_manufacture._comp_4: case Net7.Table_item_manufacture._comp_5: case Net7.Table_item_manufacture._comp_6: { int componentIndex = getComponentIndexFromEnum(manuField); if (componentIndex == -1) { // TODO: Handle data error throw (new Exception("Invalid component index")); } else { dataBinding.control.Text = (dataRow == null) ? UnspecifiedComponentId : ColumnData.GetString(dataRow, dataBinding.enumeration); if (dataBinding.control.Text.Length == 0) { dataBinding.control.Text = UnspecifiedComponentId; } m_listComponentFields[componentIndex].setDescription(); return true; } } } return false; }
/// <summary> /// <para> /// Display the value within the appropriate DataRow column into /// the field contained within DataBinding</para> /// </summary> /// <returns> /// <para>True: the field has been displayed.</para> /// <para>False: the field has not been displayed, use the default code </para> /// </returns> public Boolean displayField(DataBinding dataBinding, DataRow dataRow) { switch ((Net7.Table_item_missile)dataBinding.enumeration) { case Net7.Table_item_missile._rest_race: case Net7.Table_item_missile._rest_prof: // Handles both race and profession restrictions return Restrictions.displayField(dataRow, Net7.Table_item_missile._rest_race, Net7.Table_item_missile._rest_prof); case Net7.Table_item_missile._ammo_per_shot: dataBinding.control.Text = (dataRow == null) ? "1" : ColumnData.GetString(dataRow, dataBinding.enumeration); return true; case Net7.Table_item_missile._energy_100: dataBinding.control.Text = (dataRow == null) ? "50" : ColumnData.GetString(dataRow, dataBinding.enumeration); return true; case Net7.Table_item_missile._reload_100: dataBinding.control.Text = (dataRow == null) ? "10" : ColumnData.GetString(dataRow, dataBinding.enumeration); return true; } return false; }
public Boolean updateField(Boolean newRecord, DataBinding dataBinding, DataRow dataRow) { if (dataBinding.enumeration.Equals(Net7.Table_item_base._description)) { // Convert to E&B style String columnName = ColumnData.GetName(dataBinding.enumeration); dataRow[columnName] = Utility.FormatDescription(dataBinding.control.Text); return(true); } else if (dataBinding.enumeration.Equals(Net7.Table_item_base._item_base_id)) { TextBox baseItemId = (TextBox)dataBinding.control; if (!baseItemId.Enabled) { String columnName = ColumnData.GetName(dataBinding.enumeration); dataRow[columnName] = DBNull.Value; return(true); } } return(false); }
/// <summary> /// <para> /// Display the value within the appropriate DataRow column into /// the field contained within DataBinding</para> /// </summary> /// <returns> /// <para>True: the field has been displayed.</para> /// <para>False: the field has not been displayed, use the default code </para> /// </returns> public Boolean displayField(DataBinding dataBinding, DataRow dataRow) { switch ((Net7.Table_item_missile)dataBinding.enumeration) { case Net7.Table_item_missile._rest_race: case Net7.Table_item_missile._rest_prof: // Handles both race and profession restrictions return(Restrictions.displayField(dataRow, Net7.Table_item_missile._rest_race, Net7.Table_item_missile._rest_prof)); case Net7.Table_item_missile._ammo_per_shot: dataBinding.control.Text = (dataRow == null) ? "1" : ColumnData.GetString(dataRow, dataBinding.enumeration); return(true); case Net7.Table_item_missile._energy_100: dataBinding.control.Text = (dataRow == null) ? "50" : ColumnData.GetString(dataRow, dataBinding.enumeration); return(true); case Net7.Table_item_missile._reload_100: dataBinding.control.Text = (dataRow == null) ? "10" : ColumnData.GetString(dataRow, dataBinding.enumeration); return(true); } return(false); }
/// <summary> /// <para> /// Display the value within the appropriate DataRow column into /// the field contained within DataBinding</para> /// </summary> /// <returns> /// <para>True: the field has been displayed.</para> /// <para>False: the field has not been displayed, use the default code </para> /// </returns> public Boolean displayField(DataBinding dataBinding, DataRow dataRow) { switch ((Net7.Table_item_engine)dataBinding.enumeration) { case Net7.Table_item_engine._rest_race: case Net7.Table_item_engine._rest_prof: // Handles both race and profession restrictions return Restrictions.displayField(dataRow, Net7.Table_item_engine._rest_race, Net7.Table_item_engine._rest_prof); case Net7.Table_item_engine._warp: dataBinding.control.Text = (dataRow == null) ? "2000" : ColumnData.GetString(dataRow, dataBinding.enumeration); return true; case Net7.Table_item_engine._signature_100: dataBinding.control.Text = (dataRow == null) ? "40000" : ColumnData.GetString(dataRow, dataBinding.enumeration); return true; case Net7.Table_item_engine._thrust_100: dataBinding.control.Text = (dataRow == null) ? "50" : ColumnData.GetString(dataRow, dataBinding.enumeration); return true; case Net7.Table_item_engine._warp_drain_100: dataBinding.control.Text = (dataRow == null) ? "5.5" : ColumnData.GetString(dataRow, dataBinding.enumeration); return true; } return false; }
/// <summary> /// <para> /// Validate the display the value of the field contained within DataBinding</para> /// </summary> /// <returns> /// <para>The data validation result.</para> /// </returns> public DataValidation.Result validField(Boolean newRecord, DataBinding dataBinding, DataRow dataRow) { DataValidation.Result dataValidationResult = null; return(dataValidationResult); }
/// <summary> /// <para> /// Update the value within the appropriate DataRow column from /// the contents of the field within DataBinding</para> /// </summary> /// <returns> /// <para>True: the data has been updated.</para> /// <para>False: the data has not been updated, use the default code </para> /// </returns> public Boolean updateField(Boolean newRecord, DataBinding dataBinding, DataRow dataRow) { return false; }
/// <summary> /// <para> /// Update the value within the appropriate DataRow column from /// the contents of the field within DataBinding</para> /// </summary> /// <returns> /// <para>True: the data has been updated.</para> /// <para>False: the data has not been updated, use the default code </para> /// </returns> public Boolean updateField(Boolean newRecord, DataBinding dataBinding, DataRow dataRow) { return(false); }
/// <summary> /// <para> /// Validate the display the value of the field contained within DataBinding</para> /// </summary> /// <returns> /// <para>The data validation result.</para> /// </returns> public DataValidation.Result validField(Boolean newRecord, DataBinding dataBinding, DataRow dataRow) { DataValidation.Result dataValidationResult = null; switch ((Net7.Table_item_manufacture)dataBinding.enumeration) { case Net7.Table_item_manufacture._item_id: { if (newRecord) { // Store the item ID String itemIdColumnName = ColumnData.GetName(Net7.Table_item_base._id); String itemId = dataRow[itemIdColumnName].ToString(); String manufacturingIdColumnName = ColumnData.GetName(Net7.Table_item_manufacture._item_id); dataRow[manufacturingIdColumnName] = itemId; } } break; case Net7.Table_item_manufacture._comp_1: case Net7.Table_item_manufacture._comp_2: case Net7.Table_item_manufacture._comp_3: case Net7.Table_item_manufacture._comp_4: case Net7.Table_item_manufacture._comp_5: case Net7.Table_item_manufacture._comp_6: { int componentIndex = getComponentIndexFromEnum((Net7.Table_item_manufacture)dataBinding.enumeration); String componentId = m_listComponentFields[componentIndex].getFields().m_field.Text; if (componentIndex == 0) { dataValidationResult = componentId.Equals(UnspecifiedComponentId) ? null : DataValidation.isInTable(componentId, Net7.Tables.item_manufacture.ToString(), Database.getQueryItem(componentId)); } else if (componentIndex > 0) { // Valid to be unspecified otherwise must be in the item table dataValidationResult = componentId.Equals(UnspecifiedComponentId) ? null : DataValidation.isInTable(componentId, "Items", Database.getQueryItem(componentId)); if (dataValidationResult == null || dataValidationResult.isValid()) { // Previous component must be specified String previousComponentId = m_listComponentFields[componentIndex - 1].getFields().m_field.Text; if (!componentId.Equals(UnspecifiedComponentId) && previousComponentId.Equals(UnspecifiedComponentId)) { if (dataValidationResult == null) { dataValidationResult = new DataValidation.Result(); } dataValidationResult.setMessage("You must define the previous component before specifying this one"); } } } } break; } return(dataValidationResult); }
/// <summary> /// <para> /// Update the value within the appropriate DataRow column from /// the contents of the field within DataBinding</para> /// </summary> /// <returns> /// <para>True: the data has been updated.</para> /// <para>False: the data has not been updated, use the default code </para> /// </returns> public Boolean updateField(Boolean newRecord, DataBinding dataBinding, DataRow dataRow) { Net7.Table_item_device deviceField = (Net7.Table_item_device)dataBinding.enumeration; switch (deviceField) { case Net7.Table_item_device._rest_race: case Net7.Table_item_device._rest_prof: // Handles both race and profession restrictions return Restrictions.updateField(newRecord, dataRow, Net7.Table_item_device._rest_race, Net7.Table_item_device._rest_prof); } return false; }
/// <summary> /// <para> /// Validate the display the value of the field contained within DataBinding</para> /// </summary> /// <returns> /// <para>The data validation result.</para> /// </returns> public DataValidation.Result validField(Boolean newRecord, DataBinding dataBinding, DataRow dataRow) { DataValidation.Result dataValidationResult = null; /*switch ((Net7_db.Table_item_device)dataBinding.enumeration) { }*/ return dataValidationResult; }
/// <summary> /// <para> /// Update the value within the appropriate DataRow column from /// the contents of the field within DataBinding</para> /// </summary> /// <returns> /// <para>True: the data has been updated.</para> /// <para>False: the data has not been updated, use the default code </para> /// </returns> public Boolean updateField(Boolean newRecord, DataBinding dataBinding, DataRow dataRow) { Net7.Table_item_engine engineField = (Net7.Table_item_engine)dataBinding.enumeration; switch (engineField) { case Net7.Table_item_engine._energy_100: case Net7.Table_item_engine._range_100: dataRow[ColumnData.GetName(engineField)] = 0; return true; case Net7.Table_item_engine._rest_race: case Net7.Table_item_engine._rest_prof: // Handles both race and profession restrictions return Restrictions.updateField(newRecord, dataRow, Net7.Table_item_engine._rest_race, Net7.Table_item_engine._rest_prof); } return false; }
/// <summary> /// <para> /// Update the value within the appropriate DataRow column from /// the contents of the field within DataBinding</para> /// </summary> /// <returns> /// <para>True: the data has been updated.</para> /// <para>False: the data has not been updated, use the default code </para> /// </returns> public Boolean updateField(Boolean newRecord, DataBinding dataBinding, DataRow dataRow) { Net7.Table_item_ammo ammoField = (Net7.Table_item_ammo)dataBinding.enumeration; switch (ammoField) { case Net7.Table_item_ammo._maneuv_100: dataRow[ColumnData.GetName(ammoField)] = 0; return true; } return false; }
/// <summary> /// <para> /// Validate the display the value of the field contained within DataBinding</para> /// </summary> /// <returns> /// <para>The data validation result.</para> /// </returns> public DataValidation.Result validField(Boolean newRecord, DataBinding dataBinding, DataRow dataRow) { DataValidation.Result dataValidationResult = null; return dataValidationResult; }
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; }
public Boolean enableField(DataBinding dataBinding, DataRow dataRow, Boolean enabled) { return false; }
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; }
/// <summary> /// Callback from TableIO /// </summary> /// <param name="dataBinding"></param> /// <param name="dataRow"></param> /// <param name="enabled"></param> /// <returns></returns> public Boolean enableField(DataBinding dataBinding, DataRow dataRow, Boolean enabled) { int componentIndex = getComponentIndexFromEnum((Net7.Table_item_manufacture)dataBinding.enumeration); enableField(componentIndex, enabled); return true; }
public Boolean updateField(Boolean newRecord, DataBinding dataBinding, DataRow dataRow) { if (dataBinding.enumeration.Equals(Net7.Table_item_base._description)) { // Convert to E&B style String columnName = ColumnData.GetName(dataBinding.enumeration); dataRow[columnName] = Utility.FormatDescription(dataBinding.control.Text); return true; } else if (dataBinding.enumeration.Equals(Net7.Table_item_base._item_base_id)) { TextBox baseItemId = (TextBox)dataBinding.control; if (!baseItemId.Enabled) { String columnName = ColumnData.GetName(dataBinding.enumeration); dataRow[columnName] = DBNull.Value; return true; } } return false; }
/// <summary> /// <para> /// Validate the display the value of the field contained within DataBinding</para> /// </summary> /// <returns> /// <para>The data validation result.</para> /// </returns> public DataValidation.Result validField(Boolean newRecord, DataBinding dataBinding, DataRow dataRow) { DataValidation.Result dataValidationResult = null; switch ((Net7.Table_item_manufacture)dataBinding.enumeration) { case Net7.Table_item_manufacture._item_id: { if (newRecord) { // Store the item ID String itemIdColumnName = ColumnData.GetName(Net7.Table_item_base._id); String itemId = dataRow[itemIdColumnName].ToString(); String manufacturingIdColumnName = ColumnData.GetName(Net7.Table_item_manufacture._item_id); dataRow[manufacturingIdColumnName] = itemId; } } break; case Net7.Table_item_manufacture._comp_1: case Net7.Table_item_manufacture._comp_2: case Net7.Table_item_manufacture._comp_3: case Net7.Table_item_manufacture._comp_4: case Net7.Table_item_manufacture._comp_5: case Net7.Table_item_manufacture._comp_6: { int componentIndex = getComponentIndexFromEnum((Net7.Table_item_manufacture)dataBinding.enumeration); String componentId = m_listComponentFields[componentIndex].getFields().m_field.Text; if (componentIndex == 0) { dataValidationResult = componentId.Equals(UnspecifiedComponentId) ? null : DataValidation.isInTable(componentId, Net7.Tables.item_manufacture.ToString(), Database.getQueryItem(componentId)); } else if (componentIndex > 0) { // Valid to be unspecified otherwise must be in the item table dataValidationResult = componentId.Equals(UnspecifiedComponentId) ? null : DataValidation.isInTable(componentId, "Items", Database.getQueryItem(componentId)); if (dataValidationResult == null || dataValidationResult.isValid()) { // Previous component must be specified String previousComponentId = m_listComponentFields[componentIndex - 1].getFields().m_field.Text; if (!componentId.Equals(UnspecifiedComponentId) && previousComponentId.Equals(UnspecifiedComponentId)) { if (dataValidationResult == null) { dataValidationResult = new DataValidation.Result(); } dataValidationResult.setMessage("You must define the previous component before specifying this one"); } } } } break; } return dataValidationResult; }
public DataValidation.Result validField(Boolean newRecord, DataBinding dataBinding, DataRow dataRow) { DataValidation.Result dataValidationResult = null; switch ((Net7.Table_item_base)dataBinding.enumeration) { case Net7.Table_item_base._id: { if (newRecord) { dataBinding.control.Text = Database.getNextItemId(); } } break; case Net7.Table_item_base._category: { ComboBox comboBox = (ComboBox)dataBinding.control; CodeValue codeValue = (CodeValue)comboBox.SelectedItem; //dataValidationResult = DataValidation.isNumericGreaterEqual(codeValue.code.ToString(), 1); dataValidationResult = DataValidation.isNonEmpty(codeValue); if (dataValidationResult.isValid() && !Enum.IsDefined(typeof(Items.ItemCategory), codeValue.code)) { dataValidationResult = new DataValidation.Result("The category '" + codeValue.code + "' is invalid"); } // TODO: Validate through the item_category table /* dataValidationResult = DataValidation.isInTable(codeValue.code.ToString(), Net7_db.Tables.item_category.ToString(), DB.getQueryItemCategory());*/ } break; case Net7.Table_item_base._sub_category: { ComboBox comboBox = (ComboBox)dataBinding.control; CodeValue codeValue = (CodeValue)comboBox.SelectedItem; // TODO: codeValue can be null even though there is something displayed on the screen //dataValidationResult = DataValidation.isNumericGreaterEqual(codeValue.code.ToString(), 1); dataValidationResult = DataValidation.isNonEmpty(codeValue); if (dataValidationResult.isValid() && !Enum.IsDefined(typeof(Items.ItemSubCategory), codeValue.code)) { dataValidationResult = new DataValidation.Result("The sub-category '" + codeValue.code + "' is invalid"); } // TODO: Validate through the item_sub_category table /* dataValidationResult = DataValidation.isInTable(codeValue.code.ToString(), Net7_db.Tables.item_sub_category.ToString(), DB.getQueryItemSubCategory());*/ /* if(dataValidationResult.isValid()) { String query = "SELECT item_id" + " FROM " + Net7_db.Tables.item_subcategory.ToString() + " WHERE " + ColumnData.GetName(Net7_db.item_subcategory._item_id) + " = '" + codeValue.code.ToString() + "'"; dataValidationResult = DataValidation.isIdInTable(codeValue.code.ToString(), Net7_db.Tables.item_subcategory.ToString(), query); } */ } break; case Net7.Table_item_base._manufacturer: { ComboBox comboBox = (ComboBox)dataBinding.control; CodeValue codeValue = (CodeValue)comboBox.SelectedItem; dataValidationResult = DataValidation.isNumeric(codeValue.code.ToString()); if(dataValidationResult.isValid()) { String query = "SELECT " + ColumnData.GetName(Net7.Table_item_manufacturer_base._id) + " FROM " + Net7.Tables.item_manufacturer_base.ToString() + " WHERE " + ColumnData.GetName(Net7.Table_item_manufacturer_base._id) + " = '" + codeValue.code.ToString() + "'"; dataValidationResult = DataValidation.isInTable(codeValue.code.ToString(), "Manufacturers", query); } } break; case Net7.Table_item_base._name: dataValidationResult = DataValidation.isNonEmpty(dataBinding.control.Text); if (dataValidationResult.isValid()) { String columnName = ColumnData.GetName(Net7.Table_item_base._name); String currentValue = newRecord ? "" : dataRow[columnName].ToString(); String newValue = dataBinding.control.Text; if( currentValue.ToLower().CompareTo(newValue.ToLower()) != 0 // It's not a simple rename && !currentValue.Equals(newValue)) { String query = "SELECT " + columnName + " FROM " + Net7.Tables.item_base.ToString() + " WHERE " + columnName + " = '" + dataBinding.control.Text.Replace("'", "''") + "'"; dataValidationResult = DataValidation.isNotInTable(dataBinding.control.Text, "Items", query); } } break; case Net7.Table_item_base._item_base_id: { TextBox baseItemId = (TextBox)dataBinding.control; if (baseItemId.Enabled) { String columnName = ColumnData.GetName(Net7.Table_item_base._id); String query = "SELECT " + columnName + " FROM " + Net7.Tables.item_base.ToString() + " WHERE " + columnName + " = '" + dataBinding.control.Text + "'"; dataValidationResult = DataValidation.isInTable(dataBinding.control.Text, "Items", query); } } break; case Net7.Table_item_base._effect_id: { TextBox equipVisualEffectId = (TextBox)dataBinding.control; if (equipVisualEffectId.Enabled) { String columnName = ColumnData.GetName(Net7.Table_effects._effect_id); String query = "SELECT " + columnName + " FROM " + Net7.Tables.effects + " WHERE " + columnName + " = '" + dataBinding.control.Text + "'"; dataValidationResult = DataValidation.isInTable(dataBinding.control.Text, "Effects", query); } } break; } return dataValidationResult; }
public DataValidation.Result validField(Boolean newRecord, DataBinding dataBinding, DataRow dataRow) { DataValidation.Result dataValidationResult = null; switch ((Net7.Table_item_base)dataBinding.enumeration) { case Net7.Table_item_base._id: { if (newRecord) { dataBinding.control.Text = Database.getNextItemId(); } } break; case Net7.Table_item_base._category: { ComboBox comboBox = (ComboBox)dataBinding.control; CodeValue codeValue = (CodeValue)comboBox.SelectedItem; //dataValidationResult = DataValidation.isNumericGreaterEqual(codeValue.code.ToString(), 1); dataValidationResult = DataValidation.isNonEmpty(codeValue); if (dataValidationResult.isValid() && !Enum.IsDefined(typeof(Items.ItemCategory), codeValue.code)) { dataValidationResult = new DataValidation.Result("The category '" + codeValue.code + "' is invalid"); } // TODO: Validate through the item_category table /* * dataValidationResult = DataValidation.isInTable(codeValue.code.ToString(), * Net7_db.Tables.item_category.ToString(), * DB.getQueryItemCategory());*/ } break; case Net7.Table_item_base._sub_category: { ComboBox comboBox = (ComboBox)dataBinding.control; CodeValue codeValue = (CodeValue)comboBox.SelectedItem; // TODO: codeValue can be null even though there is something displayed on the screen //dataValidationResult = DataValidation.isNumericGreaterEqual(codeValue.code.ToString(), 1); dataValidationResult = DataValidation.isNonEmpty(codeValue); if (dataValidationResult.isValid() && !Enum.IsDefined(typeof(Items.ItemSubCategory), codeValue.code)) { dataValidationResult = new DataValidation.Result("The sub-category '" + codeValue.code + "' is invalid"); } // TODO: Validate through the item_sub_category table /* * dataValidationResult = DataValidation.isInTable(codeValue.code.ToString(), * Net7_db.Tables.item_sub_category.ToString(), * DB.getQueryItemSubCategory());*/ /* * if(dataValidationResult.isValid()) * { * String query = "SELECT item_id" + " FROM " + Net7_db.Tables.item_subcategory.ToString() + " WHERE " + ColumnData.GetName(Net7_db.item_subcategory._item_id) + " = '" + codeValue.code.ToString() + "'"; + dataValidationResult = DataValidation.isIdInTable(codeValue.code.ToString(), + Net7_db.Tables.item_subcategory.ToString(), + query); + } */ } break; case Net7.Table_item_base._manufacturer: { ComboBox comboBox = (ComboBox)dataBinding.control; CodeValue codeValue = (CodeValue)comboBox.SelectedItem; dataValidationResult = DataValidation.isNumeric(codeValue.code.ToString()); if (dataValidationResult.isValid()) { String query = "SELECT " + ColumnData.GetName(Net7.Table_item_manufacturer_base._id) + " FROM " + Net7.Tables.item_manufacturer_base.ToString() + " WHERE " + ColumnData.GetName(Net7.Table_item_manufacturer_base._id) + " = '" + codeValue.code.ToString() + "'"; dataValidationResult = DataValidation.isInTable(codeValue.code.ToString(), "Manufacturers", query); } } break; case Net7.Table_item_base._name: dataValidationResult = DataValidation.isNonEmpty(dataBinding.control.Text); if (dataValidationResult.isValid()) { String columnName = ColumnData.GetName(Net7.Table_item_base._name); String currentValue = newRecord ? "" : dataRow[columnName].ToString(); String newValue = dataBinding.control.Text; if (currentValue.ToLower().CompareTo(newValue.ToLower()) != 0 && // It's not a simple rename !currentValue.Equals(newValue)) { String query = "SELECT " + columnName + " FROM " + Net7.Tables.item_base.ToString() + " WHERE " + columnName + " = '" + dataBinding.control.Text.Replace("'", "''") + "'"; dataValidationResult = DataValidation.isNotInTable(dataBinding.control.Text, "Items", query); } } break; case Net7.Table_item_base._item_base_id: { TextBox baseItemId = (TextBox)dataBinding.control; if (baseItemId.Enabled) { String columnName = ColumnData.GetName(Net7.Table_item_base._id); String query = "SELECT " + columnName + " FROM " + Net7.Tables.item_base.ToString() + " WHERE " + columnName + " = '" + dataBinding.control.Text + "'"; dataValidationResult = DataValidation.isInTable(dataBinding.control.Text, "Items", query); } } break; case Net7.Table_item_base._effect_id: { TextBox equipVisualEffectId = (TextBox)dataBinding.control; if (equipVisualEffectId.Enabled) { String columnName = ColumnData.GetName(Net7.Table_effects._effect_id); String query = "SELECT " + columnName + " FROM " + Net7.Tables.effects + " WHERE " + columnName + " = '" + dataBinding.control.Text + "'"; dataValidationResult = DataValidation.isInTable(dataBinding.control.Text, "Effects", query); } } break; } return(dataValidationResult); }
/// <summary> /// <para>Associate a control/widget with a database field.</para> /// <para>This list is used to automate the display, validation, and update of data.</para> /// </summary> /// <returns>The data binding instance created for the control and field association</returns> /// <param name="control">The control/widget on the form</param> /// <param name="enumeration">The field within the database</param> /// <param name="controlName">The name of the control/widget, to be displayed within validation errors</param> /// <param name="autoEditMode">Whether changes within that field trigger a state change to edit mode</param> /// <remarks>The returned DataBinding can be used to specify data validations</remarks> public DataBinding bind(Control control, Enum enumeration, String controlName, Boolean autoEditMode) { if (control != null && enumeration != null) { // Specify the database table name and column name as the tooltip. This first needs to // be cleaned up as the table information initially results in: // Net7_Tools.Net7+Table_item_reactor String databaseTableAndField = enumeration.GetType().ToString() + "." + ColumnData.GetName(enumeration); int index = databaseTableAndField.Contains("+") ? databaseTableAndField.IndexOf('+') : 0; if (index != 0) { databaseTableAndField = databaseTableAndField.Substring(index + 1); } if (databaseTableAndField.StartsWith("Table_")) { databaseTableAndField = databaseTableAndField.Substring(6); } ToolTip toolTip = new ToolTip(); String database = enumeration.GetType().ToString(); toolTip.SetToolTip(control, databaseTableAndField); } DataBinding dataBinding = new DataBinding(control, enumeration, controlName); listDataBinding.Add(dataBinding); if (autoEditMode && control != null) { if (control.GetType() == typeof(CheckBox)) { ((CheckBox)control).CheckedChanged += new EventHandler(valueChanged); } else { control.TextChanged += new EventHandler(valueChanged); } } if (control != null && control.GetType() == typeof(TextBox)) { control.Enter += new EventHandler(onTextBoxEnter); } return dataBinding; }
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); }
public Boolean enableField(DataBinding dataBinding, DataRow dataRow, Boolean enabled) { return(false); }