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 void addValidation(DataValidation dataValidation) { m_listDataValidation.Add(dataValidation); }
public ValidationConditional(Boolean condition, DataValidation whenConditionTrue, DataValidation whenConditionFalse) { m_condition = condition; m_dataValidationWhenTrue = whenConditionTrue; m_dataValidationWhenFalse = whenConditionFalse; }
/// <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); }