Beispiel #1
0
        public Solver.Criteria ShowDialog(Solver.Criteria criteria)
        {
            if (criteria == null)
            {
                Criteria_         = null;
                Text              = "Add Criteria";
                btnRevert.Enabled = false;
            }
            else
            {
                Criteria_         = criteria.DeepCopy();
                Text              = "Edit Criteria";
                btnRevert.Enabled = true;
            }

            LoadFromCriteria();

            DialogResult result = base.ShowDialog();

            if (result == DialogResult.OK)
            {
                return(Criteria_);
            }
            return(null);
        }
Beispiel #2
0
        private void ListBoxCriteriaDragDrop(object sender, DragEventArgs e)
        {
            if (!e.Data.GetDataPresent(typeof(Solver.Criteria)))
            {
                return;
            }

            var location = listBoxCriteria.PointToClient(new Point(e.X, e.Y));

            _dragTarget   = listBoxCriteria.IndexFromPoint(location);
            _dragCriteria = (Solver.Criteria)e.Data.GetData(typeof(Solver.Criteria));
        }
Beispiel #3
0
        private void ListBoxCriteriaMouseDown(object sender, MouseEventArgs e)
        {
            var index = listBoxCriteria.IndexFromPoint(e.Location);

            if (index == -1)
            {
                listBoxCriteria.SelectedIndex = -1;
                return;
            }

            if (e.Clicks == 2 && e.Button == MouseButtons.Left)
            {
                EditCriteria();
                return;
            }

            var criteria = (Solver.Criteria)listBoxCriteria.Items[index];

            _dragTarget   = -1;
            _dragCriteria = null;
            // drag drop failed
            if (listBoxCriteria.DoDragDrop(criteria, DragDropEffects.Move) != DragDropEffects.Move)
            {
                return;
            }
            // some sort of conflict
            if (_dragTarget == -1 || _dragCriteria != criteria)
            {
                return;
            }
            // moving back to same position
            if (_dragTarget == index)
            {
                return;
            }
            if (_dragTarget > index)
            {
                listBoxCriteria.Items.Insert(_dragTarget + 1, criteria);
                listBoxCriteria.Items.RemoveAt(index);
            }
            else
            {
                listBoxCriteria.Items.RemoveAt(index);
                listBoxCriteria.Items.Insert(_dragTarget, criteria);
            }
            listBoxCriteria.SelectedIndex = _dragTarget;

            // not preset anymore
            comboBoxPresets.SelectedIndex = -1;
        }
Beispiel #4
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (ddField.SelectedIndex == -1)
            {
                MessageBox.Show("Please select a criteria.", "Criteria Details", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
                ddField.Focus();
                return;
            }
            if (ddPreference.SelectedIndex == -1)
            {
                MessageBox.Show("Please select a preference.", "Criteria Details", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
                ddPreference.Focus();
                return;
            }

            Criteria_ = new Solver.Criteria(
                (Solver.FieldIndex)ddField.SelectedIndex,
                (Solver.Preference)ddPreference.SelectedIndex);

            DialogResult = DialogResult.OK;
            Close();
        }