예제 #1
0
        private void dgv_Resources_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
        {
            if (((DataGridView)sender).Rows[e.RowIndex].IsNewRow)
            {
                return;
            }
            if (!((DataGridView)sender).IsCurrentRowDirty)
            {
                return;
            }

            // Constraint: Id must be > 0
            var resourceRecord = (ResourceRecord)((DataGridView)sender).Rows[e.RowIndex].DataBoundItem;

            if (resourceRecord.Id < 1)
            {
                MessageBox.Show("The Id must be greater than 0.");
                e.Cancel = true;
            }

            // Identity
            if (Resources.Count(c => c.Id == resourceRecord.Id) > 1)
            {
                MessageBox.Show($"There is already a Resource with Id '{resourceRecord.Id}'.");
                e.Cancel = true;
            }

            // Foreign Key
            if (ResistConfigurations.All(c => c.Id != resourceRecord.BonusResistConfigurationId))
            {
                MessageBox.Show($"The Resist Id '{resourceRecord.BonusResistConfigurationId}' does not exist.");
                e.Cancel = true;
                return;
            }

            // Primary Key
            if (Resources.Count(c => c.BonusResistConfigurationId == resourceRecord.BonusResistConfigurationId) > 1)
            {
                MessageBox.Show("This configuration already exists!");
                e.Cancel = true;
            }
        }
예제 #2
0
        private void dgv_ArmorTypes_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
        {
            if (((DataGridView)sender).Rows[e.RowIndex].IsNewRow)
            {
                return;
            }
            if (!((DataGridView)sender).IsCurrentRowDirty)
            {
                return;
            }

            var armorRecord = (ArmorRecord)((DataGridView)sender).Rows[e.RowIndex].DataBoundItem;

            // Constraint: Must be explicit slot
            if (armorRecord.Slot == SlotTypes.Unknown)
            {
                MessageBox.Show(@"The Slot cannot be 'Unknown'.");
                e.Cancel = true;
            }

            // Constraint: Type and Slot must be unique combinations
            if (ArmorTypes.Where(c => c.Type.ToLower() == armorRecord.Type.ToLower()).Any(c => c.Slot != armorRecord.Slot))
            {
                MessageBox.Show($@"That Type '{armorRecord.Type}' already belongs to another Slot.");
                e.Cancel = true;
            }

            // Constraint: Type and Color must be unique combinations
            if (ArmorTypes.Count(c => c.Type.ToLower() == armorRecord.Type.ToLower() && c.Color == armorRecord.Color) > 1)
            {
                MessageBox.Show($@"There is already a Type '{armorRecord.Type}' and Color '{armorRecord.Color}'.");
                e.Cancel = true;
            }

            // Foreign Key: Resist Id must exist
            if (ResistConfigurations.All(c => c.Id != armorRecord.BaseResistConfigurationId))
            {
                MessageBox.Show($@"The Resist Id '{armorRecord.BaseResistConfigurationId}' does not exist.");
                e.Cancel = true;
            }
        }
예제 #3
0
        private void dgv_ResistConfigurations_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
        {
            if (((DataGridView)sender).Rows[e.RowIndex].IsNewRow)
            {
                return;
            }
            if (!((DataGridView)sender).IsCurrentRowDirty)
            {
                return;
            }

            // Constraint: Must be > 0
            var resistConfiguration = (ResistConfiguration)((DataGridView)sender).Rows[e.RowIndex].DataBoundItem;

            if (resistConfiguration.Id < 1)
            {
                MessageBox.Show("The Id must be greater than 0.");
                e.Cancel = true;
            }

            // Identity
            if (ResistConfigurations.Count(c => c.Id == resistConfiguration.Id) > 1)
            {
                MessageBox.Show($"There is already a record with Id '{resistConfiguration.Id}'.");
                e.Cancel = true;
            }

            // Primary Key on all resists
            if (ResistConfigurations.Count(c =>
                                           c.Physical == resistConfiguration.Physical &&
                                           c.Fire == resistConfiguration.Fire &&
                                           c.Cold == resistConfiguration.Cold &&
                                           c.Poison == resistConfiguration.Poison &&
                                           c.Energy == resistConfiguration.Energy) > 1)
            {
                MessageBox.Show("This configuration already exists!");
                e.Cancel = true;
            }
        }