Example #1
0
        private void CheckedListBoxChange(object sender, InputType type, ItemCheckEventArgs e)
        {
            switch (type)
            {
            case InputType.FeatTargets:
            {
                if (e.NewValue == CheckState.Unchecked)
                {
                    foreach (FeatTargetSelection selection in FeatTargetsSelected)
                    {
                        if (TargetModel.GetNameFromId(selection.Model.TargetId) == FeatTargetsCheckedListBox.Items[e.Index].ToString())
                        {
                            selection.DeleteRecord = true;
                            RecordChanged          = true;
                            return;
                        }
                    }
                }
                else
                {
                    //let see if model exist already, if not then we need to add one otherwise set deleterecord to false.
                    foreach (FeatTargetSelection selection in FeatTargetsSelected)
                    {
                        if (TargetModel.GetNameFromId(selection.Model.TargetId) == FeatTargetsCheckedListBox.Items[e.Index].ToString())
                        {
                            selection.DeleteRecord = false;
                            RecordChanged          = true;
                            return;
                        }
                    }
                    // we made it this far, so we need to add a model
                    FeatTargetsSelected.Add(new FeatTargetSelection());
                    FeatTargetsSelected[FeatTargetsSelected.Count - 1].Model          = new FeatTargetModel();
                    FeatTargetsSelected[FeatTargetsSelected.Count - 1].Model.FeatId   = Model.Id;
                    FeatTargetsSelected[FeatTargetsSelected.Count - 1].Model.TargetId = TargetModel.GetIdFromName(FeatTargetsCheckedListBox.Items[e.Index].ToString());
                    FeatTargetsSelected[FeatTargetsSelected.Count - 1].DeleteRecord   = false;
                    RecordChanged = true;
                }
                break;
            }

            case InputType.FeatTypes:
            {
                if (e.NewValue == CheckState.Unchecked)
                {
                    foreach (FeatTypeSelection selection in FeatTypesSelected)
                    {
                        if (FeatTypeModel.GetNameFromId(selection.Model.FeatTypeId) == FeatTypesCheckedListBox.Items[e.Index].ToString())
                        {
                            selection.DeleteRecord = true;
                            RecordChanged          = true;
                            return;
                        }
                    }
                }
                else
                {
                    //let see if model exist already, if not then we need to add one otherwise set deleterecord to false.
                    foreach (FeatTypeSelection selection in FeatTypesSelected)
                    {
                        if (FeatTypeModel.GetNameFromId(selection.Model.FeatTypeId) == FeatTypesCheckedListBox.Items[e.Index].ToString())
                        {
                            selection.DeleteRecord = false;
                            RecordChanged          = true;
                            return;
                        }
                    }
                    // we made it this far, so we need to add a model
                    FeatTypesSelected.Add(new FeatTypeSelection());
                    FeatTypesSelected[FeatTypesSelected.Count - 1].Model            = new FeatFeatTypeModel();
                    FeatTypesSelected[FeatTypesSelected.Count - 1].Model.FeatId     = Model.Id;
                    FeatTypesSelected[FeatTypesSelected.Count - 1].Model.FeatTypeId = FeatTypeModel.GetIdFromName(FeatTypesCheckedListBox.Items[e.Index].ToString());
                    FeatTypesSelected[FeatTypesSelected.Count - 1].DeleteRecord     = false;
                    RecordChanged = true;
                }
                break;
            }
            }
        }